Browse Source

test: playwright - OpenID auth flow test

pull/7569/head
Pranav C 11 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 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<any>, 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<any>, 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 || {}

4
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);

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;
clientId: string;
clientSecret: string;
@ -102,15 +104,24 @@ export class AccountAuthenticationPage extends BasePage {
jwkUrl: string;
scopes: Array<string>;
userAttributes: string;
}) {
},
setupRedirectUrlCbk?: ({ redirectUrl: string }) => Promise<void>
) {
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);

Loading…
Cancel
Save