Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OAuth migration | Add E2E tests for OAuth authentication #1274

Merged
merged 7 commits into from
Dec 18, 2023

Conversation

raphaelkabo
Copy link
Contributor

@raphaelkabo raphaelkabo commented Dec 5, 2023

What does this change?

This adds a small suite of end-to-end (E2E) Cypress tests to manage-frontend. The existing Cypress tests all mock various API endpoints to allow testing specific user and supporter conditions. However to do this, they entirely skip the authentication middleware, and for our OAuth migration we really want to have that middleware tested end-to-end. Hence these new tests!

A lot of the changes here are refactoring file locations; most of the rest is support to allow end-to-end testing to work on local machines and the GHA runners. Specifically, we borrow from the general strategy in Gateway, using Nginx configs to proxy the CODE locations of Gateway, IDAPI and MDAPI to .thegulocal.com domains. This allows a locally running MMA on manage.thegulocal.com to interact with, and read cookies set on, CODE services.

  • We move the original mocked Cypress tests to cypress/tests/mocked, and rename the GitHub Actions workflow file to cypress-mocked.yml.
  • The new tests live in cypress/tests/e2e, and use the cypress-e2e.yml workflow file.
  • We add an Nginx config file, cypress/cypress-nginx.conf, which is used in GitHub Actions.
  • We add a basic suite of E2E Cypress tests which we will expand on down the line, and some docs explaining how to set them up and run them locally.
  • When running in Cypress (defined by the presence of the RUNNING_IN_CYPRESS environment variable), we skip metrics as these aren't authorised to be added in GHA, and always run the authentication middleware via OAuth/Okta.
  • We change some Yarn commands and add some new ones:
    • yarn cypress:mocked:server: starts a dev server (essentially the same as the standard yarn watch command but with the CYPRESS variable set to 'SKIP_IDAPI', and doesn't open a new browser tab).
    • yarn cypress:mocked:open: opens the Cypress test runner in mocked mode.
    • yarn cypress:mocked:run: runs the Cypress tests headless in mocked mode.
    • yarn cypress:e2e:server: starts a dev server without setting the CYPRESS variable.
    • yarn cypress:e2e:open: opens the Cypress test runner in E2E mode.
    • yarn cypress:e2e:run: runs the Cypress tests headless in E2E mode.

Notes

  • The E2E tests only run against the new, Okta-enabled authentication middleware, by overwriting the Okta config when Cypress is running.

Copy link
Contributor

@andrewHEguardian andrewHEguardian left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As a Retention dev I'm happy with this 👍 but will let someone from Identity approve

Copy link
Member

@kelvin-chappell kelvin-chappell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can understand a lot more of this than I expected and I'm relieved that a large part of it was references to moved code. It's very clear and well structured. Great work!

.github/workflows/cypress-e2e.yml Show resolved Hide resolved
cypress/cypress-nginx.conf Outdated Show resolved Hide resolved
cypress/cypress-nginx.conf Outdated Show resolved Hide resolved
cypress/cypress-nginx.conf Outdated Show resolved Hide resolved
cypress/lib/signInOkta.ts Show resolved Hide resolved
cypress/tests/e2e/e2e.cy.ts Outdated Show resolved Hide resolved
nginx/identity-frontend-CODE-fallback.conf Show resolved Hide resolved
nginx/identity-frontend-CODE-fallback.conf Show resolved Hide resolved
nginx/identity-frontend-CODE-fallback.conf Show resolved Hide resolved
Copy link
Member

@kelvin-chappell kelvin-chappell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@raphaelkabo raphaelkabo merged commit 4715bec into main Dec 18, 2023
11 checks passed
@raphaelkabo raphaelkabo deleted the rk/e2e-cypress-okta branch December 18, 2023 11:22
@prout-bot
Copy link
Collaborator

Seen on PROD (merged by @raphaelkabo 11 minutes and 38 seconds ago) Please check your changes!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants