ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
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 ()
 
 testModifiedTimestampAddTime ()
 
 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

disabled disabled disabled

Definition at line 48 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 355 of file ilWACTokenTest.php.

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

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

356  {
358  $signed_path = ilWACSignedPath::signFile($this->file_one->url());
359 
360  $parts = parse_url($signed_path);
361  $path = $parts['path'];
362  $query = $parts['query'];
363  parse_str($query, $query_array);
364  $token = $override_token ? $override_token : $query_array['il_wac_token'];
365  $ttl = (int) $query_array['il_wac_ttl'];
366  $ts = (int) $query_array['il_wac_ts'];
367  $path_with_token = $path . '?il_wac_token=' . $token;
368 
369  $modified_ttl = $ttl + $add_ttl;
370  $modified_ts = $ts + $add_timestamp;
371 
372  return $path_with_token . '&il_wac_ttl=' . $modified_ttl . '&il_wac_ts=' . $modified_ts;
373  }
$token
Definition: xapitoken.php:52
$query
static signFile($path_to_file)
static setTokenMaxLifetimeInSeconds($token_max_lifetime_in_seconds)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setUp()

ilWACTokenTest::setUp ( )
protected

Setup.

Definition at line 99 of file ilWACTokenTest.php.

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

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

◆ testCookieGeneration()

ilWACTokenTest::testCookieGeneration ( )

Definition at line 200 of file ilWACTokenTest.php.

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

201  {
202  $this->markTestSkipped('unable to use http cookies at this point');
203  $expected_cookies = [
204  '19ab58dae37d8d8cf931727c35514642',
205  '19ab58dae37d8d8cf931727c35514642ts',
206  '19ab58dae37d8d8cf931727c35514642ttl',
207  ];
208 
209  $cookieJar = Mockery::mock(CookieJar::class);
210 
211  $response = Mockery::mock(ResponseInterface::class);
212 
213  $this->http
214  ->shouldReceive('response')
215  ->times(3)
216  ->withNoArgs()
217  ->andReturn($response)
218  ->getMock();
219 
220  $cookieJar
221  ->shouldReceive('with')
222  ->times(3)
223  ->with(new CookieWrapper(SetCookie::create('')))
224  ->andReturnSelf()
225  ->getMock()
226 
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  $this->http->shouldReceive('cookieJar')
240  ->withNoArgs()
241  ->andReturn($cookieJar);
242 
243  ilWACSignedPath::signFolderOfStartFile($this->file_one->url());
244 
245  // in subfolder
246  ilWACSignedPath::signFolderOfStartFile($this->file_one_subfolder->url());
247 
248  // in sub-subfolder
249  ilWACSignedPath::signFolderOfStartFile($this->file_one_subfolder->url());
250  }
static signFolderOfStartFile($start_file_path)
static http()
Fetches the global http state from ILIAS.
$response
+ Here is the call graph for this function:

◆ testFileToken()

ilWACTokenTest::testFileToken ( )

Definition at line 253 of file ilWACTokenTest.php.

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

254  {
257 
258  // Request within lifetime
259  $signed_path = ilWACSignedPath::signFile($this->file_one->url());
260  $ilWACSignedPath = new ilWACSignedPath(new ilWACPath($signed_path, false), $this->http, $this->cookieFactory);
261 
262  $this->assertTrue($ilWACSignedPath->isSignedPath());
263  $this->assertTrue($ilWACSignedPath->isSignedPathValid());
264  $this->assertEquals($ilWACSignedPath->getPathObject()->getClient(), self::CLIENT_NAME);
265  $this->assertFalse($ilWACSignedPath->getPathObject()->isInSecFolder());
266  $this->assertTrue($ilWACSignedPath->getPathObject()->isImage());
267  $this->assertFalse($ilWACSignedPath->getPathObject()->isAudio());
268  $this->assertFalse($ilWACSignedPath->getPathObject()->isVideo());
269  $this->assertTrue($ilWACSignedPath->getPathObject()->hasTimestamp());
270  $this->assertTrue($ilWACSignedPath->getPathObject()->hasToken());
271 
272  // Request after lifetime
273  $signed_path = ilWACSignedPath::signFile($this->file_four->url());
274  sleep($lifetime + self::ADDITIONAL_TIME);
275  $ilWACSignedPath = new ilWACSignedPath(new ilWACPath($signed_path, false), $this->http, $this->cookieFactory);
276  $this->assertTrue($ilWACSignedPath->isSignedPath());
277  $this->assertFalse($ilWACSignedPath->isSignedPathValid());
278  }
const CLIENT_NAME
Definition: constants.php:40
Class ilWACPath.
static http()
Fetches the global http state from ILIAS.
Class ilWACSignedPath.
static signFile($path_to_file)
static setTokenMaxLifetimeInSeconds($token_max_lifetime_in_seconds)
static getTokenMaxLifetimeInSeconds()
+ Here is the call graph for this function:

◆ testModifiedTimestampAddTime()

ilWACTokenTest::testModifiedTimestampAddTime ( )

Definition at line 298 of file ilWACTokenTest.php.

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

299  {
300  // self::markTestSkipped("WIP");
301  // return;
302  $ilWACSignedPath = new ilWACSignedPath(new ilWACPath($this->getModifiedSignedPath(self::ADDITIONAL_TIME, 0), false), $this->http, $this->cookieFactory);
303  $this->assertTrue($ilWACSignedPath->isSignedPath());
304  $this->assertFalse($ilWACSignedPath->isSignedPathValid());
305  }
getModifiedSignedPath($add_ttl=0, $add_timestamp=0, $override_token=null)
Class ilWACPath.
static http()
Fetches the global http state from ILIAS.
Class ilWACSignedPath.
+ Here is the call graph for this function:

◆ testModifiedTimestampNoMod()

ilWACTokenTest::testModifiedTimestampNoMod ( )

Definition at line 285 of file ilWACTokenTest.php.

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

286  {
287  // self::markTestSkipped("WIP");
288  // return;
289  $ilWACSignedPath = new ilWACSignedPath(new ilWACPath($this->getModifiedSignedPath(0, 0), false), $this->http, $this->cookieFactory);
290  $this->assertTrue($ilWACSignedPath->isSignedPath());
291  $this->assertTrue($ilWACSignedPath->isSignedPathValid());
292  }
getModifiedSignedPath($add_ttl=0, $add_timestamp=0, $override_token=null)
Class ilWACPath.
static http()
Fetches the global http state from ILIAS.
Class ilWACSignedPath.
+ Here is the call graph for this function:

◆ testModifiedTimestampSubTime()

ilWACTokenTest::testModifiedTimestampSubTime ( )

Definition at line 308 of file ilWACTokenTest.php.

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

309  {
310  // self::markTestSkipped("WIP");
311  // return;
312  $ilWACSignedPath = new ilWACSignedPath(new ilWACPath($this->getModifiedSignedPath(self::ADDITIONAL_TIME
313  * -1, 0), false), $this->http, $this->cookieFactory);
314  $this->assertTrue($ilWACSignedPath->isSignedPath());
315  $this->assertFalse($ilWACSignedPath->isSignedPathValid());
316  }
getModifiedSignedPath($add_ttl=0, $add_timestamp=0, $override_token=null)
Class ilWACPath.
static http()
Fetches the global http state from ILIAS.
Class ilWACSignedPath.
+ Here is the call graph for this function:

◆ testModifiedToken()

ilWACTokenTest::testModifiedToken ( )

Definition at line 339 of file ilWACTokenTest.php.

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

340  {
341  // self::markTestSkipped("WIP");
342  // return;
343  $ilWACSignedPath = new ilWACSignedPath(new ilWACPath($this->getModifiedSignedPath(0, 0, md5('LOREM')), false), $this->http, $this->cookieFactory);
344  $this->assertTrue($ilWACSignedPath->isSignedPath());
345  $this->assertFalse($ilWACSignedPath->isSignedPathValid());
346  }
getModifiedSignedPath($add_ttl=0, $add_timestamp=0, $override_token=null)
Class ilWACPath.
static http()
Fetches the global http state from ILIAS.
Class ilWACSignedPath.
+ Here is the call graph for this function:

◆ testModifiedTTL()

ilWACTokenTest::testModifiedTTL ( )

Definition at line 319 of file ilWACTokenTest.php.

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

320  {
321  // self::markTestSkipped("WIP");
322  // return;
323  $ilWACSignedPath = new ilWACSignedPath(new ilWACPath($this->getModifiedSignedPath(0, 1), false), $this->http, $this->cookieFactory);
324  $this->assertTrue($ilWACSignedPath->isSignedPath());
325  $this->assertFalse($ilWACSignedPath->isSignedPathValid());
326  }
getModifiedSignedPath($add_ttl=0, $add_timestamp=0, $override_token=null)
Class ilWACPath.
static http()
Fetches the global http state from ILIAS.
Class ilWACSignedPath.
+ Here is the call graph for this function:

◆ testModifiedTTLAndTimestamp()

ilWACTokenTest::testModifiedTTLAndTimestamp ( )

Definition at line 329 of file ilWACTokenTest.php.

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

330  {
331  // self::markTestSkipped("WIP");
332  // return;
333  $ilWACSignedPath = new ilWACSignedPath(new ilWACPath($this->getModifiedSignedPath(1, 1), false), $this->http, $this->cookieFactory);
334  $this->assertTrue($ilWACSignedPath->isSignedPath());
335  $this->assertFalse($ilWACSignedPath->isSignedPathValid());
336  }
getModifiedSignedPath($add_ttl=0, $add_timestamp=0, $override_token=null)
Class ilWACPath.
static http()
Fetches the global http state from ILIAS.
Class ilWACSignedPath.
+ Here is the call graph for this function:

◆ testSomeBasics()

ilWACTokenTest::testSomeBasics ( )

Definition at line 169 of file ilWACTokenTest.php.

References $query, CLIENT_NAME, and ILIAS\FileDelivery\http().

170  {
171  $query = 'myparam=1234';
172  $ilWACSignedPath = new ilWACSignedPath(new ilWACPath($this->file_four->url() . '?'
173  . $query, false), $this->http, $this->cookieFactory);
174 
175  $this->assertEquals('dummy.jpg', $ilWACSignedPath->getPathObject()->getFileName());
176  $this->assertEquals($query, $ilWACSignedPath->getPathObject()->getQuery());
177  $this->assertEquals('./data/' . self::CLIENT_NAME
178  . '/sec/ilBlog/mm_124/', $ilWACSignedPath->getPathObject()
179  ->getSecurePath());
180  $this->assertEquals('ilBlog', $ilWACSignedPath->getPathObject()->getSecurePathId());
181  $this->assertFalse($ilWACSignedPath->getPathObject()->isStreamable());
182  }
const CLIENT_NAME
Definition: constants.php:40
Class ilWACPath.
static http()
Fetches the global http state from ILIAS.
Class ilWACSignedPath.
$query
+ Here is the call graph for this function:

◆ testTokenGeneration()

ilWACTokenTest::testTokenGeneration ( )

Definition at line 185 of file ilWACTokenTest.php.

References CLIENT_NAME, ilWACToken\generateToken(), and ilWACToken\getSALT().

186  {
187  $ilWacPath = new ilWacPath($this->file_four->url(), false);
188  $ilWACToken = new ilWACToken($ilWacPath->getPath(), self::CLIENT_NAME, 123456, 20);
189  $ilWACToken->generateToken();
190  $this->assertEquals('SALT-client_name-123456-20', $ilWACToken->getRawToken());
191  $this->assertEquals('./data/client_name/sec/ilBlog/mm_124/dummy.jpg', $ilWACToken->getId());
192 
193  $this->assertEquals(self::SALT, ilWACToken::getSALT());
194  $ilWACToken = new ilWACToken($ilWacPath->getPath(), self::CLIENT_NAME, 123456, 20);
195  $this->assertEquals('b541e2bae42ee222f9be959b7ad2ab8844cbb05b', $ilWACToken->getToken());
196  $this->assertEquals('e45b98f267dc891c8206c844f7df29ea', $ilWACToken->getHashedId());
197  }
const CLIENT_NAME
Definition: constants.php:40
static getSALT()
Class ilWACToken.
+ Here is the call graph for this function:

◆ testWithoutSigning()

ilWACTokenTest::testWithoutSigning ( )

Definition at line 137 of file ilWACTokenTest.php.

References ILIAS\FileDelivery\http().

138  {
139  $ilWACSignedPath = new ilWACSignedPath(new ilWACPath($this->file_one->url(), false), $this->http, $this->cookieFactory);
140 
141  $cookieJar = Mockery::mock(CookieJar::class);
142 
143  $cookieJar
144  ->shouldReceive('getAll')
145  ->times(2)
146  ->withAnyArgs()
147  ->andReturn([]);
148 
149  $this->http->shouldReceive('cookieJar')
150  ->twice()
151  ->withNoArgs()
152  ->andReturn($cookieJar);
153 
154  $request = Mockery::mock(Psr\Http\Message\RequestInterface::class);
155  $request->shouldReceive('getCookieParams')
156  ->andReturn([]);
157 
158  $this->http->shouldReceive('request')
159  ->withNoArgs()
160  ->andReturn($request);
161 
162  $this->assertFalse($ilWACSignedPath->isSignedPath());
163  $this->assertFalse($ilWACSignedPath->isSignedPathValid());
164  $this->assertFalse($ilWACSignedPath->isFolderSigned());
165  $this->assertFalse($ilWACSignedPath->isFolderTokenValid());
166  }
Class ilWACPath.
static http()
Fetches the global http state from ILIAS.
Class ilWACSignedPath.
+ Here is the call graph for this function:

Field Documentation

◆ $backupGlobals

ilWACTokenTest::$backupGlobals = false
protected

Definition at line 57 of file ilWACTokenTest.php.

◆ $cookieFactory

CookieFactory MockInterface ilWACTokenTest::$cookieFactory
private

Definition at line 93 of file ilWACTokenTest.php.

◆ $file_four

ilWACTokenTest::$file_four
protected

Definition at line 81 of file ilWACTokenTest.php.

◆ $file_one

ilWACTokenTest::$file_one
protected

Definition at line 61 of file ilWACTokenTest.php.

◆ $file_one_subfolder

ilWACTokenTest::$file_one_subfolder
protected

Definition at line 65 of file ilWACTokenTest.php.

◆ $file_one_subfolder_two

ilWACTokenTest::$file_one_subfolder_two
protected

Definition at line 69 of file ilWACTokenTest.php.

◆ $file_three

ilWACTokenTest::$file_three
protected

Definition at line 77 of file ilWACTokenTest.php.

◆ $file_two

ilWACTokenTest::$file_two
protected

Definition at line 73 of file ilWACTokenTest.php.

◆ $http

GlobalHttpState MockInterface ilWACTokenTest::$http
private

Definition at line 89 of file ilWACTokenTest.php.

◆ $root

ilWACTokenTest::$root
protected

Definition at line 85 of file ilWACTokenTest.php.

◆ ADDITIONAL_TIME

const ilWACTokenTest::ADDITIONAL_TIME = 1

Definition at line 50 of file ilWACTokenTest.php.

◆ CLIENT_NAME

const ilWACTokenTest::CLIENT_NAME = 'client_name'

Definition at line 53 of file ilWACTokenTest.php.

◆ LIFETIME

const ilWACTokenTest::LIFETIME = 2

Definition at line 51 of file ilWACTokenTest.php.

◆ SALT

const ilWACTokenTest::SALT = 'SALT'

Definition at line 52 of file ilWACTokenTest.php.


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