ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
ilWACTokenTest Class Reference

TestCase for the ilWACTokenTest. More...

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

Public Member Functions

 testWithoutSigning ()
 
 testSomeBasics ()
 
 testTokenGeneration ()
 
 testCookieGeneration ()
 
 testFileToken ()
 
 testFolderToken ()
 
 testFolderTokenWithSecondFile ()
 
 testModifiedTimestampNoMod ()
 
 testModifiedTimestampAddTime ()
 
 testModifiedTimestampSubTime ()
 
 testModifiedTTL ()
 
 testModifiedTTLAndTimestamp ()
 
 testModifiedToken ()
 

Data Fields

const ADDITIONAL_TIME = 0.5
 
const LIFETIME = 1
 
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
 

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 37 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 317 of file ilWACTokenTest.php.

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

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

317  {
319  $signed_path = ilWACSignedPath::signFile($this->file_one->url());
320 
321  $parts = parse_url($signed_path);
322  $path = $parts['path'];
323  $query = $parts['query'];
324  parse_str($query, $query_array);
325  $token = $override_token ? $override_token : $query_array['il_wac_token'];
326  $ttl = (int)$query_array['il_wac_ttl'];
327  $ts = (int)$query_array['il_wac_ts'];
328  $path_with_token = $path . '?il_wac_token=' . $token;
329 
330  $modified_ttl = $ttl + $add_ttl;
331  $modified_ts = $ts + $add_timestamp;
332 
333  return $path_with_token . '&il_wac_ttl=' . $modified_ttl . '&il_wac_ts=' . $modified_ts;
334  }
$path
Definition: aliased.php:25
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 80 of file ilWACTokenTest.php.

References ilWACToken\setSALT().

80  {
81  require_once('./Services/WebAccessChecker/classes/class.ilWACSignedPath.php');
82  require_once('./Services/WebAccessChecker/classes/class.ilWebAccessChecker.php');
83  require_once('./Services/WebAccessChecker/classes/class.ilWACSignedPath.php');
84  require_once('./Services/WebAccessChecker/classes/class.ilWACToken.php');
85  require_once('./Services/WebAccessChecker/test/Token/mock/class.ilWACDummyCookie.php');
86  require_once('./libs/composer/vendor/autoload.php');
87  $this->root = vfs\vfsStream::setup('ilias.de');
88  $this->file_one = vfs\vfsStream::newFile('data/client_name/mobs/mm_123/dummy.jpg')->at($this->root)->setContent('dummy');
89  $this->file_one_subfolder = vfs\vfsStream::newFile('data/client_name/mobs/mm_123/mobile/dummy.jpg')->at($this->root)->setContent('dummy');
90  $this->file_one_subfolder_two = vfs\vfsStream::newFile('data/client_name/mobs/mm_123/mobile/device/dummy.jpg')->at($this->root)
91  ->setContent('dummy');
92  $this->file_two = vfs\vfsStream::newFile('data/client_name/mobs/mm_123/dummy2.jpg')->at($this->root)->setContent('dummy2');
93  $this->file_three = vfs\vfsStream::newFile('data/client_name/mobs/mm_124/dummy.jpg')->at($this->root)->setContent('dummy');
94  $this->file_four = vfs\vfsStream::newFile('data/client_name/sec/ilBlog/mm_124/dummy.jpg')->at($this->root)->setContent('dummy');
95  ilWACToken::setSALT(self::SALT);
96  parent::setUp();
97  }
static setSALT($SALT)
+ Here is the call graph for this function:

◆ testCookieGeneration()

ilWACTokenTest::testCookieGeneration ( )

Definition at line 145 of file ilWACTokenTest.php.

References $_SERVER, array, ilWACDummyCookie\clear(), ilWebAccessChecker\setDEBUG(), and ilWACSignedPath\signFolderOfStartFile().

145  {
148  $_SERVER['REMOTE_ADDR'] = '127.0.0.1';
149  $ilWACCookieInterface = new ilWACDummyCookie();
150  ilWACSignedPath::signFolderOfStartFile($this->file_one->url(), $ilWACCookieInterface);
151  $expected_cookies = array(
152  '19ab58dae37d8d8cf931727c35514642',
153  '19ab58dae37d8d8cf931727c35514642ts',
154  '19ab58dae37d8d8cf931727c35514642ttl',
155  );
156  $this->assertEquals($expected_cookies, array_keys($ilWACCookieInterface->getAll()));
157  // in subfolder
159  $_SERVER['REMOTE_ADDR'] = '127.0.0.1';
160  $ilWACCookieInterface = new ilWACDummyCookie();
161  ilWACSignedPath::signFolderOfStartFile($this->file_one_subfolder->url(), $ilWACCookieInterface);
162  $this->assertEquals($expected_cookies, array_keys($ilWACCookieInterface->getAll()));
163  // in sub-subfolder
165  $_SERVER['REMOTE_ADDR'] = '127.0.0.1';
166  $ilWACCookieInterface = new ilWACDummyCookie();
167  ilWACSignedPath::signFolderOfStartFile($this->file_one_subfolder->url(), $ilWACCookieInterface);
168  $this->assertEquals($expected_cookies, array_keys($ilWACCookieInterface->getAll()));
169  }
if((!isset($_SERVER['DOCUMENT_ROOT'])) OR(empty($_SERVER['DOCUMENT_ROOT']))) $_SERVER['DOCUMENT_ROOT']
static signFolderOfStartFile($start_file_path, ilWACCookieInterface $ilWACCookieInterface=null)
Create styles array
The data for the language used.
Class ilWACDummyCookie.
+ Here is the call graph for this function:

◆ testFileToken()

ilWACTokenTest::testFileToken ( )

Definition at line 172 of file ilWACTokenTest.php.

References ilWACSignedPath\getTokenMaxLifetimeInSeconds(), ilWACSignedPath\setTokenMaxLifetimeInSeconds(), and ilWACSignedPath\signFile().

172  {
175 
176  // Request within lifetime
177  $signed_path = ilWACSignedPath::signFile($this->file_one->url());
178  $ilWACSignedPath = new ilWACSignedPath(new ilWACPath($signed_path));
179 
180  $this->assertTrue($ilWACSignedPath->isSignedPath());
181  $this->assertTrue($ilWACSignedPath->isSignedPathValid());
182  $this->assertEquals($ilWACSignedPath->getPathObject()->getClient(), self::CLIENT_NAME);
183  $this->assertFalse($ilWACSignedPath->getPathObject()->isInSecFolder());
184  $this->assertTrue($ilWACSignedPath->getPathObject()->isImage());
185  $this->assertFalse($ilWACSignedPath->getPathObject()->isAudio());
186  $this->assertFalse($ilWACSignedPath->getPathObject()->isVideo());
187  $this->assertTrue($ilWACSignedPath->getPathObject()->hasTimestamp());
188  $this->assertTrue($ilWACSignedPath->getPathObject()->hasToken());
189 
190  // Request after lifetime
191  $signed_path = ilWACSignedPath::signFile($this->file_four->url());
192  sleep($lifetime + self::ADDITIONAL_TIME);
193  $ilWACSignedPath = new ilWACSignedPath(new ilWACPath($signed_path));
194  $this->assertTrue($ilWACSignedPath->isSignedPath());
195  $this->assertFalse($ilWACSignedPath->isSignedPathValid());
196  }
Class ilWACPath.
Class ilWACSignedPath.
static signFile($path_to_file)
static setTokenMaxLifetimeInSeconds($token_max_lifetime_in_seconds)
static getTokenMaxLifetimeInSeconds()
+ Here is the call graph for this function:

◆ testFolderToken()

ilWACTokenTest::testFolderToken ( )

Definition at line 199 of file ilWACTokenTest.php.

References ilWACDummyCookie\clear(), ilWACSignedPath\getCookieMaxLifetimeInSeconds(), ilWACSignedPath\setCookieMaxLifetimeInSeconds(), and ilWACSignedPath\signFolderOfStartFile().

199  {
203 
204  $signed_path = $this->file_one->url();
206 
207  $ilWACSignedPath = new ilWACSignedPath(new ilWACPath($signed_path), new ilWACDummyCookie());
208  $this->assertTrue($ilWACSignedPath->isFolderSigned());
209  $this->assertTrue($ilWACSignedPath->isFolderTokenValid());
210  $this->assertEquals($ilWACSignedPath->getPathObject()->getClient(), self::CLIENT_NAME);
211  $this->assertFalse($ilWACSignedPath->getPathObject()->isInSecFolder());
212  $this->assertTrue($ilWACSignedPath->getPathObject()->isImage());
213  $this->assertFalse($ilWACSignedPath->getPathObject()->isAudio());
214  $this->assertFalse($ilWACSignedPath->getPathObject()->isVideo());
215  $this->assertTrue($ilWACSignedPath->getPathObject()->hasTimestamp());
216  $this->assertTrue($ilWACSignedPath->getPathObject()->hasToken());
217 
218  // Request after lifetime
220  sleep($lifetime + self::ADDITIONAL_TIME);
221  $ilWACSignedPath = new ilWACSignedPath(new ilWACPath($signed_path), new ilWACDummyCookie());
222  $this->assertTrue($ilWACSignedPath->isFolderSigned());
223  $this->assertFalse($ilWACSignedPath->isFolderTokenValid());
224 
225  // Revalidating cookie
226  $ilWACSignedPath->revalidatingFolderToken();
227  $ilWACSignedPath = new ilWACSignedPath(new ilWACPath($signed_path), new ilWACDummyCookie());
228  $this->assertTrue($ilWACSignedPath->isFolderSigned());
229  $this->assertTrue($ilWACSignedPath->isFolderTokenValid());
230 
231  // Check other file
232  $ilWACSignedPath = new ilWACSignedPath(new ilWACPath($this->file_three->url()), new ilWACDummyCookie());
233  $this->assertTrue($ilWACSignedPath->isFolderSigned());
234  $this->assertTrue($ilWACSignedPath->isFolderTokenValid());
235  }
static getCookieMaxLifetimeInSeconds()
static signFolderOfStartFile($start_file_path, ilWACCookieInterface $ilWACCookieInterface=null)
Class ilWACPath.
static setCookieMaxLifetimeInSeconds($cookie_max_lifetime_in_seconds)
Class ilWACSignedPath.
Class ilWACDummyCookie.
+ Here is the call graph for this function:

◆ testFolderTokenWithSecondFile()

ilWACTokenTest::testFolderTokenWithSecondFile ( )

Definition at line 238 of file ilWACTokenTest.php.

References $file_two, ilWACSignedPath\getCookieMaxLifetimeInSeconds(), ilWACSignedPath\setCookieMaxLifetimeInSeconds(), and ilWACSignedPath\signFolderOfStartFile().

238  {
241  // Sign File One
242  $ilWACCookieInterface = new ilWACDummyCookie();
243  ilWACSignedPath::signFolderOfStartFile($this->file_one->url(), $ilWACCookieInterface);
244  // Check File Two
245  $file_two = $this->file_two->url();
246  $ilWACSignedPath = new ilWACSignedPath(new ilWACPath($file_two), $ilWACCookieInterface);
247  $this->assertTrue($ilWACSignedPath->isFolderSigned());
248  $this->assertTrue($ilWACSignedPath->isFolderTokenValid());
249 
250  // Request after lifetime
251  ilWACSignedPath::signFolderOfStartFile($file_two, $ilWACCookieInterface);
252  sleep($lifetime + self::ADDITIONAL_TIME);
253  $ilWACSignedPath = new ilWACSignedPath(new ilWACPath($file_two), $ilWACCookieInterface);
254  $this->assertTrue($ilWACSignedPath->isFolderSigned());
255  $this->assertFalse($ilWACSignedPath->isFolderTokenValid());
256 
257  // Revalidating cookie
258  $ilWACSignedPath->revalidatingFolderToken();
259  $this->assertTrue($ilWACSignedPath->isFolderSigned());
260  $this->assertTrue($ilWACSignedPath->isFolderTokenValid());
261 
262  // Check other file
263  $ilWACSignedPath = new ilWACSignedPath(new ilWACPath($this->file_three->url()), $ilWACCookieInterface);
264  $this->assertTrue($ilWACSignedPath->isFolderSigned());
265  $this->assertTrue($ilWACSignedPath->isFolderTokenValid());
266  }
static getCookieMaxLifetimeInSeconds()
static signFolderOfStartFile($start_file_path, ilWACCookieInterface $ilWACCookieInterface=null)
Class ilWACPath.
static setCookieMaxLifetimeInSeconds($cookie_max_lifetime_in_seconds)
Class ilWACSignedPath.
Class ilWACDummyCookie.
+ Here is the call graph for this function:

◆ testModifiedTimestampAddTime()

ilWACTokenTest::testModifiedTimestampAddTime ( )

Definition at line 276 of file ilWACTokenTest.php.

References getModifiedSignedPath().

276  {
277  $ilWACSignedPath = new ilWACSignedPath(new ilWACPath($this->getModifiedSignedPath(self::ADDITIONAL_TIME, 0)));
278  $this->assertTrue($ilWACSignedPath->isSignedPath());
279  $this->assertFalse($ilWACSignedPath->isSignedPathValid());
280  }
getModifiedSignedPath($add_ttl=0, $add_timestamp=0, $override_token=null)
Class ilWACPath.
Class ilWACSignedPath.
+ Here is the call graph for this function:

◆ testModifiedTimestampNoMod()

ilWACTokenTest::testModifiedTimestampNoMod ( )

Definition at line 269 of file ilWACTokenTest.php.

References getModifiedSignedPath().

269  {
270  $ilWACSignedPath = new ilWACSignedPath(new ilWACPath($this->getModifiedSignedPath(0, 0)));
271  $this->assertTrue($ilWACSignedPath->isSignedPath());
272  $this->assertTrue($ilWACSignedPath->isSignedPathValid());
273  }
getModifiedSignedPath($add_ttl=0, $add_timestamp=0, $override_token=null)
Class ilWACPath.
Class ilWACSignedPath.
+ Here is the call graph for this function:

◆ testModifiedTimestampSubTime()

ilWACTokenTest::testModifiedTimestampSubTime ( )

Definition at line 283 of file ilWACTokenTest.php.

References getModifiedSignedPath().

283  {
284  $ilWACSignedPath = new ilWACSignedPath(new ilWACPath($this->getModifiedSignedPath(self::ADDITIONAL_TIME * - 1, 0)));
285  $this->assertTrue($ilWACSignedPath->isSignedPath());
286  $this->assertFalse($ilWACSignedPath->isSignedPathValid());
287  }
getModifiedSignedPath($add_ttl=0, $add_timestamp=0, $override_token=null)
Class ilWACPath.
Class ilWACSignedPath.
+ Here is the call graph for this function:

◆ testModifiedToken()

ilWACTokenTest::testModifiedToken ( )

Definition at line 304 of file ilWACTokenTest.php.

References getModifiedSignedPath().

304  {
305  $ilWACSignedPath = new ilWACSignedPath(new ilWACPath($this->getModifiedSignedPath(0, 0, md5('LOREM'))));
306  $this->assertTrue($ilWACSignedPath->isSignedPath());
307  $this->assertFalse($ilWACSignedPath->isSignedPathValid());
308  }
getModifiedSignedPath($add_ttl=0, $add_timestamp=0, $override_token=null)
Class ilWACPath.
Class ilWACSignedPath.
+ Here is the call graph for this function:

◆ testModifiedTTL()

ilWACTokenTest::testModifiedTTL ( )

Definition at line 290 of file ilWACTokenTest.php.

References getModifiedSignedPath().

290  {
291  $ilWACSignedPath = new ilWACSignedPath(new ilWACPath($this->getModifiedSignedPath(0, 1)));
292  $this->assertTrue($ilWACSignedPath->isSignedPath());
293  $this->assertFalse($ilWACSignedPath->isSignedPathValid());
294  }
getModifiedSignedPath($add_ttl=0, $add_timestamp=0, $override_token=null)
Class ilWACPath.
Class ilWACSignedPath.
+ Here is the call graph for this function:

◆ testModifiedTTLAndTimestamp()

ilWACTokenTest::testModifiedTTLAndTimestamp ( )

Definition at line 297 of file ilWACTokenTest.php.

References getModifiedSignedPath().

297  {
298  $ilWACSignedPath = new ilWACSignedPath(new ilWACPath($this->getModifiedSignedPath(1, 1)));
299  $this->assertTrue($ilWACSignedPath->isSignedPath());
300  $this->assertFalse($ilWACSignedPath->isSignedPathValid());
301  }
getModifiedSignedPath($add_ttl=0, $add_timestamp=0, $override_token=null)
Class ilWACPath.
Class ilWACSignedPath.
+ Here is the call graph for this function:

◆ testSomeBasics()

ilWACTokenTest::testSomeBasics ( )

Definition at line 110 of file ilWACTokenTest.php.

References $query, ilWACToken\DEBUG, ilWACLog\getInstance(), and ilWebAccessChecker\isDEBUG().

110  {
111  $query = 'myparam=1234';
112  $ilWACSignedPath = new ilWACSignedPath(new ilWACPath($this->file_four->url() . '?' . $query), new ilWACDummyCookie());
113 
114  $this->assertEquals('dummy.jpg', $ilWACSignedPath->getPathObject()->getFileName());
115  $this->assertEquals($query, $ilWACSignedPath->getPathObject()->getQuery());
116  $this->assertEquals('./data/' . self::CLIENT_NAME . '/sec/ilBlog/mm_124/', $ilWACSignedPath->getPathObject()->getSecurePath());
117  $this->assertEquals('ilBlog', $ilWACSignedPath->getPathObject()->getSecurePathId());
118  $this->assertFalse($ilWACSignedPath->getPathObject()->isStreamable());
119 
120  $this->assertEquals('ilWACLogDummy', get_class(ilWACLog::getInstance()));
121 
122  $this->assertFalse(ilWebAccessChecker::isDEBUG());
123  $this->assertFalse(ilWACToken::DEBUG);
124  }
static getInstance()
Class ilWACPath.
Class ilWACSignedPath.
Class ilWACDummyCookie.
+ Here is the call graph for this function:

◆ testTokenGeneration()

ilWACTokenTest::testTokenGeneration ( )

Definition at line 127 of file ilWACTokenTest.php.

References $_SERVER, ilWACToken\getSALT(), ilWebAccessChecker\setDEBUG(), and ilWACToken\setIp().

127  {
129  $ilWacPath = new ilWacPath($this->file_four->url());
130  $ilWACToken = new ilWACToken($ilWacPath->getPath(), self::CLIENT_NAME, 123456, 20);
131  $ilWACToken->setIp('127.0.0.1');
132  $ilWACToken->generateToken();
133  $this->assertEquals('SALT-127.0.0.1-client_name-123456-20', $ilWACToken->getRawToken());
134  $this->assertEquals('./data/client_name/sec/ilBlog/mm_124/dummy.jpg', $ilWACToken->getId());
135 
137  $_SERVER['REMOTE_ADDR'] = '127.0.0.1';
138  $this->assertEquals(self::SALT, ilWACToken::getSALT());
139  $ilWACToken = new ilWACToken($ilWacPath->getPath(), self::CLIENT_NAME, 123456, 20);
140  $this->assertEquals('cd5a43304b232c785ef4f9796053b8bf5d6d829a', $ilWACToken->getToken());
141  $this->assertEquals('e45b98f267dc891c8206c844f7df29ea', $ilWACToken->getHashedId());
142  }
if((!isset($_SERVER['DOCUMENT_ROOT'])) OR(empty($_SERVER['DOCUMENT_ROOT']))) $_SERVER['DOCUMENT_ROOT']
static getSALT()
Class ilWACToken.
+ Here is the call graph for this function:

◆ testWithoutSigning()

ilWACTokenTest::testWithoutSigning ( )

Definition at line 100 of file ilWACTokenTest.php.

100  {
101  $ilWACSignedPath = new ilWACSignedPath(new ilWACPath($this->file_one->url()), new ilWACDummyCookie());
102 
103  $this->assertFalse($ilWACSignedPath->isSignedPath());
104  $this->assertFalse($ilWACSignedPath->isSignedPathValid());
105  $this->assertFalse($ilWACSignedPath->isFolderSigned());
106  $this->assertFalse($ilWACSignedPath->isFolderTokenValid());
107  }
Class ilWACPath.
Class ilWACSignedPath.
Class ilWACDummyCookie.

Field Documentation

◆ $backupGlobals

ilWACTokenTest::$backupGlobals = false
protected

Definition at line 46 of file ilWACTokenTest.php.

◆ $file_four

ilWACTokenTest::$file_four
protected

Definition at line 70 of file ilWACTokenTest.php.

◆ $file_one

ilWACTokenTest::$file_one
protected

Definition at line 50 of file ilWACTokenTest.php.

◆ $file_one_subfolder

ilWACTokenTest::$file_one_subfolder
protected

Definition at line 54 of file ilWACTokenTest.php.

◆ $file_one_subfolder_two

ilWACTokenTest::$file_one_subfolder_two
protected

Definition at line 58 of file ilWACTokenTest.php.

◆ $file_three

ilWACTokenTest::$file_three
protected

Definition at line 66 of file ilWACTokenTest.php.

◆ $file_two

ilWACTokenTest::$file_two
protected

Definition at line 62 of file ilWACTokenTest.php.

Referenced by testFolderTokenWithSecondFile().

◆ $root

ilWACTokenTest::$root
protected

Definition at line 74 of file ilWACTokenTest.php.

◆ ADDITIONAL_TIME

const ilWACTokenTest::ADDITIONAL_TIME = 0.5

Definition at line 39 of file ilWACTokenTest.php.

◆ CLIENT_NAME

const ilWACTokenTest::CLIENT_NAME = 'client_name'

Definition at line 42 of file ilWACTokenTest.php.

◆ LIFETIME

const ilWACTokenTest::LIFETIME = 1

Definition at line 40 of file ilWACTokenTest.php.

◆ SALT

const ilWACTokenTest::SALT = 'SALT'

Definition at line 41 of file ilWACTokenTest.php.


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