From a6f2dc57db85a8aac3557bccebfcb90358f1deea Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 11 Sep 2023 01:26:52 +0000 Subject: [PATCH 1/5] Bump actions/checkout from 3 to 4 Bumps [actions/checkout](https://github.com/actions/checkout) from 3 to 4. - [Release notes](https://github.com/actions/checkout/releases) - [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md) - [Commits](https://github.com/actions/checkout/compare/v3...v4) --- updated-dependencies: - dependency-name: actions/checkout dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/ci.yml | 4 ++-- .github/workflows/deploy_docs_2x.yml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c4cdff3b..6c4d0493 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -24,7 +24,7 @@ jobs: prefer-lowest: 'prefer-lowest' steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Setup PHP uses: shivammathur/setup-php@v2 @@ -79,7 +79,7 @@ jobs: runs-on: ubuntu-22.04 steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Setup PHP uses: shivammathur/setup-php@v2 diff --git a/.github/workflows/deploy_docs_2x.yml b/.github/workflows/deploy_docs_2x.yml index 5700a3a0..ba0f8618 100644 --- a/.github/workflows/deploy_docs_2x.yml +++ b/.github/workflows/deploy_docs_2x.yml @@ -12,7 +12,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Cloning repo - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: fetch-depth: 0 From 9ff4df7b18f4220e27793f3403cc6784daa9d3b8 Mon Sep 17 00:00:00 2001 From: Mark Story Date: Sun, 1 Oct 2023 11:48:12 -0700 Subject: [PATCH 2/5] Fix deprecated method usage We didn't need to use query() here as find() will do the same work and is compatible with 4.5 as well. --- src/Identifier/Resolver/OrmResolver.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Identifier/Resolver/OrmResolver.php b/src/Identifier/Resolver/OrmResolver.php index 9068fa00..3785d3a4 100644 --- a/src/Identifier/Resolver/OrmResolver.php +++ b/src/Identifier/Resolver/OrmResolver.php @@ -56,7 +56,7 @@ public function find(array $conditions, $type = self::TYPE_AND) { $table = $this->getTableLocator()->get($this->_config['userModel']); - $query = $table->query(); + $query = $table->find(); $finders = (array)$this->_config['finder']; foreach ($finders as $finder => $options) { if (is_string($options)) { From 46e801f7c8957639db37205ad40f39de7e7e5390 Mon Sep 17 00:00:00 2001 From: Mark Story Date: Sun, 1 Oct 2023 11:55:15 -0700 Subject: [PATCH 3/5] Fix dynamic property warnings --- .../Authenticator/HttpBasicAuthenticatorTest.php | 10 ++++++++++ .../Authenticator/HttpDigestAuthenticatorTest.php | 10 ++++++++++ tests/TestCase/Authenticator/JwtAuthenticatorTest.php | 5 +++++ .../Authenticator/SessionAuthenticatorTest.php | 7 +++++++ .../TestCase/Authenticator/TokenAuthenticatorTest.php | 10 ++++++++++ .../Middleware/AuthenticationMiddlewareTest.php | 10 ++++++++++ 6 files changed, 52 insertions(+) diff --git a/tests/TestCase/Authenticator/HttpBasicAuthenticatorTest.php b/tests/TestCase/Authenticator/HttpBasicAuthenticatorTest.php index f11fdb53..4f4a9920 100644 --- a/tests/TestCase/Authenticator/HttpBasicAuthenticatorTest.php +++ b/tests/TestCase/Authenticator/HttpBasicAuthenticatorTest.php @@ -37,6 +37,16 @@ class HttpBasicAuthenticatorTest extends TestCase 'core.Users', ]; + /** + * @var \Authentication\IdentifierCollection + */ + protected $identifiers; + + /** + * @var \Autnentication\Authenticator\HttpBasicAuthenticator + */ + protected $auth; + /** * @inheritDoc */ diff --git a/tests/TestCase/Authenticator/HttpDigestAuthenticatorTest.php b/tests/TestCase/Authenticator/HttpDigestAuthenticatorTest.php index ec304c8b..fa57838c 100644 --- a/tests/TestCase/Authenticator/HttpDigestAuthenticatorTest.php +++ b/tests/TestCase/Authenticator/HttpDigestAuthenticatorTest.php @@ -43,6 +43,16 @@ class HttpDigestAuthenticatorTest extends TestCase 'core.Users', ]; + /** + * @var \Authentication\IdentifierCollection + */ + protected $identifiers; + + /** + * @var \Autnentication\Authenticator\HttpDigestAuthenticator + */ + protected $auth; + /** * setup * diff --git a/tests/TestCase/Authenticator/JwtAuthenticatorTest.php b/tests/TestCase/Authenticator/JwtAuthenticatorTest.php index 43117c96..a88f8d00 100644 --- a/tests/TestCase/Authenticator/JwtAuthenticatorTest.php +++ b/tests/TestCase/Authenticator/JwtAuthenticatorTest.php @@ -59,6 +59,11 @@ class JwtAuthenticatorTest extends TestCase */ public $identifiers; + /** + * @var \Cake\Http\ServerRequest + */ + protected $request; + /** * @inheritDoc */ diff --git a/tests/TestCase/Authenticator/SessionAuthenticatorTest.php b/tests/TestCase/Authenticator/SessionAuthenticatorTest.php index b8be6d07..d7437dfa 100644 --- a/tests/TestCase/Authenticator/SessionAuthenticatorTest.php +++ b/tests/TestCase/Authenticator/SessionAuthenticatorTest.php @@ -40,6 +40,13 @@ class SessionAuthenticatorTest extends TestCase 'core.Users', ]; + /** + * @var \Authentication\IdentifierCollection + */ + protected $identifiers; + + protected $sessionMock; + /** * @inheritDoc */ diff --git a/tests/TestCase/Authenticator/TokenAuthenticatorTest.php b/tests/TestCase/Authenticator/TokenAuthenticatorTest.php index 363c31ff..f7437646 100644 --- a/tests/TestCase/Authenticator/TokenAuthenticatorTest.php +++ b/tests/TestCase/Authenticator/TokenAuthenticatorTest.php @@ -34,6 +34,16 @@ class TokenAuthenticatorTest extends TestCase 'core.Users', ]; + /** + * @var \Authentication\IdentifierCollection + */ + protected $identifiers; + + /** + * @var \Cake\Http\ServerRequest + */ + protected $request; + /** * @inheritDoc */ diff --git a/tests/TestCase/Middleware/AuthenticationMiddlewareTest.php b/tests/TestCase/Middleware/AuthenticationMiddlewareTest.php index 654c59a5..1733f56d 100644 --- a/tests/TestCase/Middleware/AuthenticationMiddlewareTest.php +++ b/tests/TestCase/Middleware/AuthenticationMiddlewareTest.php @@ -33,6 +33,16 @@ class AuthenticationMiddlewareTest extends TestCase { + /** + * @var \Authentication\AuthenticationService + */ + protected $service; + + /** + * @var \TestApp\Application + */ + protected $application; + /** * Fixtures */ From bdbe04b37863e8ed3a272ddbd1a57bc59739bc88 Mon Sep 17 00:00:00 2001 From: Kevin Pfeifer Date: Sat, 11 Nov 2023 11:03:36 +0100 Subject: [PATCH 4/5] add authentication service to DIC by default --- src/Middleware/AuthenticationMiddleware.php | 6 +++ .../AuthenticationMiddlewareTest.php | 46 ++++++++----------- 2 files changed, 25 insertions(+), 27 deletions(-) diff --git a/src/Middleware/AuthenticationMiddleware.php b/src/Middleware/AuthenticationMiddleware.php index 4f185214..15d860d0 100644 --- a/src/Middleware/AuthenticationMiddleware.php +++ b/src/Middleware/AuthenticationMiddleware.php @@ -22,6 +22,7 @@ use Authentication\Authenticator\AuthenticationRequiredException; use Authentication\Authenticator\StatelessInterface; use Authentication\Authenticator\UnauthenticatedException; +use Cake\Core\ContainerApplicationInterface; use Cake\Core\InstanceConfigTrait; use InvalidArgumentException; use Laminas\Diactoros\Response; @@ -101,6 +102,11 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface { $service = $this->getAuthenticationService($request); + if ($this->subject instanceof ContainerApplicationInterface) { + $container = $this->subject->getContainer(); + $container->add(AuthenticationService::class, $service); + } + try { $result = $service->authenticate($request); } catch (AuthenticationRequiredException $e) { diff --git a/tests/TestCase/Middleware/AuthenticationMiddlewareTest.php b/tests/TestCase/Middleware/AuthenticationMiddlewareTest.php index 654c59a5..16d64f74 100644 --- a/tests/TestCase/Middleware/AuthenticationMiddlewareTest.php +++ b/tests/TestCase/Middleware/AuthenticationMiddlewareTest.php @@ -17,13 +17,12 @@ namespace Authentication\Test\TestCase\Middleware; use Authentication\AuthenticationService; -use Authentication\AuthenticationServiceInterface; use Authentication\AuthenticationServiceProviderInterface; -use Authentication\Authenticator\ResultInterface; use Authentication\Authenticator\UnauthenticatedException; use Authentication\IdentityInterface; use Authentication\Middleware\AuthenticationMiddleware; use Authentication\Test\TestCase\AuthenticationTestCase as TestCase; +use Cake\Core\TestSuite\ContainerStubTrait; use Cake\Http\Response; use Cake\Http\ServerRequestFactory; use Cake\Http\Uri; @@ -33,6 +32,8 @@ class AuthenticationMiddlewareTest extends TestCase { + use ContainerStubTrait; + /** * Fixtures */ @@ -105,31 +106,6 @@ public function testProviderAuthentication() $this->assertTrue($service->authenticators()->has('Form')); } - public function testApplicationAuthenticationRequestResponse() - { - $request = ServerRequestFactory::fromGlobals(); - $handler = new TestRequestHandler(); - - $service = $this->createMock(AuthenticationServiceInterface::class); - - $service->method('authenticate') - ->willReturn($this->createMock(ResultInterface::class)); - $service->method('getIdentityAttribute')->willReturn('identity'); - - $application = $this->getMockBuilder(Application::class) - ->disableOriginalConstructor() - ->setMethods(['getAuthenticationService', 'middleware']) - ->getMock(); - - $application->expects($this->once()) - ->method('getAuthenticationService') - ->with($request) - ->willReturn($service); - - $middleware = new AuthenticationMiddleware($application); - $middleware->process($request, $handler); - } - public function testInvalidSubject() { $this->expectException('InvalidArgumentException'); @@ -770,4 +746,20 @@ public function testServiceConfigurationFallback() $this->assertSame('redirect', $service->getConfig('queryParam')); $this->assertSame('/login', $service->getConfig('unauthenticatedRedirect')); } + + public function testMiddlewareInjectsServiceIntoDIC(): void + { + $request = ServerRequestFactory::fromGlobals( + ['REQUEST_URI' => '/testpath'], + [], + ['username' => 'mariano', 'password' => 'password'] + ); + $handler = new TestRequestHandler(); + + $middleware = new AuthenticationMiddleware($this->application); + $middleware->process($request, $handler); + + $container = $this->application->getContainer(); + $this->assertInstanceOf(AuthenticationService::class, $container->get(AuthenticationService::class)); + } } From 9be055c588290a914b008acdbd900024e1a5a369 Mon Sep 17 00:00:00 2001 From: Kevin Pfeifer Date: Tue, 26 Dec 2023 18:18:16 +0100 Subject: [PATCH 5/5] fix tests --- .github/workflows/ci.yml | 4 ++-- tests/TestCase/Middleware/AuthenticationMiddlewareTest.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5d50917a..a0a6b733 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -3,8 +3,8 @@ name: CI on: push: branches: - - 2.x - - 2.next + - 3.x + - 3.next pull_request: branches: - '*' diff --git a/tests/TestCase/Middleware/AuthenticationMiddlewareTest.php b/tests/TestCase/Middleware/AuthenticationMiddlewareTest.php index e402ce1c..1627cd6f 100644 --- a/tests/TestCase/Middleware/AuthenticationMiddlewareTest.php +++ b/tests/TestCase/Middleware/AuthenticationMiddlewareTest.php @@ -129,8 +129,8 @@ public function testApplicationAuthenticationRequestResponse() $service->method('getIdentityAttribute')->willReturn('identity'); $application = $this->getMockBuilder(Application::class) - ->disableOriginalConstructor() - ->setMethods(['getAuthenticationService', 'middleware']) + ->setConstructorArgs(['config']) + ->onlyMethods(['getAuthenticationService', 'middleware']) ->getMock(); $application->expects($this->once())