mirror of
https://github.com/inventree/InvenTree.git
synced 2026-11-28 02:28:43 +00:00
SSO e2e testing (#12739)
* Extend SSO auth workflows * SSO e2e testing workflow * Remove orphaned code * Add unit tests for SSO * improved error messaging * Add test for SSO registration disabled * Fix gating on LOGIN_ENABLE_SSO * Adjust UI state management * Add playwright test for SSO disabled * Add backend unit tests * Adjust API version * Additional playwright tests * Retain desired page state on login failure * Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> * Adjust test code * Stricter matcher checking --------- Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
1 parent
69afe7723f
commit
a205717171
23 files changed
+893
-72
No files matched your search
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* A minimal OIDC provider, used only by the Playwright e2e suite to exercise
|
||||
* real SSO logins without depending on an external identity provider.
|
||||
*
|
||||
* Started as a 'webServer' entry in playwright.config.ts. The identity it
|
||||
* always authenticates as is configured via env vars (set from
|
||||
* tests/defaults.ts's `mockSsoUser`, so the test spec and this process agree
|
||||
* on the same values) - see tests/pui_sso.spec.ts.
|
||||
*
|
||||
* oauth2-mock-server auto-approves every /authorize request (no login UI),
|
||||
* which is what makes this usable headlessly in CI.
|
||||
*/
|
||||
import { Events, OAuth2Server } from 'oauth2-mock-server';
|
||||
|
||||
const port = Number(process.env.MOCK_OIDC_PORT ?? 9950);
|
||||
const host = process.env.MOCK_OIDC_HOST ?? 'localhost';
|
||||
|
||||
const claims = {
|
||||
sub: process.env.MOCK_OIDC_SUB,
|
||||
preferred_username: process.env.MOCK_OIDC_USERNAME,
|
||||
email: process.env.MOCK_OIDC_EMAIL,
|
||||
email_verified: true,
|
||||
given_name: process.env.MOCK_OIDC_FIRST_NAME,
|
||||
family_name: process.env.MOCK_OIDC_LAST_NAME
|
||||
};
|
||||
|
||||
const server = new OAuth2Server();
|
||||
await server.issuer.keys.generate('RS256');
|
||||
|
||||
server.service.on(Events.BeforeTokenSigning, (token) => {
|
||||
Object.assign(token.payload, claims);
|
||||
});
|
||||
|
||||
server.service.on(Events.BeforeUserinfo, (userInfoResponse) => {
|
||||
userInfoResponse.body = { ...claims };
|
||||
});
|
||||
|
||||
await server.start(port, host);
|
||||
console.log(`Mock OIDC server listening at ${server.issuer.url}`);
|
||||
|
||||
for (const signal of ['SIGINT', 'SIGTERM']) {
|
||||
process.on(signal, async () => {
|
||||
await server.stop();
|
||||
process.exit(0);
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user