Skip to content

Commit

Permalink
feat(rbac): edit nested conditions
Browse files Browse the repository at this point in the history
Signed-off-by: Yi Cai <[email protected]>
  • Loading branch information
ciiay committed Jul 8, 2024
1 parent 622090e commit e8167ed
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -676,7 +676,7 @@ export const ConditionsFormRow = ({
)
}
>
<RemoveIcon />
<RemoveIcon data-testid="remove-nested-condition" />
</IconButton>
)}
</div>
Expand Down
87 changes: 87 additions & 0 deletions plugins/rbac/tests/rbac.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -321,4 +321,91 @@ test.describe('RBAC plugin', () => {

await page.locator(`a`).filter({ hasText: 'RBAC' }).click();
});

test('Edit existing nested conditional policy', async () => {
await expect(
page.getByRole('heading', { name: 'All roles (2)' }),
).toBeVisible({ timeout: 20000 });

// edit/update policies
await page
.locator(`a`)
.filter({ hasText: 'role:default/rbac_admin' })
.click();
await expect(
page.getByRole('heading', { name: 'role:default/rbac_admin' }),
).toBeVisible({
timeout: 20000,
});
await page.getByRole('tab', { name: 'Overview' }).click();

await page.locator(RoleOverviewPO.updatePolicies).click();
await expect(page.getByRole('heading', { name: 'Edit Role' })).toBeVisible({
timeout: 20000,
});

// update nested conditions
await page.getByText('Configure access (3 rules)', { exact: true }).click();
await expect(page.getByText('AllOf')).toHaveCount(2, { timeout: 20000 });
await page.getByText('Add nested condition').click();
await page.getByText('Not', { exact: true }).last().click();
await page.getByPlaceholder('Select a rule').last().click();
await page.getByText('HAS_LABEL').last().click();
await page.getByLabel('label').last().fill('test');
await page.getByTestId('save-conditions').click();

expect(
page.getByText('Configure access (4 rules)', { exact: true }),
).toBeVisible();

await common.clickButton('Next');
expect(page.getByText('4 rules', { exact: true })).toBeVisible();
await common.clickButton('Save');
await verifyText('Role role:default/rbac_admin updated successfully', page);

await page.locator(`a`).filter({ hasText: 'RBAC' }).click();
});

test('Remove existing nested conditional policy', async () => {
await expect(
page.getByRole('heading', { name: 'All roles (2)' }),
).toBeVisible({ timeout: 20000 });

// edit/update policies
await page
.locator(`a`)
.filter({ hasText: 'role:default/rbac_admin' })
.click();
await expect(
page.getByRole('heading', { name: 'role:default/rbac_admin' }),
).toBeVisible({
timeout: 20000,
});
await page.getByRole('tab', { name: 'Overview' }).click();

await page.locator(RoleOverviewPO.updatePolicies).click();
await expect(page.getByRole('heading', { name: 'Edit Role' })).toBeVisible({
timeout: 20000,
});
expect(
page.getByText('Configure access (2 rules)', { exact: true }),
).toHaveCount(1);

// update nested conditions
await page.getByText('Configure access (3 rules)', { exact: true }).click();
await expect(page.getByText('AllOf')).toHaveCount(2, { timeout: 20000 });
await page.getByTestId('remove-nested-condition').click();
await page.getByTestId('save-conditions').click();

expect(
page.getByText('Configure access (2 rules)', { exact: true }),
).toHaveCount(2);

await common.clickButton('Next');
expect(page.getByText('2 rules', { exact: true })).toHaveCount(2);
await common.clickButton('Save');
await verifyText('Role role:default/rbac_admin updated successfully', page);

await page.locator(`a`).filter({ hasText: 'RBAC' }).click();
});
});

0 comments on commit e8167ed

Please sign in to comment.