19declare(strict_types=1);
24use PHPUnit\Framework\Attributes\DataProvider;
25use PHPUnit\Framework\TestCase;
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());
50 $this->assertFalse($config->isActivated());
51 $this->assertNull($config->getContentDomain());
52 $this->assertNull($config->getIliasDomain());
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());
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());
93 $this->assertSame(
'https://content.example.org', $config->getContentDomain());
94 $this->assertSame(
'https://app.example.org', $config->getIliasDomain());
104 $this->assertFalse($config->isActivated());
117 $this->assertTrue($config->isActivated());
118 $this->assertSame(
'https://content.example.org', $config->getContentDomain());
119 $this->assertNull($config->getIliasDomain());
130 $this->assertFalse($config->isActivated());
131 $this->assertSame(
'https://content.example.org', $config->getContentDomain());
132 $this->assertSame(
'https://app.example.org', $config->getIliasDomain());
135 #[DataProvider('unusableDomainProvider')]
145 $this->assertNull($config->getContentDomain());
146 $this->assertFalse($config->isActivated());
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']];
172 ], $config->toArray());
186 $this->assertSame($once, $twice);
189 #[DataProvider('originNormalizationProvider')]
192 string $expected_domain,
193 string $expected_host
201 $this->assertSame($expected_domain, $config->getContentDomain());
202 $this->assertSame($expected_host, $config->getContentHost());
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'];
215 #[DataProvider('rejectedOriginProvider')]
224 $this->assertNull($config->getContentDomain());
225 $this->assertNull($config->getContentHost());
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)'];
239 #[DataProvider('trustedOriginProvider')]
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];
262 $path = (string) tempnam(sys_get_temp_dir(),
'iso_artefact_') .
'.php';
263 file_put_contents($path, $php);
264 $this->artefacts[] = $path;
270 foreach ($this->artefacts as $path) {
271 if (is_file($path)) {
275 $this->artefacts = [];
282 $this->assertFalse($config->isActivated());
283 $this->assertNull($config->getContentDomain());
284 $this->assertNull($config->getIliasDomain());
289 $path = $this->artefact(
290 "<?php return ['activated' => true, 'content_domain' => 'content.example.org',"
291 .
" 'ilias_domain' => 'https://app.example.org'];"
295 $this->assertTrue($config->isActivated());
296 $this->assertSame(
'https://content.example.org', $config->getContentDomain());
297 $this->assertSame(
'https://app.example.org', $config->getIliasDomain());
304 $this->assertFalse($config->isActivated());
305 $this->assertNull($config->getContentDomain());
312 $this->assertFalse($config->isActivated());
313 $this->assertNull($config->getContentDomain());
Read-only configuration of the IRSS User Content Isolation feature.
static fromArray(array $data)
static originFromUrl(mixed $value)
Reduce a (trusted) application URL to its bare origin "scheme://host[:port]".
static fromArtefact(?string $path=null)
Load the configuration from the static artefact written by the setup.
testFromArtefactWithNonArrayContentIsDisabled()
testActivatedWithoutContentDomainIsForcedOff()
testInactiveStillParsesDomains()
testValidValuesNormalizeToBareOrigin(string $input, string $expected_domain, string $expected_host)
testFromArtefactReadsTheStoredSettings()
testBareHostnamesGetHttpsScheme()
static rejectedOriginProvider()
testFromEmptyArrayIsDisabled()
static unusableDomainProvider()
static trustedOriginProvider()
testActivatedWithoutIliasDomainStaysActiveWithNullIliasDomain()
testFromArtefactWithoutReturnValueIsDisabled()
testFromArtefactWithoutFileIsDisabled()
testUnusableDomainsNormalizeToNull(mixed $value)
testTrailingSlashIsStripped()
static originNormalizationProvider()
testNonBareOriginsAreRejected(string $input)
testOriginFromUrlReducesTrustedAppUrlToBareOrigin(?string $input, ?string $expected)
testToArrayUsesSpecKeys()
testFromArrayWithFullSpecExample()
testFromArrayToArrayRoundtripIsStable()