composer update

This commit is contained in:
Manish Verma
2018-12-05 10:50:52 +05:30
parent 9eabcacfa7
commit 4addd1e9c6
3328 changed files with 156676 additions and 138988 deletions

View File

@@ -337,7 +337,8 @@ class BinaryFileResponseTest extends ResponseTestCase
{
return array(
array('/var/www/var/www/files/foo.txt', '/var/www/=/files/', '/files/var/www/files/foo.txt'),
array('/home/foo/bar.txt', '/var/www/=/files/,/home/foo/=/baz/', '/baz/bar.txt'),
array('/home/Foo/bar.txt', '/var/www/=/files/,/home/Foo/=/baz/', '/baz/bar.txt'),
array('/home/Foo/bar.txt', '"/var/www/"="/files/", "/home/Foo/"="/baz/"', '/baz/bar.txt'),
);
}

View File

@@ -45,7 +45,7 @@ class CookieTest extends TestCase
*/
public function testInstantiationThrowsExceptionIfCookieNameContainsInvalidCharacters($name)
{
new Cookie($name);
Cookie::create($name);
}
/**
@@ -53,12 +53,12 @@ class CookieTest extends TestCase
*/
public function testInvalidExpiration()
{
new Cookie('MyCookie', 'foo', 'bar');
Cookie::create('MyCookie', 'foo', 'bar');
}
public function testNegativeExpirationIsNotPossible()
{
$cookie = new Cookie('foo', 'bar', -100);
$cookie = Cookie::create('foo', 'bar', -100);
$this->assertSame(0, $cookie->getExpiresTime());
}
@@ -66,32 +66,32 @@ class CookieTest extends TestCase
public function testGetValue()
{
$value = 'MyValue';
$cookie = new Cookie('MyCookie', $value);
$cookie = Cookie::create('MyCookie', $value);
$this->assertSame($value, $cookie->getValue(), '->getValue() returns the proper value');
}
public function testGetPath()
{
$cookie = new Cookie('foo', 'bar');
$cookie = Cookie::create('foo', 'bar');
$this->assertSame('/', $cookie->getPath(), '->getPath() returns / as the default path');
}
public function testGetExpiresTime()
{
$cookie = new Cookie('foo', 'bar');
$cookie = Cookie::create('foo', 'bar');
$this->assertEquals(0, $cookie->getExpiresTime(), '->getExpiresTime() returns the default expire date');
$cookie = new Cookie('foo', 'bar', $expire = time() + 3600);
$cookie = Cookie::create('foo', 'bar', $expire = time() + 3600);
$this->assertEquals($expire, $cookie->getExpiresTime(), '->getExpiresTime() returns the expire date');
}
public function testGetExpiresTimeIsCastToInt()
{
$cookie = new Cookie('foo', 'bar', 3600.9);
$cookie = Cookie::create('foo', 'bar', 3600.9);
$this->assertSame(3600, $cookie->getExpiresTime(), '->getExpiresTime() returns the expire date as an integer');
}
@@ -99,7 +99,7 @@ class CookieTest extends TestCase
public function testConstructorWithDateTime()
{
$expire = new \DateTime();
$cookie = new Cookie('foo', 'bar', $expire);
$cookie = Cookie::create('foo', 'bar', $expire);
$this->assertEquals($expire->format('U'), $cookie->getExpiresTime(), '->getExpiresTime() returns the expire date');
}
@@ -107,7 +107,7 @@ class CookieTest extends TestCase
public function testConstructorWithDateTimeImmutable()
{
$expire = new \DateTimeImmutable();
$cookie = new Cookie('foo', 'bar', $expire);
$cookie = Cookie::create('foo', 'bar', $expire);
$this->assertEquals($expire->format('U'), $cookie->getExpiresTime(), '->getExpiresTime() returns the expire date');
}
@@ -115,7 +115,7 @@ class CookieTest extends TestCase
public function testGetExpiresTimeWithStringValue()
{
$value = '+1 day';
$cookie = new Cookie('foo', 'bar', $value);
$cookie = Cookie::create('foo', 'bar', $value);
$expire = strtotime($value);
$this->assertEquals($expire, $cookie->getExpiresTime(), '->getExpiresTime() returns the expire date', 1);
@@ -123,99 +123,99 @@ class CookieTest extends TestCase
public function testGetDomain()
{
$cookie = new Cookie('foo', 'bar', 0, '/', '.myfoodomain.com');
$cookie = Cookie::create('foo', 'bar', 0, '/', '.myfoodomain.com');
$this->assertEquals('.myfoodomain.com', $cookie->getDomain(), '->getDomain() returns the domain name on which the cookie is valid');
}
public function testIsSecure()
{
$cookie = new Cookie('foo', 'bar', 0, '/', '.myfoodomain.com', true);
$cookie = Cookie::create('foo', 'bar', 0, '/', '.myfoodomain.com', true);
$this->assertTrue($cookie->isSecure(), '->isSecure() returns whether the cookie is transmitted over HTTPS');
}
public function testIsHttpOnly()
{
$cookie = new Cookie('foo', 'bar', 0, '/', '.myfoodomain.com', false, true);
$cookie = Cookie::create('foo', 'bar', 0, '/', '.myfoodomain.com', false, true);
$this->assertTrue($cookie->isHttpOnly(), '->isHttpOnly() returns whether the cookie is only transmitted over HTTP');
}
public function testCookieIsNotCleared()
{
$cookie = new Cookie('foo', 'bar', time() + 3600 * 24);
$cookie = Cookie::create('foo', 'bar', time() + 3600 * 24);
$this->assertFalse($cookie->isCleared(), '->isCleared() returns false if the cookie did not expire yet');
}
public function testCookieIsCleared()
{
$cookie = new Cookie('foo', 'bar', time() - 20);
$cookie = Cookie::create('foo', 'bar', time() - 20);
$this->assertTrue($cookie->isCleared(), '->isCleared() returns true if the cookie has expired');
$cookie = new Cookie('foo', 'bar');
$cookie = Cookie::create('foo', 'bar');
$this->assertFalse($cookie->isCleared());
$cookie = new Cookie('foo', 'bar', 0);
$cookie = Cookie::create('foo', 'bar');
$this->assertFalse($cookie->isCleared());
$cookie = new Cookie('foo', 'bar', -1);
$cookie = Cookie::create('foo', 'bar', -1);
$this->assertFalse($cookie->isCleared());
}
public function testToString()
{
$cookie = new Cookie('foo', 'bar', $expire = strtotime('Fri, 20-May-2011 15:25:52 GMT'), '/', '.myfoodomain.com', true);
$cookie = Cookie::create('foo', 'bar', $expire = strtotime('Fri, 20-May-2011 15:25:52 GMT'), '/', '.myfoodomain.com', true, true, false, null);
$this->assertEquals('foo=bar; expires=Fri, 20-May-2011 15:25:52 GMT; Max-Age=0; path=/; domain=.myfoodomain.com; secure; httponly', (string) $cookie, '->__toString() returns string representation of the cookie');
$cookie = new Cookie('foo', 'bar with white spaces', strtotime('Fri, 20-May-2011 15:25:52 GMT'), '/', '.myfoodomain.com', true);
$cookie = Cookie::create('foo', 'bar with white spaces', strtotime('Fri, 20-May-2011 15:25:52 GMT'), '/', '.myfoodomain.com', true, true, false, null);
$this->assertEquals('foo=bar%20with%20white%20spaces; expires=Fri, 20-May-2011 15:25:52 GMT; Max-Age=0; path=/; domain=.myfoodomain.com; secure; httponly', (string) $cookie, '->__toString() encodes the value of the cookie according to RFC 3986 (white space = %20)');
$cookie = new Cookie('foo', null, 1, '/admin/', '.myfoodomain.com');
$cookie = Cookie::create('foo', null, 1, '/admin/', '.myfoodomain.com', false, true, false, null);
$this->assertEquals('foo=deleted; expires='.gmdate('D, d-M-Y H:i:s T', $expire = time() - 31536001).'; Max-Age=0; path=/admin/; domain=.myfoodomain.com; httponly', (string) $cookie, '->__toString() returns string representation of a cleared cookie if value is NULL');
$cookie = new Cookie('foo', 'bar', 0, '/', '');
$this->assertEquals('foo=bar; path=/; httponly', (string) $cookie);
$cookie = Cookie::create('foo', 'bar');
$this->assertEquals('foo=bar; path=/; httponly; samesite=lax', (string) $cookie);
}
public function testRawCookie()
{
$cookie = new Cookie('foo', 'b a r', 0, '/', null, false, false);
$cookie = Cookie::create('foo', 'b a r', 0, '/', null, false, false, false, null);
$this->assertFalse($cookie->isRaw());
$this->assertEquals('foo=b%20a%20r; path=/', (string) $cookie);
$cookie = new Cookie('foo', 'b+a+r', 0, '/', null, false, false, true);
$cookie = Cookie::create('foo', 'b+a+r', 0, '/', null, false, false, true, null);
$this->assertTrue($cookie->isRaw());
$this->assertEquals('foo=b+a+r; path=/', (string) $cookie);
}
public function testGetMaxAge()
{
$cookie = new Cookie('foo', 'bar');
$cookie = Cookie::create('foo', 'bar');
$this->assertEquals(0, $cookie->getMaxAge());
$cookie = new Cookie('foo', 'bar', $expire = time() + 100);
$cookie = Cookie::create('foo', 'bar', $expire = time() + 100);
$this->assertEquals($expire - time(), $cookie->getMaxAge());
$cookie = new Cookie('foo', 'bar', $expire = time() - 100);
$cookie = Cookie::create('foo', 'bar', $expire = time() - 100);
$this->assertEquals(0, $cookie->getMaxAge());
}
public function testFromString()
{
$cookie = Cookie::fromString('foo=bar; expires=Fri, 20-May-2011 15:25:52 GMT; path=/; domain=.myfoodomain.com; secure; httponly');
$this->assertEquals(new Cookie('foo', 'bar', strtotime('Fri, 20-May-2011 15:25:52 GMT'), '/', '.myfoodomain.com', true, true, true), $cookie);
$this->assertEquals(Cookie::create('foo', 'bar', strtotime('Fri, 20-May-2011 15:25:52 GMT'), '/', '.myfoodomain.com', true, true, true, null), $cookie);
$cookie = Cookie::fromString('foo=bar', true);
$this->assertEquals(new Cookie('foo', 'bar', 0, '/', null, false, false), $cookie);
$this->assertEquals(Cookie::create('foo', 'bar', 0, '/', null, false, false, false, null), $cookie);
$cookie = Cookie::fromString('foo', true);
$this->assertEquals(new Cookie('foo', null, 0, '/', null, false, false), $cookie);
$this->assertEquals(Cookie::create('foo', null, 0, '/', null, false, false, false, null), $cookie);
}
public function testFromStringWithHttpOnly()
@@ -227,9 +227,27 @@ class CookieTest extends TestCase
$this->assertFalse($cookie->isHttpOnly());
}
public function testSameSiteAttributeIsCaseInsensitive()
public function testSameSiteAttribute()
{
$cookie = new Cookie('foo', 'bar', 0, '/', null, false, true, false, 'Lax');
$this->assertEquals('lax', $cookie->getSameSite());
$cookie = new Cookie('foo', 'bar', 0, '/', null, false, true, false, '');
$this->assertNull($cookie->getSameSite());
}
public function testSetSecureDefault()
{
$cookie = Cookie::create('foo', 'bar');
$this->assertFalse($cookie->isSecure());
$cookie->setSecureDefault(true);
$this->assertTrue($cookie->isSecure());
$cookie->setSecureDefault(false);
$this->assertFalse($cookie->isSecure());
}
}

View File

@@ -22,7 +22,7 @@ error_reporting(-1);
ini_set('html_errors', 0);
ini_set('display_errors', 1);
if (ini_get('xdebug.default_enable')) {
if (filter_var(ini_get('xdebug.default_enable'), FILTER_VALIDATE_BOOLEAN)) {
xdebug_disable();
}

View File

@@ -4,7 +4,7 @@ use Symfony\Component\HttpFoundation\Cookie;
$r = require __DIR__.'/common.inc';
$r->headers->setCookie(new Cookie('foo', 'bar', 253402310800, '', null, false, false));
$r->headers->setCookie(new Cookie('foo', 'bar', 253402310800, '', null, false, false, false, null));
$r->sendHeaders();
setcookie('foo2', 'bar', 253402310800, '/');

View File

@@ -6,7 +6,7 @@ $r = require __DIR__.'/common.inc';
$str = '?*():@&+$/%#[]';
$r->headers->setCookie(new Cookie($str, $str, 0, '/', null, false, false, true));
$r->headers->setCookie(new Cookie($str, $str, 0, '/', null, false, false, true, null));
$r->sendHeaders();
setrawcookie($str, $str, 0, '/', null, false, false);

View File

@@ -6,7 +6,7 @@ $r = require __DIR__.'/common.inc';
$str = '?*():@&+$/%#[]';
$r->headers->setCookie(new Cookie($str, $str, 0, '', null, false, false));
$r->headers->setCookie(new Cookie($str, $str, 0, '', null, false, false, false, null));
$r->sendHeaders();
setcookie($str, $str, 0, '/');

View File

@@ -5,7 +5,7 @@ use Symfony\Component\HttpFoundation\Cookie;
$r = require __DIR__.'/common.inc';
try {
$r->headers->setCookie(new Cookie('Hello + world', 'hodor'));
$r->headers->setCookie(Cookie::create('Hello + world', 'hodor'));
} catch (\InvalidArgumentException $e) {
echo $e->getMessage();
}

View File

@@ -82,4 +82,53 @@ class HeaderUtilsTest extends TestCase
$this->assertEquals('foo "bar"', HeaderUtils::unquote('"foo \"\b\a\r\""'));
$this->assertEquals('foo \\ bar', HeaderUtils::unquote('"foo \\\\ bar"'));
}
/**
* @expectedException \InvalidArgumentException
*/
public function testMakeDispositionInvalidDisposition()
{
HeaderUtils::makeDisposition('invalid', 'foo.html');
}
/**
* @dataProvider provideMakeDisposition
*/
public function testMakeDisposition($disposition, $filename, $filenameFallback, $expected)
{
$this->assertEquals($expected, HeaderUtils::makeDisposition($disposition, $filename, $filenameFallback));
}
public function provideMakeDisposition()
{
return array(
array('attachment', 'foo.html', 'foo.html', 'attachment; filename=foo.html'),
array('attachment', 'foo.html', '', 'attachment; filename=foo.html'),
array('attachment', 'foo bar.html', '', 'attachment; filename="foo bar.html"'),
array('attachment', 'foo "bar".html', '', 'attachment; filename="foo \\"bar\\".html"'),
array('attachment', 'foo%20bar.html', 'foo bar.html', 'attachment; filename="foo bar.html"; filename*=utf-8\'\'foo%2520bar.html'),
array('attachment', 'föö.html', 'foo.html', 'attachment; filename=foo.html; filename*=utf-8\'\'f%C3%B6%C3%B6.html'),
);
}
/**
* @dataProvider provideMakeDispositionFail
* @expectedException \InvalidArgumentException
*/
public function testMakeDispositionFail($disposition, $filename)
{
HeaderUtils::makeDisposition($disposition, $filename);
}
public function provideMakeDispositionFail()
{
return array(
array('attachment', 'foo%20bar.html'),
array('attachment', 'foo/bar.html'),
array('attachment', '/foo.html'),
array('attachment', 'foo\bar.html'),
array('attachment', '\foo.html'),
array('attachment', 'föö.html'),
);
}
}

View File

@@ -78,6 +78,21 @@ class RequestMatcherTest extends TestCase
$this->assertSame($isMatch, $matcher->matches($request));
}
public function testPort()
{
$matcher = new RequestMatcher();
$request = Request::create('', 'get', array(), array(), array(), array('HTTP_HOST' => null, 'SERVER_PORT' => 8000));
$matcher->matchPort(8000);
$this->assertTrue($matcher->matches($request));
$matcher->matchPort(9000);
$this->assertFalse($matcher->matches($request));
$matcher = new RequestMatcher(null, null, null, null, array(), null, 8000);
$this->assertTrue($matcher->matches($request));
}
public function getHostData()
{
return array(

View File

@@ -232,6 +232,55 @@ class RequestTest extends TestCase
$this->assertEquals(80, $request->getPort());
$this->assertEquals('test.com', $request->getHttpHost());
$this->assertFalse($request->isSecure());
// Fragment should not be included in the URI
$request = Request::create('http://test.com/foo#bar');
$this->assertEquals('http://test.com/foo', $request->getUri());
}
public function testCreateWithRequestUri()
{
$request = Request::create('http://test.com:80/foo');
$request->server->set('REQUEST_URI', 'http://test.com:80/foo');
$this->assertEquals('http://test.com/foo', $request->getUri());
$this->assertEquals('/foo', $request->getPathInfo());
$this->assertEquals('test.com', $request->getHost());
$this->assertEquals('test.com', $request->getHttpHost());
$this->assertEquals(80, $request->getPort());
$this->assertFalse($request->isSecure());
$request = Request::create('http://test.com:8080/foo');
$request->server->set('REQUEST_URI', 'http://test.com:8080/foo');
$this->assertEquals('http://test.com:8080/foo', $request->getUri());
$this->assertEquals('/foo', $request->getPathInfo());
$this->assertEquals('test.com', $request->getHost());
$this->assertEquals('test.com:8080', $request->getHttpHost());
$this->assertEquals(8080, $request->getPort());
$this->assertFalse($request->isSecure());
$request = Request::create('http://test.com/foo?bar=foo', 'GET', array('bar' => 'baz'));
$request->server->set('REQUEST_URI', 'http://test.com/foo?bar=foo');
$this->assertEquals('http://test.com/foo?bar=baz', $request->getUri());
$this->assertEquals('/foo', $request->getPathInfo());
$this->assertEquals('bar=baz', $request->getQueryString());
$this->assertEquals('test.com', $request->getHost());
$this->assertEquals('test.com', $request->getHttpHost());
$this->assertEquals(80, $request->getPort());
$this->assertFalse($request->isSecure());
$request = Request::create('https://test.com:443/foo');
$request->server->set('REQUEST_URI', 'https://test.com:443/foo');
$this->assertEquals('https://test.com/foo', $request->getUri());
$this->assertEquals('/foo', $request->getPathInfo());
$this->assertEquals('test.com', $request->getHost());
$this->assertEquals('test.com', $request->getHttpHost());
$this->assertEquals(443, $request->getPort());
$this->assertTrue($request->isSecure());
// Fragment should not be included in the URI
$request = Request::create('http://test.com/foo#bar');
$request->server->set('REQUEST_URI', 'http://test.com/foo#bar');
$this->assertEquals('http://test.com/foo', $request->getUri());
}
public function testCreateCheckPrecedence()
@@ -332,6 +381,9 @@ class RequestTest extends TestCase
{
$request = new Request();
$this->assertEquals('json', $request->getFormat('application/json; charset=utf-8'));
$this->assertEquals('json', $request->getFormat('application/json;charset=utf-8'));
$this->assertEquals('json', $request->getFormat('application/json ; charset=utf-8'));
$this->assertEquals('json', $request->getFormat('application/json ;charset=utf-8'));
}
/**

View File

@@ -110,9 +110,9 @@ class ResponseHeaderBagTest extends TestCase
public function testToStringIncludesCookieHeaders()
{
$bag = new ResponseHeaderBag(array());
$bag->setCookie(new Cookie('foo', 'bar'));
$bag->setCookie(Cookie::create('foo', 'bar'));
$this->assertSetCookieHeader('foo=bar; path=/; httponly', $bag);
$this->assertSetCookieHeader('foo=bar; path=/; httponly; samesite=lax', $bag);
$bag->clearCookie('foo');
@@ -154,24 +154,24 @@ class ResponseHeaderBagTest extends TestCase
public function testCookiesWithSameNames()
{
$bag = new ResponseHeaderBag();
$bag->setCookie(new Cookie('foo', 'bar', 0, '/path/foo', 'foo.bar'));
$bag->setCookie(new Cookie('foo', 'bar', 0, '/path/bar', 'foo.bar'));
$bag->setCookie(new Cookie('foo', 'bar', 0, '/path/bar', 'bar.foo'));
$bag->setCookie(new Cookie('foo', 'bar'));
$bag->setCookie(Cookie::create('foo', 'bar', 0, '/path/foo', 'foo.bar'));
$bag->setCookie(Cookie::create('foo', 'bar', 0, '/path/bar', 'foo.bar'));
$bag->setCookie(Cookie::create('foo', 'bar', 0, '/path/bar', 'bar.foo'));
$bag->setCookie(Cookie::create('foo', 'bar'));
$this->assertCount(4, $bag->getCookies());
$this->assertEquals('foo=bar; path=/path/foo; domain=foo.bar; httponly', $bag->get('set-cookie'));
$this->assertEquals('foo=bar; path=/path/foo; domain=foo.bar; httponly; samesite=lax', $bag->get('set-cookie'));
$this->assertEquals(array(
'foo=bar; path=/path/foo; domain=foo.bar; httponly',
'foo=bar; path=/path/bar; domain=foo.bar; httponly',
'foo=bar; path=/path/bar; domain=bar.foo; httponly',
'foo=bar; path=/; httponly',
'foo=bar; path=/path/foo; domain=foo.bar; httponly; samesite=lax',
'foo=bar; path=/path/bar; domain=foo.bar; httponly; samesite=lax',
'foo=bar; path=/path/bar; domain=bar.foo; httponly; samesite=lax',
'foo=bar; path=/; httponly; samesite=lax',
), $bag->get('set-cookie', null, false));
$this->assertSetCookieHeader('foo=bar; path=/path/foo; domain=foo.bar; httponly', $bag);
$this->assertSetCookieHeader('foo=bar; path=/path/bar; domain=foo.bar; httponly', $bag);
$this->assertSetCookieHeader('foo=bar; path=/path/bar; domain=bar.foo; httponly', $bag);
$this->assertSetCookieHeader('foo=bar; path=/; httponly', $bag);
$this->assertSetCookieHeader('foo=bar; path=/path/foo; domain=foo.bar; httponly; samesite=lax', $bag);
$this->assertSetCookieHeader('foo=bar; path=/path/bar; domain=foo.bar; httponly; samesite=lax', $bag);
$this->assertSetCookieHeader('foo=bar; path=/path/bar; domain=bar.foo; httponly; samesite=lax', $bag);
$this->assertSetCookieHeader('foo=bar; path=/; httponly; samesite=lax', $bag);
$cookies = $bag->getCookies(ResponseHeaderBag::COOKIES_ARRAY);
@@ -186,8 +186,8 @@ class ResponseHeaderBagTest extends TestCase
$bag = new ResponseHeaderBag();
$this->assertFalse($bag->has('set-cookie'));
$bag->setCookie(new Cookie('foo', 'bar', 0, '/path/foo', 'foo.bar'));
$bag->setCookie(new Cookie('bar', 'foo', 0, '/path/bar', 'foo.bar'));
$bag->setCookie(Cookie::create('foo', 'bar', 0, '/path/foo', 'foo.bar'));
$bag->setCookie(Cookie::create('bar', 'foo', 0, '/path/bar', 'foo.bar'));
$this->assertTrue($bag->has('set-cookie'));
$cookies = $bag->getCookies(ResponseHeaderBag::COOKIES_ARRAY);
@@ -209,8 +209,8 @@ class ResponseHeaderBagTest extends TestCase
public function testRemoveCookieWithNullRemove()
{
$bag = new ResponseHeaderBag();
$bag->setCookie(new Cookie('foo', 'bar', 0));
$bag->setCookie(new Cookie('bar', 'foo', 0));
$bag->setCookie(Cookie::create('foo', 'bar'));
$bag->setCookie(Cookie::create('bar', 'foo'));
$cookies = $bag->getCookies(ResponseHeaderBag::COOKIES_ARRAY);
$this->assertArrayHasKey('/', $cookies['']);
@@ -228,12 +228,12 @@ class ResponseHeaderBagTest extends TestCase
{
$bag = new ResponseHeaderBag();
$bag->set('set-cookie', 'foo=bar');
$this->assertEquals(array(new Cookie('foo', 'bar', 0, '/', null, false, false, true)), $bag->getCookies());
$this->assertEquals(array(Cookie::create('foo', 'bar', 0, '/', null, false, false, true, null)), $bag->getCookies());
$bag->set('set-cookie', 'foo2=bar2', false);
$this->assertEquals(array(
new Cookie('foo', 'bar', 0, '/', null, false, false, true),
new Cookie('foo2', 'bar2', 0, '/', null, false, false, true),
Cookie::create('foo', 'bar', 0, '/', null, false, false, true, null),
Cookie::create('foo2', 'bar2', 0, '/', null, false, false, true, null),
), $bag->getCookies());
$bag->remove('set-cookie');
@@ -250,26 +250,6 @@ class ResponseHeaderBagTest extends TestCase
$bag->getCookies('invalid_argument');
}
/**
* @expectedException \InvalidArgumentException
*/
public function testMakeDispositionInvalidDisposition()
{
$headers = new ResponseHeaderBag();
$headers->makeDisposition('invalid', 'foo.html');
}
/**
* @dataProvider provideMakeDisposition
*/
public function testMakeDisposition($disposition, $filename, $filenameFallback, $expected)
{
$headers = new ResponseHeaderBag();
$this->assertEquals($expected, $headers->makeDisposition($disposition, $filename, $filenameFallback));
}
public function testToStringDoesntMessUpHeaders()
{
$headers = new ResponseHeaderBag();
@@ -284,41 +264,6 @@ class ResponseHeaderBagTest extends TestCase
$this->assertEquals(array('text/html'), $allHeaders['Content-type']);
}
public function provideMakeDisposition()
{
return array(
array('attachment', 'foo.html', 'foo.html', 'attachment; filename=foo.html'),
array('attachment', 'foo.html', '', 'attachment; filename=foo.html'),
array('attachment', 'foo bar.html', '', 'attachment; filename="foo bar.html"'),
array('attachment', 'foo "bar".html', '', 'attachment; filename="foo \\"bar\\".html"'),
array('attachment', 'foo%20bar.html', 'foo bar.html', 'attachment; filename="foo bar.html"; filename*=utf-8\'\'foo%2520bar.html'),
array('attachment', 'föö.html', 'foo.html', 'attachment; filename=foo.html; filename*=utf-8\'\'f%C3%B6%C3%B6.html'),
);
}
/**
* @dataProvider provideMakeDispositionFail
* @expectedException \InvalidArgumentException
*/
public function testMakeDispositionFail($disposition, $filename)
{
$headers = new ResponseHeaderBag();
$headers->makeDisposition($disposition, $filename);
}
public function provideMakeDispositionFail()
{
return array(
array('attachment', 'foo%20bar.html'),
array('attachment', 'foo/bar.html'),
array('attachment', '/foo.html'),
array('attachment', 'foo\bar.html'),
array('attachment', '\foo.html'),
array('attachment', 'föö.html'),
);
}
public function testDateHeaderAddedOnCreation()
{
$now = time();

View File

@@ -11,6 +11,7 @@
namespace Symfony\Component\HttpFoundation\Tests;
use Symfony\Component\HttpFoundation\Cookie;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
@@ -573,6 +574,24 @@ class ResponseTest extends ResponseTestCase
$this->assertFalse($response->headers->has('expires'));
}
public function testPrepareSetsCookiesSecure()
{
$cookie = Cookie::create('foo', 'bar');
$response = new Response('foo');
$response->headers->setCookie($cookie);
$request = Request::create('/', 'GET');
$response->prepare($request);
$this->assertFalse($cookie->isSecure());
$request = Request::create('https://localhost/', 'GET');
$response->prepare($request);
$this->assertTrue($cookie->isSecure());
}
public function testSetCache()
{
$response = new Response();

View File

@@ -45,7 +45,7 @@ class AttributeBagTest extends TestCase
),
),
);
$this->bag = new AttributeBag('_sf2');
$this->bag = new AttributeBag('_sf');
$this->bag->initialize($this->array);
}
@@ -67,7 +67,7 @@ class AttributeBagTest extends TestCase
public function testGetStorageKey()
{
$this->assertEquals('_sf2', $this->bag->getStorageKey());
$this->assertEquals('_sf', $this->bag->getStorageKey());
$attributeBag = new AttributeBag('test');
$this->assertEquals('test', $attributeBag->getStorageKey());
}

View File

@@ -70,6 +70,27 @@ class SessionTest extends TestCase
$this->assertEquals('0123456789abcdef', $this->session->getId());
}
public function testSetIdAfterStart()
{
$this->session->start();
$id = $this->session->getId();
$e = null;
try {
$this->session->setId($id);
} catch (\Exception $e) {
}
$this->assertNull($e);
try {
$this->session->setId('different');
} catch (\Exception $e) {
}
$this->assertInstanceOf('\LogicException', $e);
}
public function testSetName()
{
$this->assertEquals('MOCKSESSID', $this->session->getName());

View File

@@ -0,0 +1,16 @@
open
validateId
read
doRead:
read
write
doWrite: foo|s:3:"bar";
close
Array
(
[0] => Content-Type: text/plain; charset=utf-8
[1] => Cache-Control: max-age=0, private, must-revalidate
[2] => Set-Cookie: sid=random_session_id; path=/; secure; HttpOnly; SameSite=lax
)
shutdown

View File

@@ -0,0 +1,13 @@
<?php
require __DIR__.'/common.inc';
use Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage;
$storage = new NativeSessionStorage(array('cookie_samesite' => 'lax'));
$storage->setSaveHandler(new TestSessionHandler());
$storage->start();
$_SESSION = array('foo' => 'bar');
ob_start(function ($buffer) { return str_replace(session_id(), 'random_session_id', $buffer); });

View File

@@ -0,0 +1,23 @@
open
validateId
read
doRead:
read
destroy
close
open
validateId
read
doRead:
read
write
doWrite: foo|s:3:"bar";
close
Array
(
[0] => Content-Type: text/plain; charset=utf-8
[1] => Cache-Control: max-age=0, private, must-revalidate
[2] => Set-Cookie: sid=random_session_id; path=/; secure; HttpOnly; SameSite=lax
)
shutdown

View File

@@ -0,0 +1,15 @@
<?php
require __DIR__.'/common.inc';
use Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage;
$storage = new NativeSessionStorage(array('cookie_samesite' => 'lax'));
$storage->setSaveHandler(new TestSessionHandler());
$storage->start();
$_SESSION = array('foo' => 'bar');
$storage->regenerate(true);
ob_start(function ($buffer) { return preg_replace('~_sf2_meta.*$~m', '', str_replace(session_id(), 'random_session_id', $buffer)); });

View File

@@ -45,7 +45,7 @@ class MongoDbSessionHandlerTest extends TestCase
'data_field' => 'data',
'time_field' => 'time',
'expiry_field' => 'expires_at',
'database' => 'sf2-test',
'database' => 'sf-test',
'collection' => 'session-test',
);

View File

@@ -33,7 +33,7 @@ class PdoSessionHandlerTest extends TestCase
protected function getPersistentSqliteDsn()
{
$this->dbFile = tempnam(sys_get_temp_dir(), 'sf2_sqlite_sessions');
$this->dbFile = tempnam(sys_get_temp_dir(), 'sf_sqlite_sessions');
return 'sqlite:'.$this->dbFile;
}
@@ -153,7 +153,7 @@ class PdoSessionHandlerTest extends TestCase
public function testReadLockedConvertsStreamToString()
{
if (ini_get('session.use_strict_mode')) {
if (filter_var(ini_get('session.use_strict_mode'), FILTER_VALIDATE_BOOLEAN)) {
$this->markTestSkipped('Strict mode needs no locking for new sessions.');
}

View File

@@ -48,7 +48,7 @@ class MockArraySessionStorageTest extends TestCase
$this->data = array(
$this->attributes->getStorageKey() => array('foo' => 'bar'),
$this->flashes->getStorageKey() => array('notice' => 'hello'),
);
);
$this->storage = new MockArraySessionStorage();
$this->storage->registerBag($this->flashes);

View File

@@ -35,7 +35,7 @@ class MockFileSessionStorageTest extends TestCase
protected function setUp()
{
$this->sessionDir = sys_get_temp_dir().'/sf2test';
$this->sessionDir = sys_get_temp_dir().'/sftest';
$this->storage = $this->getStorage();
}

View File

@@ -36,7 +36,7 @@ class NativeSessionStorageTest extends TestCase
protected function setUp()
{
$this->iniSet('session.save_handler', 'files');
$this->iniSet('session.save_path', $this->savePath = sys_get_temp_dir().'/sf2test');
$this->iniSet('session.save_path', $this->savePath = sys_get_temp_dir().'/sftest');
if (!is_dir($this->savePath)) {
mkdir($this->savePath);
}
@@ -171,6 +171,10 @@ class NativeSessionStorageTest extends TestCase
'cookie_httponly' => false,
);
if (\PHP_VERSION_ID >= 70300) {
$options['cookie_samesite'] = 'lax';
}
$this->getStorage($options);
$temp = session_get_cookie_params();
$gco = array();

View File

@@ -32,7 +32,7 @@ class PhpBridgeSessionStorageTest extends TestCase
protected function setUp()
{
$this->iniSet('session.save_handler', 'files');
$this->iniSet('session.save_path', $this->savePath = sys_get_temp_dir().'/sf2test');
$this->iniSet('session.save_path', $this->savePath = sys_get_temp_dir().'/sftest');
if (!is_dir($this->savePath)) {
mkdir($this->savePath);
}