Permalink
Browse files

fixed tests

  • Loading branch information...
1 parent 8636e7e commit ec299747f85d47eaddcb1049fc8184ce0a91afd4 @jfsimon jfsimon committed Dec 3, 2011
View
9 README.md
@@ -2,16 +2,9 @@ SSO authentication for Symfony2
===============================
-*Tests fail since this commit : 9e038c005cdcb349eb1de2c9e44e53ccc4f7db43 ... cant see why, maybe a session issue?*
+*Tests OK!*
-**Warnings:**
-
- Only CAS protocol is implemented for now.
-- Login functional test fails :(
-
-
-**Resources:**
-
- Documentation in Resources/doc
- License in Resources/meta/LICENSE
View
2 Security/Http/Firewall/TrustedSsoAuthenticationListener.php
@@ -36,4 +36,4 @@ protected function attemptAuthentication(Request $request)
return $this->authenticationManager->authenticate($ssoProvider->createToken($request));
}
-}
+}
View
4 Security/Http/Logout/SsoLogoutSuccessHandler.php
@@ -6,7 +6,7 @@
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Bundle\FrameworkBundle\HttpKernel;
-use BeSimple\SsoAuthBundle\Sso\SsoFactory;
+use BeSimple\SsoAuthBundle\Sso\Factory;
class SsoLogoutSuccessHandler implements LogoutSuccessHandlerInterface
{
@@ -30,7 +30,7 @@ class SsoLogoutSuccessHandler implements LogoutSuccessHandlerInterface
* @param SsoProviderFactory $ssoFactory
* @param array $ssoConfig
*/
- public function __construct(HttpKernel $httpKernel, SsoFactory $ssoFactory, array $config)
+ public function __construct(HttpKernel $httpKernel, Factory $ssoFactory, array $config)
{
$this->httpKernel = $httpKernel;
$this->ssoFactory = $ssoFactory;
View
2 Tests/Controller/Server/Controller.php
@@ -100,4 +100,4 @@ protected function isValidCredentials($credentials)
* @return string
*/
abstract protected function getValidationView(Request $request, $name);
-}
+}
View
22 Tests/Controller/TestController.php
@@ -4,10 +4,12 @@
class TestController extends Controller
{
- const ANON_MESSAGE = 'hello anon';
- const SECURED_MESSAGE = 'hello secured';
- const USER_MESSAGE = 'hello user';
- const ADMIN_MESSAGE = 'hello admin';
+ const ANON_MESSAGE = 'hello anon';
+ const SECURED_MESSAGE = 'hello secured';
+ const USER_MESSAGE = 'hello user';
+ const ADMIN_MESSAGE = 'hello admin';
+ const FORBIDDEN_MESSAGE = 'access denied';
+ const LOGIN_MESSAGE = 'login required';
public function anonAction()
{
@@ -29,8 +31,18 @@ public function adminAction()
return $this->renderMessage(self::ADMIN_MESSAGE);
}
+ public function forbiddenAction()
+ {
+ return $this->renderMessage(self::FORBIDDEN_MESSAGE);
+ }
+
+ public function loginAction()
+ {
+ return $this->renderMessage(self::LOGIN_MESSAGE);
+ }
+
private function renderMessage($message)
{
return $this->render('common/message.html.twig', array('message' => $message));
}
-}
+}
View
2 Tests/Controller/TrustedSsoController.php
@@ -26,4 +26,4 @@ public function logoutAction(ProviderInterface $provider, Request $request)
'url' => $provider->getServer()->getLogoutUrl()
));
}
-}
+}
View
3 Tests/Functional/AnonTest.php
@@ -43,7 +43,8 @@ public function testAdmin(Client $client)
private function processTest(Client $client, $url, $expectedMessage)
{
- $message = $client->request('GET', $url)->filter('#message')->text();
+ $crawler = $client->request('GET', $url);
+ $message = $crawler->filter('#message')->text();
$this->assertEquals($expectedMessage, $message);
}
}
View
4 Tests/Functional/LoginTest.php
@@ -59,10 +59,10 @@ private function provideCases()
{
return array(
array('/secured', self::LOGIN_USER, TestController::SECURED_MESSAGE),
- array('/secured', self::LOGIN_INVALID, TrustedSsoController::LOGIN_REQUIRED_MESSAGE),
+ array('/secured', self::LOGIN_INVALID, TestController::LOGIN_MESSAGE),
array('/secured/user', self::LOGIN_USER, TestController::USER_MESSAGE),
array('/secured/admin', self::LOGIN_ADMIN, TestController::ADMIN_MESSAGE),
- // got 500 AccessDenied with array('/secured/admin', self::LOGIN_USER, TrustedSsoController::LOGIN_REQUIRED_MESSAGE)
+ array('/secured/admin', self::LOGIN_USER, TestController::FORBIDDEN_MESSAGE)
);
}
}
View
17 Tests/Functional/WebTestCase.php
@@ -23,9 +23,8 @@
public function provideClients()
{
$clients = array();
- $names = array('cas');
- foreach ($names as $name) {
+ foreach (array('cas') as $name) {
$clients[] = array(static::createClient(array('sso_server_name' => $name)));
}
@@ -62,4 +61,18 @@ static protected function createKernel(array $options)
return $kernel;
}
+
+ /**
+ * Shuts the kernel down if it was used in the test
+ * and remove temp files.
+ */
+ protected function tearDown()
+ {
+ if (null !== static::$kernel) {
+ static::$kernel->shutdown();
+
+ $fs = new Filesystem();
+ $fs->remove(static::$tmpPath);
+ }
+ }
}
View
8 Tests/HttpClient.php
@@ -20,19 +20,21 @@ static public function setKernel(Kernel $kernel)
public function send(BuzzRequest $buzzRequest, BuzzResponse $buzzResponse)
{
+ $session = session_id();
$request = Request::create($buzzRequest->getUrl(), $buzzRequest->getMethod());
$response = static::$kernel->handle($request);
$buzzResponse->setContent($response->getContent());
+
+ // kernel handling set session_id to empty string
+ session_id($session);
}
public function setTimeout($timeout)
{
- return;
}
public function setMaxRedirects($maxRedirects)
{
- return;
}
-}
+}
View
8 Tests/Resources/config/cas.yml
@@ -13,16 +13,16 @@ services:
security:
firewalls:
cas:
- pattern: ^/secured.*$
+ access_denied_url: /forbidden
+ pattern: ^/secured.*$
trusted_sso:
server: cas
- login_path: /secured
+ login_path: /login
check_path: /secured/check
login_action: be_simple_sso_auth.test_controller.trusted:loginAction
logout_action: be_simple_sso_auth.test_controller.trusted:logoutAction
logout:
- path: /secured/logout
- target: /secured
+ path: /secured/logout
be_simple_sso_auth:
cas:
View
10 Tests/Resources/config/common.yml
@@ -2,14 +2,12 @@ framework:
charset: UTF-8
secret: test
csrf_protection:
- enabled: false
-
+ enabled: true
validation: { enabled: true, enable_annotations: true }
templating: { engines: ["twig"] }
form: ~
test: ~
session:
- default_locale: en
lifetime: 3600
auto_start: true
storage_id: session.storage.filesystem
@@ -39,8 +37,8 @@ security:
providers:
in_memory:
users:
- "user": { password: user, roles: ["ROLE_USER"] }
+ "user": { password: user, roles: ["ROLE_USER"] }
"admin": { password: admin, roles: ["ROLE_ADMIN"] }
access_control:
- - { path: /secured/user, roles: ROLE_USER }
- - { path: /secured/admin, roles: ROLE_ADMIN }
+ - { path: ^/secured/user, roles: ROLE_USER }
+ - { path: ^/secured/admin, roles: ROLE_ADMIN }
View
12 Tests/Resources/routing/common.yml
@@ -5,7 +5,7 @@ anon:
secured:
pattern: /secured
defaults: { _controller: be_simple_sso_auth.test_controller.test:securedAction }
-
+
secured_user:
pattern: /secured/user
defaults: { _controller: be_simple_sso_auth.test_controller.test:userAction }
@@ -15,4 +15,12 @@ secured_admin:
defaults: { _controller: be_simple_sso_auth.test_controller.test:adminAction }
logout:
- pattern: /secured/logout
+ pattern: /secured/logout
+
+forbidden:
+ pattern: /forbidden
+ defaults: { _controller: be_simple_sso_auth.test_controller.test:forbiddenAction }
+
+login:
+ pattern: /login
+ defaults: { _controller: be_simple_sso_auth.test_controller.test:loginAction }
View
4 Tests/Unit/Cas/CasProviderTest.php
@@ -37,10 +37,10 @@ public function testCreateToken(CasProvider $provider)
$this->assertTrue($token instanceof SsoToken);
$this->assertFalse($token->isAuthenticated());
$this->assertEquals($this->credentials, $token->getCredentials());
- $this->assertEquals($provider, $token->getSsoProvider());
+ $this->assertEquals($provider, $token->getProvider());
$this->assertEquals(null, $token->getUsername());
$this->assertEquals(null, $token->getUser());
$this->assertEquals(array(), $token->getRoles());
$this->assertEquals(array(), $token->getAttributes());
}
-}
+}

0 comments on commit ec29974

Please sign in to comment.