|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* File containing the eZ\Publish\Core\MVC\Symfony\SiteAccess\Tests\RouterHostPortURITest class. |
|
5
|
|
|
* |
|
6
|
|
|
* @copyright Copyright (C) eZ Systems AS. All rights reserved. |
|
7
|
|
|
* @license For full copyright and license information view LICENSE file distributed with this source code. |
|
8
|
|
|
*/ |
|
9
|
|
|
namespace eZ\Publish\Core\MVC\Symfony\SiteAccess\Tests; |
|
10
|
|
|
|
|
11
|
|
|
use eZ\Publish\Core\MVC\Symfony\SiteAccess\Matcher\Map\Host; |
|
12
|
|
|
use eZ\Publish\Core\MVC\Symfony\SiteAccess\Matcher\Map\Port; |
|
13
|
|
|
use eZ\Publish\Core\MVC\Symfony\SiteAccess\Router; |
|
14
|
|
|
use eZ\Publish\Core\MVC\Symfony\Routing\SimplifiedRequest; |
|
15
|
|
|
use Psr\Log\LoggerInterface; |
|
16
|
|
|
|
|
17
|
|
|
class RouterHostPortURITest extends RouterBaseTest |
|
18
|
|
|
{ |
|
19
|
|
View Code Duplication |
public function matchProvider(): array |
|
20
|
|
|
{ |
|
21
|
|
|
return [ |
|
22
|
|
|
[SimplifiedRequest::fromUrl('http://example.com'), 'fifth_sa'], |
|
23
|
|
|
[SimplifiedRequest::fromUrl('https://example.com'), 'fourth_sa'], |
|
24
|
|
|
[SimplifiedRequest::fromUrl('http://example.com/'), 'fifth_sa'], |
|
25
|
|
|
[SimplifiedRequest::fromUrl('https://example.com/'), 'fourth_sa'], |
|
26
|
|
|
[SimplifiedRequest::fromUrl('http://example.com//'), 'fifth_sa'], |
|
27
|
|
|
[SimplifiedRequest::fromUrl('https://example.com//'), 'fourth_sa'], |
|
28
|
|
|
[SimplifiedRequest::fromUrl('http://example.com:8080/'), 'default_sa'], |
|
29
|
|
|
[SimplifiedRequest::fromUrl('http://example.com/first_siteaccess/'), 'fifth_sa'], |
|
30
|
|
|
[SimplifiedRequest::fromUrl('http://example.com/?first_siteaccess'), 'fifth_sa'], |
|
31
|
|
|
[SimplifiedRequest::fromUrl('http://example.com/?first_sa'), 'fifth_sa'], |
|
32
|
|
|
[SimplifiedRequest::fromUrl('http://example.com/first_salt'), 'fifth_sa'], |
|
33
|
|
|
[SimplifiedRequest::fromUrl('http://example.com/first_sa.foo'), 'fifth_sa'], |
|
34
|
|
|
[SimplifiedRequest::fromUrl('http://example.com/test'), 'fifth_sa'], |
|
35
|
|
|
[SimplifiedRequest::fromUrl('http://example.com/test/foo/'), 'fifth_sa'], |
|
36
|
|
|
[SimplifiedRequest::fromUrl('http://example.com/test/foo/bar/'), 'fifth_sa'], |
|
37
|
|
|
[SimplifiedRequest::fromUrl('http://example.com/test/foo/bar/first_sa'), 'fifth_sa'], |
|
38
|
|
|
[SimplifiedRequest::fromUrl('http://example.com/default_sa'), 'fifth_sa'], |
|
39
|
|
|
|
|
40
|
|
|
[SimplifiedRequest::fromUrl('http://example.com/first_sa'), 'fifth_sa'], |
|
41
|
|
|
[SimplifiedRequest::fromUrl('http://example.com/first_sa/'), 'fifth_sa'], |
|
42
|
|
|
[SimplifiedRequest::fromUrl('http://example.com/first_sa//'), 'fifth_sa'], |
|
43
|
|
|
[SimplifiedRequest::fromUrl('http://example.com/first_sa///test'), 'fifth_sa'], |
|
44
|
|
|
[SimplifiedRequest::fromUrl('http://example.com/first_sa/foo'), 'fifth_sa'], |
|
45
|
|
|
[SimplifiedRequest::fromUrl('http://example.com/first_sa/foo/bar'), 'fifth_sa'], |
|
46
|
|
|
[SimplifiedRequest::fromUrl('http://example.com:82/first_sa/'), 'fourth_sa'], |
|
47
|
|
|
[SimplifiedRequest::fromUrl('http://third_siteaccess/first_sa/'), 'third_sa'], |
|
48
|
|
|
[SimplifiedRequest::fromUrl('http://first_sa/'), 'first_sa'], |
|
49
|
|
|
[SimplifiedRequest::fromUrl('https://first_sa/'), 'first_sa'], |
|
50
|
|
|
[SimplifiedRequest::fromUrl('http://first_sa:81/'), 'first_sa'], |
|
51
|
|
|
[SimplifiedRequest::fromUrl('http://first_siteaccess/'), 'first_sa'], |
|
52
|
|
|
[SimplifiedRequest::fromUrl('http://first_siteaccess:82/'), 'first_sa'], |
|
53
|
|
|
[SimplifiedRequest::fromUrl('http://first_siteaccess:83/'), 'first_sa'], |
|
54
|
|
|
[SimplifiedRequest::fromUrl('http://first_siteaccess/foo/'), 'first_sa'], |
|
55
|
|
|
[SimplifiedRequest::fromUrl('http://first_siteaccess:82/foo/'), 'first_sa'], |
|
56
|
|
|
[SimplifiedRequest::fromUrl('http://first_siteaccess:83/foo/'), 'first_sa'], |
|
57
|
|
|
|
|
58
|
|
|
[SimplifiedRequest::fromUrl('http://example.com/second_sa'), 'fifth_sa'], |
|
59
|
|
|
[SimplifiedRequest::fromUrl('http://example.com/second_sa/'), 'fifth_sa'], |
|
60
|
|
|
[SimplifiedRequest::fromUrl('http://example.com/second_sa?param1=foo'), 'fifth_sa'], |
|
61
|
|
|
[SimplifiedRequest::fromUrl('http://example.com/second_sa/foo/'), 'fifth_sa'], |
|
62
|
|
|
[SimplifiedRequest::fromUrl('http://example.com:82/second_sa/'), 'fourth_sa'], |
|
63
|
|
|
[SimplifiedRequest::fromUrl('http://example.com:83/second_sa/'), 'first_sa'], |
|
64
|
|
|
[SimplifiedRequest::fromUrl('http://first_siteaccess:82/second_sa/'), 'first_sa'], |
|
65
|
|
|
[SimplifiedRequest::fromUrl('http://first_siteaccess:83/second_sa/'), 'first_sa'], |
|
66
|
|
|
|
|
67
|
|
|
[SimplifiedRequest::fromUrl('http://first_sa:123/second_sa'), 'first_sa'], |
|
68
|
|
|
[SimplifiedRequest::fromUrl('http://first_siteaccess:123/second_sa/'), 'first_sa'], |
|
69
|
|
|
[SimplifiedRequest::fromUrl('http://example.com:123/second_sa?param1=foo'), 'second_sa'], |
|
70
|
|
|
[SimplifiedRequest::fromUrl('http://example.com:123/second_sa/foo/'), 'second_sa'], |
|
71
|
|
|
[SimplifiedRequest::fromUrl('http://example.com:123/second_sa'), 'second_sa'], |
|
72
|
|
|
[SimplifiedRequest::fromUrl('http://example.com:123/second_sa/'), 'second_sa'], |
|
73
|
|
|
[SimplifiedRequest::fromUrl('http://example.com:123/second_sa?param1=foo'), 'second_sa'], |
|
74
|
|
|
[SimplifiedRequest::fromUrl('http://example.com:123/second_sa/foo/'), 'second_sa'], |
|
75
|
|
|
|
|
76
|
|
|
[SimplifiedRequest::fromUrl('http://example.com:81/'), 'third_sa'], |
|
77
|
|
|
[SimplifiedRequest::fromUrl('https://example.com:81/'), 'third_sa'], |
|
78
|
|
|
[SimplifiedRequest::fromUrl('http://example.com:81/foo'), 'third_sa'], |
|
79
|
|
|
[SimplifiedRequest::fromUrl('http://example.com:81/foo/bar'), 'third_sa'], |
|
80
|
|
|
|
|
81
|
|
|
[SimplifiedRequest::fromUrl('http://example.com:82/'), 'fourth_sa'], |
|
82
|
|
|
[SimplifiedRequest::fromUrl('https://example.com:82/'), 'fourth_sa'], |
|
83
|
|
|
[SimplifiedRequest::fromUrl('https://example.com:82/foo'), 'fourth_sa'], |
|
84
|
|
|
]; |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
View Code Duplication |
public function testSetGetRequestMapHost() |
|
88
|
|
|
{ |
|
89
|
|
|
$mapKey = 'phoenix-rises.fm'; |
|
90
|
|
|
$request = new SimplifiedRequest(['host' => $mapKey]); |
|
91
|
|
|
$matcher = new Host(['foo' => $mapKey]); |
|
92
|
|
|
$matcher->setRequest($request); |
|
93
|
|
|
$this->assertSame($request, $matcher->getRequest()); |
|
94
|
|
|
$this->assertSame($mapKey, $matcher->getMapKey()); |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
public function testReverseHostMatchFail() |
|
98
|
|
|
{ |
|
99
|
|
|
$config = ['foo' => 'bar']; |
|
100
|
|
|
$matcher = new Host($config); |
|
101
|
|
|
$this->assertNull($matcher->reverseMatch('non_existent')); |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
View Code Duplication |
public function testReverseMatchHost() |
|
105
|
|
|
{ |
|
106
|
|
|
$config = [ |
|
107
|
|
|
'ez.no' => 'some_siteaccess', |
|
108
|
|
|
'something_else' => 'another_siteaccess', |
|
109
|
|
|
'phoenix-rises.fm' => 'ezdemo_site', |
|
110
|
|
|
]; |
|
111
|
|
|
$request = new SimplifiedRequest(['host' => 'ez.no']); |
|
112
|
|
|
$matcher = new Host($config); |
|
113
|
|
|
$matcher->setRequest($request); |
|
114
|
|
|
$this->assertSame('ez.no', $matcher->getMapKey()); |
|
115
|
|
|
|
|
116
|
|
|
$result = $matcher->reverseMatch('ezdemo_site'); |
|
117
|
|
|
$this->assertInstanceOf(Host::class, $result); |
|
118
|
|
|
$this->assertSame($request, $matcher->getRequest()); |
|
119
|
|
|
$this->assertSame('phoenix-rises.fm', $result->getMapKey()); |
|
120
|
|
|
$this->assertSame('phoenix-rises.fm', $result->getRequest()->host); |
|
121
|
|
|
} |
|
122
|
|
|
|
|
123
|
|
View Code Duplication |
public function testSetGetRequestMapPort() |
|
124
|
|
|
{ |
|
125
|
|
|
$mapKey = '8000'; |
|
126
|
|
|
$request = new SimplifiedRequest(['port' => $mapKey]); |
|
127
|
|
|
$matcher = new Port(['foo' => $mapKey]); |
|
128
|
|
|
$matcher->setRequest($request); |
|
129
|
|
|
$this->assertSame($request, $matcher->getRequest()); |
|
130
|
|
|
$this->assertSame($mapKey, $matcher->getMapKey()); |
|
131
|
|
|
} |
|
132
|
|
|
|
|
133
|
|
|
public function testReversePortMatchFail() |
|
134
|
|
|
{ |
|
135
|
|
|
$config = ['foo' => '8080']; |
|
136
|
|
|
$matcher = new Port($config); |
|
137
|
|
|
$this->assertNull($matcher->reverseMatch('non_existent')); |
|
138
|
|
|
} |
|
139
|
|
|
|
|
140
|
|
|
public function testReverseMatchPort() |
|
141
|
|
|
{ |
|
142
|
|
|
$config = [ |
|
143
|
|
|
'80' => 'some_siteaccess', |
|
144
|
|
|
'443' => 'another_siteaccess', |
|
145
|
|
|
8000 => 'ezdemo_site', |
|
146
|
|
|
]; |
|
147
|
|
|
$request = new SimplifiedRequest(['scheme' => 'http', 'host' => 'ez.no']); |
|
148
|
|
|
$matcher = new Port($config); |
|
149
|
|
|
$matcher->setRequest($request); |
|
150
|
|
|
$this->assertSame(80, $matcher->getMapKey()); |
|
151
|
|
|
|
|
152
|
|
|
$result = $matcher->reverseMatch('ezdemo_site'); |
|
153
|
|
|
$this->assertInstanceOf(Port::class, $result); |
|
154
|
|
|
$this->assertSame($request, $matcher->getRequest()); |
|
155
|
|
|
$this->assertSame(8000, $result->getMapKey()); |
|
156
|
|
|
$this->assertSame(8000, $result->getRequest()->port); |
|
157
|
|
|
$this->assertSame('http', $result->getRequest()->scheme); |
|
158
|
|
|
} |
|
159
|
|
|
|
|
160
|
|
View Code Duplication |
protected function createRouter(): Router |
|
161
|
|
|
{ |
|
162
|
|
|
return new Router( |
|
163
|
|
|
$this->matcherBuilder, |
|
164
|
|
|
$this->createMock(LoggerInterface::class), |
|
165
|
|
|
'default_sa', |
|
166
|
|
|
[ |
|
167
|
|
|
'Map\\Host' => [ |
|
168
|
|
|
'first_sa' => 'first_sa', |
|
169
|
|
|
'first_siteaccess' => 'first_sa', |
|
170
|
|
|
'third_siteaccess' => 'third_sa', |
|
171
|
|
|
], |
|
172
|
|
|
'Map\\Port' => [ |
|
173
|
|
|
80 => 'fifth_sa', |
|
174
|
|
|
81 => 'third_sa', |
|
175
|
|
|
82 => 'fourth_sa', |
|
176
|
|
|
83 => 'first_sa', |
|
177
|
|
|
85 => 'first_sa', |
|
178
|
|
|
443 => 'fourth_sa', |
|
179
|
|
|
], |
|
180
|
|
|
'Map\\URI' => [ |
|
181
|
|
|
'first_sa' => 'first_sa', |
|
182
|
|
|
'second_sa' => 'second_sa', |
|
183
|
|
|
], |
|
184
|
|
|
], |
|
185
|
|
|
$this->siteAccessProvider |
|
186
|
|
|
); |
|
187
|
|
|
} |
|
188
|
|
|
|
|
189
|
|
|
/** |
|
190
|
|
|
* @return \eZ\Publish\Core\MVC\Symfony\SiteAccess\Tests\SiteAccessSetting[] |
|
191
|
|
|
*/ |
|
192
|
|
View Code Duplication |
public function getSiteAccessProviderSettings(): array |
|
193
|
|
|
{ |
|
194
|
|
|
return [ |
|
195
|
|
|
new SiteAccessSetting('first_sa', true), |
|
196
|
|
|
new SiteAccessSetting('second_sa', true), |
|
197
|
|
|
new SiteAccessSetting('third_sa', true), |
|
198
|
|
|
new SiteAccessSetting('fourth_sa', true), |
|
199
|
|
|
new SiteAccessSetting('fifth_sa', true), |
|
200
|
|
|
]; |
|
201
|
|
|
} |
|
202
|
|
|
} |
|
203
|
|
|
|