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

Public Member Functions

 testArtifactName ()
 
 testBuildProducesContentDomainWithNullIliasDomain ()
 
 testDefaultBuildIsDisabledArtifact ()
 
 testBuildInDerivesIliasDomainFromHttpPath ()
 
 testBuildInWithoutIniResourceLeavesIliasDomainNull ()
 
 testBuildInThrowsWhenContentHostEqualsIliasHost ()
 
 testBuildInDoesNotThrowForSameHostWhenInactive ()
 
 testMaliciousDomainIsEscapedAndNotExecuted ()
 Regression for the review concern that a generated PHP artefact could allow code injection via an unescaped string. More...
 

Private Member Functions

 environmentWithHttpPath (string $http_path)
 
 evaluateArtifact (Artifact $artifact)
 Execute the serialized artefact exactly the way the runtime loads it (include $path) and return the produced array. More...
 

Detailed Description

Member Function Documentation

◆ environmentWithHttpPath()

ILIAS\Tests\FileDelivery\Setup\IsolationObjectiveTest::environmentWithHttpPath ( string  $http_path)
private

Definition at line 140 of file IsolationObjectiveTest.php.

140 : 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 }

References ILIAS\$ini.

Referenced by ILIAS\Tests\FileDelivery\Setup\IsolationObjectiveTest\testBuildInDerivesIliasDomainFromHttpPath(), ILIAS\Tests\FileDelivery\Setup\IsolationObjectiveTest\testBuildInDoesNotThrowForSameHostWhenInactive(), and ILIAS\Tests\FileDelivery\Setup\IsolationObjectiveTest\testBuildInThrowsWhenContentHostEqualsIliasHost().

+ Here is the caller graph for this function:

◆ evaluateArtifact()

ILIAS\Tests\FileDelivery\Setup\IsolationObjectiveTest::evaluateArtifact ( Artifact  $artifact)
private

Execute the serialized artefact exactly the way the runtime loads it (include $path) and return the produced array.

Returns
array<string, mixed>

Definition at line 157 of file IsolationObjectiveTest.php.

157 : 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 }

References ILIAS\Setup\Artifact\serialize().

Referenced by ILIAS\Tests\FileDelivery\Setup\IsolationObjectiveTest\testBuildInDerivesIliasDomainFromHttpPath(), ILIAS\Tests\FileDelivery\Setup\IsolationObjectiveTest\testBuildInDoesNotThrowForSameHostWhenInactive(), ILIAS\Tests\FileDelivery\Setup\IsolationObjectiveTest\testBuildInWithoutIniResourceLeavesIliasDomainNull(), ILIAS\Tests\FileDelivery\Setup\IsolationObjectiveTest\testBuildProducesContentDomainWithNullIliasDomain(), ILIAS\Tests\FileDelivery\Setup\IsolationObjectiveTest\testDefaultBuildIsDisabledArtifact(), and ILIAS\Tests\FileDelivery\Setup\IsolationObjectiveTest\testMaliciousDomainIsEscapedAndNotExecuted().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ testArtifactName()

ILIAS\Tests\FileDelivery\Setup\IsolationObjectiveTest::testArtifactName ( )

Definition at line 35 of file IsolationObjectiveTest.php.

35 : void
36 {
37 $this->assertSame('isolation', (new IsolationObjective())->getArtifactName());
38 }

◆ testBuildInDerivesIliasDomainFromHttpPath()

ILIAS\Tests\FileDelivery\Setup\IsolationObjectiveTest::testBuildInDerivesIliasDomainFromHttpPath ( )

Definition at line 72 of file IsolationObjectiveTest.php.

72 : void
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 }
evaluateArtifact(Artifact $artifact)
Execute the serialized artefact exactly the way the runtime loads it (include $path) and return the p...

References ILIAS\Tests\FileDelivery\Setup\IsolationObjectiveTest\environmentWithHttpPath(), ILIAS\Tests\FileDelivery\Setup\IsolationObjectiveTest\evaluateArtifact(), 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:

◆ testBuildInDoesNotThrowForSameHostWhenInactive()

ILIAS\Tests\FileDelivery\Setup\IsolationObjectiveTest::testBuildInDoesNotThrowForSameHostWhenInactive ( )

Definition at line 109 of file IsolationObjectiveTest.php.

109 : void
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 }

References ILIAS\Tests\FileDelivery\Setup\IsolationObjectiveTest\environmentWithHttpPath(), ILIAS\Tests\FileDelivery\Setup\IsolationObjectiveTest\evaluateArtifact(), and ILIAS\FileDelivery\Isolation\IsolationConfig\KEY_ACTIVATED.

+ Here is the call graph for this function:

◆ testBuildInThrowsWhenContentHostEqualsIliasHost()

ILIAS\Tests\FileDelivery\Setup\IsolationObjectiveTest::testBuildInThrowsWhenContentHostEqualsIliasHost ( )

Definition at line 99 of file IsolationObjectiveTest.php.

99 : void
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 }

References ILIAS\Tests\FileDelivery\Setup\IsolationObjectiveTest\environmentWithHttpPath().

+ Here is the call graph for this function:

◆ testBuildInWithoutIniResourceLeavesIliasDomainNull()

ILIAS\Tests\FileDelivery\Setup\IsolationObjectiveTest::testBuildInWithoutIniResourceLeavesIliasDomainNull ( )

Definition at line 87 of file IsolationObjectiveTest.php.

87 : void
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 }

References ILIAS\Tests\FileDelivery\Setup\IsolationObjectiveTest\evaluateArtifact(), ILIAS\FileDelivery\Isolation\IsolationConfig\KEY_ACTIVATED, and ILIAS\FileDelivery\Isolation\IsolationConfig\KEY_ILIAS_DOMAIN.

+ Here is the call graph for this function:

◆ testBuildProducesContentDomainWithNullIliasDomain()

ILIAS\Tests\FileDelivery\Setup\IsolationObjectiveTest::testBuildProducesContentDomainWithNullIliasDomain ( )

Definition at line 40 of file IsolationObjectiveTest.php.

40 : void
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 }

References ILIAS\Tests\FileDelivery\Setup\IsolationObjectiveTest\evaluateArtifact(), 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:

◆ testDefaultBuildIsDisabledArtifact()

ILIAS\Tests\FileDelivery\Setup\IsolationObjectiveTest::testDefaultBuildIsDisabledArtifact ( )

◆ testMaliciousDomainIsEscapedAndNotExecuted()

ILIAS\Tests\FileDelivery\Setup\IsolationObjectiveTest::testMaliciousDomainIsEscapedAndNotExecuted ( )

Regression for the review concern that a generated PHP artefact could allow code injection via an unescaped string.

var_export() must escape the value so the malicious payload survives as a literal string and is never executed.

Definition at line 125 of file IsolationObjectiveTest.php.

125 : void
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 }

References ILIAS\Tests\FileDelivery\Setup\IsolationObjectiveTest\evaluateArtifact(), and ILIAS\FileDelivery\Isolation\IsolationConfig\KEY_CONTENT_DOMAIN.

+ Here is the call graph for this function:

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