Skip to content

Commit

Permalink
Can redirect in Welsh
Browse files Browse the repository at this point in the history
  • Loading branch information
MishNajam committed Nov 27, 2023
1 parent e1f6ab8 commit e687cee
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 11 deletions.
8 changes: 8 additions & 0 deletions service-front/app/features/context/UI/AccountContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -2113,6 +2113,14 @@ public function iAmRedirectedToTheErrorPage($errorType): void
$this->ui->assertPageAddress('/home?error=' . $errorType);
}

/**
* @Then /^I am redirected to the Welsh login page with a "(.*)" error message$/
*/
public function iAmRedirectedToTheWelshErrorPage($errorType): void
{
$this->ui->assertPageAddress('/cy/home?error=' . $errorType);
}

/**
* @Then /^I should be told "(.*)"$/
*/
Expand Down
10 changes: 9 additions & 1 deletion service-front/app/features/context/UI/CommonContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -392,11 +392,19 @@ public function iShouldBeOnTheWelshHomepageOfTheService()
/**
* @Then /^I should be shown an error page$/
*/
public function iShouldBeShownAnErrorPage()
public function iShouldBeShownAnErrorPage(): void
{
$this->ui->assertPageContainsText('Sorry, there is a problem with the service');
}

/**
* @Then /^I should be shown an error page in Welsh$/
*/
public function iShouldBeShownAnErrorPageInWelsh(): void
{
$this->ui->assertPageContainsText('Mae’n ddrwg gennym, mae problem gyda’r gwasanaeth');
}

/**
* @When /^I should be shown an error page with details$/
*/
Expand Down
30 changes: 30 additions & 0 deletions service-front/app/features/one-login.feature
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,43 @@
| access_denied | Tried to login however access is denied |
| temporarily_unavailable | One Login is temporarily unavailable |

@ui @actor @ff:allow_gov_one_login:true
Scenario Outline: One Login returns a specific Welsh error
Given I am on the temporary one login page
And I select the Welsh language
And I click the one login button
When One Login returns a "<error_type>" error
Then I am redirected to the Welsh login page with a "<error_type>" error message
And I should be told "Mae problem"

Examples:
| error_type |
| access_denied |
| temporarily_unavailable |

@ui @actor @ff:allow_gov_one_login:true
Scenario Outline: One Login returns a generic error
Given I am on the temporary one login page
And I click the one login button
When One Login returns a "<error_type>" error
Then I should be shown an error page

Examples:
| error_type |
| unauthorized_client |
| invalid_request |
| invalid_scope |
| unsupported_response_type |
| server_error |

@ui @actor @ff:allow_gov_one_login:true
Scenario Outline: One Login returns a generic error in Welsh
Given I am on the temporary one login page
And I select the Welsh language
And I click the one login button
When One Login returns a "<error_type>" error
Then I should be shown an error page in Welsh

Examples:
| error_type |
| unauthorized_client |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,17 @@ public function handle(ServerRequestInterface $request): ResponseInterface
throw new RuntimeException('Session state does not match redirect state', 500);
}

//TODO: Content and Welsh translations
////http://localhost:9002/home/login?error=invalid_request&error_description=Unsupported%20response&state=
if (array_key_exists('error', $authParams)) {
$this->logger->notice('User attempted to login via OneLogin however there was an error');
return match ($authParams['error']) {
//http://localhost:9002/home/login?error=access_denied&error_description=Unsupported%20response&state=
'access_denied' => $this->redirectToRoute('home', [], [
'error' => 'access_denied',
]),
//http://localhost:9002/home/login?error=temporarily_unavailable&error_description=Unsupported%20response&state=
],
$ui_locale),
'temporarily_unavailable' => $this->redirectToRoute('home', [], [
'error' => 'temporarily_unavailable',
]),
],
$ui_locale),
default => throw new RuntimeException('Error returned from OneLogin', 500)
};
}
Expand Down
10 changes: 6 additions & 4 deletions service-front/app/src/Common/src/Handler/AbstractHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,12 @@ abstract public function handle(ServerRequestInterface $request): ResponseInterf
* @param array $queryParams
* @return RedirectResponse
*/
protected function redirectToRoute($route, $routeParams = [], $queryParams = []): RedirectResponse
protected function redirectToRoute($route, $routeParams = [], $queryParams = [], ?string $uiLocale = null): RedirectResponse

Check warning on line 40 in service-front/app/src/Common/src/Handler/AbstractHandler.php

View check run for this annotation

Codecov / codecov/patch

service-front/app/src/Common/src/Handler/AbstractHandler.php#L40

Added line #L40 was not covered by tests
{
return new RedirectResponse(
$this->urlHelper->generate($route, $routeParams, $queryParams)
);
$url = $this->urlHelper->generate($route, $routeParams, $queryParams);
if ($uiLocale === 'cy' && !str_contains($url, 'cy')) {
$url = '/cy' . $url;

Check warning on line 44 in service-front/app/src/Common/src/Handler/AbstractHandler.php

View check run for this annotation

Codecov / codecov/patch

service-front/app/src/Common/src/Handler/AbstractHandler.php#L42-L44

Added lines #L42 - L44 were not covered by tests
}
return new RedirectResponse($url);

Check warning on line 46 in service-front/app/src/Common/src/Handler/AbstractHandler.php

View check run for this annotation

Codecov / codecov/patch

service-front/app/src/Common/src/Handler/AbstractHandler.php#L46

Added line #L46 was not covered by tests
}
}

0 comments on commit e687cee

Please sign in to comment.