From 67e808f288d5a976ea12e3b9db3e4a6e28140746 Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Fri, 25 Feb 2022 16:46:26 -0800 Subject: [PATCH] AllFlowsTest - If `Authorization:` support is disabled, then it's ignored completely. This means that the request is effectively anonymous -- the same as it would be if you had not sent an `Authorization:` header. --- .../tests/phpunit/Civi/Authx/AllFlowsTest.php | 26 +++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/ext/authx/tests/phpunit/Civi/Authx/AllFlowsTest.php b/ext/authx/tests/phpunit/Civi/Authx/AllFlowsTest.php index 1c374fc05e..026a05aada 100644 --- a/ext/authx/tests/phpunit/Civi/Authx/AllFlowsTest.php +++ b/ext/authx/tests/phpunit/Civi/Authx/AllFlowsTest.php @@ -128,7 +128,7 @@ class AllFlowsTest extends \PHPUnit\Framework\TestCase implements EndToEndInterf // Phase 1: Request fails if this credential type is not enabled \Civi::settings()->set("authx_{$flowType}_cred", []); $response = $http->send($request); - $this->assertFailedDueToProhibition($response); + $this->assertNotAuthenticated($flowType === 'header' ? 'anon' : 'prohibit', $response); // Phase 2: Request succeeds if this credential type is enabled \Civi::settings()->set("authx_{$flowType}_cred", [$credType]); @@ -159,7 +159,7 @@ class AllFlowsTest extends \PHPUnit\Framework\TestCase implements EndToEndInterf // Phase 1: Request fails if this credential type is not enabled \Civi::settings()->set("authx_{$flowType}_cred", []); $response = $http->send($request); - $this->assertFailedDueToProhibition($response); + $this->assertNotAuthenticated($flowType === 'header' ? 'anon' : 'prohibit', $response); // Phase 2: Request succeeds if this credential type is enabled \Civi::settings()->set("authx_{$flowType}_cred", [$credType]); @@ -793,6 +793,28 @@ class AllFlowsTest extends \PHPUnit\Framework\TestCase implements EndToEndInterf return NULL; } + /** + * Assert that a request was not authenticated. + * + * @param string $mode + * Expect that the 'prohibited' or 'anon' + * @param \Psr\Http\Message\ResponseInterface $response + */ + private function assertNotAuthenticated(string $mode, $response) { + switch ($mode) { + case 'anon': + $this->assertAnonymousContact($response); + break; + + case 'prohibit': + $this->assertFailedDueToProhibition($response); + break; + + default: + throw new \RuntimeException("Invalid option: mode=$mode"); + } + } + /** * @param \Psr\Http\Message\ResponseInterface $response */ -- 2.25.1