TestCase for the ilWACTokenTest.
More...
TestCase for the ilWACTokenTest.
- Author
- Fabian Schmid fs@st.nosp@m.uder.nosp@m.-raim.nosp@m.ann..nosp@m.ch
- Version
- 1.0.0
disabled disabled disabled
Definition at line 52 of file ilWACTokenTest.php.
◆ getModifiedSignedPath()
ilWACTokenTest::getModifiedSignedPath |
( |
|
$add_ttl = 0 , |
|
|
|
$add_timestamp = 0 , |
|
|
|
$override_token = null |
|
) |
| |
|
protected |
- Parameters
-
int | $add_ttl | |
int | $add_timestamp | |
null | $override_token | |
- Returns
- string
Definition at line 366 of file ilWACTokenTest.php.
References $path, $query, PHPMailer\PHPMailer\$token, ilWACSignedPath\setTokenMaxLifetimeInSeconds(), and ilWACSignedPath\signFile().
Referenced by testModifiedTimestampAddTime(), testModifiedTimestampNoMod(), testModifiedTimestampSubTime(), testModifiedToken(), testModifiedTTL(), and testModifiedTTLAndTimestamp().
371 $parts = parse_url($signed_path);
372 $path = $parts[
'path'];
374 parse_str(
$query, $query_array);
375 $token = $override_token ? $override_token : $query_array[
'il_wac_token'];
376 $ttl = (int) $query_array[
'il_wac_ttl'];
377 $ts = (int) $query_array[
'il_wac_ts'];
378 $path_with_token =
$path .
'?il_wac_token=' .
$token;
380 $modified_ttl = $ttl + $add_ttl;
381 $modified_ts = $ts + $add_timestamp;
383 return $path_with_token .
'&il_wac_ttl=' . $modified_ttl .
'&il_wac_ts=' . $modified_ts;
static signFile($path_to_file)
static setTokenMaxLifetimeInSeconds($token_max_lifetime_in_seconds)
◆ setUp()
ilWACTokenTest::setUp |
( |
| ) |
|
|
protected |
Setup.
Definition at line 103 of file ilWACTokenTest.php.
References $c, $container, $GLOBALS, ILIAS\FileDelivery\http(), and ilWACToken\setSALT().
107 $this->root = vfs\vfsStream::setup(
'ilias.de');
108 $this->file_one = vfs\vfsStream::newFile(
'data/client_name/mobs/mm_123/dummy.jpg')
109 ->at($this->root)->setContent(
'dummy');
110 $this->file_one_subfolder = vfs\vfsStream::newFile(
'data/client_name/mobs/mm_123/mobile/dummy.jpg')
111 ->at($this->root)->setContent(
'dummy');
112 $this->file_one_subfolder_two = vfs\vfsStream::newFile(
'data/client_name/mobs/mm_123/mobile/device/dummy.jpg')
113 ->at($this->root)->setContent(
'dummy');
114 $this->file_two = vfs\vfsStream::newFile(
'data/client_name/mobs/mm_123/dummy2.jpg')
115 ->at($this->root)->setContent(
'dummy2');
116 $this->file_three = vfs\vfsStream::newFile(
'data/client_name/mobs/mm_124/dummy.jpg')
117 ->at($this->root)->setContent(
'dummy');
118 $this->file_four = vfs\vfsStream::newFile(
'data/client_name/sec/ilBlog/mm_124/dummy.jpg')
119 ->at($this->root)->setContent(
'dummy');
124 return Mockery::mock(GlobalHttpState::class);
132 $this->cookieFactory = Mockery::mock(CookieFactoryImpl::class);
135 $this->cookieFactory->shouldDeferMissing();
static http()
Fetches the global http state from ILIAS.
$GLOBALS['JPEG_Segment_Names']
Global Variable: XMP_tag_captions.
◆ testCookieGeneration()
ilWACTokenTest::testCookieGeneration |
( |
| ) |
|
Definition at line 196 of file ilWACTokenTest.php.
References $response, ILIAS\HTTP\Cookies\Cookie\getName(), ILIAS\FileDelivery\http(), Sabre\Event\on(), and ilWACSignedPath\signFolderOfStartFile().
198 $expected_cookies = [
199 '19ab58dae37d8d8cf931727c35514642',
200 '19ab58dae37d8d8cf931727c35514642ts',
201 '19ab58dae37d8d8cf931727c35514642ttl',
204 $cookieJar = Mockery::mock(CookieJar::class);
206 $response = Mockery::mock(ResponseInterface::class);
209 ->shouldReceive(
'response')
215 ->shouldReceive(
'saveResponse')
220 ->shouldReceive(
'with')
223 return strcmp($cookie->
getName(), $expected_cookies[0]) === 0;
228 ->shouldReceive(
'with')
231 return strcmp($cookie->
getName(), $expected_cookies[1]) === 0;
236 ->shouldReceive(
'with')
239 return strcmp($cookie->
getName(), $expected_cookies[2]) === 0;
244 ->shouldReceive(
'renderIntoResponseHeader')
249 $this->
http->shouldReceive(
'cookieJar')
252 ->andReturn($cookieJar);
on($eventName, callable $callBack, $priority=100)
Subscribe to an event.
static signFolderOfStartFile($start_file_path)
static http()
Fetches the global http state from ILIAS.
◆ testFileToken()
ilWACTokenTest::testFileToken |
( |
| ) |
|
Definition at line 264 of file ilWACTokenTest.php.
References ilWACSignedPath\getTokenMaxLifetimeInSeconds(), ILIAS\FileDelivery\http(), ilWACSignedPath\setTokenMaxLifetimeInSeconds(), and ilWACSignedPath\signFile().
273 $this->assertTrue($ilWACSignedPath->isSignedPath());
274 $this->assertTrue($ilWACSignedPath->isSignedPathValid());
275 $this->assertEquals($ilWACSignedPath->getPathObject()->getClient(), self::CLIENT_NAME);
276 $this->assertFalse($ilWACSignedPath->getPathObject()->isInSecFolder());
277 $this->assertTrue($ilWACSignedPath->getPathObject()->isImage());
278 $this->assertFalse($ilWACSignedPath->getPathObject()->isAudio());
279 $this->assertFalse($ilWACSignedPath->getPathObject()->isVideo());
280 $this->assertTrue($ilWACSignedPath->getPathObject()->hasTimestamp());
281 $this->assertTrue($ilWACSignedPath->getPathObject()->hasToken());
285 sleep($lifetime + self::ADDITIONAL_TIME);
287 $this->assertTrue($ilWACSignedPath->isSignedPath());
288 $this->assertFalse($ilWACSignedPath->isSignedPathValid());
static http()
Fetches the global http state from ILIAS.
static signFile($path_to_file)
static setTokenMaxLifetimeInSeconds($token_max_lifetime_in_seconds)
static getTokenMaxLifetimeInSeconds()
◆ testModifiedTimestampAddTime()
ilWACTokenTest::testModifiedTimestampAddTime |
( |
| ) |
|
Definition at line 309 of file ilWACTokenTest.php.
References getModifiedSignedPath(), and ILIAS\FileDelivery\http().
314 $this->assertTrue($ilWACSignedPath->isSignedPath());
315 $this->assertFalse($ilWACSignedPath->isSignedPathValid());
getModifiedSignedPath($add_ttl=0, $add_timestamp=0, $override_token=null)
static http()
Fetches the global http state from ILIAS.
◆ testModifiedTimestampNoMod()
ilWACTokenTest::testModifiedTimestampNoMod |
( |
| ) |
|
Definition at line 296 of file ilWACTokenTest.php.
References getModifiedSignedPath(), and ILIAS\FileDelivery\http().
301 $this->assertTrue($ilWACSignedPath->isSignedPath());
302 $this->assertTrue($ilWACSignedPath->isSignedPathValid());
getModifiedSignedPath($add_ttl=0, $add_timestamp=0, $override_token=null)
static http()
Fetches the global http state from ILIAS.
◆ testModifiedTimestampSubTime()
ilWACTokenTest::testModifiedTimestampSubTime |
( |
| ) |
|
Definition at line 319 of file ilWACTokenTest.php.
References getModifiedSignedPath(), and ILIAS\FileDelivery\http().
324 * -1, 0)), $this->
http, $this->cookieFactory);
325 $this->assertTrue($ilWACSignedPath->isSignedPath());
326 $this->assertFalse($ilWACSignedPath->isSignedPathValid());
getModifiedSignedPath($add_ttl=0, $add_timestamp=0, $override_token=null)
static http()
Fetches the global http state from ILIAS.
◆ testModifiedToken()
ilWACTokenTest::testModifiedToken |
( |
| ) |
|
Definition at line 350 of file ilWACTokenTest.php.
References getModifiedSignedPath(), and ILIAS\FileDelivery\http().
355 $this->assertTrue($ilWACSignedPath->isSignedPath());
356 $this->assertFalse($ilWACSignedPath->isSignedPathValid());
getModifiedSignedPath($add_ttl=0, $add_timestamp=0, $override_token=null)
static http()
Fetches the global http state from ILIAS.
◆ testModifiedTTL()
ilWACTokenTest::testModifiedTTL |
( |
| ) |
|
Definition at line 330 of file ilWACTokenTest.php.
References getModifiedSignedPath(), and ILIAS\FileDelivery\http().
335 $this->assertTrue($ilWACSignedPath->isSignedPath());
336 $this->assertFalse($ilWACSignedPath->isSignedPathValid());
getModifiedSignedPath($add_ttl=0, $add_timestamp=0, $override_token=null)
static http()
Fetches the global http state from ILIAS.
◆ testModifiedTTLAndTimestamp()
ilWACTokenTest::testModifiedTTLAndTimestamp |
( |
| ) |
|
Definition at line 340 of file ilWACTokenTest.php.
References getModifiedSignedPath(), and ILIAS\FileDelivery\http().
345 $this->assertTrue($ilWACSignedPath->isSignedPath());
346 $this->assertFalse($ilWACSignedPath->isSignedPathValid());
getModifiedSignedPath($add_ttl=0, $add_timestamp=0, $override_token=null)
static http()
Fetches the global http state from ILIAS.
◆ testSomeBasics()
ilWACTokenTest::testSomeBasics |
( |
| ) |
|
Definition at line 165 of file ilWACTokenTest.php.
References $query, and ILIAS\FileDelivery\http().
169 .
$query), $this->
http, $this->cookieFactory);
171 $this->assertEquals(
'dummy.jpg', $ilWACSignedPath->getPathObject()->getFileName());
172 $this->assertEquals(
$query, $ilWACSignedPath->getPathObject()->getQuery());
173 $this->assertEquals(
'./data/' . self::CLIENT_NAME
174 .
'/sec/ilBlog/mm_124/', $ilWACSignedPath->getPathObject()
176 $this->assertEquals(
'ilBlog', $ilWACSignedPath->getPathObject()->getSecurePathId());
177 $this->assertFalse($ilWACSignedPath->getPathObject()->isStreamable());
static http()
Fetches the global http state from ILIAS.
◆ testTokenGeneration()
ilWACTokenTest::testTokenGeneration |
( |
| ) |
|
Definition at line 181 of file ilWACTokenTest.php.
References ilWACToken\generateToken(), and ilWACToken\getSALT().
183 $ilWacPath =
new ilWacPath($this->file_four->url());
184 $ilWACToken =
new ilWACToken($ilWacPath->getPath(), self::CLIENT_NAME, 123456, 20);
186 $this->assertEquals(
'SALT-client_name-123456-20', $ilWACToken->getRawToken());
187 $this->assertEquals(
'./data/client_name/sec/ilBlog/mm_124/dummy.jpg', $ilWACToken->getId());
190 $ilWACToken =
new ilWACToken($ilWacPath->getPath(), self::CLIENT_NAME, 123456, 20);
191 $this->assertEquals(
'b541e2bae42ee222f9be959b7ad2ab8844cbb05b', $ilWACToken->getToken());
192 $this->assertEquals(
'e45b98f267dc891c8206c844f7df29ea', $ilWACToken->getHashedId());
◆ testWithoutSigning()
ilWACTokenTest::testWithoutSigning |
( |
| ) |
|
Definition at line 141 of file ilWACTokenTest.php.
References ILIAS\FileDelivery\http().
145 $cookieJar = Mockery::mock(CookieJar::class);
148 ->shouldReceive(
'get')
153 $this->
http->shouldReceive(
'cookieJar')
156 ->andReturn($cookieJar);
158 $this->assertFalse($ilWACSignedPath->isSignedPath());
159 $this->assertFalse($ilWACSignedPath->isSignedPathValid());
160 $this->assertFalse($ilWACSignedPath->isFolderSigned());
161 $this->assertFalse($ilWACSignedPath->isFolderTokenValid());
static http()
Fetches the global http state from ILIAS.
◆ $backupGlobals
ilWACTokenTest::$backupGlobals = false |
|
protected |
◆ $cookieFactory
◆ $file_four
ilWACTokenTest::$file_four |
|
protected |
◆ $file_one
ilWACTokenTest::$file_one |
|
protected |
◆ $file_one_subfolder
ilWACTokenTest::$file_one_subfolder |
|
protected |
◆ $file_one_subfolder_two
ilWACTokenTest::$file_one_subfolder_two |
|
protected |
◆ $file_three
ilWACTokenTest::$file_three |
|
protected |
◆ $file_two
ilWACTokenTest::$file_two |
|
protected |
◆ $http
◆ $root
◆ ADDITIONAL_TIME
const ilWACTokenTest::ADDITIONAL_TIME = 1 |
◆ CLIENT_NAME
const ilWACTokenTest::CLIENT_NAME = 'client_name' |
◆ LIFETIME
const ilWACTokenTest::LIFETIME = 2 |
◆ SALT
const ilWACTokenTest::SALT = 'SALT' |
The documentation for this class was generated from the following file: