From 8db459e1ea3abf3b2318f172184e4cf06da2c29d Mon Sep 17 00:00:00 2001 From: jvoisin Date: Mon, 10 Sep 2018 12:17:41 +0000 Subject: Improve a bit the coverage --- src/tests/crypt_session_corrupted_session.phpt | 30 +++++++++++ src/tests/crypt_session_invalid.phpt | 2 +- src/tests/set_custom_session_handler.phpt | 72 ++++++++++++++++++++++++++ src/tests/set_custom_session_handler_ini.phpt | 17 ++++++ 4 files changed, 120 insertions(+), 1 deletion(-) create mode 100644 src/tests/crypt_session_corrupted_session.phpt create mode 100644 src/tests/set_custom_session_handler.phpt create mode 100644 src/tests/set_custom_session_handler_ini.phpt (limited to 'src') 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 @@ +--TEST-- +Set a custom session handler +--SKIPIF-- + +--INI-- +sp.configuration_file={PWD}/config/config_crypt_session.ini +session.save_path = "/tmp" +--ENV-- +return << +--EXPECTF-- +Fatal 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 var_dump($_SESSION); // Dump the session ?> --EXPECTF-- -Fatal 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 +Fatal 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 @@ +--TEST-- +Set a custom session handler +--SKIPIF-- + +--INI-- +sp.configuration_file={PWD}/config/config_crypt_session.ini +session.save_path = "/tmp" +--ENV-- +return <<savePath = $savePath; + if (!is_dir($this->savePath)) { + mkdir($this->savePath, 0777); + } + + return true; + } + + function close() { + return true; + } + + function read($id) { + return (string)@file_get_contents("$this->savePath/sess_$id"); + } + + function write($id, $data) { + return file_put_contents("$this->savePath/sess_$id", $data) === false ? false : true; + } + + function destroy($id) { + $file = "$this->savePath/sess_$id"; + if (file_exists($file)) { + unlink($file); + } + + return true; + } + + function gc($maxlifetime) { + foreach (glob("$this->savePath/sess_*") as $file) { + if (filemtime($file) + $maxlifetime < time() && file_exists($file)) { + unlink($file); + } + } + return true; + } +} + +$handler = new FileSessionHandler(); +session_set_save_handler( + array($handler, 'open'), + array($handler, 'close'), + array($handler, 'read'), + array($handler, 'write'), + array($handler, 'destroy'), + array($handler, 'gc') + ); + +// the following prevents unexpected effects when using objects as save handlers +register_shutdown_function('session_write_close'); + +session_start(); +// proceed to set and retrieve values by key from $_SESSION +--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 @@ +--TEST-- +Set a custom session handler +--SKIPIF-- + +--INI-- +sp.configuration_file={PWD}/config/config_crypt_session.ini +session.save_handler = files +--ENV-- +return << +--EXPECT-- +win -- cgit v1.3