ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
HttpPathBuilderTest Class Reference
+ Inheritance diagram for HttpPathBuilderTest:
+ Collaboration diagram for HttpPathBuilderTest:

Public Member Functions

 testValidHostsTriggerNoExceptions (array|ArrayAccess $server_data, string $http_path, string $wsdl_path, string $allowed_hosts)
 
 testUnknownHostWillRaiseException ()
 

Static Public Member Functions

static environmentProvider ()
 

Private Member Functions

 getSettingsMock (string $wsdl_path, string $allowed_hosts)
 
 getHttpsMock ()
 
 getIniMock (string $http_path)
 

Detailed Description

Definition at line 22 of file HttpPathBuilderTest.php.

Member Function Documentation

◆ environmentProvider()

static HttpPathBuilderTest::environmentProvider ( )
static
Returns
Generator<string, array{ server_data: array<string, mixed>|ArrayAccess<string, mixed>, http_path: string, wsdl_path: string, allowed_hosts: string }>

Definition at line 32 of file HttpPathBuilderTest.php.

32 : Generator
33 {
34 yield 'Host matches configured HTTP path (no `allowed_hosts` configuration)' => [
35 'server_data' => [
36 'HTTP_HOST' => 'localhost',
37 'REQUEST_URI' => '/login.php',
38 ],
39 'http_path' => 'http://localhost',
40 'wsdl_path' => 'https://localhost/soap/server.php?wsdl=1',
41 'allowed_hosts' => '',
42 ];
43
44 yield 'Host matches configured WSDL path (no `allowed_hosts` configuration)' => [
45 'server_data' => [
46 'HTTP_HOST' => 'soap.ilias.de',
47 'REQUEST_URI' => '/login.php',
48 ],
49 'http_path' => 'https://test.ilias.de',
50 'wsdl_path' => 'https://soap.ilias.de/soap/server.php?wsdl=1',
51 'allowed_hosts' => '',
52 ];
53
54 yield 'Localhost is always allowed (no `allowed_hosts` configuration)' => [
55 'server_data' => [
56 'HTTP_HOST' => 'localhost',
57 'REQUEST_URI' => '/login.php',
58 ],
59 'http_path' => 'https://test.ilias.de',
60 'wsdl_path' => 'https://test.ilias.de/soap/server.php?wsdl=1',
61 'allowed_hosts' => '',
62 ];
63
64 yield 'Host is in `allowed_hosts` list' => [
65 'server_data' => [
66 'HTTP_HOST' => 'test2.ilias.de',
67 'REQUEST_URI' => '/login.php',
68 ],
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',
72 ];
73 }

◆ getHttpsMock()

HttpPathBuilderTest::getHttpsMock ( )
private

Definition at line 134 of file HttpPathBuilderTest.php.

134 : ilHttps&\PHPUnit\Framework\MockObject\MockObject
135 {
136 $https = $this
137 ->getMockBuilder(ilHTTPS::class)
138 ->disableOriginalConstructor()
139 ->onlyMethods(['isDetected'])
140 ->getMock();
141 $https->method('isDetected')->willReturn(true);
142
143 return $https;
144 }

◆ getIniMock()

HttpPathBuilderTest::getIniMock ( string  $http_path)
private

Definition at line 146 of file HttpPathBuilderTest.php.

146 : ilIniFile&\PHPUnit\Framework\MockObject\MockObject
147 {
148 $ini = $this
149 ->getMockBuilder(ilIniFile::class)
150 ->disableOriginalConstructor()
151 ->onlyMethods(['readVariable'])
152 ->getMock();
153 $ini->method('readVariable')->willReturnCallback(
154 static fn(string $group, string $variable): string => match ($variable) {
155 'http_path' => $http_path,
156 default => ''
157 }
158 );
159
160 return $ini;
161 }
INIFile Parser Early access in init proceess! Avoid further dependencies like logging or other servic...
$ini
Definition: raiseError.php:20

References $ini.

◆ getSettingsMock()

HttpPathBuilderTest::getSettingsMock ( string  $wsdl_path,
string  $allowed_hosts 
)
private

Definition at line 114 of file HttpPathBuilderTest.php.

117 : ilSetting&\PHPUnit\Framework\MockObject\MockObject {
118 $settings = $this
119 ->getMockBuilder(ilSetting::class)
120 ->disableOriginalConstructor()
121 ->onlyMethods(['get'])
122 ->getMock();
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,
127 default => $default
128 }
129 );
130
131 return $settings;
132 }
ILIAS Setting Class.

◆ testUnknownHostWillRaiseException()

HttpPathBuilderTest::testUnknownHostWillRaiseException ( )

Definition at line 96 of file HttpPathBuilderTest.php.

96 : void
97 {
98 $this->expectException(RuntimeException::class);
99
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'),
105 [
106 'HTTP_HOST' => 'phishing.ilias.de',
107 'REQUEST_URI' => '/login.php',
108 ]
109 );
110
111 $path_builder->build();
112 }
getIniMock(string $http_path)
getSettingsMock(string $wsdl_path, string $allowed_hosts)
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.

◆ testValidHostsTriggerNoExceptions()

HttpPathBuilderTest::testValidHostsTriggerNoExceptions ( array|ArrayAccess  $server_data,
string  $http_path,
string  $wsdl_path,
string  $allowed_hosts 
)
Parameters
array<string,mixed>|ArrayAccess<string,mixed>$server_data

Definition at line 79 of file HttpPathBuilderTest.php.

84 : void {
85 $path_builder = new \ILIAS\Init\Environment\HttpPathBuilder(
86 new \ILIAS\Data\Factory(),
87 $this->getSettingsMock($wsdl_path, $allowed_hosts),
88 $this->getHttpsMock(),
89 $this->getIniMock($http_path),
90 $server_data
91 );
92
93 $this->assertNotEmpty((string) $path_builder->build());
94 }

The documentation for this class was generated from the following file: