Commit 485cad9f authored by Fabien Potencier's avatar Fabien Potencier

Merge branch '1.2' into 1.3

* 1.2:
  removed obsolete code
  Improve Silex\Route\SecurityTrait coverage
  updated CHANGELOG

Conflicts:
	doc/changelog.rst
parents b1cd6501 2057560b
......@@ -10,6 +10,12 @@ Changelog
* removed deprecated TwigCoreExtension class (register the new HttpFragmentServiceProvider instead)
* bumped minimum version of PHP to 5.3.9
1.2.4 (2015-04-11)
------------------
* fixed the exception message when mounting a collection that doesn't return a ControllerCollection
* fixed Symfony dependencies (Silex 1.2 is not compatible with Symfony 2.7)
1.2.3 (2015-01-20)
------------------
......
......@@ -530,13 +530,9 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase
{
$app = new Application();
try {
$response = $app->sendFile(__FILE__, 200, array('Content-Type: application/php'));
$this->assertInstanceOf('Symfony\Component\HttpFoundation\BinaryFileResponse', $response);
$this->assertEquals(__FILE__, (string) $response->getFile());
} catch (\RuntimeException $e) {
$this->assertFalse(class_exists('Symfony\Component\HttpFoundation\BinaryFileResponse'));
}
}
/**
......
......@@ -24,20 +24,9 @@ use Symfony\Component\HttpFoundation\Request;
*/
class SecurityTraitTest extends \PHPUnit_Framework_TestCase
{
public function testSecure()
public function testSecureWithNoAuthenticatedUser()
{
$app = new Application();
$app['route_class'] = 'Silex\Tests\Route\SecurityRoute';
$app->register(new SecurityServiceProvider(), array(
'security.firewalls' => array(
'default' => array(
'http' => true,
'users' => array(
'fabien' => array('ROLE_ADMIN', '5FZ2Z8QIkA7UTZ4BYkoC+GsReLf569mSKDsfods6LYQ8t+a8EW9oaircfMpmaLbPBh4FOBiiFyLfuZmTSUwzZg=='),
),
),
),
));
$app = $this->createApplication();
$app->get('/', function () { return 'foo'; })
->secure('ROLE_ADMIN')
......@@ -46,6 +35,15 @@ class SecurityTraitTest extends \PHPUnit_Framework_TestCase
$request = Request::create('/');
$response = $app->handle($request);
$this->assertEquals(401, $response->getStatusCode());
}
public function testSecureWithAuthorizedRoles()
{
$app = $this->createApplication();
$app->get('/', function () { return 'foo'; })
->secure('ROLE_ADMIN')
;
$request = Request::create('/');
$request->headers->set('PHP_AUTH_USER', 'fabien');
......@@ -53,4 +51,37 @@ class SecurityTraitTest extends \PHPUnit_Framework_TestCase
$response = $app->handle($request);
$this->assertEquals(200, $response->getStatusCode());
}
public function testSecureWithUnauthorizedRoles()
{
$app = $this->createApplication();
$app->get('/', function () { return 'foo'; })
->secure('ROLE_SUPER_ADMIN')
;
$request = Request::create('/');
$request->headers->set('PHP_AUTH_USER', 'fabien');
$request->headers->set('PHP_AUTH_PW', 'foo');
$response = $app->handle($request);
$this->assertEquals(403, $response->getStatusCode());
}
private function createApplication()
{
$app = new Application();
$app['route_class'] = 'Silex\Tests\Route\SecurityRoute';
$app->register(new SecurityServiceProvider(), array(
'security.firewalls' => array(
'default' => array(
'http' => true,
'users' => array(
'fabien' => array('ROLE_ADMIN', '5FZ2Z8QIkA7UTZ4BYkoC+GsReLf569mSKDsfods6LYQ8t+a8EW9oaircfMpmaLbPBh4FOBiiFyLfuZmTSUwzZg=='),
),
),
),
));
return $app;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment