Created
May 25, 2011 07:51
-
-
Save rich97/990533 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* li3_access plugin for Lithium: the most rad php framework. | |
* | |
* @author Tom Maiaroto | |
* @copyright Copyright 2010, Union of RAD (http://union-of-rad.org) | |
* @license http://opensource.org/licenses/bsd-license.php The BSD License | |
*/ | |
namespace li3_access\tests\cases\extensions\adapter\security\access; | |
use lithium\net\http\Request; | |
use lithium\security\Auth; | |
use li3_access\security\Access; | |
class AuthRbacTest extends \lithium\test\Unit { | |
public function setUp() { | |
Auth::config(array( | |
'user' => array( | |
'adapter' => '\li3_access\tests\mocks\extensions\adapter\auth\MockAuthAdapter' | |
) | |
)); | |
Access::config(array( | |
'test_no_roles_configured' => array( | |
'adapter' => 'AuthRbac' | |
), | |
'test_simple_check' => array( | |
'adapter' => 'AuthRbac', | |
'message' => 'Generic access denied message.', | |
'redirect' => '', | |
'roles' => array( | |
'deny' => array( | |
'auths' => '*', | |
'match' => array('controller' => '*', 'action' => '*') | |
), | |
'allow' => array( | |
'message' => 'Rule access denied message.', | |
'redirect' => '/', | |
'auths' => 'user', | |
'match' => array('controller' => 'Tests', 'action' => 'granted') | |
) | |
) | |
) | |
)); | |
} | |
public function tearDown() { | |
Auth::clear('user'); | |
} | |
public function testCheck() { | |
$request = new Request(); | |
$request->params = array('controller' => 'Tests', 'action' => 'denied'); | |
$guest = Auth::check('user', array()); | |
$success = true; | |
$user = Auth::check('user', array('user' => array('id' => 1)), compact('success')); | |
/*$expected = array('message' => 'Generic access denied message.', 'redirect' => '/'); | |
$result = Access::check('test_simple_check', $user, $request); | |
$this->assertIdentical($expected, $result); | |
/*$request->params = array('controller' => 'Tests', 'action' => 'granted'); | |
$expected = array('message' => 'Rule access denied message.', 'redirect' => '/'); | |
$result = Access::check('test_simple_check', $guest, $request); | |
$this->assertIdentical($expected, $result); | |
$expected = array(); | |
$result = Access::check('test_simple_check', $user, $request); | |
$this->assertIdentical($expected, $result);*/ | |
} | |
public function testGetRolesByAuth() { | |
$request = new Request(array('params' => array('controller' => 'Tests', 'action' => 'deny'))); | |
$request->data = array('username' => 'richard'); | |
$result = Access::adapter('test_simple_check')->getRolesByAuth($request, array('checkSession' => false)); | |
$this->assertIdentical(array('*' => '*'), $result); | |
$expected = array('*' => '*', 'user' => array('username' => 'richard')); | |
$result = Access::adapter('test_simple_check')->getRolesByAuth($request, array('checkSession' => false, 'success' => true)); | |
$this->assertIdentical($expected, $result); | |
} | |
public function testMatchRole() { | |
$request = new Request(array('params' => array('controller' => 'Tests', 'action' => 'deny'))); | |
$match = array(''); | |
$result = Access::adapter('test_simple_check')->matchRole($match, $request); | |
} | |
public function testNoRolesConfigured() { | |
$request = new Request(); | |
$config = Access::config('test_no_roles_configured'); | |
$request->params = array('controller' => 'Tests', 'action' => 'granted'); | |
$this->assertTrue(empty($config['roles'])); | |
$this->expectException('No roles defined for adapter configuration.'); | |
Access::check('test_no_roles_configured', array('guest' => null), $request);; | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment