Created
January 11, 2013 18:38
-
-
Save eminetto/4512919 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
public function testAuthorize() | |
{ | |
$authService = $this->getService('Admin\Service\Auth'); | |
$admin = $this->addUser(); | |
//adiciona visitante | |
$visitante = new User(); | |
$visitante->username = 'bill'; | |
$visitante->password = md5('ms'); | |
$visitante->name = 'Bill Gates'; | |
$visitante->valid = 1; | |
$visitante->role = 'visitante'; | |
$saved = $this->getTable('Admin\Model\User')->save($visitante); | |
//cria novas configurações de acl | |
$config = $this->serviceManager->get('Config'); | |
$config['acl']['roles']['visitante'] = null; | |
$config['acl']['roles']['admin'] = 'visitante'; | |
$config['acl']['resources'] = array ( | |
'Application\Controller\Index.index', | |
'Admin\Controller\Index.save' | |
); | |
$config['acl']['privilege']['visitante']['allow'] = array('Application\Controller\Index.index'); | |
$config['acl']['privilege']['admin']['allow'] = array('Admin\Controller\Index.save'); | |
//atualiza a configuração | |
$this->serviceManager->setService('Config', $config); | |
//authentica com o visitante | |
$result = $authService->authenticate( | |
array('username' => $visitante->username, 'password' => 'ms') | |
); | |
$result = $authService->authorize('application', 'Application\Controller\Index', 'index'); | |
$this->assertTrue($result); | |
$result = $authService->authorize('admin', 'Admin\Controller\Index', 'save'); | |
$this->assertFalse($result); | |
//authentica com o admin | |
$result = $authService->authenticate( | |
array('username' => $admin->username, 'password' => 'apple') | |
); | |
$result = $authService->authorize('application', 'Application\Controller\Index', 'index'); | |
$this->assertTrue($result); | |
$result = $authService->authorize('admin', 'Admin\Controller\Index', 'save'); | |
$this->assertTrue($result); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment