19declare(strict_types=1);
21use PHPUnit\Framework\TestCase;
35 yield
'Host matches configured HTTP path (no `allowed_hosts` configuration)' => [
37 'HTTP_HOST' =>
'localhost',
38 'REQUEST_URI' =>
'/login.php',
40 'http_path' =>
'http://localhost',
41 'wsdl_path' =>
'https://localhost/soap/server.php?wsdl=1',
42 'allowed_hosts' =>
'',
45 yield
'Host matches configured WSDL path (no `allowed_hosts` configuration)' => [
47 'HTTP_HOST' =>
'soap.ilias.de',
48 'REQUEST_URI' =>
'/login.php',
50 'http_path' =>
'https://test.ilias.de',
51 'wsdl_path' =>
'https://soap.ilias.de/soap/server.php?wsdl=1',
52 'allowed_hosts' =>
'',
55 yield
'Localhost is always allowed (no `allowed_hosts` configuration)' => [
57 'HTTP_HOST' =>
'localhost',
58 'REQUEST_URI' =>
'/login.php',
60 'http_path' =>
'https://test.ilias.de',
61 'wsdl_path' =>
'https://test.ilias.de/soap/server.php?wsdl=1',
62 'allowed_hosts' =>
'',
65 yield
'Host is in `allowed_hosts` list' => [
67 'HTTP_HOST' =>
'test2.ilias.de',
68 'REQUEST_URI' =>
'/login.php',
70 'http_path' =>
'https://test.ilias.de',
71 'wsdl_path' =>
'https://test.ilias.de/soap/server.php?wsdl=1',
72 'allowed_hosts' =>
'test2.ilias.de',
79 #[\PHPUnit\Framework\Attributes\DataProvider('environmentProvider')]
81 array|ArrayAccess $server_data,
86 $path_builder = new \
ILIAS\Init\Environment\HttpPathBuilder(
87 new \
ILIAS\Data\Factory(),
94 $this->assertNotEmpty((
string) $path_builder->build());
99 $this->expectException(RuntimeException::class);
101 $path_builder = new \ILIAS\Init\Environment\HttpPathBuilder(
102 new \
ILIAS\Data\Factory(),
103 $this->getSettingsMock(
'https://test.ilias.de/soap/server.php?wsdl=1',
'test.ilias.de'),
104 $this->getHttpsMock(),
105 $this->getIniMock(
'https://test.ilias.de'),
107 'HTTP_HOST' =>
'phishing.ilias.de',
108 'REQUEST_URI' =>
'/login.php',
112 $path_builder->build();
117 $this->expectException(RuntimeException::class);
118 $this->expectExceptionMessage(
'reserved for asset delivery');
120 $path_builder = new \ILIAS\Init\Environment\HttpPathBuilder(
121 new \
ILIAS\Data\Factory(),
123 $this->getSettingsMock(
'https://app.ilias.de/soap/server.php?wsdl=1',
'content.ilias.de'),
124 $this->getHttpsMock(),
125 $this->getIniMock(
'https://app.ilias.de'),
127 'HTTP_HOST' =>
'content.ilias.de',
128 'REQUEST_URI' =>
'/login.php',
132 \
ILIAS\
FileDelivery\Isolation\IsolationConfig::KEY_CONTENT_DOMAIN =>
'https://content.ilias.de',
133 \
ILIAS\
FileDelivery\Isolation\IsolationConfig::KEY_ILIAS_DOMAIN =>
'https://app.ilias.de',
137 $path_builder->build();
142 $path_builder = new \ILIAS\Init\Environment\HttpPathBuilder(
143 new \
ILIAS\Data\Factory(),
144 $this->getSettingsMock(
'https://app.ilias.de/soap/server.php?wsdl=1',
''),
145 $this->getHttpsMock(),
146 $this->getIniMock(
'https://app.ilias.de'),
148 'HTTP_HOST' =>
'app.ilias.de',
149 'REQUEST_URI' =>
'/login.php',
153 \
ILIAS\
FileDelivery\Isolation\IsolationConfig::KEY_CONTENT_DOMAIN =>
'https://content.ilias.de',
154 \
ILIAS\
FileDelivery\Isolation\IsolationConfig::KEY_ILIAS_DOMAIN =>
'https://app.ilias.de',
158 $this->assertSame(
'app.ilias.de', $path_builder->build()->getHost());
165 $path_builder = new \ILIAS\Init\Environment\HttpPathBuilder(
166 new \
ILIAS\Data\Factory(),
167 $this->getSettingsMock(
'https://app.ilias.de/soap/server.php?wsdl=1',
'content.ilias.de'),
168 $this->getHttpsMock(),
169 $this->getIniMock(
'https://app.ilias.de'),
171 'HTTP_HOST' =>
'content.ilias.de',
172 'REQUEST_URI' =>
'/login.php',
177 $this->assertSame(
'content.ilias.de', $path_builder->build()->getHost());
182 string $allowed_hosts
183 ):
ilSetting&\PHPUnit\Framework\MockObject\MockObject {
186 ->disableOriginalConstructor()
187 ->onlyMethods([
'get'])
189 $settings->method(
'get')->willReturnCallback(
190 static fn(
string $key, ?
string $default =
null): ?
string => match ($key) {
191 'soap_wsdl_path' => $wsdl_path,
192 'allowed_hosts' => $allowed_hosts,
200 private function getHttpsMock(): ilHttps&\PHPUnit\Framework\MockObject\MockObject
203 ->getMockBuilder(ilHTTPS::class)
204 ->disableOriginalConstructor()
205 ->onlyMethods([
'isDetected'])
207 $https->method(
'isDetected')->willReturn(
true);
215 ->getMockBuilder(ilIniFile::class)
216 ->disableOriginalConstructor()
217 ->onlyMethods([
'readVariable'])
219 $ini->method(
'readVariable')->willReturnCallback(
220 static fn(
string $group,
string $variable):
string => match ($variable) {
221 'http_path' => $http_path,
testContentDomainNotRejectedWhenIsolationInactive()
testApplicationHostStillAllowedWhenIsolationActive()
getIniMock(string $http_path)
getSettingsMock(string $wsdl_path, string $allowed_hosts)
static environmentProvider()
testUnknownHostWillRaiseException()
testValidHostsTriggerNoExceptions(array|ArrayAccess $server_data, string $http_path, string $wsdl_path, string $allowed_hosts)
testContentDomainIsRejectedAsApplicationHostWhenIsolationActive()
INI file parser — compatibility wrapper.
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.