mirror of https://github.com/nocodb/nocodb
Pranav C
11 months ago
committed by
GitHub
25 changed files with 428 additions and 55 deletions
@ -1,15 +1,27 @@
|
||||
import { Injectable } from '@nestjs/common'; |
||||
import { ConfigService } from '@nestjs/config'; |
||||
import type { NestMiddleware } from '@nestjs/common'; |
||||
import type { AppConfig } from '~/interface/config'; |
||||
import Noco from '~/Noco'; |
||||
|
||||
@Injectable() |
||||
export class GlobalMiddleware implements NestMiddleware { |
||||
constructor(protected readonly config: ConfigService<AppConfig>) {} |
||||
|
||||
use(req: any, res: any, next: () => void) { |
||||
req.ncSiteUrl = |
||||
Noco.config?.envs?.[Noco.env]?.publicUrl || |
||||
Noco.config?.publicUrl || |
||||
req.protocol + '://' + req.get('host'); |
||||
req.ncFullUrl = req.protocol + '://' + req.get('host') + req.originalUrl; |
||||
|
||||
const dashboardPath = this.config.get('dashboardPath', { |
||||
infer: true, |
||||
}); |
||||
|
||||
// used for playwright tests so env is not documented
|
||||
req.dashboardUrl = |
||||
process.env.NC_DASHBOARD_URL || req.ncSiteUrl + dashboardPath; |
||||
next(); |
||||
} |
||||
} |
||||
|
@ -0,0 +1,162 @@
|
||||
import BasePage from '../Base'; |
||||
import { AccountPage } from './index'; |
||||
import * as assert from 'assert'; |
||||
import { expect } from '@playwright/test'; |
||||
|
||||
export class AccountAuthenticationPage extends BasePage { |
||||
private accountPage: AccountPage; |
||||
|
||||
constructor(accountPage: AccountPage) { |
||||
super(accountPage.rootPage); |
||||
this.accountPage = accountPage; |
||||
} |
||||
|
||||
async goto() { |
||||
await this.waitForResponse({ |
||||
uiAction: () => this.rootPage.goto('/#/account/authentication', { waitUntil: 'networkidle' }), |
||||
httpMethodsToMatch: ['GET'], |
||||
requestUrlPathToMatch: '/api/v2/sso-client', |
||||
}); |
||||
} |
||||
|
||||
get() { |
||||
return this.accountPage.get().locator(`[data-test-id="nc-authentication"]`); |
||||
} |
||||
|
||||
async verifySAMLProviderCount({ count }: { count: number }) { |
||||
await expect.poll(async () => await this.get().locator('.nc-saml-provider').count()).toBe(count); |
||||
} |
||||
|
||||
async verifyOIDCProviderCount({ count }: { count: number }) { |
||||
await expect.poll(async () => await this.get().locator('.nc-oidc-provider').count()).toBe(count); |
||||
} |
||||
|
||||
async getProvider(provider: 'saml' | 'oidc', title: string) { |
||||
return this.rootPage.locator(`[data-test-id="nc-${provider}-provider-${title}"]`); |
||||
} |
||||
|
||||
async deleteProvider(provider: 'saml' | 'oidc', title: string) { |
||||
await this.rootPage.locator(`.nc-${provider}-${title}-more-option`).click(); |
||||
await this.waitForResponse({ |
||||
uiAction: () => this.rootPage.locator(`[data-test-id="nc-${provider}-delete"]`).click(), |
||||
httpMethodsToMatch: ['DELETE'], |
||||
requestUrlPathToMatch: `/api/v2/sso-client/`, |
||||
}); |
||||
} |
||||
|
||||
async toggleProvider(provider: 'saml' | 'oidc', title: string) { |
||||
await this.waitForResponse({ |
||||
uiAction: () => this.get().locator(`.nc-${provider}-${title}-enable .nc-switch`).click(), |
||||
httpMethodsToMatch: ['PATCH'], |
||||
requestUrlPathToMatch: `/api/v2/sso-client/`, |
||||
}); |
||||
} |
||||
|
||||
async selectScope({ type, locator }: { type: string[] }) { |
||||
await this.rootPage.locator('.ant-select-selector').click(); |
||||
|
||||
await this.rootPage.locator('.ant-select-selection-search-input[aria-expanded="true"]').waitFor(); |
||||
for (const t of type) { |
||||
await this.rootPage.locator('.rc-virtual-list-holder-inner > div').locator(`text="${t}"`).click(); |
||||
} |
||||
} |
||||
|
||||
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'); |
||||
|
||||
// wait until redirect url is generated
|
||||
await samlModal.locator('[data-test-id="nc-saml-redirect-url"]:has-text("http://")').waitFor(); |
||||
|
||||
if (setupRedirectUrlCbk) { |
||||
const redirectUrl = ( |
||||
await samlModal.locator('[data-test-id="nc-saml-redirect-url"]:has-text("http://")').textContent() |
||||
).trim(); |
||||
const audience = ( |
||||
await samlModal.locator('[data-test-id="nc-saml-issuer-url"]:has-text("http://")').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); |
||||
} |
||||
if (p.xml) { |
||||
await samlModal.locator('[data-test-id="nc-saml-xml"]').fill(p.xml); |
||||
} |
||||
|
||||
await this.waitForResponse({ |
||||
uiAction: () => samlModal.locator('[data-test-id="nc-saml-submit"]').click(), |
||||
httpMethodsToMatch: ['GET'], |
||||
requestUrlPathToMatch: '/api/v2/sso-client', |
||||
}); |
||||
} |
||||
|
||||
async createOIDCProvider( |
||||
p: { |
||||
issuer: string; |
||||
title: string; |
||||
clientId: string; |
||||
clientSecret: string; |
||||
authUrl: string; |
||||
userInfoUrl: string; |
||||
tokenUrl: string; |
||||
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'); |
||||
|
||||
// wait until redirect url is generated
|
||||
await oidcModal.locator('[data-test-id="nc-openid-redirect-url"]:has-text("http://")').waitFor(); |
||||
|
||||
if (setupRedirectUrlCbk) { |
||||
const redirectUrl = ( |
||||
await oidcModal.locator('[data-test-id="nc-openid-redirect-url"]:has-text("http://")').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); |
||||
|
||||
await oidcModal.locator('[data-test-id="nc-oidc-auth-url"]').fill(p.authUrl); |
||||
|
||||
await oidcModal.locator('[data-test-id="nc-oidc-token-url"]').fill(p.tokenUrl); |
||||
|
||||
await oidcModal.locator('[data-test-id="nc-oidc-user-info-url"]').fill(p.userInfoUrl); |
||||
|
||||
await oidcModal.locator('[data-test-id="nc-oidc-jwk-url"]').fill(p.jwkUrl); |
||||
|
||||
await this.selectScope({ |
||||
type: p.scopes, |
||||
locator: oidcModal.locator('[data-test-id="nc-oidc-scope"]'), |
||||
}); |
||||
|
||||
await oidcModal.locator('[data-test-id="nc-oidc-user-attribute"]').fill(p.userAttributes); |
||||
|
||||
await this.waitForResponse({ |
||||
uiAction: () => oidcModal.locator('[data-test-id="nc-oidc-save-btn"]').click(), |
||||
httpMethodsToMatch: ['GET'], |
||||
requestUrlPathToMatch: '/api/v2/sso-client', |
||||
}); |
||||
} |
||||
} |
@ -0,0 +1,41 @@
|
||||
import { Page } from '@playwright/test'; |
||||
import BasePage from '../Base'; |
||||
import { ProjectsPage } from '../ProjectsPage'; |
||||
|
||||
export class OpenIDLoginPage extends BasePage { |
||||
readonly projectsPage: ProjectsPage; |
||||
|
||||
constructor(rootPage: Page) { |
||||
super(rootPage); |
||||
this.projectsPage = new ProjectsPage(rootPage); |
||||
} |
||||
|
||||
async goto(title = 'test') { |
||||
// reload page to get latest app info
|
||||
await this.rootPage.reload({ waitUntil: 'networkidle' }); |
||||
// click sign in with SAML
|
||||
await this.rootPage.locator(`button:has-text("Sign in with ${title}")`).click(); |
||||
} |
||||
|
||||
get() { |
||||
return this.rootPage.locator('html'); |
||||
} |
||||
|
||||
async signIn({ email }: { email: string }) { |
||||
const signIn = this.get(); |
||||
await signIn.locator('[name="login"]').waitFor(); |
||||
|
||||
await signIn.locator(`[name="login"]`).fill(email); |
||||
await signIn.locator(`[name="password"]`).fill('dummy-password'); |
||||
|
||||
await signIn.locator(`[type="submit"]`).click(); |
||||
const authorize = this.get(); |
||||
|
||||
await Promise.all([ |
||||
this.rootPage.waitForNavigation({ url: /localhost:3000/ }), |
||||
authorize.locator(`[type="submit"]`).click(), |
||||
]); |
||||
|
||||
await this.rootPage.locator(`[data-testid="nc-sidebar-userinfo"]:has-text("${email.split('@')[0]}")`); |
||||
} |
||||
} |
@ -0,0 +1,38 @@
|
||||
import { Page } from '@playwright/test'; |
||||
import BasePage from '../Base'; |
||||
import { ProjectsPage } from '../ProjectsPage'; |
||||
import { expect } from '@playwright/test'; |
||||
|
||||
export class SAMLLoginPage extends BasePage { |
||||
readonly projectsPage: ProjectsPage; |
||||
|
||||
constructor(rootPage: Page) { |
||||
super(rootPage); |
||||
this.projectsPage = new ProjectsPage(rootPage); |
||||
} |
||||
|
||||
async goto(title = 'test') { |
||||
// reload page to get latest app info
|
||||
await this.rootPage.reload({ waitUntil: 'networkidle' }); |
||||
// click sign in with SAML
|
||||
await this.rootPage.locator(`button:has-text("Sign in with ${title}")`).click(); |
||||
} |
||||
|
||||
get() { |
||||
return this.rootPage.locator('html'); |
||||
} |
||||
|
||||
async signIn({ email }: { email: string }) { |
||||
const signIn = this.get(); |
||||
await signIn.locator('#userName').waitFor(); |
||||
|
||||
await signIn.locator(`#userName`).fill(email); |
||||
await signIn.locator(`#email`).fill(email); |
||||
await Promise.all([ |
||||
this.rootPage.waitForNavigation({ url: /localhost:3000/ }), |
||||
signIn.locator(`#btn-sign-in`).click(), |
||||
]); |
||||
|
||||
await this.rootPage.locator(`[data-testid="nc-sidebar-userinfo"]:has-text("${email.split('@')[0]}")`); |
||||
} |
||||
} |
Loading…
Reference in new issue