aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/utils/ReferenceSessionIdHashes.php
diff options
context:
space:
mode:
authorVirtualTam <virtualtam@flibidi.net>2015-09-06 16:16:53 +0200
committerVirtualTam <virtualtam@flibidi.net>2015-09-06 16:16:53 +0200
commitf5d6b19b73cd026cb1d937aab16d48b43e412c77 (patch)
tree8c100e6ca4cba5870640cf3e0ec688b1f0fa7474 /tests/utils/ReferenceSessionIdHashes.php
parenta02257b8aed58ef2f8536c877ce2fb222f84ac40 (diff)
parent68bc21353a6138a898724c8bb87684bb2b6b2c1c (diff)
downloadShaarli-f5d6b19b73cd026cb1d937aab16d48b43e412c77.tar.gz
Shaarli-f5d6b19b73cd026cb1d937aab16d48b43e412c77.tar.zst
Shaarli-f5d6b19b73cd026cb1d937aab16d48b43e412c77.zip
Merge pull request #338 from virtualtam/fix/unique-uniqid
Session ID: extend the regex to match possible hash representations
Diffstat (limited to 'tests/utils/ReferenceSessionIdHashes.php')
-rw-r--r--tests/utils/ReferenceSessionIdHashes.php55
1 files changed, 55 insertions, 0 deletions
diff --git a/tests/utils/ReferenceSessionIdHashes.php b/tests/utils/ReferenceSessionIdHashes.php
new file mode 100644
index 00000000..60b1c007
--- /dev/null
+++ b/tests/utils/ReferenceSessionIdHashes.php
@@ -0,0 +1,55 @@
1<?php
2/**
3 * Testing the untestable - Session ID generation
4 */
5class ReferenceSessionIdHashes
6{
7 // Session ID hashes
8 protected static $sidHashes = null;
9
10 /**
11 * Generates session ID hashes for all algorithms & bit representations
12 */
13 public static function genAllHashes()
14 {
15 foreach (hash_algos() as $algo) {
16 self::$sidHashes[$algo] = array();
17
18 foreach (array(4, 5, 6) as $bpc) {
19 self::$sidHashes[$algo][$bpc] = self::genSidHash($algo, $bpc);
20 }
21 }
22 }
23
24 /**
25 * Generates a session ID for a given hash algorithm and bit representation
26 *
27 * @param string $function name of the hash function
28 * @param int $bits_per_character representation type
29 *
30 * @return string the generated session ID
31 */
32 protected static function genSidHash($function, $bits_per_character)
33 {
34 if (session_id()) {
35 session_destroy();
36 }
37
38 ini_set('session.hash_function', $function);
39 ini_set('session.hash_bits_per_character', $bits_per_character);
40
41 session_start();
42 return session_id();
43 }
44
45 /**
46 * Returns the reference hash array
47 *
48 * @return array session IDs generated for all available algorithms and bit
49 * representations
50 */
51 public static function getHashes()
52 {
53 return self::$sidHashes;
54 }
55}