18declare(strict_types=1);
20use PHPUnit\Framework\TestCase;
34 yield
'Host matches configured HTTP path (no `allowed_hosts` configuration)' => [
36 'HTTP_HOST' =>
'localhost',
37 'REQUEST_URI' =>
'/login.php',
39 'http_path' =>
'http://localhost',
40 'wsdl_path' =>
'https://localhost/soap/server.php?wsdl=1',
41 'allowed_hosts' =>
'',
44 yield
'Host matches configured WSDL path (no `allowed_hosts` configuration)' => [
46 'HTTP_HOST' =>
'soap.ilias.de',
47 'REQUEST_URI' =>
'/login.php',
49 'http_path' =>
'https://test.ilias.de',
50 'wsdl_path' =>
'https://soap.ilias.de/soap/server.php?wsdl=1',
51 'allowed_hosts' =>
'',
54 yield
'Localhost is always allowed (no `allowed_hosts` configuration)' => [
56 'HTTP_HOST' =>
'localhost',
57 'REQUEST_URI' =>
'/login.php',
59 'http_path' =>
'https://test.ilias.de',
60 'wsdl_path' =>
'https://test.ilias.de/soap/server.php?wsdl=1',
61 'allowed_hosts' =>
'',
64 yield
'Host is in `allowed_hosts` list' => [
66 'HTTP_HOST' =>
'test2.ilias.de',
67 'REQUEST_URI' =>
'/login.php',
69 'http_path' =>
'https://test.ilias.de',
70 'wsdl_path' =>
'https://test.ilias.de/soap/server.php?wsdl=1',
71 'allowed_hosts' =>
'test2.ilias.de',
78 #[\PHPUnit\Framework\Attributes\DataProvider('environmentProvider')]
80 array|ArrayAccess $server_data,
85 $path_builder = new \
ILIAS\Init\Environment\HttpPathBuilder(
86 new \
ILIAS\Data\Factory(),
93 $this->assertNotEmpty((
string) $path_builder->build());
98 $this->expectException(RuntimeException::class);
100 $path_builder = new \ILIAS\Init\Environment\HttpPathBuilder(
101 new \
ILIAS\Data\Factory(),
102 $this->getSettingsMock(
'https://test.ilias.de/soap/server.php?wsdl=1',
'test.ilias.de'),
103 $this->getHttpsMock(),
104 $this->getIniMock(
'https://test.ilias.de'),
106 'HTTP_HOST' =>
'phishing.ilias.de',
107 'REQUEST_URI' =>
'/login.php',
111 $path_builder->build();
116 string $allowed_hosts
117 ):
ilSetting&\PHPUnit\Framework\MockObject\MockObject {
120 ->disableOriginalConstructor()
121 ->onlyMethods([
'get'])
123 $settings->method(
'get')->willReturnCallback(
124 static fn(
string $key, ?
string $default =
null): ?
string => match ($key) {
125 'soap_wsdl_path' => $wsdl_path,
126 'allowed_hosts' => $allowed_hosts,
134 private function getHttpsMock(): ilHttps&\PHPUnit\Framework\MockObject\MockObject
137 ->getMockBuilder(ilHTTPS::class)
138 ->disableOriginalConstructor()
139 ->onlyMethods([
'isDetected'])
141 $https->method(
'isDetected')->willReturn(
true);
149 ->getMockBuilder(ilIniFile::class)
150 ->disableOriginalConstructor()
151 ->onlyMethods([
'readVariable'])
153 $ini->method(
'readVariable')->willReturnCallback(
154 static fn(
string $group,
string $variable):
string => match ($variable) {
155 'http_path' => $http_path,
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)
INIFile Parser Early access in init proceess! Avoid further dependencies like logging or other servic...
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.