summaryrefslogtreecommitdiff
path: root/src/tests/session_encryption/set_custom_session_handler.phpt
diff options
context:
space:
mode:
authorjvoisin2019-01-14 19:29:25 +0000
committerGitHub2019-01-14 19:29:25 +0000
commite79f7e3bd992c7f0915ef9afe7afb6d79740527a (patch)
treef881c25694eb00da2331a9ab280ec1c24a5662ab /src/tests/session_encryption/set_custom_session_handler.phpt
parentc943db586ac46b686b49bdf61d8473e39dd93000 (diff)
Reorganize the testsuite
Splitting the testsuite in several components makes it easier to manage and comprehend. This was also needed some some tests aren't passing on Alpine Linux, but we still want to run as many of them as we can on this platform.
Diffstat (limited to 'src/tests/session_encryption/set_custom_session_handler.phpt')
-rw-r--r--src/tests/session_encryption/set_custom_session_handler.phpt72
1 files changed, 72 insertions, 0 deletions
diff --git a/src/tests/session_encryption/set_custom_session_handler.phpt b/src/tests/session_encryption/set_custom_session_handler.phpt
new file mode 100644
index 0000000..5b46fbc
--- /dev/null
+++ b/src/tests/session_encryption/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--