Skip to content

Commit 3badb40

Browse files
committed
Add two-user RBAC test
1 parent 7b6e66f commit 3badb40

File tree

1 file changed

+79
-0
lines changed

1 file changed

+79
-0
lines changed
+79
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
import { expect, test } from "@playwright/test";
2+
import { navigateToRepositories } from "../UI/helpers/navHelpers";
3+
import { switchToUser, logInWithUsernameAndPassword } from "../helpers/loginHelpers";
4+
import { randomName, randomUrl } from '../UI/helpers/repoHelpers';
5+
import { closePopupsIfExist, getRowByNameOrUrl } from '../UI/helpers/helpers';
6+
import { deleteAllRepos } from '../UI/helpers/deleteRepositories';
7+
8+
9+
10+
11+
const repoNamePrefix = 'Repo-RBAC';
12+
const repoName = `${repoNamePrefix}-${randomName()}`;
13+
14+
const url = randomUrl();
15+
16+
17+
18+
test.describe("Run as first user", { tag: "@admin" }, async () => {
19+
test("Login as user 1", async ({ page }) => {
20+
await test.step('Navigate to the repository page', async () => {
21+
await switchToUser(page, process.env.USER1USERNAME!);
22+
await logInWithUsernameAndPassword(page, process.env.USER1USERNAME!, process.env.USER1PASSWORD!);
23+
await navigateToRepositories(page);
24+
await closePopupsIfExist(page);
25+
});
26+
await test.step('Delete any test repos that exist', async () => {
27+
await deleteAllRepos(page, `&search=${repoNamePrefix}`);
28+
});
29+
await test.step('Create a repository', async () => {
30+
// Click on the 'Add repositories' button
31+
// HMS-5268 There are two buttons on the ZeroState page
32+
await page.getByRole('button', { name: 'Add repositories' }).first().click();
33+
await expect(page.getByRole('dialog', { name: 'Add custom repositories' })).toBeVisible();
34+
35+
// Fill in the repository details
36+
await page.getByLabel('Name').fill(`${repoName}`);
37+
await page.getByLabel('Introspect only').click();
38+
await page.getByLabel('URL').fill(url);
39+
await page.getByRole('button', { name: 'Save', exact: true }).click();
40+
});
41+
await test.step('Read the repo', async () => {
42+
// Search for the created repo
43+
const row = await getRowByNameOrUrl(page, repoName);
44+
await expect(row.getByText('Valid')).toBeVisible();
45+
await row.getByLabel('Kebab toggle').click();
46+
// Click on the Edit button to see the repo
47+
await row.getByRole('menuitem', { name: 'Edit' }).click();
48+
await expect(page.getByRole('dialog', { name: 'Edit custom repository' })).toBeVisible();
49+
// Assert we can read some values
50+
await expect(page.getByPlaceholder('Enter name', { exact: true })).toHaveValue(`${repoName}`);
51+
await expect(page.getByPlaceholder('https://', { exact: true })).toHaveValue(`${url}`);
52+
});
53+
await test.step('Update the repository', async () => {
54+
await page.getByPlaceholder('Enter name', { exact: true }).fill(`${repoName}-Edited`);
55+
await page.getByRole('button', { name: 'Save changes', exact: true }).click();
56+
});
57+
});
58+
});
59+
test.describe("Run as second user", { tag: "@read-only" }, async () => {
60+
test("Login as user 2", async ({ page }) => {
61+
await test.step('Navigate to the repository page', async () => {
62+
await switchToUser(page, process.env.STAGE_RO_USER_USERNAME!);
63+
await logInWithUsernameAndPassword(page, process.env.STAGE_RO_USER_USERNAME!, process.env.STAGE_RO_USER_PASSWORD!)
64+
await navigateToRepositories(page);
65+
await closePopupsIfExist(page);
66+
});
67+
await test.step('Read the repo', async () => {
68+
// Search for the created repo
69+
const row = await getRowByNameOrUrl(page, repoName);
70+
await expect(row.getByText('Valid')).toBeVisible({ timeout: 60000 });
71+
await row.getByLabel('Kebab toggle').click();
72+
// Assert we cannot click on the Edit button to see the repo
73+
// You do not have the required permissions to perform this action.
74+
await row.getByRole('menuitem', { name: 'Edit' }).click();
75+
await expect(page.getByText('You do not have the required permissions to perform this action')).toBeVisible();
76+
await expect(page.getByRole('dialog', { name: 'Edit custom repository' })).not.toBeVisible();
77+
});
78+
});
79+
});

0 commit comments

Comments
 (0)