summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorjvoisin2018-09-10 12:17:41 +0000
committerGitHub2018-09-10 12:17:41 +0000
commit8db459e1ea3abf3b2318f172184e4cf06da2c29d (patch)
tree73ebeaf7d32a52204f3d87f61e73f3377303c610 /src
parentf103c8203140550e6a1658c31c071038ddc816af (diff)
Improve a bit the coverage
Diffstat (limited to 'src')
-rw-r--r--src/tests/crypt_session_corrupted_session.phpt30
-rw-r--r--src/tests/crypt_session_invalid.phpt2
-rw-r--r--src/tests/set_custom_session_handler.phpt72
-rw-r--r--src/tests/set_custom_session_handler_ini.phpt17
4 files changed, 120 insertions, 1 deletions
diff --git a/src/tests/crypt_session_corrupted_session.phpt b/src/tests/crypt_session_corrupted_session.phpt
new file mode 100644
index 0000000..6ab6612
--- /dev/null
+++ b/src/tests/crypt_session_corrupted_session.phpt
@@ -0,0 +1,30 @@
1--TEST--
2Set a custom session handler
3--SKIPIF--
4<?php if (!extension_loaded("snuffleupagus")) die "skip"; ?>
5--INI--
6sp.configuration_file={PWD}/config/config_crypt_session.ini
7session.save_path = "/tmp"
8--ENV--
9return <<<EOF
10REMOTE_ADDR=127.0.0.1
11EOF;
12--FILE--
13<?php
14
15session_start(); // Start new_session , it will read an empty session
16$_SESSION["tete"] = "titi"; // Encrypt and write the session
17$id = session_id(); // Get the session_id to use it later
18$filename = session_save_path() . '/sess_' . $id;
19session_write_close();
20
21$file_handle = fopen($filename, 'w');
22fwrite($file_handle, 'toto|s:4:"tata";');
23fclose($file_handle);
24
25session_id($id);
26session_start();
27var_dump($_SESSION);
28?>
29--EXPECTF--
30Fatal error: [snuffleupagus][cookie_encryption] Buffer underflow tentative detected in cookie encryption handling in %s/tests/crypt_session_corrupted_session.php on line %s
diff --git a/src/tests/crypt_session_invalid.phpt b/src/tests/crypt_session_invalid.phpt
index b7880db..cc6e80e 100644
--- a/src/tests/crypt_session_invalid.phpt
+++ b/src/tests/crypt_session_invalid.phpt
@@ -21,4 +21,4 @@ session_start(); // Re start the session, It will read and decrypt the non em
21var_dump($_SESSION); // Dump the session 21var_dump($_SESSION); // Dump the session
22?> 22?>
23--EXPECTF-- 23--EXPECTF--
24Fatal error: [snuffleupagus][cookie_encryption] Something went wrong with the decryption of the session in %a/src/tests/crypt_session_invalid.php on line 9 \ No newline at end of file 24Fatal error: [snuffleupagus][cookie_encryption] Something went wrong with the decryption of the session in %s/tests/crypt_session_invalid.php on line %d
diff --git a/src/tests/set_custom_session_handler.phpt b/src/tests/set_custom_session_handler.phpt
new file mode 100644
index 0000000..5b46fbc
--- /dev/null
+++ b/src/tests/set_custom_session_handler.phpt
@@ -0,0 +1,72 @@
1--TEST--
2Set a custom session handler
3--SKIPIF--
4<?php if (!extension_loaded("snuffleupagus")) die "skip"; ?>
5--INI--
6sp.configuration_file={PWD}/config/config_crypt_session.ini
7session.save_path = "/tmp"
8--ENV--
9return <<<EOF
10REMOTE_ADDR=127.0.0.1
11EOF;
12--FILE--
13<?php
14class FileSessionHandler {
15 private $savePath;
16
17 function open($savePath, $sessionName) {
18 $this->savePath = $savePath;
19 if (!is_dir($this->savePath)) {
20 mkdir($this->savePath, 0777);
21 }
22
23 return true;
24 }
25
26 function close() {
27 return true;
28 }
29
30 function read($id) {
31 return (string)@file_get_contents("$this->savePath/sess_$id");
32 }
33
34 function write($id, $data) {
35 return file_put_contents("$this->savePath/sess_$id", $data) === false ? false : true;
36 }
37
38 function destroy($id) {
39 $file = "$this->savePath/sess_$id";
40 if (file_exists($file)) {
41 unlink($file);
42 }
43
44 return true;
45 }
46
47 function gc($maxlifetime) {
48 foreach (glob("$this->savePath/sess_*") as $file) {
49 if (filemtime($file) + $maxlifetime < time() && file_exists($file)) {
50 unlink($file);
51 }
52 }
53 return true;
54 }
55}
56
57$handler = new FileSessionHandler();
58session_set_save_handler(
59 array($handler, 'open'),
60 array($handler, 'close'),
61 array($handler, 'read'),
62 array($handler, 'write'),
63 array($handler, 'destroy'),
64 array($handler, 'gc')
65 );
66
67// the following prevents unexpected effects when using objects as save handlers
68register_shutdown_function('session_write_close');
69
70session_start();
71// proceed to set and retrieve values by key from $_SESSION
72--EXPECTF--
diff --git a/src/tests/set_custom_session_handler_ini.phpt b/src/tests/set_custom_session_handler_ini.phpt
new file mode 100644
index 0000000..ef5fdcc
--- /dev/null
+++ b/src/tests/set_custom_session_handler_ini.phpt
@@ -0,0 +1,17 @@
1--TEST--
2Set a custom session handler
3--SKIPIF--
4<?php if (!extension_loaded("snuffleupagus")) die "skip"; ?>
5--INI--
6sp.configuration_file={PWD}/config/config_crypt_session.ini
7session.save_handler = files
8--ENV--
9return <<<EOF
10REMOTE_ADDR=127.0.0.1
11EOF;
12--FILE--
13<?php
14echo "win";
15?>
16--EXPECT--
17win