Skip to content
This repository has been archived by the owner on Nov 8, 2020. It is now read-only.

Commit

Permalink
Renamed <var> to <any>
Browse files Browse the repository at this point in the history
  • Loading branch information
klapuch committed Mar 16, 2017
1 parent 50c3d8d commit 85a8869
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 23 deletions.
10 changes: 5 additions & 5 deletions Core/HttpRole.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Role intended to inspect HTTP based permissions
*/
final class HttpRole implements Role {
private const VARIABLE_CHARACTERS = [
private const ANY_PARAMETER = [
'a-z',
'A-Z',
'0-9',
Expand All @@ -15,7 +15,7 @@ final class HttpRole implements Role {
'\~',
'-',
];
private const NUMERIC_CHARACTERS = ['0-9'];
private const NUMERIC_PARAMETER = ['0-9'];
private $permissions;

public function __construct(Permissions $permissions) {
Expand All @@ -35,10 +35,10 @@ private function resources(Permissions $permissions): array {
return array_map(
function(Permission $permission): string {
return str_ireplace(
['<var>', '<num>'],
['<any>', '<num>'],
[
sprintf('[%s]+', implode(self::VARIABLE_CHARACTERS)),
sprintf('[%s]+', implode(self::NUMERIC_CHARACTERS)),
sprintf('[%s]+', implode(self::ANY_PARAMETER)),
sprintf('[%s]+', implode(self::NUMERIC_PARAMETER)),
],
$permission->resource()
);
Expand Down
36 changes: 18 additions & 18 deletions Tests/Unit/HttpRole.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ final class HttpRole extends Tester\TestCase {
Assert::true($role->allowed('parts'));
}

public function testMatchingWithVariableParameter() {
public function testMatchingWithAnyParameter() {
$permissions = new Authorization\FakePermissions([
new Authorization\FakePermission('parts/<var>'),
new Authorization\FakePermission('parts/<any>'),
]);
$role = new Authorization\HttpRole($permissions);
Assert::false($role->allowed('parts'));
Expand All @@ -89,45 +89,45 @@ final class HttpRole extends Tester\TestCase {
Assert::true($role->allowed('parts/foo_bar'));
}

public function testMatchingCaseInsensitiveVariableParameter() {
public function testMatchingCaseInsensitiveAnyParameter() {
$permissions = new Authorization\FakePermissions([
new Authorization\FakePermission('parts/<VAR>'),
new Authorization\FakePermission('parts/<ANY>'),
]);
$role = new Authorization\HttpRole($permissions);
Assert::true($role->allowed('parts/123'));
Assert::true($role->allowed('parts/foo'));
}

public function testMatchingVariableParameterAsSingleValue() {
public function testMatchingAnyParameterAsSingleValue() {
$permissions = new Authorization\FakePermissions([
new Authorization\FakePermission('parts/<var>'),
new Authorization\FakePermission('parts/<any>'),
]);
$role = new Authorization\HttpRole($permissions);
Assert::false($role->allowed('parts/foo/'));
Assert::false($role->allowed('parts/foo/bar'));
}

public function testVariableParameterOutOfUnreservedCharacters() {
public function testAnyParameterOutOfUnreservedCharacters() {
$permissions = new Authorization\FakePermissions([
new Authorization\FakePermission('parts/<var>'),
new Authorization\FakePermission('parts/<any>'),
]);
$role = new Authorization\HttpRole($permissions);
Assert::false($role->allowed('parts//'));
Assert::false($role->allowed('parts//foo'));
}

public function testVariableParameterInBetween() {
public function testAnyParameterInBetween() {
$permissions = new Authorization\FakePermissions([
new Authorization\FakePermission('parts/<var>/view'),
new Authorization\FakePermission('parts/<any>/view'),
]);
$role = new Authorization\HttpRole($permissions);
Assert::true($role->allowed('parts/foo/view'));
Assert::true($role->allowed('parts/123/view'));
}

public function testMatchingWithMultipleVariableParameters() {
public function testMatchingWithMultipleAnyParameters() {
$permissions = new Authorization\FakePermissions([
new Authorization\FakePermission('parts/<var>/view/<var>'),
new Authorization\FakePermission('parts/<any>/view/<any>'),
]);
$role = new Authorization\HttpRole($permissions);
Assert::true($role->allowed('parts/foo/view/123'));
Expand All @@ -136,10 +136,10 @@ final class HttpRole extends Tester\TestCase {

public function testNotMatchingPlaceholder() {
$permissions = new Authorization\FakePermissions([
new Authorization\FakePermission('parts/<var>'),
new Authorization\FakePermission('parts/<any>'),
]);
$role = new Authorization\HttpRole($permissions);
Assert::false($role->allowed('parts/<var>'));
Assert::false($role->allowed('parts/<any>'));
}

public function testMatchingWithNumericParameter() {
Expand All @@ -157,9 +157,9 @@ final class HttpRole extends Tester\TestCase {
Assert::true($role->allowed('parts/66666666666666666666'));
}

public function testCombibingVariableAndNumericParameter() {
public function testCombibingAnyAndNumericParameter() {
$permissions = new Authorization\FakePermissions([
new Authorization\FakePermission('parts/<num>/foo/<var>'),
new Authorization\FakePermission('parts/<num>/foo/<any>'),
]);
$role = new Authorization\HttpRole($permissions);
Assert::true($role->allowed('parts/123/foo/bar'));
Expand All @@ -169,12 +169,12 @@ final class HttpRole extends Tester\TestCase {

public function testConflictingParametersStrongerWinner() {
$firstStronger = new Authorization\FakePermissions([
new Authorization\FakePermission('parts/<var>'),
new Authorization\FakePermission('parts/<any>'),
new Authorization\FakePermission('parts/<num>'),
]);
$firstWeaker = new Authorization\FakePermissions([
new Authorization\FakePermission('parts/<num>'),
new Authorization\FakePermission('parts/<var>'),
new Authorization\FakePermission('parts/<any>'),
]);
Assert::true(
(new Authorization\HttpRole($firstStronger))->allowed('parts/foo')
Expand Down

0 comments on commit 85a8869

Please sign in to comment.