ILIAS  trunk Revision v13.0_alpha-62-g3b72d83f2e5
ILIAS\Tests\FileDelivery\Isolation\IsolationConfigTest Class Reference
+ Inheritance diagram for ILIAS\Tests\FileDelivery\Isolation\IsolationConfigTest:
+ Collaboration diagram for ILIAS\Tests\FileDelivery\Isolation\IsolationConfigTest:

Public Member Functions

 testDisabledFactory ()
 
 testFromEmptyArrayIsDisabled ()
 
 testFromArrayWithFullSpecExample ()
 
 testBareHostnamesGetHttpsScheme ()
 
 testTrailingSlashIsStripped ()
 
 testActivatedWithoutContentDomainIsForcedOff ()
 
 testActivatedWithoutIliasDomainStaysActiveWithNullIliasDomain ()
 
 testInactiveStillParsesDomains ()
 
 testUnusableDomainsNormalizeToNull (mixed $value)
 
 testToArrayUsesSpecKeys ()
 
 testFromArrayToArrayRoundtripIsStable ()
 
 testValidValuesNormalizeToBareOrigin (string $input, string $expected_domain, string $expected_host)
 
 testNonBareOriginsAreRejected (string $input)
 
 testOriginFromUrlReducesTrustedAppUrlToBareOrigin (?string $input, ?string $expected)
 
 testFromArtefactWithoutFileIsDisabled ()
 
 testFromArtefactReadsTheStoredSettings ()
 
 testFromArtefactWithNonArrayContentIsDisabled ()
 
 testFromArtefactWithoutReturnValueIsDisabled ()
 

Static Public Member Functions

static unusableDomainProvider ()
 
static originNormalizationProvider ()
 
static rejectedOriginProvider ()
 
static trustedOriginProvider ()
 

Protected Member Functions

 tearDown ()
 

Private Member Functions

 artefact (string $php)
 

Private Attributes

array $artefacts = []
 

Detailed Description

Author
Fabian Schmid fabia.nosp@m.n@sr.nosp@m..solu.nosp@m.tion.nosp@m.s

Definition at line 30 of file IsolationConfigTest.php.

Member Function Documentation

◆ artefact()

ILIAS\Tests\FileDelivery\Isolation\IsolationConfigTest::artefact ( string  $php)
private

Definition at line 260 of file IsolationConfigTest.php.

260 : string
261 {
262 $path = (string) tempnam(sys_get_temp_dir(), 'iso_artefact_') . '.php';
263 file_put_contents($path, $php);
264 $this->artefacts[] = $path;
265 return $path;
266 }

◆ originNormalizationProvider()

static ILIAS\Tests\FileDelivery\Isolation\IsolationConfigTest::originNormalizationProvider ( )
static

Definition at line 205 of file IsolationConfigTest.php.

205 : \Iterator
206 {
207 yield 'bare host gets https' => ['content.example.org', 'https://content.example.org', 'content.example.org'];
208 yield 'https kept' => ['https://content.example.org', 'https://content.example.org', 'content.example.org'];
209 yield 'http kept' => ['http://localhost', 'http://localhost', 'localhost'];
210 yield 'port preserved' => ['https://content.example.org:8443', 'https://content.example.org:8443', 'content.example.org'];
211 yield 'host lowercased' => ['https://Content.Example.ORG', 'https://content.example.org', 'content.example.org'];
212 yield 'root slash stripped' => ['https://content.example.org/', 'https://content.example.org', 'content.example.org'];
213 }

◆ rejectedOriginProvider()

static ILIAS\Tests\FileDelivery\Isolation\IsolationConfigTest::rejectedOriginProvider ( )
static

Definition at line 228 of file IsolationConfigTest.php.

228 : \Iterator
229 {
230 yield 'with path' => ['https://content.example.org/foo'];
231 yield 'with userinfo' => ['https://user:pass@content.example.org'];
232 yield 'with query' => ['https://content.example.org/?a=b'];
233 yield 'with fragment' => ['https://content.example.org/#x'];
234 yield 'ftp scheme' => ['ftp://content.example.org'];
235 yield 'file scheme' => ['file:///etc/passwd'];
236 yield 'javascript scheme' => ['javascript:alert(1)'];
237 }

◆ tearDown()

ILIAS\Tests\FileDelivery\Isolation\IsolationConfigTest::tearDown ( )
protected

Definition at line 268 of file IsolationConfigTest.php.

268 : void
269 {
270 foreach ($this->artefacts as $path) {
271 if (is_file($path)) {
272 unlink($path);
273 }
274 }
275 $this->artefacts = [];
276 }

◆ testActivatedWithoutContentDomainIsForcedOff()

ILIAS\Tests\FileDelivery\Isolation\IsolationConfigTest::testActivatedWithoutContentDomainIsForcedOff ( )

◆ testActivatedWithoutIliasDomainStaysActiveWithNullIliasDomain()

ILIAS\Tests\FileDelivery\Isolation\IsolationConfigTest::testActivatedWithoutIliasDomainStaysActiveWithNullIliasDomain ( )

Definition at line 107 of file IsolationConfigTest.php.

107 : void
108 {
109 // The ILIAS domain is optional in the artefact: when http_path could not
110 // be resolved at build time it is simply null (the CORS allow-origin
111 // header is then omitted), isolation stays on.
114 IsolationConfig::KEY_CONTENT_DOMAIN => 'https://content.example.org',
115 ]);
116
117 $this->assertTrue($config->isActivated());
118 $this->assertSame('https://content.example.org', $config->getContentDomain());
119 $this->assertNull($config->getIliasDomain());
120 }

References ILIAS\FileDelivery\Isolation\IsolationConfig\fromArray(), ILIAS\FileDelivery\Isolation\IsolationConfig\KEY_ACTIVATED, and ILIAS\FileDelivery\Isolation\IsolationConfig\KEY_CONTENT_DOMAIN.

+ Here is the call graph for this function:

◆ testBareHostnamesGetHttpsScheme()

ILIAS\Tests\FileDelivery\Isolation\IsolationConfigTest::testBareHostnamesGetHttpsScheme ( )

Definition at line 71 of file IsolationConfigTest.php.

71 : void
72 {
75 IsolationConfig::KEY_CONTENT_DOMAIN => 'content.example.org',
76 IsolationConfig::KEY_ILIAS_DOMAIN => 'app.example.org',
77 ]);
78
79 $this->assertSame('https://content.example.org', $config->getContentDomain());
80 $this->assertSame('https://app.example.org', $config->getIliasDomain());
81 $this->assertSame('content.example.org', $config->getContentHost());
82 $this->assertSame('app.example.org', $config->getIliasHost());
83 }

References ILIAS\FileDelivery\Isolation\IsolationConfig\fromArray(), ILIAS\FileDelivery\Isolation\IsolationConfig\KEY_ACTIVATED, ILIAS\FileDelivery\Isolation\IsolationConfig\KEY_CONTENT_DOMAIN, and ILIAS\FileDelivery\Isolation\IsolationConfig\KEY_ILIAS_DOMAIN.

+ Here is the call graph for this function:

◆ testDisabledFactory()

ILIAS\Tests\FileDelivery\Isolation\IsolationConfigTest::testDisabledFactory ( )

Definition at line 35 of file IsolationConfigTest.php.

35 : void
36 {
37 $config = IsolationConfig::disabled();
38
39 $this->assertFalse($config->isActivated());
40 $this->assertNull($config->getContentDomain());
41 $this->assertNull($config->getIliasDomain());
42 $this->assertNull($config->getContentHost());
43 $this->assertNull($config->getIliasHost());
44 }

References ILIAS\FileDelivery\Isolation\IsolationConfig\disabled().

+ Here is the call graph for this function:

◆ testFromArrayToArrayRoundtripIsStable()

ILIAS\Tests\FileDelivery\Isolation\IsolationConfigTest::testFromArrayToArrayRoundtripIsStable ( )

Definition at line 175 of file IsolationConfigTest.php.

175 : void
176 {
177 $source = [
179 IsolationConfig::KEY_CONTENT_DOMAIN => 'content.example.org',
180 IsolationConfig::KEY_ILIAS_DOMAIN => 'app.example.org',
181 ];
182
183 $once = IsolationConfig::fromArray($source)->toArray();
184 $twice = IsolationConfig::fromArray($once)->toArray();
185
186 $this->assertSame($once, $twice);
187 }

References ILIAS\FileDelivery\Isolation\IsolationConfig\fromArray(), ILIAS\FileDelivery\Isolation\IsolationConfig\KEY_ACTIVATED, ILIAS\FileDelivery\Isolation\IsolationConfig\KEY_CONTENT_DOMAIN, and ILIAS\FileDelivery\Isolation\IsolationConfig\KEY_ILIAS_DOMAIN.

+ Here is the call graph for this function:

◆ testFromArrayWithFullSpecExample()

ILIAS\Tests\FileDelivery\Isolation\IsolationConfigTest::testFromArrayWithFullSpecExample ( )

Definition at line 55 of file IsolationConfigTest.php.

55 : void
56 {
57 // exact artefact shape from the feature spec
60 IsolationConfig::KEY_CONTENT_DOMAIN => 'https://test11.iliascontent.de',
61 IsolationConfig::KEY_ILIAS_DOMAIN => 'https://test11.ilias.de',
62 ]);
63
64 $this->assertTrue($config->isActivated());
65 $this->assertSame('https://test11.iliascontent.de', $config->getContentDomain());
66 $this->assertSame('https://test11.ilias.de', $config->getIliasDomain());
67 $this->assertSame('test11.iliascontent.de', $config->getContentHost());
68 $this->assertSame('test11.ilias.de', $config->getIliasHost());
69 }

References ILIAS\FileDelivery\Isolation\IsolationConfig\fromArray(), ILIAS\FileDelivery\Isolation\IsolationConfig\KEY_ACTIVATED, ILIAS\FileDelivery\Isolation\IsolationConfig\KEY_CONTENT_DOMAIN, and ILIAS\FileDelivery\Isolation\IsolationConfig\KEY_ILIAS_DOMAIN.

+ Here is the call graph for this function:

◆ testFromArtefactReadsTheStoredSettings()

ILIAS\Tests\FileDelivery\Isolation\IsolationConfigTest::testFromArtefactReadsTheStoredSettings ( )

Definition at line 287 of file IsolationConfigTest.php.

287 : void
288 {
289 $path = $this->artefact(
290 "<?php return ['activated' => true, 'content_domain' => 'content.example.org',"
291 . " 'ilias_domain' => 'https://app.example.org'];"
292 );
293 $config = IsolationConfig::fromArtefact($path);
294
295 $this->assertTrue($config->isActivated());
296 $this->assertSame('https://content.example.org', $config->getContentDomain());
297 $this->assertSame('https://app.example.org', $config->getIliasDomain());
298 }
static fromArtefact(?string $path=null)
Load the configuration from the static artefact written by the setup.

References ILIAS\FileDelivery\Isolation\IsolationConfig\fromArtefact().

+ Here is the call graph for this function:

◆ testFromArtefactWithNonArrayContentIsDisabled()

ILIAS\Tests\FileDelivery\Isolation\IsolationConfigTest::testFromArtefactWithNonArrayContentIsDisabled ( )

Definition at line 300 of file IsolationConfigTest.php.

300 : void
301 {
302 $config = IsolationConfig::fromArtefact($this->artefact('<?php return "nonsense";'));
303
304 $this->assertFalse($config->isActivated());
305 $this->assertNull($config->getContentDomain());
306 }

References ILIAS\FileDelivery\Isolation\IsolationConfig\fromArtefact().

+ Here is the call graph for this function:

◆ testFromArtefactWithoutFileIsDisabled()

ILIAS\Tests\FileDelivery\Isolation\IsolationConfigTest::testFromArtefactWithoutFileIsDisabled ( )

Definition at line 278 of file IsolationConfigTest.php.

278 : void
279 {
280 $config = IsolationConfig::fromArtefact(sys_get_temp_dir() . '/does_not_exist_isolation.php');
281
282 $this->assertFalse($config->isActivated());
283 $this->assertNull($config->getContentDomain());
284 $this->assertNull($config->getIliasDomain());
285 }

References ILIAS\FileDelivery\Isolation\IsolationConfig\fromArtefact().

+ Here is the call graph for this function:

◆ testFromArtefactWithoutReturnValueIsDisabled()

ILIAS\Tests\FileDelivery\Isolation\IsolationConfigTest::testFromArtefactWithoutReturnValueIsDisabled ( )

Definition at line 308 of file IsolationConfigTest.php.

308 : void
309 {
310 $config = IsolationConfig::fromArtefact($this->artefact('<?php // nothing returned'));
311
312 $this->assertFalse($config->isActivated());
313 $this->assertNull($config->getContentDomain());
314 }

References ILIAS\FileDelivery\Isolation\IsolationConfig\fromArtefact().

+ Here is the call graph for this function:

◆ testFromEmptyArrayIsDisabled()

ILIAS\Tests\FileDelivery\Isolation\IsolationConfigTest::testFromEmptyArrayIsDisabled ( )

Definition at line 46 of file IsolationConfigTest.php.

46 : void
47 {
48 $config = IsolationConfig::fromArray([]);
49
50 $this->assertFalse($config->isActivated());
51 $this->assertNull($config->getContentDomain());
52 $this->assertNull($config->getIliasDomain());
53 }

References ILIAS\FileDelivery\Isolation\IsolationConfig\fromArray().

+ Here is the call graph for this function:

◆ testInactiveStillParsesDomains()

ILIAS\Tests\FileDelivery\Isolation\IsolationConfigTest::testInactiveStillParsesDomains ( )

Definition at line 122 of file IsolationConfigTest.php.

122 : void
123 {
126 IsolationConfig::KEY_CONTENT_DOMAIN => 'https://content.example.org',
127 IsolationConfig::KEY_ILIAS_DOMAIN => 'https://app.example.org',
128 ]);
129
130 $this->assertFalse($config->isActivated());
131 $this->assertSame('https://content.example.org', $config->getContentDomain());
132 $this->assertSame('https://app.example.org', $config->getIliasDomain());
133 }

References ILIAS\FileDelivery\Isolation\IsolationConfig\fromArray(), ILIAS\FileDelivery\Isolation\IsolationConfig\KEY_ACTIVATED, ILIAS\FileDelivery\Isolation\IsolationConfig\KEY_CONTENT_DOMAIN, and ILIAS\FileDelivery\Isolation\IsolationConfig\KEY_ILIAS_DOMAIN.

+ Here is the call graph for this function:

◆ testNonBareOriginsAreRejected()

ILIAS\Tests\FileDelivery\Isolation\IsolationConfigTest::testNonBareOriginsAreRejected ( string  $input)

Definition at line 216 of file IsolationConfigTest.php.

216 : void
217 {
221 IsolationConfig::KEY_ILIAS_DOMAIN => 'https://app.example.org',
222 ]);
223
224 $this->assertNull($config->getContentDomain());
225 $this->assertNull($config->getContentHost());
226 }

References ILIAS\FileDelivery\Isolation\IsolationConfig\fromArray(), ILIAS\FileDelivery\Isolation\IsolationConfig\KEY_ACTIVATED, ILIAS\FileDelivery\Isolation\IsolationConfig\KEY_CONTENT_DOMAIN, and ILIAS\FileDelivery\Isolation\IsolationConfig\KEY_ILIAS_DOMAIN.

+ Here is the call graph for this function:

◆ testOriginFromUrlReducesTrustedAppUrlToBareOrigin()

ILIAS\Tests\FileDelivery\Isolation\IsolationConfigTest::testOriginFromUrlReducesTrustedAppUrlToBareOrigin ( ?string  $input,
?string  $expected 
)

Definition at line 240 of file IsolationConfigTest.php.

240 : void
241 {
242 // originFromUrl is used at build time to derive the ILIAS domain from
243 // http_path, which may carry a sub-directory path that must be discarded.
244 $this->assertSame($expected, IsolationConfig::originFromUrl($input));
245 }
static originFromUrl(mixed $value)
Reduce a (trusted) application URL to its bare origin "scheme://host[:port]".

References ILIAS\FileDelivery\Isolation\IsolationConfig\originFromUrl().

+ Here is the call graph for this function:

◆ testToArrayUsesSpecKeys()

ILIAS\Tests\FileDelivery\Isolation\IsolationConfigTest::testToArrayUsesSpecKeys ( )

Definition at line 160 of file IsolationConfigTest.php.

160 : void
161 {
164 IsolationConfig::KEY_CONTENT_DOMAIN => 'https://content.example.org',
165 IsolationConfig::KEY_ILIAS_DOMAIN => 'https://app.example.org',
166 ]);
167
168 $this->assertSame([
170 IsolationConfig::KEY_CONTENT_DOMAIN => 'https://content.example.org',
171 IsolationConfig::KEY_ILIAS_DOMAIN => 'https://app.example.org',
172 ], $config->toArray());
173 }

References ILIAS\FileDelivery\Isolation\IsolationConfig\fromArray(), ILIAS\FileDelivery\Isolation\IsolationConfig\KEY_ACTIVATED, ILIAS\FileDelivery\Isolation\IsolationConfig\KEY_CONTENT_DOMAIN, and ILIAS\FileDelivery\Isolation\IsolationConfig\KEY_ILIAS_DOMAIN.

+ Here is the call graph for this function:

◆ testTrailingSlashIsStripped()

ILIAS\Tests\FileDelivery\Isolation\IsolationConfigTest::testTrailingSlashIsStripped ( )

Definition at line 85 of file IsolationConfigTest.php.

85 : void
86 {
89 IsolationConfig::KEY_CONTENT_DOMAIN => 'https://content.example.org/',
90 IsolationConfig::KEY_ILIAS_DOMAIN => 'https://app.example.org/',
91 ]);
92
93 $this->assertSame('https://content.example.org', $config->getContentDomain());
94 $this->assertSame('https://app.example.org', $config->getIliasDomain());
95 }

References ILIAS\FileDelivery\Isolation\IsolationConfig\fromArray(), ILIAS\FileDelivery\Isolation\IsolationConfig\KEY_ACTIVATED, ILIAS\FileDelivery\Isolation\IsolationConfig\KEY_CONTENT_DOMAIN, and ILIAS\FileDelivery\Isolation\IsolationConfig\KEY_ILIAS_DOMAIN.

+ Here is the call graph for this function:

◆ testUnusableDomainsNormalizeToNull()

ILIAS\Tests\FileDelivery\Isolation\IsolationConfigTest::testUnusableDomainsNormalizeToNull ( mixed  $value)

Definition at line 136 of file IsolationConfigTest.php.

136 : void
137 {
141 IsolationConfig::KEY_ILIAS_DOMAIN => 'https://app.example.org',
142 ]);
143
144 // unusable content domain -> null -> isolation forced off
145 $this->assertNull($config->getContentDomain());
146 $this->assertFalse($config->isActivated());
147 }

References ILIAS\FileDelivery\Isolation\IsolationConfig\fromArray(), ILIAS\FileDelivery\Isolation\IsolationConfig\KEY_ACTIVATED, ILIAS\FileDelivery\Isolation\IsolationConfig\KEY_CONTENT_DOMAIN, and ILIAS\FileDelivery\Isolation\IsolationConfig\KEY_ILIAS_DOMAIN.

+ Here is the call graph for this function:

◆ testValidValuesNormalizeToBareOrigin()

ILIAS\Tests\FileDelivery\Isolation\IsolationConfigTest::testValidValuesNormalizeToBareOrigin ( string  $input,
string  $expected_domain,
string  $expected_host 
)

Definition at line 190 of file IsolationConfigTest.php.

194 : void {
198 IsolationConfig::KEY_ILIAS_DOMAIN => 'https://app.example.org',
199 ]);
200
201 $this->assertSame($expected_domain, $config->getContentDomain());
202 $this->assertSame($expected_host, $config->getContentHost());
203 }

◆ trustedOriginProvider()

static ILIAS\Tests\FileDelivery\Isolation\IsolationConfigTest::trustedOriginProvider ( )
static

Definition at line 247 of file IsolationConfigTest.php.

247 : \Iterator
248 {
249 yield 'bare origin' => ['https://app.example.org', 'https://app.example.org'];
250 yield 'path discarded' => ['https://app.example.org/ilias/index.php', 'https://app.example.org'];
251 yield 'query discarded' => ['https://app.example.org/?a=b', 'https://app.example.org'];
252 yield 'bare host gets https' => ['app.example.org', 'https://app.example.org'];
253 yield 'http kept' => ['http://localhost/sub', 'http://localhost'];
254 yield 'port preserved' => ['https://app.example.org:8443/sub', 'https://app.example.org:8443'];
255 yield 'empty stays null' => ['', null];
256 yield 'null stays null' => [null, null];
257 yield 'non-http scheme rejected' => ['ftp://app.example.org', null];
258 }

◆ unusableDomainProvider()

static ILIAS\Tests\FileDelivery\Isolation\IsolationConfigTest::unusableDomainProvider ( )
static

Definition at line 149 of file IsolationConfigTest.php.

149 : \Iterator
150 {
151 yield 'empty string' => [''];
152 yield 'whitespace only' => [' '];
153 yield 'scheme without host' => ['https://'];
154 yield 'non-string int' => [123];
155 yield 'non-string bool' => [true];
156 yield 'null' => [null];
157 yield 'array' => [['x']];
158 }

Field Documentation

◆ $artefacts

array ILIAS\Tests\FileDelivery\Isolation\IsolationConfigTest::$artefacts = []
private

Definition at line 33 of file IsolationConfigTest.php.


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