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

Persist osm login across playwright tests (temp login removed) #1910

Merged
merged 2 commits into from
Nov 27, 2024

Conversation

spwoodcock
Copy link
Member

@spwoodcock spwoodcock commented Nov 22, 2024

What type of PR is this? (check all applicable)

  • πŸ• Feature
  • πŸ› Bug Fix
  • πŸ“ Documentation
  • πŸ§‘β€πŸ’» Refactor
  • βœ… Test
  • πŸ€– Build or CI
  • ❓ Other (please specify)

Related

#1903 as the PR where this issue was discussed

Describe this PR

  • Didn't get a chance to finish this due to my flight, but hopefully you get the idea here @NSUWAL123
  • If I don't get to look at this until Monday, we could go over it together in person πŸ˜„
  • The context should probably be set just after the OSM login succeeds, then waiting for the redirect will allow the cookie to be set for the subsequent test.
  • The context wont save the cookie as it's httpOnly, but should save the OSM login part hopefully, to avoid having to do the Oauth flow for OSM again - let's see!
  • In the end the main goal is automated OSM login. To do that we need to make a test OSM account and can just hardcode the creds to this repo. If we optimise by reducing calls to OSM via the auth context, this is a bonus, but not essential for now.

Alternative Approaches Considered

  • Disable auth on the backend when DEBUG=true.
  • But this would mean we can't test properly with roles, and this could be important in future.

Checklist before requesting a review

[optional] What gif best describes this PR or how it makes you feel?

@spwoodcock
Copy link
Member Author

This was a lot more complicated that I imagined, due to OpenStreetMap oauth restrictions:

  • https must be used for all URLs, other than 127.0.0.1.
  • As we are testing in one container, but accessing the frontend in another, we cannot use 127.0.0.1.
  • This forces us to use https for the domain fmtm.dev.test, so we have to configure a certificate on the vite dev server and add the CA cert to the playwright container trusted cert chain.
  • Documented the work in that direction here: Example (WIP) config for https Playwright testingΒ #1920

Instead, in this PR I decided to make a simple workaround via temp auth for the React frontend:

  • The auth is not actually used anyway, as we have DEBUG=True on the backend, so the localadmin user is used.
  • This simply sets the temp auth cookie & authDetails in the frontend state, so we can continue as if we are logged in.

@github-actions github-actions bot added the backend Related to backend code label Nov 27, 2024
@spwoodcock spwoodcock changed the base branch from development to feat/mapper-login November 27, 2024 04:24
@spwoodcock spwoodcock force-pushed the test/persist-playwright-login branch from 7aadaba to b3a10aa Compare November 27, 2024 04:25
@github-actions github-actions bot added the docs Improvements or additions to documentation label Nov 27, 2024
@spwoodcock spwoodcock force-pushed the test/persist-playwright-login branch from b3a10aa to d809ea4 Compare November 27, 2024 04:27
@spwoodcock spwoodcock marked this pull request as ready for review November 27, 2024 04:29
@spwoodcock spwoodcock merged commit 71cec9c into feat/mapper-login Nov 27, 2024
2 checks passed
@spwoodcock spwoodcock deleted the test/persist-playwright-login branch November 27, 2024 04:29
spwoodcock added a commit that referenced this pull request Nov 27, 2024
…1903)

* feat(osm-logo): logo add to mapper

* feat(login): login store add

* fix(layer-switcher): close layer-switcher by default

* feat(login): login dialog popup add

* fix(login): util functions add for login

* fix(login): store current path on localStorage

* fix(osmAuth): if user request redirection to mapper frontend then treat as external url

* feat(logo): hot logo add

* fix(header): header component ui slice

* feat(login): toggle modal state add

* fix(layout): replace hot-header with custom header component

* fix(login): replace modalOpen state on parent with stores

* fix(+layout): barlow font add to root

* feat(header): display username and profile image if user logged in

* fix(login): signOut add

* feat(drawerItems): drawer menu items add

* feat(header): drawer comp add, signout func add

* fix(layerSwitchMenu): width & height fix

* fix(mapLegends): fix(mapLegends): show map legend in dropdown

* fix(mapControlComponent): add mapLegend to mapControlComponent

* fix(projectDetailsV2): remove showing map legend on accordion, btn linking to mapper frontend add

* remove(login): remove temporary login from react frontend

* test: persist osm login across playwright tests (temp login removed) (#1910)

* test: wip persist osm login across playwright tests

* test: add temp auth config as a playwright workaround

* test: fix mapper flow tests, first open page, then click card

* test: disable firefox and webkit tests entirely for now

* docs: add note about attempting test auth with webkit

* test: use btnTestId prop to identify specific button during tests

---------

Co-authored-by: Sam <[email protected]>
Co-authored-by: spwoodcock <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend Related to backend code docs Improvements or additions to documentation frontend Related to frontend code tests Related to automated code tests
Projects
Development

Successfully merging this pull request may close these issues.

2 participants