Browse Source

test: playwright - SAML auth flow test

pull/7569/head
Pranav C 8 months ago
parent
commit
c698d27fb1
  1. 2
      packages/nc-gui/composables/useApi/interceptors.ts
  2. 9
      packages/nc-gui/middleware/auth.global.ts
  3. 11
      tests/playwright/pages/Account/Authentication.ts
  4. 11
      tests/playwright/pages/SsoIdpPage/SAMLLoginPage.ts

2
packages/nc-gui/composables/useApi/interceptors.ts

@ -16,7 +16,7 @@ export function addAxiosInterceptors(api: Api<any>) {
axiosInstance.interceptors.request.use((config) => {
config.headers['xc-gui'] = 'true'
if (state.token.value) config.headers['xc-auth'] = state.token.value
if (state.token.value && !config.headers['xc-short-token']) config.headers['xc-auth'] = state.token.value
if (!config.url?.endsWith('/user/me') && !config.url?.endsWith('/admin/roles') && state.previewAs?.value) {
config.headers['xc-preview'] = state.previewAs.value

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

@ -167,9 +167,9 @@ async function tryShortTokenAuth(api: Api<any>, signIn: Actions['signIn']) {
try {
// `extra` prop is used in our cloud implementation, so we are keeping it
const {
data: { token, extra },
data,
} = await api.instance.post(
`/auth/long-lived-token-refresh`,
`/auth/long-lived-token`,
{},
{
headers: {
@ -178,6 +178,11 @@ 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 || {}

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

@ -61,13 +61,22 @@ export class AccountAuthenticationPage extends BasePage {
}
}
async createSAMLProvider(p: { title: string; url?: string; xml?: string }) {
async createSAMLProvider(
p: { title: string; url?: string; xml?: string },
setupRedirectUrlCbk?: ({ redirectUrl: string, audience: string }) => Promise<void>
) {
const newSamlBtn = this.get().locator('[data-test-id="nc-new-saml-provider"]');
await newSamlBtn.click();
const samlModal = this.accountPage.rootPage.locator('.nc-saml-modal');
if (setupRedirectUrlCbk) {
const redirectUrl = (await samlModal.locator('[data-test-id="nc-saml-redirect-url"]').textContent()).trim();
const audience = (await samlModal.locator('[data-test-id="nc-saml-issuer-url"]').textContent()).trim();
await setupRedirectUrlCbk({ redirectUrl, audience });
}
await samlModal.locator('[data-test-id="nc-saml-title"]').fill(p.title);
if (p.url) {
await samlModal.locator('[data-test-id="nc-saml-metadata-url"]').fill(p.url);

11
tests/playwright/pages/SsoIdpPage/SAMLLoginPage.ts

@ -29,6 +29,15 @@ export class SAMLLoginPage extends BasePage {
await signIn.locator(`#userName`).fill(email);
await signIn.locator(`#email`).fill(email);
await signIn.locator(`#btn-sign-in`).click();
await Promise.all([
this.rootPage.waitForNavigation({ url: /localhost:8080/ }),
signIn.locator(`#btn-sign-in`).click(),
]);
await this.rootPage.goto(`http://localhost:3000?` + this.rootPage.url().split('?')[1]);
await this.projectsPage.waitToBeRendered();
console.log('111');
}
}

Loading…
Cancel
Save