8000 Test $sameSite from Cookie and remove useless code in common.inc · symfony/symfony@30cac90 · GitHub
[go: up one dir, main page]

Skip to content

Commit 30cac90

Browse files
committed
Test $sameSite from Cookie and remove useless code in common.inc
1 parent 11f14c2 commit 30cac90

File tree

8 files changed

+53
-143
lines changed

8 files changed

+53
-143
lines changed
Lines changed: 0 additions & 119 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
<?php
22

3-
use Symfony\Component\HttpFoundation\Session\Storage\Handler\AbstractSessionHandler;
4-
53
$parent = __DIR__;
64
while (!@file_exists($parent.'/vendor/autoload.php')) {
75
if (!@file_exists($parent)) {
@@ -21,24 +19,6 @@ require $parent.'/vendor/autoload.php';
2119
error_reporting(-1);
2220
ini_set('html_errors', 0);
2321
ini_set('display_errors', 1);
24-
ini_set('session.gc_probability', 0);
25-
ini_set('session.serialize_handler', 'php');
26-
ini_set('session.cookie_lifetime', 0);
27-
ini_set('session.cookie_domain', '');
28-
ini_set('session.cookie_secure', '');
29-
ini_set('session.cookie_httponly', '');
30-
ini_set('session.use_cookies', 1);
31-
ini_set('session.use_only_cookies', 1);
32-
ini_set('session.cache_expire', 180);
33-
ini_set('session.cookie_path', '/');
34-
ini_set('session.cookie_domain', '');
35-
ini_set('session.cookie_secure', 1);
36-
ini_set('session.cookie_httponly', 1);
37-
ini_set('session.use_strict_mode', 1);
38-
ini_set('session.lazy_write', 1);
39-
ini_set('session.name', 'sid');
40-
ini_set('session.save_path', __DIR__);
41-
ini_set('session.cache_limiter', '');
4222

4323
header_remove('X-Powered-By');
4424
header('Content-Type: text/plain; charset=utf-8');
@@ -50,102 +30,3 @@ register_shutdown_function(function () {
5030
echo "shutdown\n";
5131
});
5232
ob_start();
53-
54-
class TestSessionHandler extends AbstractSessionHandler
55-
{
56-
private $data;
57-
58-
public function __construct($data = '')
59-
{
60-
$this->data = $data;
61-
}
62-
63-
public function open($path, $name)
64-
{
65-
echo __FUNCTION__, "\n";
66-
67-
return parent::open($path, $name);
68-
}
69-
70-
public function validateId($sessionId)
71-
{
72-
echo __FUNCTION__, "\n";
73-
74-
return parent::validateId($sessionId);
75-
}
76-
77-
/**
78-
* {@inheritdoc}
79-
*/
80-
public function read($sessionId)
81-
{
82-
echo __FUNCTION__, "\n";
83-
84-
return parent::read($sessionId);
85-
}
86-
87-
/**
88-
* {@inheritdoc}
89-
*/
90-
public function updateTimestamp($sessionId, $data)
91-
{
92-
echo __FUNCTION__, "\n";
93-
94-
return true;
95-
}
96-
97-
/**
98-
* {@inheritdoc}
99-
*/
100-
public function write($sessionId, $data)
101-
{
102-
echo __FUNCTION__, "\n";
103-
104-
return parent::write($sessionId, $data);
105-
}
106-
107-
/**
108-
* {@inheritdoc}
109-
*/
110-
public function destroy($sessionId)
111-
{
112-
echo __FUNCTION__, "\n";
113-
114-
return parent::destroy($sessionId);
115-
}
116-
117-
public function close()
118-
{
119-
echo __FUNCTION__, "\n";
120-
121-
return true;
122-
}
123-
124-
public function gc($maxLifetime)
125-
{
126-
echo __FUNCTION__, "\n";
127-
128-
return true;
129-
}
130-
131-
protected function doRead($sessionId)
132-
{
133-
echo __FUNCTION__.': ', $this->data, "\n";
134-
135-
return $this->data;
136-
}
137-
138-
protected function doWrite($sessionId, $data)
139-
{
140-
echo __FUNCTION__.': ', $data, "\n";
141-
142-
return true;
143-
}
144-
145-
protected function doDestroy($sessionId)
146-
{
147-
echo __FUNCTION__, "\n";
148-
149-
return true;
150-
}
151-
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
2+
Array
3+
(
4+
[0] => Content-Type: text/plain; charset=utf-8
5+
[1] => Cache-Control: no-cache, private
6+
[2] => Date: Sat, 12 Nov 1955 20:04:00 GMT
7+
[3] => Set-Cookie: CookieSamesiteLaxTest=LaxValue; path=/; httponly; samesite=lax
8+
)
9+
shutdown
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
use Symfony\Component\HttpFoundation\Cookie;
4+
use Symfony\Component\HttpFoundation\Response;
5+
6+
require __DIR__ . '/common.inc';
7+
8+
$r = new Response();
9+
$r->headers->set('Date', 'Sat, 12 Nov 1955 20:04:00 GMT');
10+
$r->headers->setCookie(new Cookie('CookieSamesiteLaxTest', 'LaxValue', 0, '/', null, false, true, false, Cookie::SAMESITE_LAX));
11+
$r->sendHeaders();
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
2+
Array
3+
(
4+
[0] => Content-Type: text/plain; charset=utf-8
5+
[1] => Cache-Control: no-cache, private
6+
[2] => Date: Sat, 12 Nov 1955 20:04:00 GMT
7+
[3] => Set-Cookie: CookieSamesiteStrictTest=StrictValue; path=/; httponly; samesite=strict
8+
)
9+
shutdown
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
use Symfony\Component\HttpFoundation\Cookie;
4+
use Symfony\Component\HttpFoundation\Response;
5+
6+
require __DIR__ . '/common.inc';
7+
8+
$r = new Response();
9+
$r->headers->set('Date', 'Sat, 12 Nov 1955 20:04:00 GMT');
10+
$r->headers->setCookie(new Cookie('CookieSamesiteStrictTest', 'StrictValue', 0, '/', null, false, true, false, Cookie::SAMESITE_STRICT));
11+
$r->sendHeaders();

src/Symfony/Component/HttpFoundation/Tests/Fixtures/send_headers_cookie_samesite.expected

Lines changed: 0 additions & 9 deletions
This file was deleted.

src/Symfony/Component/HttpFoundation/Tests/Fixtures/send_headers_cookie_samesite.php

Lines changed: 0 additions & 11 deletions
This file was deleted.

src/Symfony/Component/HttpFoundation/Tests/HeaderTest.php renamed to src/Symfony/Component/HttpFoundation/Tests/RequestFunctionalTest.php

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
use PHPUnit\Framework\TestCase;
1515

16-
class HeaderTest extends TestCase
16+
class RequestFunctionalTest extends TestCase
1717
{
1818
private static $server;
1919

@@ -37,10 +37,19 @@ public static function tearDownAfterClass()
3737
}
3838
}
3939

40-
public function testHeader()
40+
/**
41+
* @dataProvider provideCookie
42+
*/
43+
public function testCookieSamesite($fixture)
4144
{
42-
$result = file_get_contents('http://localhost:8054/send_headers_cookie_samesite.php');
43-
$this->assertStringEqualsFile(__DIR__ . '/Fixtures/send_headers_cookie_samesite.expected', $result);
45+
$result = file_get_contents(sprintf('http://localhost:8054/%s.php', $fixture));
46+
$this->assertStringEqualsFile(__DIR__.sprintf('/Fixtures/%s.expected', $fixture), $result);
4447
}
4548

49+
public function provideCookie()
50+
{
51+
foreach (glob(__DIR__.'/Fixtures/cookie_*.php') as $file) {
52+
yield array(pathinfo($file, PATHINFO_FILENAME));
53+
}
54+
}
4655
}

0 commit comments

Comments
 (0)
0