From 6bb9439df17c72846f2f1937d865a4bb2f09a9e1 Mon Sep 17 00:00:00 2001 From: Pranav C Date: Wed, 7 Feb 2024 12:26:49 +0000 Subject: [PATCH] test: playwright - OpenID auth flow test --- packages/nc-gui/middleware/auth.global.ts | 9 ++--- .../nocodb/src/strategies/jwt.strategy.ts | 4 ++- .../pages/Account/Authentication.ts | 33 ++++++++++++------- 3 files changed, 27 insertions(+), 19 deletions(-) diff --git a/packages/nc-gui/middleware/auth.global.ts b/packages/nc-gui/middleware/auth.global.ts index 45914fa013..74d6819740 100644 --- a/packages/nc-gui/middleware/auth.global.ts +++ b/packages/nc-gui/middleware/auth.global.ts @@ -51,7 +51,7 @@ export default defineNuxtRouteMiddleware(async (to, from) => { 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 (to.meta.public) return @@ -166,9 +166,7 @@ async function tryShortTokenAuth(api: Api, signIn: Actions['signIn']) { let extraProps: any = {} try { // `extra` prop is used in our cloud implementation, so we are keeping it - const { - data, - } = await api.instance.post( + const { data } = await api.instance.post( `/auth/long-lived-token`, {}, { @@ -178,11 +176,8 @@ async function tryShortTokenAuth(api: Api, signIn: Actions['signIn']) { }, ) - console.log(data) - debugger const { token, extra } = data - // if extra prop is null/undefined set it as an empty object as fallback extraProps = extra || {} diff --git a/packages/nocodb/src/strategies/jwt.strategy.ts b/packages/nocodb/src/strategies/jwt.strategy.ts index ac91e672e0..26ad46123a 100644 --- a/packages/nocodb/src/strategies/jwt.strategy.ts +++ b/packages/nocodb/src/strategies/jwt.strategy.ts @@ -14,7 +14,9 @@ export class JwtStrategy extends PassportStrategy(Strategy) { } async validate(req, jwtPayload) { - if (!jwtPayload?.email) return jwtPayload; + if (!jwtPayload?.email) { + return jwtPayload + } const user = await User.getByEmail(jwtPayload?.email); diff --git a/tests/playwright/pages/Account/Authentication.ts b/tests/playwright/pages/Account/Authentication.ts index 133d40f7a7..da7aaacf4b 100644 --- a/tests/playwright/pages/Account/Authentication.ts +++ b/tests/playwright/pages/Account/Authentication.ts @@ -92,25 +92,36 @@ export class AccountAuthenticationPage extends BasePage { }); } - async createOIDCProvider(p: { - title: string; - clientId: string; - clientSecret: string; - authUrl: string; - userInfoUrl: string; - tokenUrl: string; - jwkUrl: string; - scopes: Array; - userAttributes: string; - }) { + async createOIDCProvider( + p: { + issuer: string; + title: string; + clientId: string; + clientSecret: string; + authUrl: string; + userInfoUrl: string; + tokenUrl: string; + jwkUrl: string; + scopes: Array; + userAttributes: string; + }, + setupRedirectUrlCbk?: ({ redirectUrl: string }) => Promise + ) { const newOIDCBtn = this.get().locator('[data-test-id="nc-new-oidc-provider"]'); await newOIDCBtn.click(); 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-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-secret"]').fill(p.clientSecret);