Permalink
Browse files

Merge for #12547

  • Loading branch information...
niden committed Dec 23, 2018
1 parent 16a51b3 commit 80ced232ff758fc92904679fff82f2349891e52f
Showing with 45 additions and 2 deletions.
  1. +1 −0 CHANGELOG-4.0.md
  2. +0 −1 CHANGELOG.md
  3. +1 −1 phalcon/acl/adapter/memory.zep
  4. +43 −0 tests/unit/Acl/Adapter/MemoryCest.php
@@ -28,6 +28,7 @@
- Added bind support to `Phalcon\Mvc\Model\Query\Builder`. The Query Builder has the same methods as `Phalcon\Mvc\Model\Query`; `getBindParams`, `setBindParams`, `getBindTypes` and `setBindTypes`. [#13368](https://github.com/phalcon/cphalcon/issues/13368)
- Added `attach()` to `Phalcon\Mvc\RouterInterface`
- Added `Phalcon\Container`, a proxy container class to the `Phalcon\DI` implementing PSR-11 [#12295](https://github.com/phalcon/cphalcon/issues/12295)
- Added `Phalcon\Acl\Adapter\Memory::getActiveKey`, `Phalcon\Acl\Adapter\Memory::activeFunctionCustomArgumentsCount` and `Phalcon\Acl\Adapter\Memory::getActiveFunction` to get latest key, number of custom arguments, and function used to acquire access

## Changed
- By configuring `prefix` and `statsKey` the `Phalcon\Cache\Backend\Redis::queryKeys` no longer returns prefixed keys, now it returns original keys without prefix. [#13656](https://github.com/phalcon/cphalcon/pull/13656)
@@ -14,5 +14,4 @@ To see what we changed in particular framework branch refer to the relevant chan
- [**`3.0.x`**](resources/CHANGELOG-3.0.md)
- [**`2.0.x`**](resources/CHANGELOG-2.0.md)
- [**`1.x.x`**](resources/CHANGELOG-1.x.md)
- Added `Phalcon\Acl\Adapter\Memory::getActiveKey`, `Phalcon\Acl\Adapter\Memory::activeFunctionCustomArgumentsCount` and `Phalcon\Acl\Adapter\Memory::getActiveFunction` to get latest key, number of custom arguments, and function used to acquire access

@@ -686,7 +686,7 @@ class Memory extends Adapter
/**
* Change activeKey to most narrow if there was no access for any patterns found
*/
let this->_activeKey = roleName . "!" . resourceName . "!" . access;
let this->_activeKey = operationName . "!" . subjectName . "!" . access;

return this->_defaultAccess == Acl::ALLOW;
}
@@ -20,6 +20,7 @@
use Phalcon\Test\Fixtures\Acl\TestOperationSubjectAware;
use PHPUnit\Framework\Exception;
use UnitTester;
use Closure;
class MemoryCest
{
@@ -661,4 +662,46 @@ public function testAclNegationOfMultilayerInheritedOperations(UnitTester $I)
$actual = (bool) $acl->isAllowed('Members', 'Login', 'index');
$I->assertTrue($actual);
}
/**
* Tests checking active key method
*
* @author Wojciech Slawski <jurigag@gmail.com>
* @since 2017-01-13
*/
public function testActiveKey(UnitTester $I)
{
$acl = new Memory();
$acl->addOperation(new Operation("Guests"));
$acl->addSubject(new Subject('Post'), ['index', 'update', 'create']);
$acl->allow('Guests', 'Post', 'create');
$I->assertTrue($acl->isAllowed('Guests', 'Post', 'create'));
$I->assertEquals('Guests!Post!create', $acl->getActiveKey());
}
/**
* Tests checking active function method
*
* @author Wojciech Slawski <jurigag@gmail.com>
* @since 2017-01-13
*/
public function testActiveFunction(UnitTester $I)
{
$function = function ($a) {
return true;
};
$acl = new Memory();
$acl->addOperation(new Operation("Guests"));
$acl->addSubject(new Subject('Post'), ['index', 'update', 'create']);
$acl->allow('Guests', 'Post', 'create', $function);
$I->assertTrue($acl->isAllowed('Guests', 'Post', 'create', ['a' => 1]));
$returnedFunction = $acl->getActiveFunction();
$I->assertInstanceOf(Closure::class, $returnedFunction);
$I->assertEquals(1, $function(1));
$I->assertEquals(1, $acl->getActiveFunctionCustomArgumentsCount());
}
}

0 comments on commit 80ced23

Please sign in to comment.