ILIAS  trunk Revision v13.0_alpha-62-g3b72d83f2e5
IsolationObjectiveTest.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
28use PHPUnit\Framework\TestCase;
29
33final class IsolationObjectiveTest extends TestCase
34{
35 public function testArtifactName(): void
36 {
37 $this->assertSame('isolation', (new IsolationObjective())->getArtifactName());
38 }
39
41 {
42 // build() has no Environment, so the ILIAS domain (derived from http_path)
43 // stays null; it is filled in by buildIn().
44 $objective = new IsolationObjective(
45 true,
46 'https://content.example.org',
47 );
48
49 $artifact = $objective->build();
50 $this->assertInstanceOf(Artifact::class, $artifact);
51
52 $value = $this->evaluateArtifact($artifact);
53
54 $this->assertSame([
56 IsolationConfig::KEY_CONTENT_DOMAIN => 'https://content.example.org',
58 ], $value);
59 }
60
61 public function testDefaultBuildIsDisabledArtifact(): void
62 {
63 $value = $this->evaluateArtifact((new IsolationObjective())->build());
64
65 $this->assertSame([
69 ], $value);
70 }
71
73 {
74 // http_path may carry a sub-directory; it is reduced to a bare origin.
75 $env = $this->environmentWithHttpPath('https://app.example.org/ilias/index.php');
76
77 $objective = new IsolationObjective(true, 'https://content.example.org');
78 $value = $this->evaluateArtifact($objective->buildIn($env));
79
80 $this->assertSame([
82 IsolationConfig::KEY_CONTENT_DOMAIN => 'https://content.example.org',
83 IsolationConfig::KEY_ILIAS_DOMAIN => 'https://app.example.org',
84 ], $value);
85 }
86
88 {
89 $env = $this->createStub(Environment::class);
90 $env->method('getResource')->willReturn(null);
91
92 $objective = new IsolationObjective(true, 'https://content.example.org');
93 $value = $this->evaluateArtifact($objective->buildIn($env));
94
95 $this->assertNull($value[IsolationConfig::KEY_ILIAS_DOMAIN]);
96 $this->assertTrue($value[IsolationConfig::KEY_ACTIVATED]);
97 }
98
100 {
101 $env = $this->environmentWithHttpPath('https://same.example.org');
102
103 $objective = new IsolationObjective(true, 'https://same.example.org');
104
105 $this->expectException(UnachievableException::class);
106 $objective->buildIn($env);
107 }
108
110 {
111 $env = $this->environmentWithHttpPath('https://same.example.org');
112
113 $objective = new IsolationObjective(false, 'https://same.example.org');
114 $value = $this->evaluateArtifact($objective->buildIn($env));
115
116 $this->assertFalse($value[IsolationConfig::KEY_ACTIVATED]);
117 }
118
126 {
127 $marker = sys_get_temp_dir() . '/isolation_injection_' . getmypid();
128 @unlink($marker);
129
130 $payload = "https://evil.example.org' . file_put_contents('" . $marker . "', 'pwned') . '";
131
132 $objective = new IsolationObjective(true, $payload);
133 $value = $this->evaluateArtifact($objective->build());
134
135 // payload preserved verbatim, no code executed
136 $this->assertSame($payload, $value[IsolationConfig::KEY_CONTENT_DOMAIN]);
137 $this->assertFileDoesNotExist($marker);
138 }
139
140 private function environmentWithHttpPath(string $http_path): Environment
141 {
142 $ini = $this->createStub(\ilIniFile::class);
143 $ini->method('readVariable')->willReturn($http_path);
144
145 $env = $this->createStub(Environment::class);
146 $env->method('getResource')->willReturn($ini);
147
148 return $env;
149 }
150
157 private function evaluateArtifact(Artifact $artifact): array
158 {
159 $file = tempnam(sys_get_temp_dir(), 'isolation_artifact_') . '.php';
160 file_put_contents($file, $artifact->serialize());
161
162 try {
163 $value = include $file;
164 } finally {
165 @unlink($file);
166 }
167
168 $this->assertIsArray($value);
169 return $value;
170 }
171}
Read-only configuration of the IRSS User Content Isolation feature.
Writes the IRSS User Content Isolation settings to a static PHP artefact so the FileDelivery runtime ...
Signals that some goal won't be achievable by actions of the system ever.
evaluateArtifact(Artifact $artifact)
Execute the serialized artefact exactly the way the runtime loads it (include $path) and return the p...
testMaliciousDomainIsEscapedAndNotExecuted()
Regression for the review concern that a generated PHP artefact could allow code injection via an une...
An artifact is some file that is build on demand per installation and is not shipped with the ILIAS s...
Definition: Artifact.php:28
serialize()
This method will be called from the source, which wants to save the artifact.
An environment holds resources to be used in the setup process.
Definition: Environment.php:28