summaryrefslogtreecommitdiff
path: root/src/tests
diff options
context:
space:
mode:
authorjvoisin2018-10-06 16:15:00 +0000
committerGitHub2018-10-06 16:15:00 +0000
commitaa550b9abadc109a2c89a7cd6dd047ac2a953027 (patch)
tree1892e9ce8f833f3f13278cd424368fe1b5e26d91 /src/tests
parent228fadf307b167a22ad6ec760f3b2ee2e9f2fee3 (diff)
Bump a bit the coverage
* `setcookie` doesn't always return `true` anymore * clang-format * Cookies with invalid decryption are dropped, but the request isn't anymore * faulty unserialize are now dumpable
Diffstat (limited to 'src/tests')
-rw-r--r--src/tests/broken_conf_cookie_encryption_without_encryption_key.phpt14
-rw-r--r--src/tests/broken_conf_cookie_encryption_without_env_var.phpt14
-rw-r--r--src/tests/broken_conf_mutually_exclusive11.phpt14
-rw-r--r--src/tests/broken_conf_mutually_exclusive12.phpt14
-rw-r--r--src/tests/broken_conf_wrapper_whitelist.phpt18
-rw-r--r--src/tests/config/broken_conf_cookie_encryption_without_encryption_key.ini2
-rw-r--r--src/tests/config/broken_conf_cookie_encryption_without_env_var.ini2
-rw-r--r--src/tests/config/broken_conf_mutually_exclusive11.ini1
-rw-r--r--src/tests/config/broken_conf_mutually_exclusive12.ini1
-rw-r--r--src/tests/config/broken_conf_wrapper_whitelist.ini1
-rw-r--r--src/tests/crypt_session_invalid.phpt2
-rw-r--r--src/tests/encrypt_cookies4.phpt7
-rw-r--r--src/tests/encrypt_cookies_empty_env.phpt3
-rw-r--r--src/tests/encrypt_cookies_invalid_decryption.phpt15
-rw-r--r--src/tests/encrypt_regexp_cookies_invalid_decryption.phpt6
15 files changed, 106 insertions, 8 deletions
diff --git a/src/tests/broken_conf_cookie_encryption_without_encryption_key.phpt b/src/tests/broken_conf_cookie_encryption_without_encryption_key.phpt
new file mode 100644
index 0000000..d0b7c0d
--- /dev/null
+++ b/src/tests/broken_conf_cookie_encryption_without_encryption_key.phpt
@@ -0,0 +1,14 @@
1--TEST--
2Borken configuration - encrypted cookie without encryption key
3--SKIPIF--
4<?php if (!extension_loaded("snuffleupagus")) print "skip"; ?>
5--INI--
6sp.configuration_file={PWD}/config/broken_conf_cookie_encryption_without_encryption_key.ini
7--FILE--
8--EXPECT--
9PHP Fatal error: [snuffleupagus][config] You're trying to use the cookie encryption featureon line 2 without having set the `.encryption_key` option in`sp.global`: please set it first in Unknown on line 0
10
11Fatal error: [snuffleupagus][config] You're trying to use the cookie encryption featureon line 2 without having set the `.encryption_key` option in`sp.global`: please set it first in Unknown on line 0
12
13Fatal error: [snuffleupagus][config] Invalid configuration file in Unknown on line 0
14Could not startup.
diff --git a/src/tests/broken_conf_cookie_encryption_without_env_var.phpt b/src/tests/broken_conf_cookie_encryption_without_env_var.phpt
new file mode 100644
index 0000000..af5d471
--- /dev/null
+++ b/src/tests/broken_conf_cookie_encryption_without_env_var.phpt
@@ -0,0 +1,14 @@
1--TEST--
2Borken configuration - encrypted cookie with without cookie env var
3--SKIPIF--
4<?php if (!extension_loaded("snuffleupagus")) print "skip"; ?>
5--INI--
6sp.configuration_file={PWD}/config/broken_conf_cookie_encryption_without_env_var.ini
7--FILE--
8--EXPECT--
9PHP Fatal error: [snuffleupagus][config] You're trying to use the cookie encryption featureon line 2 without having set the `.cookie_env_var` option in`sp.global`: please set it first in Unknown on line 0
10
11Fatal error: [snuffleupagus][config] You're trying to use the cookie encryption featureon line 2 without having set the `.cookie_env_var` option in`sp.global`: please set it first in Unknown on line 0
12
13Fatal error: [snuffleupagus][config] Invalid configuration file in Unknown on line 0
14Could not startup.
diff --git a/src/tests/broken_conf_mutually_exclusive11.phpt b/src/tests/broken_conf_mutually_exclusive11.phpt
new file mode 100644
index 0000000..507d7fa
--- /dev/null
+++ b/src/tests/broken_conf_mutually_exclusive11.phpt
@@ -0,0 +1,14 @@
1--TEST--
2Broken configuration - ret and var are mutually exclusives
3--SKIPIF--
4<?php if (!extension_loaded("snuffleupagus")) print "skip"; ?>
5--INI--
6sp.configuration_file={PWD}/config/broken_conf_mutually_exclusive11.ini
7--FILE--
8--EXPECT--
9PHP Fatal error: [snuffleupagus][config] Invalid configuration line: 'sp.disabled_functions.function("strcmp").drop().ret("hip").var("hop");':`ret` and `var` are mutually exclusive on line 1 in Unknown on line 0
10
11Fatal error: [snuffleupagus][config] Invalid configuration line: 'sp.disabled_functions.function("strcmp").drop().ret("hip").var("hop");':`ret` and `var` are mutually exclusive on line 1 in Unknown on line 0
12
13Fatal error: [snuffleupagus][config] Invalid configuration file in Unknown on line 0
14Could not startup.
diff --git a/src/tests/broken_conf_mutually_exclusive12.phpt b/src/tests/broken_conf_mutually_exclusive12.phpt
new file mode 100644
index 0000000..d823de9
--- /dev/null
+++ b/src/tests/broken_conf_mutually_exclusive12.phpt
@@ -0,0 +1,14 @@
1--TEST--
2Broken configuration - ret and value are mutually exclusive
3--SKIPIF--
4<?php if (!extension_loaded("snuffleupagus")) print "skip"; ?>
5--INI--
6sp.configuration_file={PWD}/config/broken_conf_mutually_exclusive12.ini
7--FILE--
8--EXPECT--
9PHP Fatal error: [snuffleupagus][config] Invalid configuration line: 'sp.disabled_functions.function("strcmp").drop().ret("hip").value("hop");':`ret` and `value` are mutually exclusive on line 1 in Unknown on line 0
10
11Fatal error: [snuffleupagus][config] Invalid configuration line: 'sp.disabled_functions.function("strcmp").drop().ret("hip").value("hop");':`ret` and `value` are mutually exclusive on line 1 in Unknown on line 0
12
13Fatal error: [snuffleupagus][config] Invalid configuration file in Unknown on line 0
14Could not startup.
diff --git a/src/tests/broken_conf_wrapper_whitelist.phpt b/src/tests/broken_conf_wrapper_whitelist.phpt
new file mode 100644
index 0000000..ea147ac
--- /dev/null
+++ b/src/tests/broken_conf_wrapper_whitelist.phpt
@@ -0,0 +1,18 @@
1--TEST--
2Broken configuration with invalid token for wrapper whitelist
3--SKIPIF--
4<?php if (!extension_loaded("snuffleupagus")) print "skip"; ?>
5--INI--
6sp.configuration_file={PWD}/config/broken_conf_wrapper_whitelist.ini
7sp.allow_broken_configuration=Off
8--FILE--
9<?php
10echo 1337;
11?>
12--EXPECT--
13PHP Fatal error: [snuffleupagus][config] Trailing chars '.invalid_param();' at the end of '.invalid_param();' on line 1 in Unknown on line 0
14
15Fatal error: [snuffleupagus][config] Trailing chars '.invalid_param();' at the end of '.invalid_param();' on line 1 in Unknown on line 0
16
17Fatal error: [snuffleupagus][config] Invalid configuration file in Unknown on line 0
18Could not startup.
diff --git a/src/tests/config/broken_conf_cookie_encryption_without_encryption_key.ini b/src/tests/config/broken_conf_cookie_encryption_without_encryption_key.ini
new file mode 100644
index 0000000..a100bd8
--- /dev/null
+++ b/src/tests/config/broken_conf_cookie_encryption_without_encryption_key.ini
@@ -0,0 +1,2 @@
1sp.global.cookie_env_var("MY_SUPER_ENV_VAR_YAY");
2sp.cookie.name("my_cookie_name").encrypt();
diff --git a/src/tests/config/broken_conf_cookie_encryption_without_env_var.ini b/src/tests/config/broken_conf_cookie_encryption_without_env_var.ini
new file mode 100644
index 0000000..54cb101
--- /dev/null
+++ b/src/tests/config/broken_conf_cookie_encryption_without_env_var.ini
@@ -0,0 +1,2 @@
1sp.global.secret_key("super secret encryption key");
2sp.cookie.name("my_cookie_name").encrypt();
diff --git a/src/tests/config/broken_conf_mutually_exclusive11.ini b/src/tests/config/broken_conf_mutually_exclusive11.ini
new file mode 100644
index 0000000..cab163f
--- /dev/null
+++ b/src/tests/config/broken_conf_mutually_exclusive11.ini
@@ -0,0 +1 @@
sp.disable_function.function("strcmp").drop().ret("hip").var("hop");
diff --git a/src/tests/config/broken_conf_mutually_exclusive12.ini b/src/tests/config/broken_conf_mutually_exclusive12.ini
new file mode 100644
index 0000000..fe140db
--- /dev/null
+++ b/src/tests/config/broken_conf_mutually_exclusive12.ini
@@ -0,0 +1 @@
sp.disable_function.function("strcmp").drop().ret("hip").value("hop");
diff --git a/src/tests/config/broken_conf_wrapper_whitelist.ini b/src/tests/config/broken_conf_wrapper_whitelist.ini
new file mode 100644
index 0000000..b8e08a8
--- /dev/null
+++ b/src/tests/config/broken_conf_wrapper_whitelist.ini
@@ -0,0 +1 @@
sp.wrappers_whitelist.invalid_param();
diff --git a/src/tests/crypt_session_invalid.phpt b/src/tests/crypt_session_invalid.phpt
index cc6e80e..4b0f4d2 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 %s/tests/crypt_session_invalid.php on line %d 24Warning: [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/encrypt_cookies4.phpt b/src/tests/encrypt_cookies4.phpt
index 14d737a..04d4076 100644
--- a/src/tests/encrypt_cookies4.phpt
+++ b/src/tests/encrypt_cookies4.phpt
@@ -16,8 +16,13 @@ EOF;
16setcookie("super_cookie", "super_value"); 16setcookie("super_cookie", "super_value");
17setcookie("awful_cookie", "awful_value"); 17setcookie("awful_cookie", "awful_value");
18setcookie("nice_cookie", "nice_value", 1, "1", "1", true, true); 18setcookie("nice_cookie", "nice_value", 1, "1", "1", true, true);
19$ret = setcookie("", "Cookie with no name", 1, "1", "1", true, true);
20if ($ret == TRUE) {
21 echo "fail :/";
22}
19var_dump($_COOKIE); 23var_dump($_COOKIE);
20?> 24?>
21--EXPECT-- 25--EXPECTF--
26Warning: Cookie names must not be empty in %a/tests/encrypt_cookies4.php on line %d
22array(0) { 27array(0) {
23} 28}
diff --git a/src/tests/encrypt_cookies_empty_env.phpt b/src/tests/encrypt_cookies_empty_env.phpt
index 252f831..23f1759 100644
--- a/src/tests/encrypt_cookies_empty_env.phpt
+++ b/src/tests/encrypt_cookies_empty_env.phpt
@@ -14,4 +14,5 @@ super_cookie=cGFkZGluZ3BhZGRpbmdwYWRkaW5ncGFkZGluZ3BhZGRpbmdwYWRkaW5ncGFkZGluZ3B
14--EXPECT-- 14--EXPECT--
15Warning: [snuffleupagus][cookie_encryption] The environment variable 'SUPER_ENV_VAR' is empty, cookies are weakly encrypted in Unknown on line 0 15Warning: [snuffleupagus][cookie_encryption] The environment variable 'SUPER_ENV_VAR' is empty, cookies are weakly encrypted in Unknown on line 0
16 16
17Fatal error: [snuffleupagus][cookie_encryption] Something went wrong with the decryption of super_cookie in Unknown on line 0 17Warning: [snuffleupagus][cookie_encryption] Something went wrong with the decryption of super_cookie in Unknown on line 0
181
diff --git a/src/tests/encrypt_cookies_invalid_decryption.phpt b/src/tests/encrypt_cookies_invalid_decryption.phpt
index c64675d..d4a0b0f 100644
--- a/src/tests/encrypt_cookies_invalid_decryption.phpt
+++ b/src/tests/encrypt_cookies_invalid_decryption.phpt
@@ -1,5 +1,5 @@
1--TEST-- 1--TEST--
2Cookie encryption 2Cookie encryption - invalid decryption
3--SKIPIF-- 3--SKIPIF--
4<?php if (!extension_loaded("snuffleupagus")) die "skip"; ?> 4<?php if (!extension_loaded("snuffleupagus")) die "skip"; ?>
5--INI-- 5--INI--
@@ -8,12 +8,19 @@ display_errors=1
8display_startup_errors=1 8display_startup_errors=1
9error_reporting=E_ALL 9error_reporting=E_ALL
10--COOKIE-- 10--COOKIE--
11super_cookie=jWjORGsgZyqzk3WA63XZBmUoSknXWnXDfAAAAAAAAAAAAAAAAAAAAAA7LiMDfkpP94jDnMVH%2Fm41GeL0Y00q3mbOFYz%2FS9mQGySu;awful_cookie=awful_cookie_value; 11super_cookie=Wk9NR1RISVNJU05PVEVOQ1JZUFRFREFUQUxMV0hBVFRIRUhFTExJU0hIRUxMQVJFWU9VRE9JTkdaT01Hb2htYXliZXRoaXNpc2Fub2xkc2Vzc2lvbmNvb2tpZQo=;awfulcookie=awfulcookievalue;
12--ENV-- 12--ENV--
13return <<<EOF 13return <<<EOF
14REMOTE_ADDR=127.0.0.1 14REMOTE_ADDR=127.0.0.1
15EOF; 15EOF;
16--FILE-- 16--FILE--
17<?php var_dump($_COOKIE); ?> 17<?php
18echo "1337\n";
19var_dump($_COOKIE); ?>
18--EXPECT-- 20--EXPECT--
19Fatal error: [snuffleupagus][cookie_encryption] Something went wrong with the decryption of super_cookie in Unknown on line 0 \ No newline at end of file 21Warning: [snuffleupagus][cookie_encryption] Something went wrong with the decryption of super_cookie in Unknown on line 0
221337
23array(1) {
24 ["awfulcookie"]=>
25 string(16) "awfulcookievalue"
26}
diff --git a/src/tests/encrypt_regexp_cookies_invalid_decryption.phpt b/src/tests/encrypt_regexp_cookies_invalid_decryption.phpt
index 0c02806..d2f9e3c 100644
--- a/src/tests/encrypt_regexp_cookies_invalid_decryption.phpt
+++ b/src/tests/encrypt_regexp_cookies_invalid_decryption.phpt
@@ -16,4 +16,8 @@ EOF;
16--FILE-- 16--FILE--
17<?php var_dump($_COOKIE); ?> 17<?php var_dump($_COOKIE); ?>
18--EXPECT-- 18--EXPECT--
19Fatal error: [snuffleupagus][cookie_encryption] Something went wrong with the decryption of super_cookie in Unknown on line 0 \ No newline at end of file 19Warning: [snuffleupagus][cookie_encryption] Something went wrong with the decryption of super_cookie in Unknown on line 0
20array(1) {
21 ["awful_cookie"]=>
22 string(18) "awful_cookie_value"
23}