ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
ilWACTokenTest Class Reference

TestCase for the ilWACTokenTest. More...

+ Inheritance diagram for ilWACTokenTest:
+ Collaboration diagram for ilWACTokenTest:

Public Member Functions

 testWithoutSigning ()
 
 testSomeBasics ()
 
 testTokenGeneration ()
 
 testCookieGeneration ()
 
 testFileToken ()
 
 testModifiedTimestampNoMod ()
 @Test More...
 
 testModifiedTimestampAddTime ()
 @Test More...
 
 testModifiedTimestampSubTime ()
 
 testModifiedTTL ()
 
 testModifiedTTLAndTimestamp ()
 
 testModifiedToken ()
 

Data Fields

const ADDITIONAL_TIME = 1
 
const LIFETIME = 2
 
const SALT = 'SALT'
 
const CLIENT_NAME = 'client_name'
 

Protected Member Functions

 setUp ()
 Setup. More...
 
 getModifiedSignedPath ($add_ttl=0, $add_timestamp=0, $override_token=null)
 

Protected Attributes

 $backupGlobals = false
 
 $file_one
 
 $file_one_subfolder
 
 $file_one_subfolder_two
 
 $file_two
 
 $file_three
 
 $file_four
 
 $root
 

Private Attributes

 $http
 
 $cookieFactory
 

Detailed Description

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

@runTestsInSeparateProcesses @preserveGlobalState disabled @backupGlobals disabled @backupStaticAttributes disabled

Definition at line 54 of file ilWACTokenTest.php.

Member Function Documentation

◆ 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 361 of file ilWACTokenTest.php.

362 {
364 $signed_path = ilWACSignedPath::signFile($this->file_one->url());
365
366 $parts = parse_url($signed_path);
367 $path = $parts['path'];
368 $query = $parts['query'];
369 parse_str($query, $query_array);
370 $token = $override_token ? $override_token : $query_array['il_wac_token'];
371 $ttl = (int) $query_array['il_wac_ttl'];
372 $ts = (int) $query_array['il_wac_ts'];
373 $path_with_token = $path . '?il_wac_token=' . $token;
374
375 $modified_ttl = $ttl + $add_ttl;
376 $modified_ts = $ts + $add_timestamp;
377
378 return $path_with_token . '&il_wac_ttl=' . $modified_ttl . '&il_wac_ts=' . $modified_ts;
379 }
static signFile($path_to_file)
static setTokenMaxLifetimeInSeconds($token_max_lifetime_in_seconds)
$query
$token
Definition: xapitoken.php:57

References $query, $token, ilWACSignedPath\setTokenMaxLifetimeInSeconds(), and ilWACSignedPath\signFile().

Referenced by testModifiedTimestampAddTime(), testModifiedTimestampNoMod(), testModifiedTimestampSubTime(), testModifiedToken(), testModifiedTTL(), and testModifiedTTLAndTimestamp().

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

◆ setUp()

ilWACTokenTest::setUp ( )
protected

Setup.

Definition at line 105 of file ilWACTokenTest.php.

105 : void
106 {
107 parent::setUp();
108
109 $this->root = vfs\vfsStream::setup('ilias.de');
110 $this->file_one = vfs\vfsStream::newFile('data/client_name/mobs/mm_123/dummy.jpg')
111 ->at($this->root)->setContent('dummy');
112 $this->file_one_subfolder = vfs\vfsStream::newFile('data/client_name/mobs/mm_123/mobile/dummy.jpg')
113 ->at($this->root)->setContent('dummy');
114 $this->file_one_subfolder_two = vfs\vfsStream::newFile('data/client_name/mobs/mm_123/mobile/device/dummy.jpg')
115 ->at($this->root)->setContent('dummy');
116 $this->file_two = vfs\vfsStream::newFile('data/client_name/mobs/mm_123/dummy2.jpg')
117 ->at($this->root)->setContent('dummy2');
118 $this->file_three = vfs\vfsStream::newFile('data/client_name/mobs/mm_124/dummy.jpg')
119 ->at($this->root)->setContent('dummy');
120 $this->file_four = vfs\vfsStream::newFile('data/client_name/sec/ilBlog/mm_124/dummy.jpg')
121 ->at($this->root)->setContent('dummy');
122
123 //setup container for HttpServiceAware classes
124 $container = new \ILIAS\DI\Container();
125 $container['http'] = function ($c) {
126 return Mockery::mock(GlobalHttpState::class);
127 };
128
129 $this->http = $container['http'];
130
131
132 $GLOBALS["DIC"] = $container;
133
134 $this->cookieFactory = Mockery::mock(CookieFactoryImpl::class);
135
136 //because the cookie have no logic except cloning it self therefore it should be no problem to defer the function calls
137 $this->cookieFactory->shouldDeferMissing();
138
139 ilWACToken::setSALT(self::SALT);
140 }
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
Definition: PEAR.php:64
static setSALT($salt)
static http()
Fetches the global http state from ILIAS.
$container
Definition: wac.php:13

References Vendor\Package\$c, $container, $GLOBALS, ILIAS\FileDelivery\http(), and ilWACToken\setSALT().

+ Here is the call graph for this function:

◆ testCookieGeneration()

ilWACTokenTest::testCookieGeneration ( )

Definition at line 206 of file ilWACTokenTest.php.

207 {
208 $this->markTestSkipped('unable to use http cookies at this point');
209 $expected_cookies = [
210 '19ab58dae37d8d8cf931727c35514642',
211 '19ab58dae37d8d8cf931727c35514642ts',
212 '19ab58dae37d8d8cf931727c35514642ttl',
213 ];
214
215 $cookieJar = Mockery::mock(CookieJar::class);
216
217 $response = Mockery::mock(ResponseInterface::class);
218
219 $this->http
220 ->shouldReceive('response')
221 ->times(3)
222 ->withNoArgs()
223 ->andReturn($response)
224 ->getMock();
225
226 $cookieJar
227 ->shouldReceive('with')
228 ->times(3)
229 ->with(new CookieWrapper(SetCookie::create('')))
230 ->andReturnSelf()
231 ->getMock()
232
233 ->shouldReceive('with')
234 ->times(3)
235 ->with(new CookieWrapper(SetCookie::create('')))
236 ->andReturnSelf()
237 ->getMock()
238
239 ->shouldReceive('with')
240 ->times(3)
241 ->with(new CookieWrapper(SetCookie::create('')))
242 ->andReturnSelf()
243 ->getMock();
244
245 $this->http->shouldReceive('cookieJar')
246 ->withNoArgs()
247 ->andReturn($cookieJar);
248
249 ilWACSignedPath::signFolderOfStartFile($this->file_one->url());
250
251 // in subfolder
252 ilWACSignedPath::signFolderOfStartFile($this->file_one_subfolder->url());
253
254 // in sub-subfolder
255 ilWACSignedPath::signFolderOfStartFile($this->file_one_subfolder->url());
256 }
static signFolderOfStartFile($start_file_path)
$response

References $response, ILIAS\FileDelivery\http(), and ilWACSignedPath\signFolderOfStartFile().

+ Here is the call graph for this function:

◆ testFileToken()

ilWACTokenTest::testFileToken ( )

Definition at line 259 of file ilWACTokenTest.php.

260 {
263
264 // Request within lifetime
265 $signed_path = ilWACSignedPath::signFile($this->file_one->url());
266 $ilWACSignedPath = new ilWACSignedPath(new ilWACPath($signed_path), $this->http, $this->cookieFactory);
267
268 $this->assertTrue($ilWACSignedPath->isSignedPath());
269 $this->assertTrue($ilWACSignedPath->isSignedPathValid());
270 $this->assertEquals($ilWACSignedPath->getPathObject()->getClient(), self::CLIENT_NAME);
271 $this->assertFalse($ilWACSignedPath->getPathObject()->isInSecFolder());
272 $this->assertTrue($ilWACSignedPath->getPathObject()->isImage());
273 $this->assertFalse($ilWACSignedPath->getPathObject()->isAudio());
274 $this->assertFalse($ilWACSignedPath->getPathObject()->isVideo());
275 $this->assertTrue($ilWACSignedPath->getPathObject()->hasTimestamp());
276 $this->assertTrue($ilWACSignedPath->getPathObject()->hasToken());
277
278 // Request after lifetime
279 $signed_path = ilWACSignedPath::signFile($this->file_four->url());
280 sleep($lifetime + self::ADDITIONAL_TIME);
281 $ilWACSignedPath = new ilWACSignedPath(new ilWACPath($signed_path), $this->http, $this->cookieFactory);
282 $this->assertTrue($ilWACSignedPath->isSignedPath());
283 $this->assertFalse($ilWACSignedPath->isSignedPathValid());
284 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class ilWACSignedPath.
static getTokenMaxLifetimeInSeconds()

References ilWACSignedPath\getTokenMaxLifetimeInSeconds(), ILIAS\FileDelivery\http(), ilWACSignedPath\setTokenMaxLifetimeInSeconds(), and ilWACSignedPath\signFile().

+ Here is the call graph for this function:

◆ testModifiedTimestampAddTime()

ilWACTokenTest::testModifiedTimestampAddTime ( )

@Test

Definition at line 304 of file ilWACTokenTest.php.

305 {
306 // self::markTestSkipped("WIP");
307 // return;
308 $ilWACSignedPath = new ilWACSignedPath(new ilWACPath($this->getModifiedSignedPath(self::ADDITIONAL_TIME, 0)), $this->http, $this->cookieFactory);
309 $this->assertTrue($ilWACSignedPath->isSignedPath());
310 $this->assertFalse($ilWACSignedPath->isSignedPathValid());
311 }
getModifiedSignedPath($add_ttl=0, $add_timestamp=0, $override_token=null)

References getModifiedSignedPath(), and ILIAS\FileDelivery\http().

+ Here is the call graph for this function:

◆ testModifiedTimestampNoMod()

ilWACTokenTest::testModifiedTimestampNoMod ( )

@Test

Definition at line 291 of file ilWACTokenTest.php.

292 {
293 // self::markTestSkipped("WIP");
294 // return;
295 $ilWACSignedPath = new ilWACSignedPath(new ilWACPath($this->getModifiedSignedPath(0, 0)), $this->http, $this->cookieFactory);
296 $this->assertTrue($ilWACSignedPath->isSignedPath());
297 $this->assertTrue($ilWACSignedPath->isSignedPathValid());
298 }

References getModifiedSignedPath(), and ILIAS\FileDelivery\http().

+ Here is the call graph for this function:

◆ testModifiedTimestampSubTime()

ilWACTokenTest::testModifiedTimestampSubTime ( )

Definition at line 314 of file ilWACTokenTest.php.

315 {
316 // self::markTestSkipped("WIP");
317 // return;
318 $ilWACSignedPath = new ilWACSignedPath(new ilWACPath($this->getModifiedSignedPath(self::ADDITIONAL_TIME
319 * -1, 0)), $this->http, $this->cookieFactory);
320 $this->assertTrue($ilWACSignedPath->isSignedPath());
321 $this->assertFalse($ilWACSignedPath->isSignedPathValid());
322 }

References getModifiedSignedPath(), and ILIAS\FileDelivery\http().

+ Here is the call graph for this function:

◆ testModifiedToken()

ilWACTokenTest::testModifiedToken ( )

Definition at line 345 of file ilWACTokenTest.php.

346 {
347 // self::markTestSkipped("WIP");
348 // return;
349 $ilWACSignedPath = new ilWACSignedPath(new ilWACPath($this->getModifiedSignedPath(0, 0, md5('LOREM'))), $this->http, $this->cookieFactory);
350 $this->assertTrue($ilWACSignedPath->isSignedPath());
351 $this->assertFalse($ilWACSignedPath->isSignedPathValid());
352 }

References getModifiedSignedPath(), and ILIAS\FileDelivery\http().

+ Here is the call graph for this function:

◆ testModifiedTTL()

ilWACTokenTest::testModifiedTTL ( )

Definition at line 325 of file ilWACTokenTest.php.

326 {
327 // self::markTestSkipped("WIP");
328 // return;
329 $ilWACSignedPath = new ilWACSignedPath(new ilWACPath($this->getModifiedSignedPath(0, 1)), $this->http, $this->cookieFactory);
330 $this->assertTrue($ilWACSignedPath->isSignedPath());
331 $this->assertFalse($ilWACSignedPath->isSignedPathValid());
332 }

References getModifiedSignedPath(), and ILIAS\FileDelivery\http().

+ Here is the call graph for this function:

◆ testModifiedTTLAndTimestamp()

ilWACTokenTest::testModifiedTTLAndTimestamp ( )

Definition at line 335 of file ilWACTokenTest.php.

336 {
337 // self::markTestSkipped("WIP");
338 // return;
339 $ilWACSignedPath = new ilWACSignedPath(new ilWACPath($this->getModifiedSignedPath(1, 1)), $this->http, $this->cookieFactory);
340 $this->assertTrue($ilWACSignedPath->isSignedPath());
341 $this->assertFalse($ilWACSignedPath->isSignedPathValid());
342 }

References getModifiedSignedPath(), and ILIAS\FileDelivery\http().

+ Here is the call graph for this function:

◆ testSomeBasics()

ilWACTokenTest::testSomeBasics ( )

Definition at line 175 of file ilWACTokenTest.php.

176 {
177 $query = 'myparam=1234';
178 $ilWACSignedPath = new ilWACSignedPath(new ilWACPath($this->file_four->url() . '?'
179 . $query), $this->http, $this->cookieFactory);
180
181 $this->assertEquals('dummy.jpg', $ilWACSignedPath->getPathObject()->getFileName());
182 $this->assertEquals($query, $ilWACSignedPath->getPathObject()->getQuery());
183 $this->assertEquals('./data/' . self::CLIENT_NAME
184 . '/sec/ilBlog/mm_124/', $ilWACSignedPath->getPathObject()
185 ->getSecurePath());
186 $this->assertEquals('ilBlog', $ilWACSignedPath->getPathObject()->getSecurePathId());
187 $this->assertFalse($ilWACSignedPath->getPathObject()->isStreamable());
188 }

References $query.

◆ testTokenGeneration()

ilWACTokenTest::testTokenGeneration ( )

Definition at line 191 of file ilWACTokenTest.php.

192 {
193 $ilWacPath = new ilWacPath($this->file_four->url());
194 $ilWACToken = new ilWACToken($ilWacPath->getPath(), self::CLIENT_NAME, 123456, 20);
195 $ilWACToken->generateToken();
196 $this->assertEquals('SALT-client_name-123456-20', $ilWACToken->getRawToken());
197 $this->assertEquals('./data/client_name/sec/ilBlog/mm_124/dummy.jpg', $ilWACToken->getId());
198
199 $this->assertEquals(self::SALT, ilWACToken::getSALT());
200 $ilWACToken = new ilWACToken($ilWacPath->getPath(), self::CLIENT_NAME, 123456, 20);
201 $this->assertEquals('b541e2bae42ee222f9be959b7ad2ab8844cbb05b', $ilWACToken->getToken());
202 $this->assertEquals('e45b98f267dc891c8206c844f7df29ea', $ilWACToken->getHashedId());
203 }
Class ilWACToken.
static getSALT()

References ilWACToken\getSALT().

+ Here is the call graph for this function:

◆ testWithoutSigning()

ilWACTokenTest::testWithoutSigning ( )

Definition at line 143 of file ilWACTokenTest.php.

144 {
145 $ilWACSignedPath = new ilWACSignedPath(new ilWACPath($this->file_one->url()), $this->http, $this->cookieFactory);
146
147 $cookieJar = Mockery::mock(CookieJar::class);
148
149 $cookieJar
150 ->shouldReceive('getAll')
151 ->times(2)
152 ->withAnyArgs()
153 ->andReturn([]);
154
155 $this->http->shouldReceive('cookieJar')
156 ->twice()
157 ->withNoArgs()
158 ->andReturn($cookieJar);
159
160 $request = Mockery::mock(Psr\Http\Message\RequestInterface::class);
161 $request->shouldReceive('getCookieParams')
162 ->andReturn([]);
163
164 $this->http->shouldReceive('request')
165 ->withNoArgs()
166 ->andReturn($request);
167
168 $this->assertFalse($ilWACSignedPath->isSignedPath());
169 $this->assertFalse($ilWACSignedPath->isSignedPathValid());
170 $this->assertFalse($ilWACSignedPath->isFolderSigned());
171 $this->assertFalse($ilWACSignedPath->isFolderTokenValid());
172 }

References ILIAS\FileDelivery\http().

+ Here is the call graph for this function:

Field Documentation

◆ $backupGlobals

ilWACTokenTest::$backupGlobals = false
protected

Definition at line 63 of file ilWACTokenTest.php.

◆ $cookieFactory

CookieFactory MockInterface ilWACTokenTest::$cookieFactory
private

Definition at line 99 of file ilWACTokenTest.php.

◆ $file_four

ilWACTokenTest::$file_four
protected

Definition at line 87 of file ilWACTokenTest.php.

◆ $file_one

ilWACTokenTest::$file_one
protected

Definition at line 67 of file ilWACTokenTest.php.

◆ $file_one_subfolder

ilWACTokenTest::$file_one_subfolder
protected

Definition at line 71 of file ilWACTokenTest.php.

◆ $file_one_subfolder_two

ilWACTokenTest::$file_one_subfolder_two
protected

Definition at line 75 of file ilWACTokenTest.php.

◆ $file_three

ilWACTokenTest::$file_three
protected

Definition at line 83 of file ilWACTokenTest.php.

◆ $file_two

ilWACTokenTest::$file_two
protected

Definition at line 79 of file ilWACTokenTest.php.

◆ $http

GlobalHttpState MockInterface ilWACTokenTest::$http
private

Definition at line 95 of file ilWACTokenTest.php.

◆ $root

ilWACTokenTest::$root
protected

Definition at line 91 of file ilWACTokenTest.php.

◆ ADDITIONAL_TIME

const ilWACTokenTest::ADDITIONAL_TIME = 1

Definition at line 56 of file ilWACTokenTest.php.

◆ CLIENT_NAME

const ilWACTokenTest::CLIENT_NAME = 'client_name'

Definition at line 59 of file ilWACTokenTest.php.

◆ LIFETIME

const ilWACTokenTest::LIFETIME = 2

Definition at line 57 of file ilWACTokenTest.php.

◆ SALT

const ilWACTokenTest::SALT = 'SALT'

Definition at line 58 of file ilWACTokenTest.php.


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