diff options
| author | jvoisin | 2017-12-27 15:43:33 +0100 |
|---|---|---|
| committer | jvoisin | 2017-12-27 15:43:33 +0100 |
| commit | 4fafa8ae5a7bcd700f368bbe6016e0b0fb2cc892 (patch) | |
| tree | 12438ccccb237e3507fb5bd08c43901d7d0bf904 /src/tests | |
| parent | 60888daa7fb433ca15157256980f8baeb8b698a0 (diff) | |
Implement simulation mode for cookies (de/en)cryption
This should close #102
This commit can be useful for two use-cases:
1. When deploying Snuffleupagus on big CMS like Magento, and not knowing
what cookies are modified via javascript.
2. When deploying Snuffleupagus on big websites: you don't want to disconnect
every single user at once.
When simulation is enabled, if the decryption fails, a log message is
now issued, and the cookie value taken as it (since odds are that it's
non-encrypted).
Diffstat (limited to 'src/tests')
3 files changed, 54 insertions, 0 deletions
diff --git a/src/tests/config/config_encrypted_cookies_simulation.ini b/src/tests/config/config_encrypted_cookies_simulation.ini new file mode 100644 index 0000000..32e24a1 --- /dev/null +++ b/src/tests/config/config_encrypted_cookies_simulation.ini | |||
| @@ -0,0 +1,3 @@ | |||
| 1 | sp.global.secret_key("abcdef").cookie_env_var("REMOTE_ADDR"); | ||
| 2 | sp.cookie.name("super_cookie").encrypt().simulation(); | ||
| 3 | sp.auto_cookie_secure.enable(); | ||
diff --git a/src/tests/encrypt_cookies_invalid_decryption_short_cookie.phpt b/src/tests/encrypt_cookies_invalid_decryption_short_cookie.phpt new file mode 100644 index 0000000..e5b6bfc --- /dev/null +++ b/src/tests/encrypt_cookies_invalid_decryption_short_cookie.phpt | |||
| @@ -0,0 +1,24 @@ | |||
| 1 | --TEST-- | ||
| 2 | Cookie encryption - invalid decryption in simulation mode with a short cookie | ||
| 3 | --SKIPIF-- | ||
| 4 | <?php if (!extension_loaded("snuffleupagus")) die "skip"; ?> | ||
| 5 | --INI-- | ||
| 6 | sp.configuration_file={PWD}/config/config_encrypted_cookies_simulation.ini | ||
| 7 | display_errors=1 | ||
| 8 | display_startup_errors=1 | ||
| 9 | error_reporting=E_ALL | ||
| 10 | --COOKIE-- | ||
| 11 | super_cookie=AAA;awful_cookie=awful_cookie_value; | ||
| 12 | --ENV-- | ||
| 13 | return <<<EOF | ||
| 14 | REMOTE_ADDR=127.0.0.1 | ||
| 15 | EOF; | ||
| 16 | --FILE-- | ||
| 17 | <?php var_dump($_COOKIE); ?> | ||
| 18 | --EXPECT-- | ||
| 19 | array(2) { | ||
| 20 | ["super_cookie"]=> | ||
| 21 | string(3) "AAA" | ||
| 22 | ["awful_cookie"]=> | ||
| 23 | string(18) "awful_cookie_value" | ||
| 24 | } | ||
diff --git a/src/tests/encrypt_cookies_invalid_decryption_simulation.phpt b/src/tests/encrypt_cookies_invalid_decryption_simulation.phpt new file mode 100644 index 0000000..0bd1dc8 --- /dev/null +++ b/src/tests/encrypt_cookies_invalid_decryption_simulation.phpt | |||
| @@ -0,0 +1,27 @@ | |||
| 1 | --TEST-- | ||
| 2 | Cookie encryption - invalid decryption in simulation mode | ||
| 3 | --SKIPIF-- | ||
| 4 | <?php if (!extension_loaded("snuffleupagus")) die "skip"; ?> | ||
| 5 | --INI-- | ||
| 6 | sp.configuration_file={PWD}/config/config_encrypted_cookies_simulation.ini | ||
| 7 | display_errors=1 | ||
| 8 | display_startup_errors=1 | ||
| 9 | error_reporting=E_ALL | ||
| 10 | --COOKIE-- | ||
| 11 | super_cookie=Wk9NR1RISVNJU05PVEVOQ1JZUFRFREFUQUxMV0hBVFRIRUhFTExJU0hIRUxMQVJFWU9VRE9JTkdaT01Hb2htYXliZXRoaXNpc2Fub2xkc2Vzc2lvbmNvb2tpZQo=;awfulcookie=awfulcookievalue; | ||
| 12 | --ENV-- | ||
| 13 | return <<<EOF | ||
| 14 | REMOTE_ADDR=127.0.0.1 | ||
| 15 | EOF; | ||
| 16 | --FILE-- | ||
| 17 | <?php | ||
| 18 | echo "1337\n"; | ||
| 19 | var_dump($_COOKIE); ?> | ||
| 20 | --EXPECT-- | ||
| 21 | 1337 | ||
| 22 | array(2) { | ||
| 23 | ["super_cookie"]=> | ||
| 24 | string(124) "Wk9NR1RISVNJU05PVEVOQ1JZUFRFREFUQUxMV0hBVFRIRUhFTExJU0hIRUxMQVJFWU9VRE9JTkdaT01Hb2htYXliZXRoaXNpc2Fub2xkc2Vzc2lvbmNvb2tpZQo=" | ||
| 25 | ["awfulcookie"]=> | ||
| 26 | string(16) "awfulcookievalue" | ||
| 27 | } | ||
