ILIAS  trunk Revision v13.0_alpha-62-g3b72d83f2e5
ILIAS\Tests\FileDelivery\Delivery\LegacyDeliveryIsolationTest Class Reference

Covers the host guard in {. More...

+ Inheritance diagram for ILIAS\Tests\FileDelivery\Delivery\LegacyDeliveryIsolationTest:
+ Collaboration diagram for ILIAS\Tests\FileDelivery\Delivery\LegacyDeliveryIsolationTest:

Public Member Functions

 testLegacyDeliveryIsRefusedOnTheContentHost ()
 
 testLegacyDeliveryIsRefusedOnTheContentHostRegardlessOfCase ()
 
 testLegacyDeliveryIsServedOnTheIliasHost ()
 
 testLegacyDeliveryIsServedOnAnyHostWhenIsolationIsDisabled ()
 

Protected Member Functions

 setUp ()
 
 tearDown ()
 

Private Member Functions

 http (string $request_host)
 
 activeConfig ()
 
 deliverInline (IsolationConfig $isolation, string $request_host, ResponseBuilder $response_builder)
 
 neverBuilding ()
 
 building ()
 

Private Attributes

string $file
 
ResponseInterface $saved = null
 

Detailed Description

Covers the host guard in {.

See also
LegacyDelivery}: the content domain is reserved for signed token delivery, so legacy delivery must answer 404 there instead of serving the file.
Author
Fabian Schmid fabia.nosp@m.n@sr.nosp@m..solu.nosp@m.tion.nosp@m.s

Definition at line 40 of file LegacyDeliveryIsolationTest.php.

Member Function Documentation

◆ activeConfig()

◆ building()

ILIAS\Tests\FileDelivery\Delivery\LegacyDeliveryIsolationTest::building ( )
private

Definition at line 116 of file LegacyDeliveryIsolationTest.php.

116 : ResponseBuilder
117 {
118 $rb = $this->createMock(ResponseBuilder::class);
119 $rb->method('getName')->willReturn('PHP');
120 $rb->expects($this->once())
121 ->method('buildForStream')
122 ->willReturnCallback(
123 static fn(ServerRequestInterface $request, ResponseInterface $r): ResponseInterface => $r
124 );
125 return $rb;
126 }
$request
@ilCtrl_Calls ilObjLearningSequenceContentGUI: ilObjLearningSequenceConditionsGUI
Definition: ltiauth.php:39

References $request.

◆ deliverInline()

ILIAS\Tests\FileDelivery\Delivery\LegacyDeliveryIsolationTest::deliverInline ( IsolationConfig  $isolation,
string  $request_host,
ResponseBuilder  $response_builder 
)
private

Definition at line 89 of file LegacyDeliveryIsolationTest.php.

93 : void {
94 $delivery = new LegacyDelivery(
95 $this->http($request_host),
96 $response_builder,
97 $response_builder,
98 $isolation
99 );
100
101 try {
102 $delivery->inline($this->file);
103 $this->fail('delivery did not terminate');
104 } catch (DeliveryTerminated) {
105 // expected: the delivery ran to its end and closed the request
106 }
107 }

References ILIAS\FileDelivery\Delivery\LegacyDelivery\inline().

+ Here is the call graph for this function:

◆ http()

ILIAS\Tests\FileDelivery\Delivery\LegacyDeliveryIsolationTest::http ( string  $request_host)
private

Definition at line 58 of file LegacyDeliveryIsolationTest.php.

58 : HttpServices
59 {
60 $uri = $this->createStub(UriInterface::class);
61 $uri->method('getHost')->willReturn($request_host);
62
63 $request = $this->createStub(ServerRequestInterface::class);
64 $request->method('getUri')->willReturn($uri);
65
66 $http = $this->createStub(HttpServices::class);
67 $http->method('request')->willReturn($request);
68 $http->method('response')->willReturn((new MessageFactoryImpl())->response());
69 $http->method('saveResponse')->willReturnCallback(
70 function (ResponseInterface $r): void {
71 $this->saved = $r;
72 }
73 );
74 // deliveries are declared `never`; the doubled close() ends them observably
75 $http->method('close')->willThrowException(new DeliveryTerminated());
76
77 return $http;
78 }

References ILIAS\BookingManager\Common\Table\$http, and $request.

◆ neverBuilding()

ILIAS\Tests\FileDelivery\Delivery\LegacyDeliveryIsolationTest::neverBuilding ( )
private

Definition at line 109 of file LegacyDeliveryIsolationTest.php.

109 : ResponseBuilder
110 {
111 $rb = $this->createMock(ResponseBuilder::class);
112 $rb->expects($this->never())->method('buildForStream');
113 return $rb;
114 }

◆ setUp()

ILIAS\Tests\FileDelivery\Delivery\LegacyDeliveryIsolationTest::setUp ( )
protected

Definition at line 45 of file LegacyDeliveryIsolationTest.php.

45 : void
46 {
47 $this->file = (string) tempnam(sys_get_temp_dir(), 'fd_iso_');
48 file_put_contents($this->file, 'legacy content');
49 }

◆ tearDown()

ILIAS\Tests\FileDelivery\Delivery\LegacyDeliveryIsolationTest::tearDown ( )
protected

Definition at line 51 of file LegacyDeliveryIsolationTest.php.

51 : void
52 {
53 if (is_file($this->file)) {
54 unlink($this->file);
55 }
56 }

◆ testLegacyDeliveryIsRefusedOnTheContentHost()

ILIAS\Tests\FileDelivery\Delivery\LegacyDeliveryIsolationTest::testLegacyDeliveryIsRefusedOnTheContentHost ( )

Definition at line 128 of file LegacyDeliveryIsolationTest.php.

128 : void
129 {
130 $this->deliverInline($this->activeConfig(), 'content.example.org', $this->neverBuilding());
131
132 $this->assertNotNull($this->saved);
133 $this->assertSame(404, $this->saved->getStatusCode());
134 }
deliverInline(IsolationConfig $isolation, string $request_host, ResponseBuilder $response_builder)

◆ testLegacyDeliveryIsRefusedOnTheContentHostRegardlessOfCase()

ILIAS\Tests\FileDelivery\Delivery\LegacyDeliveryIsolationTest::testLegacyDeliveryIsRefusedOnTheContentHostRegardlessOfCase ( )

Definition at line 136 of file LegacyDeliveryIsolationTest.php.

136 : void
137 {
138 $this->deliverInline($this->activeConfig(), 'CONTENT.Example.ORG', $this->neverBuilding());
139
140 $this->assertNotNull($this->saved);
141 $this->assertSame(404, $this->saved->getStatusCode());
142 }

◆ testLegacyDeliveryIsServedOnAnyHostWhenIsolationIsDisabled()

ILIAS\Tests\FileDelivery\Delivery\LegacyDeliveryIsolationTest::testLegacyDeliveryIsServedOnAnyHostWhenIsolationIsDisabled ( )

Definition at line 158 of file LegacyDeliveryIsolationTest.php.

158 : void
159 {
160 $this->deliverInline(IsolationConfig::disabled(), 'content.example.org', $this->building());
161
162 $this->assertNotNull($this->saved);
163 $this->assertSame(200, $this->saved->getStatusCode());
164 $this->assertFalse($this->saved->hasHeader('X-Content-Type-Options'));
165 $this->assertFalse($this->saved->hasHeader('Access-Control-Allow-Origin'));
166 }

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

+ Here is the call graph for this function:

◆ testLegacyDeliveryIsServedOnTheIliasHost()

ILIAS\Tests\FileDelivery\Delivery\LegacyDeliveryIsolationTest::testLegacyDeliveryIsServedOnTheIliasHost ( )

Definition at line 144 of file LegacyDeliveryIsolationTest.php.

144 : void
145 {
146 $this->deliverInline($this->activeConfig(), 'app.example.org', $this->building());
147
148 $this->assertNotNull($this->saved);
149 $this->assertSame(200, $this->saved->getStatusCode());
150 // the delivered response carries the isolation headers
151 $this->assertSame('nosniff', $this->saved->getHeaderLine('X-Content-Type-Options'));
152 $this->assertSame(
153 'https://app.example.org',
154 $this->saved->getHeaderLine('Access-Control-Allow-Origin')
155 );
156 }

Field Documentation

◆ $file

string ILIAS\Tests\FileDelivery\Delivery\LegacyDeliveryIsolationTest::$file
private

Definition at line 42 of file LegacyDeliveryIsolationTest.php.

◆ $saved

ResponseInterface ILIAS\Tests\FileDelivery\Delivery\LegacyDeliveryIsolationTest::$saved = null
private

Definition at line 43 of file LegacyDeliveryIsolationTest.php.


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