summaryrefslogtreecommitdiff
path: root/src/tests/samesite_cookies.phpt
blob: fe74172a749231650a6177c760ec73bad46d2aaa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
--TEST--
Cookie samesite
--SKIPIF--
<?php if (!extension_loaded("snuffleupagus")) die "skip"; ?>
--INI--
sp.configuration_file={PWD}/config/config_samesite_cookies.ini
--COOKIE--
super_cookie=if_there_is_no_cookie_here_there_is_no_header_list
--ENV--
return <<<EOF
REMOTE_ADDR=2001:0db8:0000:0000:0000:fe00:0042:8329
HTTP_USER_AGENT=Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/59.0.3071.109 Chrome/59.0.3071.109 Safari/537.36
HTTPS=1
EOF;
--FILE--
<?php
if (!setcookie("super_cookie", "super_value")) {
  echo "setcookie failed.\n";
}
if (!setcookie("awful_cookie", "awful_value")) {
  echo "setcookie failed.\n";
}
if (!setcookie("not_encrypted", "test_value", 1, "1", "1", false, true)) {
  echo "setcookie failed.\n";
}
if (!setcookie("nice_cookie", "nice_value", 1, "1", "1", true, true)) {
  echo "setcookie failed.\n";
}

$expected = array(
    'Set-Cookie: super_cookie=super_value; path=; samesite=Lax',
    'Set-Cookie: awful_cookie=AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAFyZcYjfEskB0AU0V3%2BvwazcRuU%2Ft6KpcUahvxw%3D; path=; samesite=Strict; HttpOnly',
    'Set-Cookie: not_encrypted=test_value; expires=Thu, 01-Jan-1970 00:00:01 GMT; Max-Age=0; path=1; domain=1; HttpOnly',
    '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',
    );

$headers = headers_list();
if (($i = count($expected)) > count($headers))
{
  echo "Fewer headers are being sent than expected - aborting";
  return;
}

do
{
  if (strncmp(current($headers), 'Set-Cookie:', 11) !== 0)
  {
    continue;
  }

  if (current($headers) === current($expected))
  {
    $i--;
  }
  else
  {
    echo "Header mismatch:\n\tExpected: "
      .current($expected)
      ."\n\tReceived: ".current($headers)."\n";
  }

  next($expected);
}
while (next($headers) !== FALSE);

echo ($i === 0)
  ? 'OK'
  : 'A total of '.$i.' errors found.';
?>
--EXPECT--
OK