Inital commit for unit test configuration
This commit is contained in:

committed by
Manish Verma

parent
2f0796e954
commit
e0436b7757
@@ -208,6 +208,19 @@ class BinaryFileResponseTest extends ResponseTestCase
|
||||
);
|
||||
}
|
||||
|
||||
public function testUnpreparedResponseSendsFullFile()
|
||||
{
|
||||
$response = BinaryFileResponse::create(__DIR__.'/File/Fixtures/test.gif', 200);
|
||||
|
||||
$data = file_get_contents(__DIR__.'/File/Fixtures/test.gif');
|
||||
|
||||
$this->expectOutputString($data);
|
||||
$response = clone $response;
|
||||
$response->sendContent();
|
||||
|
||||
$this->assertEquals(200, $response->getStatusCode());
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provideInvalidRanges
|
||||
*/
|
||||
|
@@ -906,7 +906,7 @@ class RequestTest extends TestCase
|
||||
|
||||
public function getClientIpsProvider()
|
||||
{
|
||||
// $expected $remoteAddr $httpForwardedFor $trustedProxies
|
||||
// $expected $remoteAddr $httpForwardedFor $trustedProxies
|
||||
return array(
|
||||
// simple IPv4
|
||||
array(array('88.88.88.88'), '88.88.88.88', null, null),
|
||||
@@ -920,8 +920,8 @@ class RequestTest extends TestCase
|
||||
|
||||
// forwarded for with remote IPv4 addr not trusted
|
||||
array(array('127.0.0.1'), '127.0.0.1', '88.88.88.88', null),
|
||||
// forwarded for with remote IPv4 addr trusted
|
||||
array(array('88.88.88.88'), '127.0.0.1', '88.88.88.88', array('127.0.0.1')),
|
||||
// forwarded for with remote IPv4 addr trusted + comma
|
||||
array(array('88.88.88.88'), '127.0.0.1', '88.88.88.88,', array('127.0.0.1')),
|
||||
// forwarded for with remote IPv4 and all FF addrs trusted
|
||||
array(array('88.88.88.88'), '127.0.0.1', '88.88.88.88', array('127.0.0.1', '88.88.88.88')),
|
||||
// forwarded for with remote IPv4 range trusted
|
||||
@@ -1025,7 +1025,7 @@ class RequestTest extends TestCase
|
||||
'HTTP_X_FORWARDED_FOR' => $httpXForwardedFor,
|
||||
);
|
||||
|
||||
Request::setTrustedProxies(array('88.88.88.88'), Request::HEADER_X_FORWARDED_ALL);
|
||||
Request::setTrustedProxies(array('88.88.88.88'), -1);
|
||||
|
||||
$request->initialize(array(), array(), array(), array(), array(), $server);
|
||||
|
||||
@@ -2153,6 +2153,55 @@ class RequestTest extends TestCase
|
||||
$this->assertEquals($expectedBaseUrl, $request->getBaseUrl());
|
||||
$this->assertEquals($expectedBasePath, $request->getBasePath());
|
||||
}
|
||||
|
||||
public function testTrustedHost()
|
||||
{
|
||||
Request::setTrustedProxies(array('1.1.1.1'), -1);
|
||||
|
||||
$request = Request::create('/');
|
||||
$request->server->set('REMOTE_ADDR', '1.1.1.1');
|
||||
$request->headers->set('Forwarded', 'host=localhost:8080');
|
||||
$request->headers->set('X-Forwarded-Host', 'localhost:8080');
|
||||
|
||||
$this->assertSame('localhost:8080', $request->getHttpHost());
|
||||
$this->assertSame(8080, $request->getPort());
|
||||
|
||||
$request = Request::create('/');
|
||||
$request->server->set('REMOTE_ADDR', '1.1.1.1');
|
||||
$request->headers->set('Forwarded', 'host="[::1]:443"');
|
||||
$request->headers->set('X-Forwarded-Host', '[::1]:443');
|
||||
$request->headers->set('X-Forwarded-Port', 443);
|
||||
|
||||
$this->assertSame('[::1]:443', $request->getHttpHost());
|
||||
$this->assertSame(443, $request->getPort());
|
||||
}
|
||||
|
||||
public function testTrustedPort()
|
||||
{
|
||||
Request::setTrustedProxies(array('1.1.1.1'), -1);
|
||||
|
||||
$request = Request::create('/');
|
||||
$request->server->set('REMOTE_ADDR', '1.1.1.1');
|
||||
$request->headers->set('Forwarded', 'host=localhost:8080');
|
||||
$request->headers->set('X-Forwarded-Port', 8080);
|
||||
|
||||
$this->assertSame(8080, $request->getPort());
|
||||
|
||||
$request = Request::create('/');
|
||||
$request->server->set('REMOTE_ADDR', '1.1.1.1');
|
||||
$request->headers->set('Forwarded', 'host=localhost');
|
||||
$request->headers->set('X-Forwarded-Port', 80);
|
||||
|
||||
$this->assertSame(80, $request->getPort());
|
||||
|
||||
$request = Request::create('/');
|
||||
$request->server->set('REMOTE_ADDR', '1.1.1.1');
|
||||
$request->headers->set('Forwarded', 'host="[::1]"');
|
||||
$request->headers->set('X-Forwarded-Proto', 'https');
|
||||
$request->headers->set('X-Forwarded-Port', 443);
|
||||
|
||||
$this->assertSame(443, $request->getPort());
|
||||
}
|
||||
}
|
||||
|
||||
class RequestContentProxy extends Request
|
||||
|
@@ -362,6 +362,11 @@ class ResponseTest extends ResponseTestCase
|
||||
$response->headers->set('Expires', -1);
|
||||
$response->expire();
|
||||
$this->assertNull($response->headers->get('Age'), '->expire() does not set the Age when the response is expired');
|
||||
|
||||
$response = new Response();
|
||||
$response->headers->set('Expires', date(DATE_RFC2822, time() + 600));
|
||||
$response->expire();
|
||||
$this->assertNull($response->headers->get('Expires'), '->expire() removes the Expires header when the response is fresh');
|
||||
}
|
||||
|
||||
public function testGetTtl()
|
||||
|
@@ -32,11 +32,6 @@ abstract class AbstractRedisSessionHandlerTestCase extends TestCase
|
||||
*/
|
||||
protected $redisClient;
|
||||
|
||||
/**
|
||||
* @var \Redis
|
||||
*/
|
||||
protected $validator;
|
||||
|
||||
/**
|
||||
* @return \Redis|\RedisArray|\RedisCluster|\Predis\Client
|
||||
*/
|
||||
@@ -52,9 +47,6 @@ abstract class AbstractRedisSessionHandlerTestCase extends TestCase
|
||||
|
||||
$host = getenv('REDIS_HOST') ?: 'localhost';
|
||||
|
||||
$this->validator = new \Redis();
|
||||
$this->validator->connect($host);
|
||||
|
||||
$this->redisClient = $this->createRedisClient($host);
|
||||
$this->storage = new RedisSessionHandler(
|
||||
$this->redisClient,
|
||||
@@ -82,8 +74,8 @@ abstract class AbstractRedisSessionHandlerTestCase extends TestCase
|
||||
|
||||
public function testReadSession()
|
||||
{
|
||||
$this->setFixture(self::PREFIX.'id1', null);
|
||||
$this->setFixture(self::PREFIX.'id2', 'abc123');
|
||||
$this->redisClient->set(self::PREFIX.'id1', null);
|
||||
$this->redisClient->set(self::PREFIX.'id2', 'abc123');
|
||||
|
||||
$this->assertEquals('', $this->storage->read('id1'));
|
||||
$this->assertEquals('abc123', $this->storage->read('id2'));
|
||||
@@ -93,14 +85,14 @@ abstract class AbstractRedisSessionHandlerTestCase extends TestCase
|
||||
{
|
||||
$this->assertTrue($this->storage->write('id', 'data'));
|
||||
|
||||
$this->assertTrue($this->hasFixture(self::PREFIX.'id'));
|
||||
$this->assertEquals('data', $this->getFixture(self::PREFIX.'id'));
|
||||
$this->assertTrue((bool) $this->redisClient->exists(self::PREFIX.'id'));
|
||||
$this->assertEquals('data', $this->redisClient->get(self::PREFIX.'id'));
|
||||
}
|
||||
|
||||
public function testUseSessionGcMaxLifetimeAsTimeToLive()
|
||||
{
|
||||
$this->storage->write('id', 'data');
|
||||
$ttl = $this->fixtureTtl(self::PREFIX.'id');
|
||||
$ttl = $this->redisClient->ttl(self::PREFIX.'id');
|
||||
|
||||
$this->assertLessThanOrEqual(ini_get('session.gc_maxlifetime'), $ttl);
|
||||
$this->assertGreaterThanOrEqual(0, $ttl);
|
||||
@@ -108,11 +100,11 @@ abstract class AbstractRedisSessionHandlerTestCase extends TestCase
|
||||
|
||||
public function testDestroySession()
|
||||
{
|
||||
$this->setFixture(self::PREFIX.'id', 'foo');
|
||||
$this->redisClient->set(self::PREFIX.'id', 'foo');
|
||||
|
||||
$this->assertTrue($this->hasFixture(self::PREFIX.'id'));
|
||||
$this->assertTrue((bool) $this->redisClient->exists(self::PREFIX.'id'));
|
||||
$this->assertTrue($this->storage->destroy('id'));
|
||||
$this->assertFalse($this->hasFixture(self::PREFIX.'id'));
|
||||
$this->assertFalse((bool) $this->redisClient->exists(self::PREFIX.'id'));
|
||||
}
|
||||
|
||||
public function testGcSession()
|
||||
@@ -122,12 +114,12 @@ abstract class AbstractRedisSessionHandlerTestCase extends TestCase
|
||||
|
||||
public function testUpdateTimestamp()
|
||||
{
|
||||
$lowTTL = 10;
|
||||
$lowTtl = 10;
|
||||
|
||||
$this->setFixture(self::PREFIX.'id', 'foo', $lowTTL);
|
||||
$this->redisClient->setex(self::PREFIX.'id', $lowTtl, 'foo');
|
||||
$this->storage->updateTimestamp('id', array());
|
||||
|
||||
$this->assertGreaterThan($lowTTL, $this->fixtureTtl(self::PREFIX.'id'));
|
||||
$this->assertGreaterThan($lowTtl, $this->redisClient->ttl(self::PREFIX.'id'));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -150,28 +142,4 @@ abstract class AbstractRedisSessionHandlerTestCase extends TestCase
|
||||
array(array('prefix' => 'sfs', 'foo' => 'bar'), false),
|
||||
);
|
||||
}
|
||||
|
||||
protected function setFixture($key, $value, $ttl = null)
|
||||
{
|
||||
if (null !== $ttl) {
|
||||
$this->validator->setex($key, $ttl, $value);
|
||||
} else {
|
||||
$this->validator->set($key, $value);
|
||||
}
|
||||
}
|
||||
|
||||
protected function getFixture($key)
|
||||
{
|
||||
return $this->validator->get($key);
|
||||
}
|
||||
|
||||
protected function hasFixture($key): bool
|
||||
{
|
||||
return $this->validator->exists($key);
|
||||
}
|
||||
|
||||
protected function fixtureTtl($key): int
|
||||
{
|
||||
return $this->validator->ttl($key);
|
||||
}
|
||||
}
|
||||
|
@@ -17,6 +17,6 @@ class PredisClusterSessionHandlerTest extends AbstractRedisSessionHandlerTestCas
|
||||
{
|
||||
protected function createRedisClient(string $host): Client
|
||||
{
|
||||
return new Client(array(array('host' => $host)));
|
||||
return new Client(array(array('host' => $host)));
|
||||
}
|
||||
}
|
||||
|
31
vendor/symfony/http-foundation/Tests/Session/Storage/Handler/RedisClusterSessionHandlerTest.php
vendored
Normal file
31
vendor/symfony/http-foundation/Tests/Session/Storage/Handler/RedisClusterSessionHandlerTest.php
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\HttpFoundation\Tests\Session\Storage\Handler;
|
||||
|
||||
class RedisClusterSessionHandlerTest extends AbstractRedisSessionHandlerTestCase
|
||||
{
|
||||
public static function setupBeforeClass()
|
||||
{
|
||||
if (!class_exists('RedisCluster')) {
|
||||
self::markTestSkipped('The RedisCluster class is required.');
|
||||
}
|
||||
|
||||
if (!$hosts = getenv('REDIS_CLUSTER_HOSTS')) {
|
||||
self::markTestSkipped('REDIS_CLUSTER_HOSTS env var is not defined.');
|
||||
}
|
||||
}
|
||||
|
||||
protected function createRedisClient(string $host): \RedisCluster
|
||||
{
|
||||
return new \RedisCluster(null, explode(' ', getenv('REDIS_CLUSTER_HOSTS')));
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user