Skip to content

Commit

Permalink
fix for phpcs
Browse files Browse the repository at this point in the history
  • Loading branch information
rrd108 committed Jan 26, 2024
1 parent 6156477 commit 6b5fd1f
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 22 deletions.
20 changes: 13 additions & 7 deletions src/ApiTokenAuthenticatorPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function routes($routes): void
/**
* Returns a service provider instance.
*
* @param \Psr\Http\Message\ServerRequestInterface $request Request
* @param \Psr\Http\Message\ServerRequestInterface $request Request
* @return \Authentication\AuthenticationServiceInterface
*/
public function getAuthenticationService(ServerRequestInterface $request): AuthenticationServiceInterface
Expand All @@ -71,21 +71,27 @@ public function getAuthenticationService(ServerRequestInterface $request): Authe
AbstractIdentifier::CREDENTIAL_PASSWORD => $options['fields']['password']
];

$service->loadAuthenticator(ProvisoryTokenAuthenticator::class, [
$service->loadAuthenticator(
ProvisoryTokenAuthenticator::class, [
'header' => $options['header'],
]);
]
);
$service->loadIdentifier('Authentication.Token');

$service->loadAuthenticator('Authentication.Form', [
$service->loadAuthenticator(
'Authentication.Form', [
'fields' => $fields,
'loginUrl' => Router::url([
'loginUrl' => Router::url(
[
'prefix' => false,
'plugin' => null,
'controller' => $options['login']['controller'],
'action' => $options['login']['action'],
'_ext' => $options['login']['_ext']
]),
]);
]
),
]
);

if ($options['passwordHasher'] == 'default') {
$service->loadIdentifier('Authentication.Password', compact('fields'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@ public function setUp(): void
{
parent::setUp();

$this->identifiers = new IdentifierCollection([
$this->identifiers = new IdentifierCollection(
[
'Authentication.Token' => [
'header' => 'Token',
],
]);
]
);
$this->request = ServerRequestFactory::fromGlobals(
['REQUEST_URI' => '/testpath'],
[],
Expand Down
12 changes: 8 additions & 4 deletions tests/TestCase/Controller/UsersControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,20 @@ public function testIndex(): void
$this->get('/users.json');
$this->assertResponseCode(401);

$this->configRequest([
$this->configRequest(
[
'headers' => ['Token' => 'FalseToken']
]);
]
);
$this->get('/users.json');
$this->assertResponseCode(401);


$this->configRequest([
$this->configRequest(
[
'headers' => ['Token' => 'token-1']
]);
]
);
$this->get('/users.json');
$this->assertResponseOk();
$this->assertHeader('Content-Type', 'application/json');
Expand Down
12 changes: 8 additions & 4 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,23 +31,27 @@
define('CONFIG', ROOT . DS . 'config' . DS);

Configure::write('debug', true);
Configure::write('App', [
Configure::write(
'App', [
'namespace' => 'TestApp',
'encoding' => 'UTF-8',
'paths' => [
'plugins' => [ROOT . 'Plugin' . DS],
'templates' => [ROOT . 'templates' . DS],
],
]);
]
);

ConnectionManager::setConfig('test', [
ConnectionManager::setConfig(
'test', [
'className' => 'Cake\Database\Connection',
'driver' => 'Cake\Database\Driver\Sqlite',
'database' => ':memory:',
'encoding' => 'utf8',
'timezone' => 'UTC',
'quoteIdentifiers' => false,
]);
]
);

Router::reload();
//Security::setSalt('rrd');
Expand Down
12 changes: 7 additions & 5 deletions tests/test_app/src/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@ class Application extends BaseApplication
public function routes(RouteBuilder $routes): void
{
$routes->setRouteClass(DashedRoute::class);
$routes->scope('/', function (RouteBuilder $builder): void {
$builder->setExtensions(['json']);
$builder->resources('Users');
$builder->fallbacks();
});
$routes->scope(
'/', function (RouteBuilder $builder): void {
$builder->setExtensions(['json']);
$builder->resources('Users');
$builder->fallbacks();
}
);
}

public function middleware(MiddlewareQueue $middlewareQueue): MiddlewareQueue
Expand Down

0 comments on commit 6b5fd1f

Please sign in to comment.