45 #[RunTestsInSeparateProcesses] 50 public const SALT =
'SALT';
97 protected function setUp(): void
101 $this->root = vfsStream::setup(
'ilias.de');
102 $this->file_one = vfsStream::newFile(
'data/client_name/mobs/mm_123/dummy.jpg')
103 ->at($this->root)->setContent(
'dummy');
104 $this->file_one_subfolder = vfsStream::newFile(
'data/client_name/mobs/mm_123/mobile/dummy.jpg')
105 ->at($this->root)->setContent(
'dummy');
106 $this->file_one_subfolder_two = vfsStream::newFile(
'data/client_name/mobs/mm_123/mobile/device/dummy.jpg')
107 ->at($this->root)->setContent(
'dummy');
108 $this->file_two = vfsStream::newFile(
'data/client_name/mobs/mm_123/dummy2.jpg')
109 ->at($this->root)->setContent(
'dummy2');
110 $this->file_three = vfsStream::newFile(
'data/client_name/mobs/mm_124/dummy.jpg')
111 ->at($this->root)->setContent(
'dummy');
112 $this->file_four = vfsStream::newFile(
'data/client_name/sec/ilBlog/mm_124/dummy.jpg')
113 ->at($this->root)->setContent(
'dummy');
117 $container[
'http'] = fn(
$c) => Mockery::mock(GlobalHttpState::class);
124 $this->cookieFactory = Mockery::mock(CookieFactoryImpl::class);
127 $this->cookieFactory->shouldDeferMissing();
135 $this->markTestSkipped(
"Failed for some unknown reason.");
139 $cookieJar = Mockery::mock(CookieJar::class);
142 ->shouldReceive(
'getAll')
147 $this->
http->shouldReceive(
'cookieJar')
150 ->andReturn($cookieJar);
152 $request = Mockery::mock(RequestInterface::class);
153 $request->shouldReceive(
'getCookieParams')
156 $this->
http->shouldReceive(
'request')
158 ->andReturn($request);
160 $this->assertFalse($ilWACSignedPath->isSignedPath());
161 $this->assertFalse($ilWACSignedPath->isSignedPathValid());
162 $this->assertFalse($ilWACSignedPath->isFolderSigned());
163 $this->assertFalse($ilWACSignedPath->isFolderTokenValid());
169 $this->markTestSkipped(
"Failed for some unknown reason.");
170 $query =
'myparam=1234';
172 . $query), $this->
http, $this->cookieFactory);
174 $this->assertEquals(
'dummy.jpg', $ilWACSignedPath->getPathObject()->getFileName());
175 $this->assertEquals($query, $ilWACSignedPath->getPathObject()->getQuery());
177 .
'/sec/ilBlog/mm_124/', $ilWACSignedPath->getPathObject()
179 $this->assertEquals(
'ilBlog', $ilWACSignedPath->getPathObject()->getSecurePathId());
180 $this->assertFalse($ilWACSignedPath->getPathObject()->isStreamable());
186 $this->markTestSkipped(
"Failed for some unknown reason.");
188 $ilWacPath =
new ilWacPath($this->file_four->url());
191 $this->assertEquals(
'SALT-client_name-123456-20', $ilWACToken->getRawToken());
192 $this->assertEquals(
'./data/client_name/sec/ilBlog/mm_124/dummy.jpg', $ilWACToken->getId());
196 $this->assertEquals(
'b541e2bae42ee222f9be959b7ad2ab8844cbb05b', $ilWACToken->getToken());
197 $this->assertEquals(
'e45b98f267dc891c8206c844f7df29ea', $ilWACToken->getHashedId());
203 $this->markTestSkipped(
'unable to use http cookies at this point');
205 $cookieJar = Mockery::mock(CookieJar::class);
207 $response = Mockery::mock(ResponseInterface::class);
210 ->shouldReceive(
'response')
217 ->shouldReceive(
'with')
223 ->shouldReceive(
'with')
229 ->shouldReceive(
'with')
235 $this->
http->shouldReceive(
'cookieJar')
237 ->andReturn($cookieJar);
251 $this->markTestSkipped(
"Failed for some unknown reason.");
259 $this->assertTrue($ilWACSignedPath->isSignedPath());
260 $this->assertTrue($ilWACSignedPath->isSignedPathValid());
261 $this->assertEquals($ilWACSignedPath->getPathObject()->getClient(),
self::CLIENT_NAME);
262 $this->assertFalse($ilWACSignedPath->getPathObject()->isInSecFolder());
263 $this->assertTrue($ilWACSignedPath->getPathObject()->isImage());
264 $this->assertFalse($ilWACSignedPath->getPathObject()->isAudio());
265 $this->assertFalse($ilWACSignedPath->getPathObject()->isVideo());
266 $this->assertTrue($ilWACSignedPath->getPathObject()->hasTimestamp());
267 $this->assertTrue($ilWACSignedPath->getPathObject()->hasToken());
271 sleep($lifetime + self::ADDITIONAL_TIME);
273 $this->assertTrue($ilWACSignedPath->isSignedPath());
274 $this->assertFalse($ilWACSignedPath->isSignedPathValid());
282 $this->markTestSkipped(
"Failed for some unknown reason.");
286 $this->assertTrue($ilWACSignedPath->isSignedPath());
287 $this->assertTrue($ilWACSignedPath->isSignedPathValid());
294 $this->markTestSkipped(
"Failed for some unknown reason.");
298 $this->assertTrue($ilWACSignedPath->isSignedPath());
299 $this->assertFalse($ilWACSignedPath->isSignedPathValid());
305 $this->markTestSkipped(
"Failed for some unknown reason.");
309 * -1, 0)), $this->
http, $this->cookieFactory);
310 $this->assertTrue($ilWACSignedPath->isSignedPath());
311 $this->assertFalse($ilWACSignedPath->isSignedPathValid());
317 $this->markTestSkipped(
"Failed for some unknown reason.");
321 $this->assertTrue($ilWACSignedPath->isSignedPath());
322 $this->assertFalse($ilWACSignedPath->isSignedPathValid());
328 $this->markTestSkipped(
"Failed for some unknown reason.");
332 $this->assertTrue($ilWACSignedPath->isSignedPath());
333 $this->assertFalse($ilWACSignedPath->isSignedPathValid());
339 $this->markTestSkipped(
"Failed for some unknown reason.");
343 $this->assertTrue($ilWACSignedPath->isSignedPath());
344 $this->assertFalse($ilWACSignedPath->isSignedPathValid());
356 $parts = parse_url($signed_path);
357 $path = $parts[
'path'];
358 $query = $parts[
'query'];
359 parse_str($query, $query_array);
360 $token = $override_token ?: $query_array[
'il_wac_token'];
361 $ttl = (
int) $query_array[
'il_wac_ttl'];
362 $ts = (
int) $query_array[
'il_wac_ts'];
363 $path_with_token =
$path .
'?il_wac_token=' .
$token;
365 $modified_ttl = $ttl + $add_ttl;
366 $modified_ts = $ts + $add_timestamp;
368 return $path_with_token .
'&il_wac_ttl=' . $modified_ttl .
'&il_wac_ts=' . $modified_ts;
static setSALT(string $salt)
if($clientAssertionType !='urn:ietf:params:oauth:client-assertion-type:jwt-bearer'|| $grantType !='client_credentials') $parts
testModifiedTimestampAddTime()
getModifiedSignedPath(int $add_ttl=0, int $add_timestamp=0, $override_token=null)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static setTokenMaxLifetimeInSeconds(int $token_max_lifetime_in_seconds)
Customizing of pimple-DIC for ILIAS.
TestCase for the ilWACTokenTest.
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
testModifiedTimestampSubTime()
static http()
Fetches the global http state from ILIAS.
static signFolderOfStartFile(string $start_file_path)
testModifiedTTLAndTimestamp()
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
testModifiedTimestampNoMod()
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static signFile(string $path_to_file)
static getTokenMaxLifetimeInSeconds()