Skip to content

Commit

Permalink
Add integration tests for GOV.UK One Login
Browse files Browse the repository at this point in the history
  • Loading branch information
tpmcgowan committed Sep 21, 2023
1 parent b6a744f commit 12aeab0
Show file tree
Hide file tree
Showing 20 changed files with 256 additions and 257 deletions.
10 changes: 5 additions & 5 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,9 @@ workflows:
- unit_test:
requires:
- build
# - integration_test:
# requires:
# - build
- integration_test:
requires:
- build
- hmpps/helm_lint:
name: helm_lint
- hmpps/build_docker:
Expand All @@ -144,7 +144,7 @@ workflows:
requires:
- helm_lint
- unit_test
# - integration_test
- integration_test
- build_docker
- hmpps/deploy_env:
<<: *feature_branch
Expand Down Expand Up @@ -182,7 +182,7 @@ workflows:
requires:
- helm_lint
- unit_test
# - integration_test
- integration_test
- build_docker

- request-staging-approval:
Expand Down
4 changes: 2 additions & 2 deletions cypress.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { defineConfig } from 'cypress'
import { resetStubs } from './integration_tests/mockApis/wiremock'
import auth from './integration_tests/mockApis/auth'
import govukOneLogin from './integration_tests/mockApis/govukOneLogin'
import tokenVerification from './integration_tests/mockApis/tokenVerification'

export default defineConfig({
Expand All @@ -17,7 +17,7 @@ export default defineConfig({
setupNodeEvents(on) {
on('task', {
reset: resetStubs,
...auth,
...govukOneLogin,
...tokenVerification,

// Log message to console
Expand Down
1 change: 1 addition & 0 deletions feature.env
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
PORT=3007
INGRESS_URL=http://localhost:3007
HMPPS_AUTH_URL=http://localhost:9091/auth
TOKEN_VERIFICATION_API_URL=http://localhost:9091/verification
TOKEN_VERIFICATION_ENABLED=true
Expand Down
54 changes: 54 additions & 0 deletions integration_tests/e2e/govukOneLogin.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import HomePage from '../pages/home'
import GovukOneLoginPage from '../pages/govukOneLogin'
import Page from '../pages/page'

context('Sign in with GOV.UK One Login', () => {
beforeEach(() => {
cy.task('reset')
cy.task('stubSignIn')
})

it('Unauthenticated user redirected to GOV.UK One Login - home page', () => {
cy.visit('/')
Page.verifyOnPage(GovukOneLoginPage)
})

it('Unauthenticated user redirected to GOV.UK One Login - sign-in URL', () => {
cy.visit('/auth/sign-in')
Page.verifyOnPage(GovukOneLoginPage)
})

it('Unauthenticated user redirected to GOV.UK One Login - callback URL', () => {
cy.visit('/auth/callback')
Page.verifyOnPage(GovukOneLoginPage)
})

it('Unauthenticated user redirected to GOV.UK One Login - non-existant route', () => {
cy.visit('/NON-EXISTANT-PAGE')
Page.verifyOnPage(GovukOneLoginPage)
})

it('User can sign in and view home page', () => {
cy.signIn()
Page.verifyOnPage(HomePage)

// just testing sample data dumped to the page for now
cy.contains('"sub": "user1"')
cy.contains('"phone_number": "+440123456789"')
cy.contains('"email": "user1@example.com"')
})

it('User sent to auth error page if sign in fails', () => {
// setting an invalid nonce value should cause ID token validation to fail
cy.signIn({ failOnStatusCode: false, nonce: 'INVALID_NONCE' })
cy.get('h1').contains('Authorisation Error')
})

it('User can log out', () => {
cy.signIn()
const homePage = Page.verifyOnPage(HomePage)
homePage.signOut().click()
Page.verifyOnPage(GovukOneLoginPage)
cy.contains('You have been logged out.')
})
})
3 changes: 0 additions & 3 deletions integration_tests/e2e/health.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ context('Healthcheck', () => {
context('All healthy', () => {
beforeEach(() => {
cy.task('reset')
cy.task('stubAuthPing')
cy.task('stubTokenVerificationPing')
})

Expand All @@ -22,11 +21,9 @@ context('Healthcheck', () => {
context('Some unhealthy', () => {
it('Reports correctly when token verification down', () => {
cy.task('reset')
cy.task('stubAuthPing')
cy.task('stubTokenVerificationPing', 500)

cy.request({ url: '/health', method: 'GET', failOnStatusCode: false }).then(response => {
expect(response.body.checks.hmppsAuth).to.equal('OK')
expect(response.body.checks.tokenVerification).to.contain({ status: 500, retries: 2 })
})
})
Expand Down
68 changes: 0 additions & 68 deletions integration_tests/e2e/login.cy.ts

This file was deleted.

3 changes: 2 additions & 1 deletion integration_tests/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ declare namespace Cypress {
interface Chainable {
/**
* Custom command to signIn. Set failOnStatusCode to false if you expect and non 200 return code
* Optionally set nonce to override the value used in the ID token
* @example cy.signIn({ failOnStatusCode: boolean })
*/
signIn(options?: { failOnStatusCode: boolean }): Chainable<AUTWindow>
signIn(options?: { failOnStatusCode: boolean; nonce?: string }): Chainable<AUTWindow>
}
}
162 changes: 0 additions & 162 deletions integration_tests/mockApis/auth.ts

This file was deleted.

Loading

0 comments on commit 12aeab0

Please sign in to comment.