Skip to content

Commit e874045

Browse files
committed
Add two-user RBAC test
1 parent 7187972 commit e874045

File tree

1 file changed

+76
-0
lines changed

1 file changed

+76
-0
lines changed
+76
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
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+
const repoNamePrefix = 'Repo-RBAC';
9+
10+
// Function to generate and cache the repo name
11+
const getRepoName = (() => {
12+
let name = null;
13+
return () => {
14+
if (!name) {
15+
name = `${repoNamePrefix}-${randomName()}`;
16+
}
17+
return name;
18+
};
19+
})();
20+
21+
const url = randomUrl();
22+
23+
test.describe("Run as first user", { tag: "@admin" }, async () => {
24+
test("Login as user 1", async ({ page }) => {
25+
await test.step('Navigate to the repository page', async () => {
26+
await switchToUser(page, process.env.USER1USERNAME!);
27+
await navigateToRepositories(page);
28+
await closePopupsIfExist(page);
29+
});
30+
await test.step('Delete any test repos that exist', async () => {
31+
// await deleteAllRepos(page, `&search=${repoNamePrefix}`);
32+
});
33+
await test.step('Create a repository', async () => {
34+
await page.getByRole('button', { name: 'Add repositories' }).first().click();
35+
await expect(page.getByRole('dialog', { name: 'Add custom repositories' })).toBeVisible();
36+
37+
// Use getRepoName() to get the consistent repo name
38+
await page.getByLabel('Name').fill(getRepoName());
39+
await page.getByLabel('Introspect only').click();
40+
await page.getByLabel('URL').fill(url);
41+
await page.getByRole('button', { name: 'Save', exact: true }).click();
42+
});
43+
await test.step('Read the repo', async () => {
44+
const row = await getRowByNameOrUrl(page, getRepoName());
45+
await expect(row.getByText('Valid')).toBeVisible();
46+
await row.getByLabel('Kebab toggle').click();
47+
await row.getByRole('menuitem', { name: 'Edit' }).click();
48+
await expect(page.getByRole('dialog', { name: 'Edit custom repository' })).toBeVisible();
49+
await expect(page.getByPlaceholder('Enter name', { exact: true })).toHaveValue(getRepoName());
50+
await expect(page.getByPlaceholder('https://', { exact: true })).toHaveValue(url);
51+
});
52+
await test.step('Update the repository', async () => {
53+
await page.getByPlaceholder('Enter name', { exact: true }).fill(`${getRepoName()}-Edited`);
54+
await page.getByRole('button', { name: 'Save changes', exact: true }).click();
55+
});
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.RO_USER_USERNAME!);
63+
await navigateToRepositories(page);
64+
await closePopupsIfExist(page);
65+
});
66+
await test.step('Read the repo', async () => {
67+
// Use getRepoName() to get the same repo name
68+
const row = await getRowByNameOrUrl(page, getRepoName());
69+
await expect(row.getByText('Valid')).toBeVisible({ timeout: 60000 });
70+
await row.getByLabel('Kebab toggle').click();
71+
await row.getByRole('menuitem', { name: 'Edit' }).click();
72+
await expect(page.getByText('You do not have the required permissions to perform this action')).toBeVisible();
73+
await expect(page.getByRole('dialog', { name: 'Edit custom repository' })).not.toBeVisible();
74+
});
75+
});
76+
});

0 commit comments

Comments
 (0)