diff options
author | VirtualTam <virtualtam+github@flibidi.net> | 2017-10-25 22:49:22 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-10-25 22:49:22 +0200 |
commit | 88d38cb290aad669ad1406e2362d85c81e46d4f6 (patch) | |
tree | 9a0689e685ba42b44e507f2ae5e22595671b3bc4 /tests/UtilsTest.php | |
parent | 6bc7afab91c78b893da314220fe346a366aefb8f (diff) | |
parent | ae7c954b1279981cc23c9f67d88f55bfecc4d828 (diff) | |
download | Shaarli-88d38cb290aad669ad1406e2362d85c81e46d4f6.tar.gz Shaarli-88d38cb290aad669ad1406e2362d85c81e46d4f6.tar.zst Shaarli-88d38cb290aad669ad1406e2362d85c81e46d4f6.zip |
Merge pull request #1005 from virtualtam/refactor/authentication
Refactor session management utilities
Diffstat (limited to 'tests/UtilsTest.php')
-rw-r--r-- | tests/UtilsTest.php | 58 |
1 files changed, 0 insertions, 58 deletions
diff --git a/tests/UtilsTest.php b/tests/UtilsTest.php index 840eaf21..6cd37a7a 100644 --- a/tests/UtilsTest.php +++ b/tests/UtilsTest.php | |||
@@ -5,10 +5,6 @@ | |||
5 | 5 | ||
6 | require_once 'application/Utils.php'; | 6 | require_once 'application/Utils.php'; |
7 | require_once 'application/Languages.php'; | 7 | require_once 'application/Languages.php'; |
8 | require_once 'tests/utils/ReferenceSessionIdHashes.php'; | ||
9 | |||
10 | // Initialize reference data before PHPUnit starts a session | ||
11 | ReferenceSessionIdHashes::genAllHashes(); | ||
12 | 8 | ||
13 | 9 | ||
14 | /** | 10 | /** |
@@ -16,9 +12,6 @@ ReferenceSessionIdHashes::genAllHashes(); | |||
16 | */ | 12 | */ |
17 | class UtilsTest extends PHPUnit_Framework_TestCase | 13 | class UtilsTest extends PHPUnit_Framework_TestCase |
18 | { | 14 | { |
19 | // Session ID hashes | ||
20 | protected static $sidHashes = null; | ||
21 | |||
22 | // Log file | 15 | // Log file |
23 | protected static $testLogFile = 'tests.log'; | 16 | protected static $testLogFile = 'tests.log'; |
24 | 17 | ||
@@ -30,13 +23,11 @@ class UtilsTest extends PHPUnit_Framework_TestCase | |||
30 | */ | 23 | */ |
31 | protected static $defaultTimeZone; | 24 | protected static $defaultTimeZone; |
32 | 25 | ||
33 | |||
34 | /** | 26 | /** |
35 | * Assign reference data | 27 | * Assign reference data |
36 | */ | 28 | */ |
37 | public static function setUpBeforeClass() | 29 | public static function setUpBeforeClass() |
38 | { | 30 | { |
39 | self::$sidHashes = ReferenceSessionIdHashes::getHashes(); | ||
40 | self::$defaultTimeZone = date_default_timezone_get(); | 31 | self::$defaultTimeZone = date_default_timezone_get(); |
41 | // Timezone without DST for test consistency | 32 | // Timezone without DST for test consistency |
42 | date_default_timezone_set('Africa/Nairobi'); | 33 | date_default_timezone_set('Africa/Nairobi'); |
@@ -221,57 +212,8 @@ class UtilsTest extends PHPUnit_Framework_TestCase | |||
221 | $this->assertEquals('?', generateLocation($ref, 'localhost')); | 212 | $this->assertEquals('?', generateLocation($ref, 'localhost')); |
222 | } | 213 | } |
223 | 214 | ||
224 | /** | ||
225 | * Test is_session_id_valid with a valid ID - TEST ALL THE HASHES! | ||
226 | * | ||
227 | * This tests extensively covers all hash algorithms / bit representations | ||
228 | */ | ||
229 | public function testIsAnyHashSessionIdValid() | ||
230 | { | ||
231 | foreach (self::$sidHashes as $algo => $bpcs) { | ||
232 | foreach ($bpcs as $bpc => $hash) { | ||
233 | $this->assertTrue(is_session_id_valid($hash)); | ||
234 | } | ||
235 | } | ||
236 | } | ||
237 | 215 | ||
238 | /** | 216 | /** |
239 | * Test is_session_id_valid with a valid ID - SHA-1 hashes | ||
240 | */ | ||
241 | public function testIsSha1SessionIdValid() | ||
242 | { | ||
243 | $this->assertTrue(is_session_id_valid(sha1('shaarli'))); | ||
244 | } | ||
245 | |||
246 | /** | ||
247 | * Test is_session_id_valid with a valid ID - SHA-256 hashes | ||
248 | */ | ||
249 | public function testIsSha256SessionIdValid() | ||
250 | { | ||
251 | $this->assertTrue(is_session_id_valid(hash('sha256', 'shaarli'))); | ||
252 | } | ||
253 | |||
254 | /** | ||
255 | * Test is_session_id_valid with a valid ID - SHA-512 hashes | ||
256 | */ | ||
257 | public function testIsSha512SessionIdValid() | ||
258 | { | ||
259 | $this->assertTrue(is_session_id_valid(hash('sha512', 'shaarli'))); | ||
260 | } | ||
261 | |||
262 | /** | ||
263 | * Test is_session_id_valid with invalid IDs. | ||
264 | */ | ||
265 | public function testIsSessionIdInvalid() | ||
266 | { | ||
267 | $this->assertFalse(is_session_id_valid('')); | ||
268 | $this->assertFalse(is_session_id_valid(array())); | ||
269 | $this->assertFalse( | ||
270 | is_session_id_valid('c0ZqcWF3VFE2NmJBdm1HMVQ0ZHJ3UmZPbTFsNGhkNHI=') | ||
271 | ); | ||
272 | } | ||
273 | |||
274 | /** | ||
275 | * Test generateSecretApi. | 217 | * Test generateSecretApi. |
276 | */ | 218 | */ |
277 | public function testGenerateSecretApi() | 219 | public function testGenerateSecretApi() |