Skip to content

testing: add shims to mock authentication locally (Bug 1978881)#440

Draft
cgsheeh wants to merge 1 commit intomozilla-conduit:mainfrom
cgsheeh:mock-auth
Draft

testing: add shims to mock authentication locally (Bug 1978881)#440
cgsheeh wants to merge 1 commit intomozilla-conduit:mainfrom
cgsheeh:mock-auth

Conversation

@cgsheeh
Copy link
Copy Markdown
Member

@cgsheeh cgsheeh commented Jul 23, 2025

Add a MockAuthBackend which overrides authenticate to always
return a mocked local user. Add a MockAuthMiddleware to log the
user in to a session.

With these shims loaded, running Lando locally with docker compose
will show an authenticated view.

Add a `MockAuthBackend` which overrides `authenticate` to always
return a mocked local user. Add a `MockAuthMiddleware` to log the
user in to a session.

With these shims loaded, running Lando locally with `docker compose`
will show an authenticated view.
@cgsheeh
Copy link
Copy Markdown
Member Author

cgsheeh commented Jul 23, 2025

@zzzeid @shtrom posting this as a draft so we can discuss the best approach for using this in the repo. Test failures are expected since it's currently loading into the main settings.py file.

My initial thought is we should add this in a separate settings.py file, and have that file load via an environment variable or CLI argument when starting Lando. Any other ideas are appreciated.

@zzzeid
Copy link
Copy Markdown
Contributor

zzzeid commented Jul 25, 2025

@zzzeid @shtrom posting this as a draft so we can discuss the best approach for using this in the repo. Test failures are expected since it's currently loading into the main settings.py file.

My initial thought is we should add this in a separate settings.py file, and have that file load via an environment variable or CLI argument when starting Lando. Any other ideas are appreciated.

Initial thoughts:

  • I am not sure we should unconditionally authenticate users, this would at least break invalid auth workflows (e.g., providing an incorrect user/password), and seems like way more than what is needed for local testing.
  • I think rather than creating a separate auth backend, adding a script that creates test users locally along with their required permissions would be better and more streamlined. There already is an auth backend that allows logging in with a user/password, so this can be used instead, and we already create an admin user in this way.

Aside from the comments above:

My initial thought is we should add this in a separate settings.py file, and have that file load via an environment variable or CLI argument when starting Lando. Any other ideas are appreciated.

See implementation of test_settings.py and remote_settings.py which could be used in a similar way for local_settings.py.

cgsheeh added a commit to cgsheeh/lando that referenced this pull request Mar 27, 2026
…927013) (mozilla-conduit#440)

The `PhabricatorDouble` mock API calls take the `limit` parameter,
but do not actually limit the number of entries in the response data.
Add a check if `limit` is set and slice the `items `list at that index.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants