-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConnectionModelTest.php
More file actions
202 lines (169 loc) · 4.22 KB
/
ConnectionModelTest.php
File metadata and controls
202 lines (169 loc) · 4.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
<?php
namespace SyncEngine\Tests\Model;
use SyncEngine\Model\ConnectionModel;
use SyncEngine\Tests\TestCase\BaseTestCase;
use SyncEngine\Webservice\HttpMultistep;
class ConnectionModelTest extends BaseTestCase
{
public function clearInternalConfig( $config )
{
unset( $config['_class'] );
unset( $config['_connect'] );
unset( $config['authorization'] );
unset( $config['authorize'] );
unset( $config['connection'] );
unset( $config['variables'] );
return $config;
}
public function getModel( $config )
{
$model = new ConnectionModel();
$model->setConfig( $config );
return $model;
}
public function testConnectionAuthorization(): void
{
$model = $this->getModel(
[
'webservice' => [
'_class' => HttpMultistep::_getClassLocator(),
'host' => 'https://localhost',
'_connect' => [
'request' => [
'query' => [
'connect' => 'Test Merge',
],
'method' => 'HEAD',
],
'endpoint' => 'Test Connect Override',
'response' => [],
],
'authorize' => [
'host' => 'https:127.0.0.1',
'request' => [
'headers' => [
'Authorization' => 'Test Authorization',
],
'format' => 'formdata',
],
'endpoint' => 'Test Authorize Override',
'response' => [
'format' => 'json',
],
],
],
]
);
//* Test connect config.
$expected = [
'host' => 'https:127.0.0.1',
'request' => [
'headers' => [
'Authorization' => 'Test Authorization',// From Authorize
],
'query' => [
'connect' => 'Test Merge',
],
'method' => 'HEAD',
'format' => 'formdata',// From Authorize
],
'endpoint' => 'Test Connect Override',
'response' => [
'format' => 'json',// From Authorize
],
];
$actual = $model->handleAuthorization( $model->getConfig('webservice._connect' ), null );
$actual = $this->clearInternalConfig( $actual );
$this->assertEquals( $expected, $actual );
//* Test task config.
$config = [
'endpoint' => 'foobar',
'request' => [
'headers' => [
'Foo' => 'Bar',
],
],
];
$expected = [
'host' => 'https:127.0.0.1',
'request' => [
'headers' => [
'Authorization' => 'Test Authorization',
'Foo' => 'Bar',
],
'format' => 'formdata',
],
'endpoint' => 'foobar',
'response' => [
'format' => 'json',
],
];
$actual = $model->handleAuthorization( $config, null );
$actual = $this->clearInternalConfig( $actual );
$this->assertEquals( $expected, $actual );
//* Test task overrides config.
$config = [
'host' => 'NOPE!', // Should not be possible.
'endpoint' => 'foobar',
'request' => [
'headers' => [
'Authorization' => 'Override Authorization',
'Foo' => 'Bar',
],
],
];
$expected = [
'host' => 'https:127.0.0.1',
'request' => [
'headers' => [
'Authorization' => 'Override Authorization',
'Foo' => 'Bar',
],
'format' => 'formdata',
],
'endpoint' => 'foobar',
'response' => [
'format' => 'json',
],
];
$actual = $model->handleAuthorization( $config, null );
$actual = $this->clearInternalConfig( $actual );
$this->assertEquals( $expected, $actual );
}
public function testConnectionAuthorizationTags(): void
{
$model = $this->getModel(
[
'webservice' => [
'_class' => HttpMultistep::_getClassLocator(),
'host' => 'https://localhost',
'variables' => [
'foo' => 'bar',
],
'authorize' => [
'host' => 'https://{{ variables.foo }}.com',
],
],
]
);
//* Test variables
$config = [];
$expected = [
'host' => 'https://bar.com',
];
$actual = $model->handleAuthorization( $config, null );
$actual = $this->clearInternalConfig( $actual );
$this->assertEquals( $expected, $actual );
//* Make sure tasks cannot use auth tags!
$config = [
'endpoint' => '{{ variables.foo }}',
];
$expected = [
'host' => 'https://bar.com',
'endpoint' => '{{ variables.foo }}', // Not supported!
];
$actual = $model->handleAuthorization( $config, null );
$actual = $this->clearInternalConfig( $actual );
$this->assertEquals( $expected, $actual );
}
}