Browse Source

test: playwright - OpenID auth flow test

pull/7569/head
Pranav C 8 months ago
parent
commit
6bb9439df1
  1. 9
      packages/nc-gui/middleware/auth.global.ts
  2. 4
      packages/nocodb/src/strategies/jwt.strategy.ts
  3. 15
      tests/playwright/pages/Account/Authentication.ts

9
packages/nc-gui/middleware/auth.global.ts

@ -51,7 +51,7 @@ export default defineNuxtRouteMiddleware(async (to, from) => {
await tryGoogleAuth(api, state.signIn) await tryGoogleAuth(api, state.signIn)
} }
await tryShortTokenAuth(api, state.signIn) if (!state.signedIn.value) await tryShortTokenAuth(api, state.signIn)
/** if public allow all visitors */ /** if public allow all visitors */
if (to.meta.public) return if (to.meta.public) return
@ -166,9 +166,7 @@ async function tryShortTokenAuth(api: Api<any>, signIn: Actions['signIn']) {
let extraProps: any = {} let extraProps: any = {}
try { try {
// `extra` prop is used in our cloud implementation, so we are keeping it // `extra` prop is used in our cloud implementation, so we are keeping it
const { const { data } = await api.instance.post(
data,
} = await api.instance.post(
`/auth/long-lived-token`, `/auth/long-lived-token`,
{}, {},
{ {
@ -178,11 +176,8 @@ async function tryShortTokenAuth(api: Api<any>, signIn: Actions['signIn']) {
}, },
) )
console.log(data)
debugger
const { token, extra } = data const { token, extra } = data
// if extra prop is null/undefined set it as an empty object as fallback // if extra prop is null/undefined set it as an empty object as fallback
extraProps = extra || {} extraProps = extra || {}

4
packages/nocodb/src/strategies/jwt.strategy.ts

@ -14,7 +14,9 @@ export class JwtStrategy extends PassportStrategy(Strategy) {
} }
async validate(req, jwtPayload) { async validate(req, jwtPayload) {
if (!jwtPayload?.email) return jwtPayload; if (!jwtPayload?.email) {
return jwtPayload
}
const user = await User.getByEmail(jwtPayload?.email); const user = await User.getByEmail(jwtPayload?.email);

15
tests/playwright/pages/Account/Authentication.ts

@ -92,7 +92,9 @@ export class AccountAuthenticationPage extends BasePage {
}); });
} }
async createOIDCProvider(p: { async createOIDCProvider(
p: {
issuer: string;
title: string; title: string;
clientId: string; clientId: string;
clientSecret: string; clientSecret: string;
@ -102,15 +104,24 @@ export class AccountAuthenticationPage extends BasePage {
jwkUrl: string; jwkUrl: string;
scopes: Array<string>; scopes: Array<string>;
userAttributes: string; userAttributes: string;
}) { },
setupRedirectUrlCbk?: ({ redirectUrl: string }) => Promise<void>
) {
const newOIDCBtn = this.get().locator('[data-test-id="nc-new-oidc-provider"]'); const newOIDCBtn = this.get().locator('[data-test-id="nc-new-oidc-provider"]');
await newOIDCBtn.click(); await newOIDCBtn.click();
const oidcModal = this.accountPage.rootPage.locator('.nc-oidc-modal'); const oidcModal = this.accountPage.rootPage.locator('.nc-oidc-modal');
if (setupRedirectUrlCbk) {
const redirectUrl = (await oidcModal.locator('[data-test-id="nc-openid-redirect-url"]').textContent()).trim();
await setupRedirectUrlCbk({ redirectUrl });
}
await oidcModal.locator('[data-test-id="nc-oidc-title"]').fill(p.title); await oidcModal.locator('[data-test-id="nc-oidc-title"]').fill(p.title);
await oidcModal.locator('[data-test-id="nc-oidc-issuer"]').fill(p.issuer);
await oidcModal.locator('[data-test-id="nc-oidc-client-id"]').fill(p.clientId); await oidcModal.locator('[data-test-id="nc-oidc-client-id"]').fill(p.clientId);
await oidcModal.locator('[data-test-id="nc-oidc-client-secret"]').fill(p.clientSecret); await oidcModal.locator('[data-test-id="nc-oidc-client-secret"]').fill(p.clientSecret);

Loading…
Cancel
Save