diff options
| author | kkadosh | 2018-05-29 19:34:16 +0000 |
|---|---|---|
| committer | jvoisin | 2018-05-29 19:34:16 +0000 |
| commit | 7832438b7abedf567ce6376f99949f419abcdff1 (patch) | |
| tree | 560e43918d1dc36ce4cf760a5b27aed0c563bc1c /src/tests/samesite_cookies.phpt | |
| parent | 9eebe8c67e03e3041d454ea28e93996f7a67740b (diff) | |
Support session encryption
Implement session encryption.
Diffstat (limited to 'src/tests/samesite_cookies.phpt')
| -rw-r--r-- | src/tests/samesite_cookies.phpt | 51 |
1 files changed, 29 insertions, 22 deletions
diff --git a/src/tests/samesite_cookies.phpt b/src/tests/samesite_cookies.phpt index fe74172..d010963 100644 --- a/src/tests/samesite_cookies.phpt +++ b/src/tests/samesite_cookies.phpt | |||
| @@ -27,12 +27,13 @@ if (!setcookie("nice_cookie", "nice_value", 1, "1", "1", true, true)) { | |||
| 27 | echo "setcookie failed.\n"; | 27 | echo "setcookie failed.\n"; |
| 28 | } | 28 | } |
| 29 | 29 | ||
| 30 | // If the cookie value start with "!", it means that we don't want the value in the headers, but the encrypted cookie | ||
| 30 | $expected = array( | 31 | $expected = array( |
| 31 | 'Set-Cookie: super_cookie=super_value; path=; samesite=Lax', | 32 | "awful_cookie" => "!awful_value", |
| 32 | 'Set-Cookie: awful_cookie=AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAFyZcYjfEskB0AU0V3%2BvwazcRuU%2Ft6KpcUahvxw%3D; path=; samesite=Strict; HttpOnly', | 33 | "not_encrypted" => "test_value", |
| 33 | 'Set-Cookie: not_encrypted=test_value; expires=Thu, 01-Jan-1970 00:00:01 GMT; Max-Age=0; path=1; domain=1; HttpOnly', | 34 | "nice_cookie" => "!nice_value", |
| 34 | 'Set-Cookie: nice_cookie=AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAJ8ko%2ByA4y%2Bmw5MGBx8fgc3TWOAvhIu%2BfF%2Bx2g%3D%3D; expires=Thu, 01-Jan-1970 00:00:01 GMT; Max-Age=0; path=1; samesite=Strict; domain=1; secure; HttpOnly', | 35 | "super_cookie" => "super_value", |
| 35 | ); | 36 | ); |
| 36 | 37 | ||
| 37 | $headers = headers_list(); | 38 | $headers = headers_list(); |
| 38 | if (($i = count($expected)) > count($headers)) | 39 | if (($i = count($expected)) > count($headers)) |
| @@ -41,31 +42,37 @@ if (($i = count($expected)) > count($headers)) | |||
| 41 | return; | 42 | return; |
| 42 | } | 43 | } |
| 43 | 44 | ||
| 44 | do | 45 | $i = 0; |
| 45 | { | 46 | |
| 47 | do { | ||
| 46 | if (strncmp(current($headers), 'Set-Cookie:', 11) !== 0) | 48 | if (strncmp(current($headers), 'Set-Cookie:', 11) !== 0) |
| 47 | { | 49 | { |
| 48 | continue; | 50 | continue; |
| 49 | } | 51 | } |
| 50 | 52 | foreach ($expected as $key => $value) { | |
| 51 | if (current($headers) === current($expected)) | 53 | if (strpos(current($headers), $key) !== false) { // If the header contains the cookie |
| 52 | { | 54 | if (substr($value, 0, 1) === "!") { // ! is because we don't want to see the cookie value in plaintext, it must be encrypted |
| 53 | $i--; | 55 | if (strpos(current($headers), substr($value,1,-1)) === false) { // If the header doesn't contain de cookie value, it's good |
| 56 | $i++; | ||
| 57 | break; | ||
| 58 | } | ||
| 59 | echo "Received : " . current($headers) . " and the cookie isn't encrypted . \n"; | ||
| 60 | } else { | ||
| 61 | if (strpos(current($headers), $value) !== false) { | ||
| 62 | $i++; | ||
| 63 | break; | ||
| 64 | } | ||
| 65 | echo "Received : " . current($headers) . " and the cookie value of " . $key . " doesn't match it's value. \n"; | ||
| 66 | } | ||
| 67 | break; | ||
| 68 | } | ||
| 54 | } | 69 | } |
| 55 | else | ||
| 56 | { | ||
| 57 | echo "Header mismatch:\n\tExpected: " | ||
| 58 | .current($expected) | ||
| 59 | ."\n\tReceived: ".current($headers)."\n"; | ||
| 60 | } | ||
| 61 | |||
| 62 | next($expected); | ||
| 63 | } | 70 | } |
| 64 | while (next($headers) !== FALSE); | 71 | while (next($headers)); |
| 65 | 72 | ||
| 66 | echo ($i === 0) | 73 | echo ($i === 4) |
| 67 | ? 'OK' | 74 | ? 'OK' |
| 68 | : 'A total of '.$i.' errors found.'; | 75 | : 'A total of '. (count($expected) - $i) .' errors found.'; |
| 69 | ?> | 76 | ?> |
| 70 | --EXPECT-- | 77 | --EXPECT-- |
| 71 | OK | 78 | OK |
