From 488c59be20d12cec71fc183527d7ffe668bc44b6 Mon Sep 17 00:00:00 2001 From: MishNajam <61416092+MishNajam@users.noreply.github.com> Date: Mon, 6 Nov 2023 09:43:29 +0000 Subject: [PATCH] UML-3132 service api one login dummy endpoint returns a user (#2398) * UML-3132 service api one login dummy endpoint returns a user * Rename handler and return test user details * Rename api calls --- service-api/app/config/routes.php | 6 ++- .../context/Acceptance/AccountContext.php | 31 ++++++++++++++ service-api/app/features/one-login.feature | 8 ++++ .../OneLoginAuthenticationCallbackHandler.php | 41 +++++++++++++++++++ .../src/Service/OneLogin/OneLoginService.php | 2 +- .../Service/OneLogin/OneLoginServiceTest.php | 4 +- 6 files changed, 87 insertions(+), 5 deletions(-) create mode 100644 service-api/app/features/one-login.feature create mode 100644 service-api/app/src/App/src/Handler/OneLoginAuthenticationCallbackHandler.php diff --git a/service-api/app/config/routes.php b/service-api/app/config/routes.php index d5fc330ed2..96f4a9ad66 100644 --- a/service-api/app/config/routes.php +++ b/service-api/app/config/routes.php @@ -19,6 +19,8 @@ use App\Handler\LpasResourceHandler; use App\Handler\LpasResourceImagesCollectionHandler; use App\Handler\NotifyHandler; +use App\Handler\OneLoginAuthenticationCallbackHandler; +use App\Handler\OneLoginAuthenticationRequestHandler; use App\Handler\RequestChangeEmailHandler; use App\Handler\RequestCleanseHandler; use App\Handler\RequestPasswordResetHandler; @@ -29,7 +31,6 @@ use Mezzio\Application; use Mezzio\MiddlewareFactory; use Psr\Container\ContainerInterface; -use App\Handler\OneLoginAuthenticationRequestHandler; /** * Setup routes with a single request method: @@ -135,7 +136,8 @@ $app->patch('/v1/auth', AuthHandler::class, 'user.auth'); - $app->get('/v1/auth-one-login', OneLoginAuthenticationRequestHandler::class, 'user.auth-one-login'); + $app->get('/v1/auth/start', OneLoginAuthenticationRequestHandler::class, 'user.auth-start'); + $app->get('/v1/auth/callback', OneLoginAuthenticationCallbackHandler::class, 'user.auth-callback'); $app->post('/v1/email-user/{emailTemplate}', NotifyHandler::class, 'lpa.user.notify'); }; diff --git a/service-api/app/features/context/Acceptance/AccountContext.php b/service-api/app/features/context/Acceptance/AccountContext.php index 6b51d0e073..abaadadf76 100644 --- a/service-api/app/features/context/Acceptance/AccountContext.php +++ b/service-api/app/features/context/Acceptance/AccountContext.php @@ -1292,4 +1292,35 @@ public function iShouldBeToldThatABadRequestWasMade(): void { $this->ui->assertSession()->statusCodeEquals(StatusCodeInterface::STATUS_BAD_REQUEST); } + + /** + * @Given /^I am on the temporary one login page$/ + */ + public function iAmOnTheTemporaryOneLoginPage(): void + { + // Not needed in this context + } + + /** + * @When /^I click the one login button$/ + */ + public function iClickTheOneLoginButton(): void + { + // Not needed in this context + } + + /** + * @Then /^I am redirected to the redirect page$/ + */ + public function iAmRedirectedToTheRedirectPage(): void + { + $this->apiGet('/v1/auth/callback', []); + + $this->ui->assertSession()->statusCodeEquals(StatusCodeInterface::STATUS_OK); + + $response = $this->getResponseAsJson(); + + Assert::assertEquals('bf9e7e77-f283-49c6-a79c-65d5d309ef77', $response['Id']); + Assert::assertEquals('opg-use-an-lpa+test-user@digital.justice.gov.uk', $response['Email']); + } } diff --git a/service-api/app/features/one-login.feature b/service-api/app/features/one-login.feature new file mode 100644 index 0000000000..4e203e163f --- /dev/null +++ b/service-api/app/features/one-login.feature @@ -0,0 +1,8 @@ +@actor @onelogin +Feature: Authorise One Login + + @acceptance + Scenario: I initiate authentication via one login + Given I am on the temporary one login page + When I click the one login button + Then I am redirected to the redirect page diff --git a/service-api/app/src/App/src/Handler/OneLoginAuthenticationCallbackHandler.php b/service-api/app/src/App/src/Handler/OneLoginAuthenticationCallbackHandler.php new file mode 100644 index 0000000000..f880535ee7 --- /dev/null +++ b/service-api/app/src/App/src/Handler/OneLoginAuthenticationCallbackHandler.php @@ -0,0 +1,41 @@ +getQueryParams(); + + $user = [ + 'Id' => 'bf9e7e77-f283-49c6-a79c-65d5d309ef77', + 'Email' => 'opg-use-an-lpa+test-user@digital.justice.gov.uk', + 'LastLogin' => (new DateTime('-1 day'))->format(DateTimeInterface::ATOM), + ]; + + return new JsonResponse($user); + } +} diff --git a/service-front/app/src/Common/src/Service/OneLogin/OneLoginService.php b/service-front/app/src/Common/src/Service/OneLogin/OneLoginService.php index 9af86873f6..9b3ffe7e5c 100644 --- a/service-front/app/src/Common/src/Service/OneLogin/OneLoginService.php +++ b/service-front/app/src/Common/src/Service/OneLogin/OneLoginService.php @@ -14,7 +14,7 @@ public function __construct(private ApiClient $apiClient) public function authenticate(string $uiLocale, string $redirectUrl): ?array { - return $this->apiClient->httpGet('/v1/auth-one-login', [ + return $this->apiClient->httpGet('/v1/auth/start', [ 'ui_locale' => $uiLocale, 'redirect_url' => $redirectUrl, ]); diff --git a/service-front/app/test/CommonTest/Service/OneLogin/OneLoginServiceTest.php b/service-front/app/test/CommonTest/Service/OneLogin/OneLoginServiceTest.php index 61b86343f9..a94570b58d 100644 --- a/service-front/app/test/CommonTest/Service/OneLogin/OneLoginServiceTest.php +++ b/service-front/app/test/CommonTest/Service/OneLogin/OneLoginServiceTest.php @@ -32,9 +32,9 @@ public function can_get_authentication_request_uri(): void $apiClientProphecy ->httpGet( - '/v1/auth-one-login', + '/v1/auth/start', [ - 'ui_locale' => 'en', + 'ui_locale' => 'en', 'redirect_url' => $redirect, ] )->willReturn(['state' => $state, 'nonce' => $nonce, 'url' => $uri]);