Skip to content

Commit 8623248

Browse files
authored
chore(e2e): update RBAC plugin version, add E2E tests to Showcase/RHDH (#2374)
* [WIP] Update RBAC plugin version, add E2E tests to Showcase/RHDH * updating RBAC e2e * updating RBAC e2e * updating RBAC e2e * updating RBAC e2e * updating RBAC e2e" * updating RBAC e2e * updating RBAC e2e * updating RBAC e2e * updating RBAC e2e * updating RBAC e2e * updating RBAC e2e * updating RBAC e2e * updating RBAC e2e and plugin version * updating RBAC e2e * updating RBAC e2e * updating RBAC e2e * updating RBAC e2e * updating RBAC e2e * updating RBAC e2e * updating RBAC e2e * updating RBAC e2e * updating RBAC e2e * updating RBAC e2e * updating RBAC e2e * Cleanup * updating plugin version * Requested changes * Requested changes
1 parent 836cc5e commit 8623248

File tree

4 files changed

+139
-49
lines changed

4 files changed

+139
-49
lines changed

dynamic-plugins/wrappers/backstage-community-plugin-rbac/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "backstage-community-plugin-rbac",
3-
"version": "1.35.0",
3+
"version": "1.38.1",
44
"main": "src/index.ts",
55
"types": "src/index.ts",
66
"license": "Apache-2.0",
@@ -28,7 +28,7 @@
2828
"export-dynamic:clean": "run export-dynamic --clean"
2929
},
3030
"dependencies": {
31-
"@backstage-community/plugin-rbac": "1.35.0",
31+
"@backstage-community/plugin-rbac": "1.38.1",
3232
"@mui/material": "5.16.14"
3333
},
3434
"devDependencies": {

e2e-tests/playwright/e2e/plugins/rbac/rbac.spec.ts

+52-27
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,18 @@ test.describe.serial("Test RBAC", () => {
6868
Roles.getPermissionPoliciesListCellsIdentifier();
6969
await uiHelper.verifyCellsInTable(permissionPoliciesCellsIdentifier);
7070

71-
await expect(page.getByRole("article")).toContainText("catalog-entity");
72-
await expect(page.getByRole("article")).toContainText("Read, Update");
73-
await expect(page.getByRole("article")).toContainText("Delete");
71+
await uiHelper.verifyRowInTableByUniqueText("rhdh-qe-2-team", [
72+
"Group",
73+
"1",
74+
]);
75+
await uiHelper.verifyRowInTableByUniqueText("catalog.entity.read", [
76+
"Read",
77+
"1 rule",
78+
]);
79+
await uiHelper.verifyRowInTableByUniqueText("catalog.entity.delete", [
80+
"Delete",
81+
"1 rule",
82+
]);
7483
});
7584
});
7685

@@ -211,6 +220,32 @@ test.describe.serial("Test RBAC", () => {
211220
const rolesHelper = new Roles(page);
212221
const uiHelper = new UIhelper(page);
213222

223+
await uiHelper.clickButton("Create");
224+
await uiHelper.verifyHeading("Create role");
225+
await uiHelper.fillTextInputByLabel("name", "sample-role-1");
226+
await uiHelper.fillTextInputByLabel(
227+
"description",
228+
"Test Description data",
229+
);
230+
231+
await uiHelper.clickButton("Next");
232+
await uiHelper.fillTextInputByLabel(
233+
"Select users and groups",
234+
"sample-role-1",
235+
);
236+
await page
237+
.getByTestId("users-and-groups-text-field")
238+
.getByLabel("clear search")
239+
.click();
240+
await expect(
241+
page.getByTestId("users-and-groups-text-field").locator("input"),
242+
).toBeEmpty();
243+
await uiHelper.verifyHeading("No users and groups selected");
244+
await uiHelper.clickButton("Cancel");
245+
await uiHelper.verifyText("Exit role creation?");
246+
await uiHelper.clickButton("Discard");
247+
await expect(page.getByRole("alert")).toHaveCount(0);
248+
214249
const rbacPo = new RbacPo(page);
215250
const testUser = "Jonathon Page";
216251
await rbacPo.createRole("test-role", [
@@ -270,15 +305,13 @@ test.describe.serial("Test RBAC", () => {
270305

271306
await page.click(ROLE_OVERVIEW_COMPONENTS.updateMembers);
272307
await uiHelper.verifyHeading("Edit Role");
273-
await page
274-
.locator(SEARCH_OBJECTS_COMPONENTS.ariaLabelSearch)
275-
.fill("Guest User");
276-
await page.click('button[aria-label="Remove"]');
308+
await uiHelper.fillTextInputByLabel(
309+
"Select users and groups",
310+
"Guest User",
311+
);
312+
await page.click(rbacPo.selectMember("Guest User"));
277313
await uiHelper.verifyHeading(rbacPo.regexpShortUsersAndGroups(1, 1));
278314
await uiHelper.clickByDataTestId("nextButton-1");
279-
await page.waitForSelector(".permission-policies-form", {
280-
state: "visible",
281-
});
282315
let nextButton2: Locator;
283316
let matchNextButton2: Locator[];
284317
let attempts = 0;
@@ -288,9 +321,7 @@ test.describe.serial("Test RBAC", () => {
288321
matchNextButton2 = await nextButton2.all();
289322
attempts++;
290323
} while (matchNextButton2.length > 1 && attempts < 5);
291-
await nextButton2.click({
292-
force: true,
293-
});
324+
await nextButton2.click({ force: true });
294325
await uiHelper.clickButton("Save");
295326
await uiHelper.verifyText(
296327
"Role role:default/test-role1 updated successfully",
@@ -299,19 +330,16 @@ test.describe.serial("Test RBAC", () => {
299330

300331
await page.click(ROLE_OVERVIEW_COMPONENTS.updatePolicies);
301332
await uiHelper.verifyHeading("Edit Role");
302-
await rbacPo.clickAddPermissionPolicy();
303-
await page.click(rbacPo.selectPermissionPolicyPlugin(1), {
304-
timeout: 10_000,
305-
});
333+
await rbacPo.selectPluginsCombobox.click();
306334
await rbacPo.selectOption("scaffolder");
307-
await page.click(rbacPo.selectPermissionPolicyPermission(1));
308-
await rbacPo.selectOption("scaffolder-template");
335+
await page.getByText("Select...").click();
336+
await rbacPo.selectPermissionCheckbox("scaffolder.template.parameter");
309337
await uiHelper.clickButton("Next");
310338
await uiHelper.clickButton("Save");
311339
await uiHelper.verifyText(
312340
"Role role:default/test-role1 updated successfully",
313341
);
314-
await uiHelper.verifyHeading("Permission Policies (3)");
342+
await uiHelper.verifyHeading("Permission Policies (2)");
315343

316344
await rolesHelper.deleteRole("role:default/test-role1");
317345
});
@@ -322,7 +350,7 @@ test.describe.serial("Test RBAC", () => {
322350
const rolesHelper = new Roles(page);
323351
const uiHelper = new UIhelper(page);
324352
await new RbacPo(page).createRole(
325-
"test-role",
353+
"test-role1",
326354
["Guest User", "rhdh-qe", "Backstage"],
327355
"anyOf",
328356
);
@@ -332,9 +360,9 @@ test.describe.serial("Test RBAC", () => {
332360
.waitFor({ state: "visible" });
333361
await page
334362
.locator(SEARCH_OBJECTS_COMPONENTS.ariaLabelSearch)
335-
.fill("test-role");
363+
.fill("test-role1");
336364
await uiHelper.verifyHeading("All roles (1)");
337-
await rolesHelper.deleteRole("role:default/test-role");
365+
await rolesHelper.deleteRole("role:default/test-role1");
338366
});
339367
});
340368

@@ -423,10 +451,7 @@ test.describe.serial("Test RBAC", () => {
423451
name: "role:default/admin",
424452
};
425453

426-
const newRole = {
427-
memberReferences: members,
428-
name: "role:default/test",
429-
};
454+
const newRole = { memberReferences: members, name: "role:default/test" };
430455

431456
const rolePostResponse = await rbacApi.createRoles(firstRole);
432457

e2e-tests/playwright/support/pageObjects/rbac-po.ts

+54-14
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,19 @@ export class RbacPo extends PageObject {
1616
private notButton: Locator;
1717
private rulesSideBar: Locator;
1818
private hasSpecButton: Locator;
19+
private hasAnnotationButton: Locator;
1920
private key: Locator;
21+
private annotation: Locator;
2022
private saveConditions: Locator;
2123
private anyOfButton: Locator;
2224
private isEntityKindButton: Locator;
2325
private addRuleButton: Locator = this.page.getByRole("button", {
2426
name: "Add rule",
2527
});
28+
private addNestedConditionButton: Locator = this.page.getByRole("button", {
29+
name: "Add Nested Condition",
30+
});
31+
2632
private hasLabel: Locator;
2733
private label: Locator;
2834

@@ -32,6 +38,9 @@ export class RbacPo extends PageObject {
3238
backstage: "Backstage",
3339
rhdhqe: "rhdh-qe",
3440
};
41+
public selectPluginsCombobox: Locator = this.page.getByRole("combobox", {
42+
name: "Select plugins",
43+
});
3544

3645
private stringForRegexUsersAndGroups = (
3746
numUsers: number,
@@ -96,7 +105,9 @@ export class RbacPo extends PageObject {
96105
this.notButton = this.page.getByRole("button", { name: "Not" });
97106
this.rulesSideBar = this.page.getByTestId("rules-sidebar");
98107
this.hasSpecButton = this.page.getByText("HAS_SPEC");
108+
this.hasAnnotationButton = this.page.getByText("HAS_ANNOTATION");
99109
this.key = this.page.getByLabel("key *");
110+
this.annotation = this.page.getByLabel("annotation *");
100111
this.saveConditions = this.page.getByTestId("save-conditions");
101112
this.anyOfButton = this.page.getByRole("button", { name: "AnyOf" });
102113
this.isEntityKindButton = this.page.getByText("IS_ENTITY_KIND");
@@ -156,7 +167,11 @@ export class RbacPo extends PageObject {
156167
}
157168

158169
public async selectOption(
159-
option: "catalog" | "catalog-entity" | "scaffolder" | "scaffolder-template",
170+
option:
171+
| "catalog"
172+
| "catalog.entity.read"
173+
| "scaffolder"
174+
| "scaffolder-template.read",
160175
) {
161176
const optionSelector = `li[role="option"]:has-text("${option}")`;
162177
await this.page.waitForSelector(optionSelector);
@@ -177,6 +192,18 @@ export class RbacPo extends PageObject {
177192
await this.usersAndGroupsField.fill(userOrRole);
178193
}
179194

195+
async selectPermissionCheckbox(name: string) {
196+
this.page.getByRole("cell", { name: name }).getByRole("checkbox").click();
197+
}
198+
199+
async pluginRuleCount(number: string) {
200+
expect(
201+
this.page
202+
.locator('span[class*="MuiBadge-badge"]')
203+
.filter({ hasText: number }),
204+
).toBeVisible();
205+
}
206+
180207
async createRole(
181208
name: string,
182209
usersAndGroups: string[],
@@ -187,9 +214,9 @@ export class RbacPo extends PageObject {
187214
await this.uiHelper.verifyHeading("Create role");
188215
await this.roleName.fill(name);
189216
await this.uiHelper.clickButton("Next");
217+
await this.usersAndGroupsField.click();
190218

191219
for (const userOrRole of usersAndGroups) {
192-
await this.addUsersAndGroups(userOrRole);
193220
await this.page.click(this.selectMember(userOrRole));
194221
}
195222

@@ -204,19 +231,18 @@ export class RbacPo extends PageObject {
204231
);
205232

206233
await this.next();
207-
await this.page.click(this.selectPermissionPolicyPlugin(0));
234+
await this.selectPluginsCombobox.click();
208235
await this.selectOption("catalog");
209-
await this.page.click(this.selectPermissionPolicyPermission(0));
210-
await this.selectOption("catalog-entity");
236+
await this.page.getByText("Select...").click();
211237

212238
if (permissionPolicyType === "none") {
213-
await this.page.uncheck(this.selectPolicy(0, 1, "Delete"));
239+
await this.selectPermissionCheckbox("catalog.entity.delete");
214240
await this.next();
215241
await this.uiHelper.verifyHeading("Review and create");
216242
await this.uiHelper.verifyText(
217243
this.regexpLongUsersAndGroups(numUsers - numGroups, numGroups),
218244
);
219-
await this.verifyPermissionPoliciesHeader(2);
245+
await this.verifyPermissionPoliciesHeader(1);
220246
await this.create();
221247
await this.page
222248
.locator(SEARCH_OBJECTS_COMPONENTS.ariaLabelSearch)
@@ -227,7 +253,11 @@ export class RbacPo extends PageObject {
227253
await this.uiHelper.verifyHeading("All roles (1)");
228254
} else if (permissionPolicyType === "anyOf") {
229255
// Scenario 2: Permission policies using AnyOf
230-
await this.configureAccess.click();
256+
await this.selectPermissionCheckbox("catalog.entity.read");
257+
await this.page
258+
.getByRole("row", { name: "catalog.entity.read" })
259+
.getByLabel("remove")
260+
.click();
231261
await this.anyOfButton.click();
232262
await this.clickOpenSidebar();
233263
await this.isEntityKindButton.click();
@@ -236,33 +266,43 @@ export class RbacPo extends PageObject {
236266
.getByPlaceholder("string, string")
237267
.fill("component,template");
238268
await this.addRuleButton.click();
239-
await this.page.getByLabel("Open").nth(3).click();
269+
await this.page.getByLabel("Open").nth(2).click();
240270
await this.hasSpecButton.click();
241271
await this.key.click();
242272
await this.key.fill("lifecycle");
243273
await this.key.press("Tab");
244274
await this.key.fill("experimental");
245275
await this.addRuleButton.click();
246-
await this.page.getByLabel("Open").nth(4).click();
276+
await this.page.getByLabel("Open").nth(3).click();
247277
await this.hasLabel.click();
248278
await this.label.click();
249279
await this.label.fill("partner");
280+
// Add nested condition
281+
await this.addNestedConditionButton.click();
282+
await this.page.getByLabel("Open").nth(4).click();
283+
await this.hasAnnotationButton.click();
284+
await this.annotation.click();
285+
await this.annotation.fill("test");
250286
await this.saveConditions.click();
251-
await this.uiHelper.verifyText("Configure access (3 rules)");
287+
await this.pluginRuleCount("4");
252288
await this.next();
253289
await this.uiHelper.verifyHeading("Review and create");
254290
await this.uiHelper.verifyText(
255291
this.regexpLongUsersAndGroups(numUsers - numGroups, numGroups),
256292
);
257293
await this.verifyPermissionPoliciesHeader(1);
258-
await this.uiHelper.verifyText("3 rules");
294+
await this.uiHelper.verifyText("4 rules");
259295
await this.uiHelper.clickButton("Create");
260296
await this.uiHelper.verifyText(
261297
`Role role:default/${name} created successfully`,
262298
);
263299
} else if (permissionPolicyType === "not") {
264300
// Scenario 3: Permission policies using Not
265-
await this.configureAccess.click();
301+
await this.selectPermissionCheckbox("catalog.entity.read");
302+
await this.page
303+
.getByRole("row", { name: "catalog.entity.read" })
304+
.getByLabel("remove")
305+
.click();
266306
await this.notButton.click();
267307
await this.clickOpenSidebar();
268308
await this.hasSpecButton.click();
@@ -271,7 +311,7 @@ export class RbacPo extends PageObject {
271311
await this.key.press("Tab");
272312
await this.key.fill("experimental");
273313
await this.saveConditions.click();
274-
await this.uiHelper.verifyText("Configure access (1 rule)");
314+
await this.pluginRuleCount("1");
275315
await this.next();
276316
await this.uiHelper.verifyHeading("Review and create");
277317
await this.verifyPermissionPoliciesHeader(1);

0 commit comments

Comments
 (0)