From 328711e908cf5847200ca64f4d787308c7813be9 Mon Sep 17 00:00:00 2001 From: Alexis Date: Mon, 19 Feb 2024 17:28:53 +0100 Subject: [PATCH] add the test architecture for created users with specific user groups --- .../(app)/users/[id=uuid]/edit/+page.svelte | 3 +- .../[id=uuid]/edit/set-password/+page.svelte | 2 +- frontend/tests/functional/nav.test.ts | 10 +-- .../tests/functional/user-permissions.test.ts | 78 +++++++++++++++++++ frontend/tests/utils/form-content.ts | 2 +- frontend/tests/utils/test-data.ts | 2 +- frontend/tests/utils/test-utils.ts | 2 + 7 files changed, 90 insertions(+), 9 deletions(-) create mode 100644 frontend/tests/functional/user-permissions.test.ts diff --git a/frontend/src/routes/(app)/users/[id=uuid]/edit/+page.svelte b/frontend/src/routes/(app)/users/[id=uuid]/edit/+page.svelte index 70675de72..aa03cc51e 100644 --- a/frontend/src/routes/(app)/users/[id=uuid]/edit/+page.svelte +++ b/frontend/src/routes/(app)/users/[id=uuid]/edit/+page.svelte @@ -16,7 +16,8 @@

In case the user cannot set their own password, you can set a temporary passwordset a temporary password. Please use a strong one and make sure to inform the user to change it as soon as possible.

diff --git a/frontend/src/routes/(app)/users/[id=uuid]/edit/set-password/+page.svelte b/frontend/src/routes/(app)/users/[id=uuid]/edit/set-password/+page.svelte index 5eb139510..64c00ce8f 100644 --- a/frontend/src/routes/(app)/users/[id=uuid]/edit/set-password/+page.svelte +++ b/frontend/src/routes/(app)/users/[id=uuid]/edit/set-password/+page.svelte @@ -41,7 +41,7 @@ mandatory />

-

diff --git a/frontend/tests/functional/nav.test.ts b/frontend/tests/functional/nav.test.ts index fc684e8cc..5116dde3d 100644 --- a/frontend/tests/functional/nav.test.ts +++ b/frontend/tests/functional/nav.test.ts @@ -42,25 +42,25 @@ test('sidebar navigation tests', async ({ logedPage, analyticsPage, sideBar, pag await test.step('more panel links are working properly', async () => { await sideBar.moreButton.click(); - await expect(sideBar.morePanel).not.toHaveAttribute('inert') + await expect(sideBar.morePanel).not.toHaveAttribute('inert'); await expect(sideBar.profileButton).toBeVisible(); await sideBar.profileButton.click(); - await expect(sideBar.morePanel).toHaveAttribute('inert') + await expect(sideBar.morePanel).toHaveAttribute('inert'); await expect(page).toHaveURL('/profile'); await expect.soft(logedPage.pageTitle).toHaveText('Profile'); await sideBar.moreButton.click(); - await expect(sideBar.morePanel).not.toHaveAttribute('inert') + await expect(sideBar.morePanel).not.toHaveAttribute('inert'); await expect(sideBar.aboutButton).toBeVisible(); await sideBar.aboutButton.click(); - await expect(sideBar.morePanel).toHaveAttribute('inert') + await expect(sideBar.morePanel).toHaveAttribute('inert'); await expect(logedPage.modalTitle).toBeVisible(); await expect.soft(logedPage.modalTitle).toHaveText('About CISO Assistant'); await page.mouse.click(20, 20); // click outside the modal to close it await expect(logedPage.modalTitle).not.toBeVisible(); await sideBar.moreButton.click(); - await expect(sideBar.morePanel).not.toHaveAttribute('inert') + await expect(sideBar.morePanel).not.toHaveAttribute('inert'); await expect(sideBar.logoutButton).toBeVisible(); await sideBar.logoutButton.click(); await logedPage.hasUrl(0); diff --git a/frontend/tests/functional/user-permissions.test.ts b/frontend/tests/functional/user-permissions.test.ts new file mode 100644 index 000000000..701b06eae --- /dev/null +++ b/frontend/tests/functional/user-permissions.test.ts @@ -0,0 +1,78 @@ +import { test, expect, setHttpResponsesListener, TestContent } from '../utils/test-utils.js'; + +const vars = TestContent.generateTestVars(); + +test.beforeEach('create user', async ({ logedPage, usersPage, foldersPage, sideBar, page }) => { + setHttpResponsesListener(page); + + await foldersPage.goto(); + await foldersPage.createItem({ + name: vars.folderName, + description: vars.description + }); + + await usersPage.goto(); + await usersPage.createItem({ + email: vars.user.email + }); + + await usersPage.editItemButton(vars.user.email).click(); + await usersPage.form.fill({ + first_name: vars.user.firstName, + last_name: vars.user.lastName, + user_groups: [ + `${vars.folderName} - ${vars.usergroups.analyst}`, + `${vars.folderName} - ${vars.usergroups.auditor}`, + `${vars.folderName} - ${vars.usergroups.domainManager}`, + `${vars.folderName} - ${vars.usergroups.validator}`, + ], + }); + await usersPage.form.saveButton.click(); + await usersPage.isToastVisible('.+ successfully saved: ' + vars.user.email); + + page.on('dialog', dialog => dialog.accept()); // Accept the alert dialog + + await usersPage.editItemButton(vars.user.email).click(); + await page.getByTestId('set-password-btn').click(); + await expect(page).toHaveURL(/.*\/users\/.+\/edit\/set-password/); + await usersPage.form.fill({ + new_password: vars.user.password, + confirm_new_password: vars.user.password + }); + await usersPage.form.saveButton.click(); + await usersPage.isToastVisible('The password was successfully set'); + + await sideBar.moreButton.click(); + await expect(sideBar.morePanel).not.toHaveAttribute('inert'); + await expect(sideBar.logoutButton).toBeVisible(); + await sideBar.logoutButton.click(); + await logedPage.hasUrl(0); +}); + +test('created user can log to his account', async ({ + loginPage, + page +}) => { + await loginPage.login(vars.user.email, vars.user.password); + await expect(page).toHaveURL(/.*\/analytics/); +}); + +test.afterEach('cleanup', async ({ loginPage, sideBar, foldersPage, usersPage, page }) => { + if (loginPage.email === vars.user.email) { + await sideBar.moreButton.click(); + await expect(sideBar.morePanel).not.toHaveAttribute('inert'); + await expect(sideBar.logoutButton).toBeVisible(); + await sideBar.logoutButton.click(); + await loginPage.hasUrl(0); + await loginPage.login(); + } + await foldersPage.goto(); + await foldersPage.deleteItemButton(vars.folderName).click(); + await foldersPage.deleteModalConfirmButton.click(); + await expect(foldersPage.getRow(vars.folderName)).not.toBeVisible(); + + await usersPage.goto(); + await usersPage.deleteItemButton(vars.user.email).click(); + await usersPage.deleteModalConfirmButton.click(); + await expect(usersPage.getRow(vars.user.email)).not.toBeVisible(); +}); diff --git a/frontend/tests/utils/form-content.ts b/frontend/tests/utils/form-content.ts index 8f7d9f242..ea4d85695 100644 --- a/frontend/tests/utils/form-content.ts +++ b/frontend/tests/utils/form-content.ts @@ -27,7 +27,7 @@ export class FormContent { this.saveButton = this.page.getByTestId("save-button"); this.cancelButton = this.page.getByTestId("cancel-button"); this.name = name; - this.fields = new Map(fields.map(field => [field.name, {locator: this.page.getByTestId("form-input-" + field.name.replace('_', '-')), type: field.type}])); + this.fields = new Map(fields.map(field => [field.name, {locator: this.page.getByTestId("form-input-" + field.name.replaceAll('_', '-')), type: field.type}])); } async fill(values: { [k: string]: any }) { diff --git a/frontend/tests/utils/test-data.ts b/frontend/tests/utils/test-data.ts index d1888ea11..2726901c6 100644 --- a/frontend/tests/utils/test-data.ts +++ b/frontend/tests/utils/test-data.ts @@ -15,7 +15,7 @@ export default { file2: new URL('../utils/test_file.txt', import.meta.url).pathname, user: { email: "User@tests.com", - password: "password", + password: "pass123wordTest", firstName: "Test", lastName: "User", }, diff --git a/frontend/tests/utils/test-utils.ts b/frontend/tests/utils/test-utils.ts index 38a298b16..92564d2da 100644 --- a/frontend/tests/utils/test-utils.ts +++ b/frontend/tests/utils/test-utils.ts @@ -194,6 +194,8 @@ export const test = base.extend({ { name: 'last_name', type: type.TEXT }, { name: 'user_groups', type: type.SELECT_MULTIPLE_AUTOCOMPLETE }, { name: 'is_active', type: type.CHECKBOX }, + { name: 'new_password', type: type.TEXT }, + { name: 'confirm_new_password', type: type.TEXT }, ]); await use(uPage); },