diff options
| author | jvoisin | 2018-10-06 16:15:00 +0000 |
|---|---|---|
| committer | GitHub | 2018-10-06 16:15:00 +0000 |
| commit | aa550b9abadc109a2c89a7cd6dd047ac2a953027 (patch) | |
| tree | 1892e9ce8f833f3f13278cd424368fe1b5e26d91 /src/tests | |
| parent | 228fadf307b167a22ad6ec760f3b2ee2e9f2fee3 (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')
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-- | ||
| 2 | Borken configuration - encrypted cookie without encryption key | ||
| 3 | --SKIPIF-- | ||
| 4 | <?php if (!extension_loaded("snuffleupagus")) print "skip"; ?> | ||
| 5 | --INI-- | ||
| 6 | sp.configuration_file={PWD}/config/broken_conf_cookie_encryption_without_encryption_key.ini | ||
| 7 | --FILE-- | ||
| 8 | --EXPECT-- | ||
| 9 | PHP 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 | |||
| 11 | 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 | ||
| 12 | |||
| 13 | Fatal error: [snuffleupagus][config] Invalid configuration file in Unknown on line 0 | ||
| 14 | Could 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-- | ||
| 2 | Borken configuration - encrypted cookie with without cookie env var | ||
| 3 | --SKIPIF-- | ||
| 4 | <?php if (!extension_loaded("snuffleupagus")) print "skip"; ?> | ||
| 5 | --INI-- | ||
| 6 | sp.configuration_file={PWD}/config/broken_conf_cookie_encryption_without_env_var.ini | ||
| 7 | --FILE-- | ||
| 8 | --EXPECT-- | ||
| 9 | PHP 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 | |||
| 11 | 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 | ||
| 12 | |||
| 13 | Fatal error: [snuffleupagus][config] Invalid configuration file in Unknown on line 0 | ||
| 14 | Could 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-- | ||
| 2 | Broken configuration - ret and var are mutually exclusives | ||
| 3 | --SKIPIF-- | ||
| 4 | <?php if (!extension_loaded("snuffleupagus")) print "skip"; ?> | ||
| 5 | --INI-- | ||
| 6 | sp.configuration_file={PWD}/config/broken_conf_mutually_exclusive11.ini | ||
| 7 | --FILE-- | ||
| 8 | --EXPECT-- | ||
| 9 | PHP 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 | |||
| 11 | 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 | ||
| 12 | |||
| 13 | Fatal error: [snuffleupagus][config] Invalid configuration file in Unknown on line 0 | ||
| 14 | Could 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-- | ||
| 2 | Broken configuration - ret and value are mutually exclusive | ||
| 3 | --SKIPIF-- | ||
| 4 | <?php if (!extension_loaded("snuffleupagus")) print "skip"; ?> | ||
| 5 | --INI-- | ||
| 6 | sp.configuration_file={PWD}/config/broken_conf_mutually_exclusive12.ini | ||
| 7 | --FILE-- | ||
| 8 | --EXPECT-- | ||
| 9 | PHP 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 | |||
| 11 | 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 | ||
| 12 | |||
| 13 | Fatal error: [snuffleupagus][config] Invalid configuration file in Unknown on line 0 | ||
| 14 | Could 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-- | ||
| 2 | Broken configuration with invalid token for wrapper whitelist | ||
| 3 | --SKIPIF-- | ||
| 4 | <?php if (!extension_loaded("snuffleupagus")) print "skip"; ?> | ||
| 5 | --INI-- | ||
| 6 | sp.configuration_file={PWD}/config/broken_conf_wrapper_whitelist.ini | ||
| 7 | sp.allow_broken_configuration=Off | ||
| 8 | --FILE-- | ||
| 9 | <?php | ||
| 10 | echo 1337; | ||
| 11 | ?> | ||
| 12 | --EXPECT-- | ||
| 13 | PHP Fatal error: [snuffleupagus][config] Trailing chars '.invalid_param();' at the end of '.invalid_param();' on line 1 in Unknown on line 0 | ||
| 14 | |||
| 15 | Fatal error: [snuffleupagus][config] Trailing chars '.invalid_param();' at the end of '.invalid_param();' on line 1 in Unknown on line 0 | ||
| 16 | |||
| 17 | Fatal error: [snuffleupagus][config] Invalid configuration file in Unknown on line 0 | ||
| 18 | Could 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 @@ | |||
| 1 | sp.global.cookie_env_var("MY_SUPER_ENV_VAR_YAY"); | ||
| 2 | sp.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 @@ | |||
| 1 | sp.global.secret_key("super secret encryption key"); | ||
| 2 | sp.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 | |||
| 21 | var_dump($_SESSION); // Dump the session | 21 | var_dump($_SESSION); // Dump the session |
| 22 | ?> | 22 | ?> |
| 23 | --EXPECTF-- | 23 | --EXPECTF-- |
| 24 | Fatal error: [snuffleupagus][cookie_encryption] Something went wrong with the decryption of the session in %s/tests/crypt_session_invalid.php on line %d | 24 | Warning: [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; | |||
| 16 | setcookie("super_cookie", "super_value"); | 16 | setcookie("super_cookie", "super_value"); |
| 17 | setcookie("awful_cookie", "awful_value"); | 17 | setcookie("awful_cookie", "awful_value"); |
| 18 | setcookie("nice_cookie", "nice_value", 1, "1", "1", true, true); | 18 | setcookie("nice_cookie", "nice_value", 1, "1", "1", true, true); |
| 19 | $ret = setcookie("", "Cookie with no name", 1, "1", "1", true, true); | ||
| 20 | if ($ret == TRUE) { | ||
| 21 | echo "fail :/"; | ||
| 22 | } | ||
| 19 | var_dump($_COOKIE); | 23 | var_dump($_COOKIE); |
| 20 | ?> | 24 | ?> |
| 21 | --EXPECT-- | 25 | --EXPECTF-- |
| 26 | Warning: Cookie names must not be empty in %a/tests/encrypt_cookies4.php on line %d | ||
| 22 | array(0) { | 27 | array(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-- |
| 15 | Warning: [snuffleupagus][cookie_encryption] The environment variable 'SUPER_ENV_VAR' is empty, cookies are weakly encrypted in Unknown on line 0 | 15 | Warning: [snuffleupagus][cookie_encryption] The environment variable 'SUPER_ENV_VAR' is empty, cookies are weakly encrypted in Unknown on line 0 |
| 16 | 16 | ||
| 17 | Fatal error: [snuffleupagus][cookie_encryption] Something went wrong with the decryption of super_cookie in Unknown on line 0 | 17 | Warning: [snuffleupagus][cookie_encryption] Something went wrong with the decryption of super_cookie in Unknown on line 0 |
| 18 | 1 | ||
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-- |
| 2 | Cookie encryption | 2 | Cookie 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 | |||
| 8 | display_startup_errors=1 | 8 | display_startup_errors=1 |
| 9 | error_reporting=E_ALL | 9 | error_reporting=E_ALL |
| 10 | --COOKIE-- | 10 | --COOKIE-- |
| 11 | super_cookie=jWjORGsgZyqzk3WA63XZBmUoSknXWnXDfAAAAAAAAAAAAAAAAAAAAAA7LiMDfkpP94jDnMVH%2Fm41GeL0Y00q3mbOFYz%2FS9mQGySu;awful_cookie=awful_cookie_value; | 11 | super_cookie=Wk9NR1RISVNJU05PVEVOQ1JZUFRFREFUQUxMV0hBVFRIRUhFTExJU0hIRUxMQVJFWU9VRE9JTkdaT01Hb2htYXliZXRoaXNpc2Fub2xkc2Vzc2lvbmNvb2tpZQo=;awfulcookie=awfulcookievalue; |
| 12 | --ENV-- | 12 | --ENV-- |
| 13 | return <<<EOF | 13 | return <<<EOF |
| 14 | REMOTE_ADDR=127.0.0.1 | 14 | REMOTE_ADDR=127.0.0.1 |
| 15 | EOF; | 15 | EOF; |
| 16 | --FILE-- | 16 | --FILE-- |
| 17 | <?php var_dump($_COOKIE); ?> | 17 | <?php |
| 18 | echo "1337\n"; | ||
| 19 | var_dump($_COOKIE); ?> | ||
| 18 | --EXPECT-- | 20 | --EXPECT-- |
| 19 | Fatal error: [snuffleupagus][cookie_encryption] Something went wrong with the decryption of super_cookie in Unknown on line 0 \ No newline at end of file | 21 | Warning: [snuffleupagus][cookie_encryption] Something went wrong with the decryption of super_cookie in Unknown on line 0 |
| 22 | 1337 | ||
| 23 | array(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-- |
| 19 | Fatal error: [snuffleupagus][cookie_encryption] Something went wrong with the decryption of super_cookie in Unknown on line 0 \ No newline at end of file | 19 | Warning: [snuffleupagus][cookie_encryption] Something went wrong with the decryption of super_cookie in Unknown on line 0 |
| 20 | array(1) { | ||
| 21 | ["awful_cookie"]=> | ||
| 22 | string(18) "awful_cookie_value" | ||
| 23 | } | ||
