Skip to content

Commit

Permalink
Merge pull request #50 from CakeDC/feature/allow-named-routes
Browse files Browse the repository at this point in the history
Feature/allow named routes
  • Loading branch information
rochamarcelo committed Aug 12, 2019
2 parents db29836 + 7ab37d3 commit d2a26fc
Show file tree
Hide file tree
Showing 10 changed files with 123 additions and 13 deletions.
1 change: 1 addition & 0 deletions src/Authentication/AuthenticationService.php
Expand Up @@ -31,6 +31,7 @@ class AuthenticationService extends BaseService
* @var Failure[]
*/
protected $failures = [];

/**
* Proceed to google verify action after a valid result result
*
Expand Down
Expand Up @@ -32,6 +32,7 @@ public function __construct($enableKey = null)
$this->enabledKey = $enableKey;
}
}

/**
* Check if two factor authentication is enabled
*
Expand Down
1 change: 1 addition & 0 deletions src/Social/Mapper/AbstractMapper.php
Expand Up @@ -62,6 +62,7 @@ public function __construct($mapFields = null)
}
$this->_mapFields = array_merge($this->_defaultMapFields, $this->_mapFields);
}

/**
* Invoke method
*
Expand Down
1 change: 1 addition & 0 deletions src/Traits/ReCaptchaTrait.php
Expand Up @@ -36,6 +36,7 @@ public function validateReCaptchaFromRequest($request)
$request->clientIp()
);
}

/**
* Validates reCaptcha response
*
Expand Down
1 change: 1 addition & 0 deletions tests/TestCase/Authenticator/CookieAuthenticatorTest.php
Expand Up @@ -36,6 +36,7 @@ public function dataProviderPersistIdentity()
[false, 'my_remember', [], ['remember_me' => 1]],
];
}

/**
* testPersistIdentity
*
Expand Down
1 change: 1 addition & 0 deletions tests/TestCase/Policy/RbacPolicyTest.php
Expand Up @@ -112,6 +112,7 @@ public function testGetRbacUseObject()
$actual = $policy->getRbac($request);
$this->assertSame($rbac, $actual);
}

/**
* Test getRbac method
*/
Expand Down
1 change: 1 addition & 0 deletions tests/TestCase/Policy/SuperuserPolicyTest.php
Expand Up @@ -36,6 +36,7 @@ public function dataProviderCanAccess()
[[], false, ['superuser_field' => 'is_master']],
];
}

/**
* Test canAccess method
*
Expand Down
33 changes: 25 additions & 8 deletions tests/TestCase/Rbac/RbacTest.php
Expand Up @@ -14,8 +14,8 @@
use CakeDC\Auth\Rbac\Rbac;
use CakeDC\Auth\Rbac\Rules\Owner;
use Cake\Http\ServerRequest;
use Cake\Routing\Router;
use Cake\TestSuite\TestCase;
use Cake\Utility\Hash;
use Psr\Log\LogLevel;
use ReflectionClass;

Expand Down Expand Up @@ -1099,6 +1099,27 @@ function () {
//expected
false,
],
'named-route' => [
//permissions
[[
'plugin' => 'CakeDC/Users',
'controller' => 'Users',
'action' => '*',
'role' => 'admin',
]],
//user
[
'id' => 1,
'username' => 'luke',
'role' => 'admin',
],
//request
[
'_name' => 'testNamed',
],
//expected
true,
],
];
}

Expand Down Expand Up @@ -1262,14 +1283,10 @@ public function badPermissionProvider()
*/
protected function _requestFromArray($params)
{
$request = new ServerRequest();
$request = new ServerRequest(Router::url($params));
$params = Router::parseRequest($request);

return $request
->withParam('plugin', Hash::get($params, 'plugin'))
->withParam('controller', Hash::get($params, 'controller'))
->withParam('action', Hash::get($params, 'action'))
->withParam('prefix', Hash::get($params, 'prefix'))
->withParam('_ext', Hash::get($params, '_ext'));
return $request->withAttribute('params', $params);
}

public function testGetPermissions()
Expand Down
1 change: 1 addition & 0 deletions tests/TestCase/Social/Service/ServiceFactoryTest.php
Expand Up @@ -26,6 +26,7 @@ class ServiceFactoryTest extends TestCase
* @var ServiceFactory
*/
public $Factory;

/**
* Setup the test case, backup the static object values so they can be restored.
* Specifically backs up the contents of Configure and paths in App if they have
Expand Down
95 changes: 90 additions & 5 deletions tests/config/routes.php
@@ -1,6 +1,91 @@
<?php
\Cake\Routing\Router::connect('/my-test', [
'plugin' => 'CakeDC/Users',
'controller' => 'Users',
'action' => 'myTest'
]);
use \Cake\Routing\Router;

Router::defaultRouteClass(\Cake\Routing\Route\DashedRoute::class);

Router::scope('/', function (\Cake\Routing\RouteBuilder $routes) {
$routes->setExtensions(['other']);
$routes->connect('/my-test', [
'plugin' => 'CakeDC/Users',
'controller' => 'Users',
'action' => 'myTest'
]);
$routes->connect('/test-named', [
'plugin' => 'CakeDC/Users',
'controller' => 'Users',
'action' => 'myTest'
], [
'_name' => 'testNamed',
]);
$routes->connect('/tests/tests/test', [
'plugin' => 'Tests',
'controller' => 'Tests',
'action' => 'test',
]);
$routes->connect('/tests/tests/one', [
'plugin' => 'Tests',
'controller' => 'Tests',
'action' => 'one',
]);
$routes->connect('/tests/tests/three', [
'plugin' => 'Tests',
'controller' => 'Tests',
'action' => 'three',
]);
$routes->connect('/tests/tests/any', [
'plugin' => 'Tests',
'controller' => 'Tests',
'action' => 'any',
]);
$routes->connect('/tests/test-tests/test-action', [
'plugin' => 'Tests',
'controller' => 'TestTests',
'action' => 'testAction',
]);
$routes->connect('/tests2/test-tests/test-action', [
'plugin' => 'tests',
'controller' => 'test-tests',
'action' => 'test-action',
]);
$routes->connect('/any/any/any', [
'plugin' => 'Any',
'controller' => 'Any',
'action' => 'any',
]);
$routes->connect('/any/tests/test', [
'plugin' => 'Any',
'controller' => 'Tests',
'action' => 'test',
]);
$routes->connect('/something/something/test', [
'plugin' => 'Something',
'controller' => 'Something',
'action' => 'test',
]);
$routes->connect('/something/something/something', [
'plugin' => 'Something',
'controller' => 'Something',
'action' => 'something',
]);
$routes->connect('/csv/tests/one', [
'prefix' => 'csv',
'controller' => 'Tests',
'action' => 'one',
]);

$routes->fallbacks(\Cake\Routing\Route\DashedRoute::class);

$routes->setExtensions(['csv']);
$routes->connect('/tests/one', [
'controller' => 'Tests',
'action' => 'one',
]);
});

Router::scope('/admin', ['prefix' => 'admin'], function (\Cake\Routing\RouteBuilder $routes) {
$routes->setExtensions(['other', 'csv']);
$routes->connect('/tests/one', [
'controller' => 'Tests',
'action' => 'one',
]);
});

0 comments on commit d2a26fc

Please sign in to comment.