Browse Source

Merge pull request #8927 from nocodb/nc-test/ui-acl

test: UI ACL
pull/8934/head
Ramesh Mane 6 months ago committed by GitHub
parent
commit
1e12d4f9e3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 6
      tests/playwright/pages/Dashboard/Settings/Acl.ts
  2. 3
      tests/playwright/pages/Dashboard/Settings/DataSources.ts
  3. 2
      tests/playwright/tests/db/usersAccounts/accountTokenManagement.spec.ts
  4. 129
      tests/playwright/tests/db/usersAccounts/rolesPreview.spec.ts

6
tests/playwright/pages/Dashboard/Settings/Acl.ts

@ -1,5 +1,6 @@
import BasePage from '../../Base'; import BasePage from '../../Base';
import { DataSourcesPage } from './DataSources'; import { DataSourcesPage } from './DataSources';
import { expect } from '@playwright/test';
export class AclPage extends BasePage { export class AclPage extends BasePage {
readonly dataSources: DataSourcesPage; readonly dataSources: DataSourcesPage;
@ -17,6 +18,11 @@ export class AclPage extends BasePage {
await this.get().locator(`.nc-acl-${table}-${role}-chkbox`).click(); await this.get().locator(`.nc-acl-${table}-${role}-chkbox`).click();
} }
async verify({ table, role, expectedValue }: { table: string; role: string; expectedValue: boolean }) {
const isChecked = await this.get().locator(`.nc-acl-${table}-${role}-chkbox`).isChecked();
expect(isChecked).toBe(expectedValue);
}
async save() { async save() {
await this.waitForResponse({ await this.waitForResponse({
uiAction: async () => await this.get().locator(`button:has-text("Save")`).click(), uiAction: async () => await this.get().locator(`button:has-text("Save")`).click(),

3
tests/playwright/pages/Dashboard/Settings/DataSources.ts

@ -40,7 +40,8 @@ export class DataSourcesPage extends BasePage {
} }
async openAcl({ dataSourceName = defaultBaseName }: { dataSourceName?: string } = {}) { async openAcl({ dataSourceName = defaultBaseName }: { dataSourceName?: string } = {}) {
await this.get().locator('.ds-table-row', { hasText: dataSourceName }).locator('button:has-text("UI ACL")').click(); await this.get().locator('.ds-table-row', { hasText: dataSourceName }).click();
await this.get().locator('[data-testid="nc-acl-tab"]').click();
} }
async openMetaSync({ rowIndex }: { rowIndex: number }) { async openMetaSync({ rowIndex }: { rowIndex: number }) {

2
tests/playwright/tests/db/usersAccounts/accountTokenManagement.spec.ts

@ -3,7 +3,7 @@ import { AccountPage } from '../../../pages/Account';
import { AccountTokenPage } from '../../../pages/Account/Token'; import { AccountTokenPage } from '../../../pages/Account/Token';
import setup, { unsetup } from '../../../setup'; import setup, { unsetup } from '../../../setup';
test.describe('User roles', () => { test.describe('Token Management', () => {
let accountTokenPage: AccountTokenPage; let accountTokenPage: AccountTokenPage;
let accountPage: AccountPage; let accountPage: AccountPage;
// @ts-ignore // @ts-ignore

129
tests/playwright/tests/db/usersAccounts/rolesPreview.spec.ts

@ -3,23 +3,77 @@ import { DashboardPage } from '../../../pages/Dashboard';
import setup, { unsetup } from '../../../setup'; import setup, { unsetup } from '../../../setup';
import { ToolbarPage } from '../../../pages/Dashboard/common/Toolbar'; import { ToolbarPage } from '../../../pages/Dashboard/common/Toolbar';
import { SettingsPage, SettingTab } from '../../../pages/Dashboard/Settings'; import { SettingsPage, SettingTab } from '../../../pages/Dashboard/Settings';
import { Api } from 'nocodb-sdk';
import { AccountUsersPage } from '../../../pages/Account/Users';
import { AccountPage } from '../../../pages/Account';
import { LoginPage } from '../../../pages/LoginPage';
import { isEE } from '../../../setup/db';
let api: Api<any>;
const roles = ['Editor', 'Commenter', 'Viewer']; const roles = ['Editor', 'Commenter', 'Viewer'];
test.describe.skip('Preview Mode', () => { test.describe('Preview Mode', () => {
test.slow(); test.slow();
let dashboard: DashboardPage; let dashboard: DashboardPage;
let toolbar: ToolbarPage; let toolbar: ToolbarPage;
let settings: SettingsPage; let settings: SettingsPage;
let accountPage: AccountPage;
let accountUsersPage: AccountUsersPage;
let loginPage: LoginPage;
let context: any; let context: any;
let userEmail = '';
test.beforeEach(async ({ page }) => { test.beforeEach(async ({ page }) => {
context = await setup({ page, isEmptyProject: false }); context = await setup({ page, isEmptyProject: false });
dashboard = new DashboardPage(page, context.base); dashboard = new DashboardPage(page, context.base);
toolbar = dashboard.grid.toolbar; toolbar = dashboard.grid.toolbar;
settings = dashboard.settings; settings = dashboard.settings;
accountPage = new AccountPage(page);
accountUsersPage = new AccountUsersPage(accountPage);
loginPage = new LoginPage(accountPage.rootPage);
try {
api = new Api({
baseURL: `http://localhost:8080/`,
headers: {
'xc-auth': context.token,
},
});
} catch (e) {
console.log(e);
}
userEmail = accountUsersPage.prefixEmail('uiACL@nocodb.com');
try {
// check if user already exists; if so- remove them
const user = await api.auth.baseUserList(context.base.id);
if (user.users.list.length > 0) {
const u = user.users.list.find((u: any) => u.email === userEmail);
if (u) {
await api.auth.baseUserRemove(context.base.id, u.id);
}
}
// create user if not exists
try {
await api.auth.signup({
email: userEmail,
password: '12345678',
});
} catch (e) {
console.log(e);
}
await api.auth.baseUserAdd(context.base.id, {
roles: 'editor',
email: userEmail,
});
} catch (e) {
// ignore error
}
}); });
test.afterEach(async () => { test.afterEach(async () => {
@ -27,6 +81,8 @@ test.describe.skip('Preview Mode', () => {
}); });
test('Preview Mode', async () => { test('Preview Mode', async () => {
if (!isEE()) test.skip();
// close 'Team & Auth' tab // close 'Team & Auth' tab
await dashboard.closeTab({ title: 'Team & Auth' }); await dashboard.closeTab({ title: 'Team & Auth' });
@ -36,7 +92,7 @@ test.describe.skip('Preview Mode', () => {
await settings.selectTab({ await settings.selectTab({
tab: SettingTab.DataSources, tab: SettingTab.DataSources,
}); });
await settings.dataSources.openAcl(); await settings.dataSources.openAcl({ dataSourceName: 'Default' });
await settings.dataSources.acl.toggle({ table: 'Language', role: 'editor' }); await settings.dataSources.acl.toggle({ table: 'Language', role: 'editor' });
await settings.dataSources.acl.toggle({ table: 'Language', role: 'commenter' }); await settings.dataSources.acl.toggle({ table: 'Language', role: 'commenter' });
await settings.dataSources.acl.toggle({ table: 'Language', role: 'viewer' }); await settings.dataSources.acl.toggle({ table: 'Language', role: 'viewer' });
@ -46,64 +102,39 @@ test.describe.skip('Preview Mode', () => {
await settings.dataSources.acl.save(); await settings.dataSources.acl.save();
await settings.close(); await settings.close();
// Role test await dashboard.gotoSettings();
for (let i = 0; i < roles.length; i++) { await settings.selectTab({
await roleTest(roles[i]); tab: SettingTab.DataSources,
}
});
async function roleTest(role: string) {
await dashboard.grid.workspaceMenu.toggle();
await dashboard.grid.workspaceMenu.click({
menu: 'Preview as',
subMenu: role,
});
// wait for preview mode to be enabled
await dashboard.rootPage.locator('.nc-preview-btn-exit-to-app').waitFor();
// todo: Otherwise grid will be stuck at loading even tho the data is loaded
await dashboard.rootPage.waitForTimeout(2500);
await dashboard.validateWorkspaceMenu({
role: role.toLowerCase(),
});
await dashboard.rootPage.waitForTimeout(1500);
await dashboard.treeView.openTable({ title: 'Country', networkResponse: false });
await dashboard.viewSidebar.validateRoleAccess({
role: role.toLowerCase(),
}); });
await settings.dataSources.openAcl({ dataSourceName: 'Default' });
await toolbar.verifyRoleAccess({ await settings.dataSources.acl.verify({ table: 'Language', role: 'editor', expectedValue: false });
role: role.toLowerCase(), await settings.dataSources.acl.verify({ table: 'Language', role: 'commenter', expectedValue: false });
}); await settings.dataSources.acl.verify({ table: 'Language', role: 'viewer', expectedValue: false });
await settings.dataSources.acl.verify({ table: 'CustomerList', role: 'editor', expectedValue: false });
await settings.dataSources.acl.verify({ table: 'CustomerList', role: 'commenter', expectedValue: false });
await settings.dataSources.acl.verify({ table: 'CustomerList', role: 'viewer', expectedValue: false });
await dashboard.treeView.validateRoleAccess({ await settings.close();
role: role.toLowerCase(), await dashboard.signOut();
});
await dashboard.grid.verifyRoleAccess({ await loginPage.signIn({
role: role.toLowerCase(), email: userEmail,
password: '12345678',
withoutPrefix: true,
}); });
await dashboard.grid.openExpandedRow({ index: 0 }); await dashboard.treeView.verifyTable({
await dashboard.expandedForm.verifyRoleAccess({ title: 'Actor',
role: role.toLowerCase(), exists: true,
}); });
// Access control validation
await dashboard.treeView.verifyTable({ await dashboard.treeView.verifyTable({
title: 'Language', title: 'Language',
exists: role.toLowerCase() === 'creator' ? true : false, exists: false,
}); });
await dashboard.treeView.verifyTable({ await dashboard.treeView.verifyTable({
title: 'CustomerList', title: 'CustomerList',
exists: role.toLowerCase() === 'creator' ? true : false, exists: false,
}); });
});
// close preview mode
await dashboard.rootPage.locator('.nc-preview-btn-exit-to-app').click();
}
}); });

Loading…
Cancel
Save