Permalink
Browse files

[Acl] - ACL tests and minor corrections

  • Loading branch information...
niden committed Dec 26, 2018
1 parent f604ed5 commit 163bcad580f7d81a3527bb6b986d5a3f073c9c6c
@@ -622,7 +622,6 @@ class Memory extends Adapter
} else {
throw new Exception("Object passed as subjectName must implement Phalcon\\Acl\\SubjectAware or Phalcon\\Acl\\SubjectInterface");
}

}

let this->_activeOperation = operationName;
@@ -663,8 +662,6 @@ class Memory extends Adapter
/**
* Check in the inherits operations
*/


let this->_accessGranted = haveAccess;
if typeof eventsManager == "object" {
eventsManager->fire("acl:afterCheckAccess", this);
@@ -749,7 +746,9 @@ class Memory extends Adapter
if count(parametersForFunction) == 0 {
if numberOfRequiredParameters > 0 {
trigger_error(
"You didn't provide any parameters when check " . operationName . " can " . access . " " . subjectName . ". We will use default action when no arguments."
"You didn't provide any parameters when '" . operationName .
"' can '" . access . "' '" . subjectName .
"'. We will use default action when no arguments."
);

return haveAccess == Acl::ALLOW && this->_noArgumentsDefaultAction == Acl::ALLOW;
@@ -766,7 +765,8 @@ class Memory extends Adapter

// We don't have enough parameters
throw new Exception(
"You didn't provide all necessary parameters for defined function when check " . operationName . " can " . access . " " . subjectName
"You didn't provide all necessary parameters for defined function when check " .
operationName . " can " . access . " " . subjectName
);
}

@@ -778,7 +778,9 @@ class Memory extends Adapter
*/
protected function _isAllowed(string operationName, string subjectName, string access) -> string | bool
{
var accessList, accessKey,checkOperationToInherit, checkOperationToInherits, usedOperationToInherits, usedOperationToInherit;
var accessList, accessKey,checkOperationToInherit,
checkOperationToInherits, usedOperationToInherits,
usedOperationToInherit;

let accessList = this->_access;

@@ -12,6 +12,8 @@
namespace Phalcon\Test\Unit\Acl\Adapter\Memory;
use Phalcon\Acl\Adapter\Memory;
use Phalcon\Acl\Operation;
use UnitTester;
/**
@@ -20,16 +22,98 @@
class AddOperationCest
{
/**
* Tests Phalcon\Acl\Adapter\Memory :: addOperation()
* Tests Phalcon\Acl\Adapter\Memory :: addOperation() - string
*
* @param UnitTester $I
*
* @author Phalcon Team <team@phalconphp.com>
* @since 2018-11-13
*/
public function aclAdapterMemoryAddOperation(UnitTester $I)
public function aclAdapterMemoryAddOperationString(UnitTester $I)
{
$I->wantToTest('Acl\Adapter\Memory - addOperation()');
$I->skipTest('Need implementation');
$I->wantToTest('Acl\Adapter\Memory - addOperation() - string');
$acl = new Memory();
$operation = new Operation('Administrators', 'Super User access');
$actual = $acl->addOperation('Administrators');
$I->assertTrue($actual);
}
/**
* Tests Phalcon\Acl\Adapter\Memory :: addOperation() - object
*
* @param UnitTester $I
*
* @author Phalcon Team <team@phalconphp.com>
* @since 2018-11-13
*/
public function aclAdapterMemoryAddOperationObject(UnitTester $I)
{
$I->wantToTest('Acl\Adapter\Memory - addOperation() - object');
$acl = new Memory();
$operation = new Operation('Administrators', 'Super User access');
$actual = $acl->addOperation($operation);
$I->assertTrue($actual);
}
/**
* Tests Phalcon\Acl\Adapter\Memory :: addOperation() - twice string
*
* @param UnitTester $I
*
* @author Phalcon Team <team@phalconphp.com>
* @since 2018-11-13
*/
public function aclAdapterMemoryAddOperationTwiceString(UnitTester $I)
{
$I->wantToTest('Acl\Adapter\Memory - addOperation() - twice string');
$acl = new Memory();
$operation = new Operation('Administrators', 'Super User access');
$actual = $acl->addOperation('Administrators');
$I->assertTrue($actual);
$actual = $acl->addOperation('Administrators');
$I->assertFalse($actual);
}
/**
* Tests Phalcon\Acl\Adapter\Memory :: addOperation() - twice object
*
* @param UnitTester $I
*
* @author Phalcon Team <team@phalconphp.com>
* @since 2018-11-13
*/
public function aclAdapterMemoryAddOperationTwiceObject(UnitTester $I)
{
$I->wantToTest('Acl\Adapter\Memory - addOperation() - twice object');
$acl = new Memory();
$operation = new Operation('Administrators', 'Super User access');
$actual = $acl->addOperation($operation);
$I->assertTrue($actual);
$actual = $acl->addOperation($operation);
$I->assertFalse($actual);
}
/**
* Tests Phalcon\Acl\Adapter\Memory :: addOperation() - numeric key
*
* @param UnitTester $I
*
* @author Phalcon Team <team@phalconphp.com>
* @since 2018-11-13
*/
public function aclAdapterMemoryAddOperationNumericKey(UnitTester $I)
{
$I->wantToTest('Acl\Adapter\Memory - addOperation() - numeric key');
$acl = new Memory();
$operation = new Operation('11', 'Super User access');
$actual = $acl->addOperation('11');
$I->assertTrue($actual);
$actual = $acl->isOperation('11');
$I->assertTrue($actual);
}
}
@@ -12,6 +12,9 @@
namespace Phalcon\Test\Unit\Acl\Adapter\Memory;
use Phalcon\Acl\Adapter\Memory;
use Phalcon\Acl\Exception;
use Phalcon\Acl\Subject;
use UnitTester;
/**
@@ -32,4 +35,47 @@ public function aclAdapterMemoryAddSubjectAccess(UnitTester $I)
$I->wantToTest('Acl\Adapter\Memory - addSubjectAccess()');
$I->skipTest('Need implementation');
}
/**
* Tests Phalcon\Acl\Adapter\Memory :: addSubjectAccess() - unknown
*
* @param UnitTester $I
*
* @author Phalcon Team <team@phalconphp.com>
* @since 2018-11-13
*/
public function aclAdapterMemoryAddSubjectAccessUnknown(UnitTester $I)
{
$I->wantToTest('Acl\Adapter\Memory - addSubjectAccess() - unknown');
$I->expectThrowable(
new Exception("Subject 'Post' does not exist in ACL"),
function () {
$acl = new Memory();
$acl->addSubjectAccess('Post', ['update']);
}
);
}
/**
* Tests Phalcon\Acl\Adapter\Memory :: addSubjectAccess() - wrong access
* list
*
* @param UnitTester $I
*
* @author Phalcon Team <team@phalconphp.com>
* @since 2018-11-13
*/
public function aclAdapterMemoryAddSubjectAccessWrongAccessList(UnitTester $I)
{
$I->wantToTest('Acl\Adapter\Memory - addSubjectAccess() - wrong access list');
$I->expectThrowable(
new Exception('Invalid value for accessList'),
function () {
$acl = new Memory();
$post = new Subject('Post');
$acl->addSubject($post, ['update']);
$acl->addSubjectAccess('Post', 123);
}
);
}
}
@@ -12,6 +12,8 @@
namespace Phalcon\Test\Unit\Acl\Adapter\Memory;
use Phalcon\Acl\Adapter\Memory;
use Phalcon\Acl\Subject;
use UnitTester;
/**
@@ -20,16 +22,58 @@
class AddSubjectCest
{
/**
* Tests Phalcon\Acl\Adapter\Memory :: addSubject()
* Tests Phalcon\Acl\Adapter\Memory :: addSubject() - string
*
* @param UnitTester $I
*
* @author Phalcon Team <team@phalconphp.com>
* @since 2018-11-13
*/
public function aclAdapterMemoryAddSubject(UnitTester $I)
public function aclAdapterMemoryAddSubjectString(UnitTester $I)
{
$I->wantToTest('Acl\Adapter\Memory - addSubject()');
$I->skipTest('Need implementation');
$I->wantToTest('Acl\Adapter\Memory - addSubject() - string');
$acl = new Memory();
$subject = new Subject('Customer', 'Customer subject');
$actual = $acl->addSubject('Customer', ['index']);
$I->assertTrue($actual);
}
/**
* Tests Phalcon\Acl\Adapter\Memory :: addSubject() - object
*
* @param UnitTester $I
*
* @author Phalcon Team <team@phalconphp.com>
* @since 2018-11-13
*/
public function aclAdapterMemoryAddSubjectObject(UnitTester $I)
{
$I->wantToTest('Acl\Adapter\Memory - addSubject() - object');
$acl = new Memory();
$subject = new Subject('Customer', 'Customer subject');
$actual = $acl->addSubject($subject, ['index']);
$I->assertTrue($actual);
}
/**
* Tests Phalcon\Acl\Adapter\Memory :: addSubject() - numeric key
*
* @param UnitTester $I
*
* @author Phalcon Team <team@phalconphp.com>
* @since 2018-11-13
*/
public function aclAdapterMemoryAddSubjectNumericKey(UnitTester $I)
{
$I->wantToTest('Acl\Adapter\Memory - addSubject() - numeric key');
$acl = new Memory();
$subject = new Subject('11', 'Customer subject');
$actual = $acl->addSubject($subject, ['index']);
$I->assertTrue($actual);
$actual = $acl->isSubject('11');
$I->assertTrue($actual);
}
}
Oops, something went wrong.

0 comments on commit 163bcad

Please sign in to comment.