Browse Source

test: UI ACL

pull/8927/head
Raju Udava 5 months ago
parent
commit
00376535e9
  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 { DataSourcesPage } from './DataSources';
import { expect } from '@playwright/test';
export class AclPage extends BasePage {
readonly dataSources: DataSourcesPage;
@ -17,6 +18,11 @@ export class AclPage extends BasePage {
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() {
await this.waitForResponse({
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 } = {}) {
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 }) {

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 setup, { unsetup } from '../../../setup';
test.describe('User roles', () => {
test.describe('Token Management', () => {
let accountTokenPage: AccountTokenPage;
let accountPage: AccountPage;
// @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 { ToolbarPage } from '../../../pages/Dashboard/common/Toolbar';
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'];
test.describe.skip('Preview Mode', () => {
test.describe('Preview Mode', () => {
test.slow();
let dashboard: DashboardPage;
let toolbar: ToolbarPage;
let settings: SettingsPage;
let accountPage: AccountPage;
let accountUsersPage: AccountUsersPage;
let loginPage: LoginPage;
let context: any;
let userEmail = '';
test.beforeEach(async ({ page }) => {
context = await setup({ page, isEmptyProject: false });
dashboard = new DashboardPage(page, context.base);
toolbar = dashboard.grid.toolbar;
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 () => {
@ -27,6 +81,8 @@ test.describe.skip('Preview Mode', () => {
});
test('Preview Mode', async () => {
if (!isEE()) test.skip();
// close 'Team & Auth' tab
await dashboard.closeTab({ title: 'Team & Auth' });
@ -36,7 +92,7 @@ test.describe.skip('Preview Mode', () => {
await settings.selectTab({
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: 'commenter' });
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.close();
// Role test
for (let i = 0; i < roles.length; i++) {
await roleTest(roles[i]);
}
});
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 dashboard.gotoSettings();
await settings.selectTab({
tab: SettingTab.DataSources,
});
await settings.dataSources.openAcl({ dataSourceName: 'Default' });
await toolbar.verifyRoleAccess({
role: role.toLowerCase(),
});
await settings.dataSources.acl.verify({ table: 'Language', role: 'editor', expectedValue: false });
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({
role: role.toLowerCase(),
});
await settings.close();
await dashboard.signOut();
await dashboard.grid.verifyRoleAccess({
role: role.toLowerCase(),
await loginPage.signIn({
email: userEmail,
password: '12345678',
withoutPrefix: true,
});
await dashboard.grid.openExpandedRow({ index: 0 });
await dashboard.expandedForm.verifyRoleAccess({
role: role.toLowerCase(),
await dashboard.treeView.verifyTable({
title: 'Actor',
exists: true,
});
// Access control validation
await dashboard.treeView.verifyTable({
title: 'Language',
exists: role.toLowerCase() === 'creator' ? true : false,
exists: false,
});
await dashboard.treeView.verifyTable({
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