|
| 1 | +/** |
| 2 | + * Regression test for UX-1217 / UX-1219 — adding a rule on edit must not wipe existing ACLs. |
| 3 | + * |
| 4 | + * Pre-fix bug: `create-acl.tsx` used `useRef(2)` for the new-rule id counter. On edit-load, |
| 5 | + * `processResourceAcls` assigns rule ids 0, 1, 2, ... When the user clicked "Add rule", |
| 6 | + * the new rule got id=2 and collided with an already-loaded rule's React key, causing |
| 7 | + * list-reconciliation state bleed that dropped ACLs on save. |
| 8 | + * |
| 9 | + * Reproducing the collision requires at least 3 distinct rule groups on edit-load |
| 10 | + * (so that id=2 is already taken). The form groups ACLs by (resourceType, pattern, name), |
| 11 | + * so three separate rule groups = three different (resourceType/name) combinations. |
| 12 | + */ |
| 13 | +import { test } from '@playwright/test'; |
| 14 | + |
| 15 | +import { |
| 16 | + ModeCustom, |
| 17 | + OperationTypeAllow, |
| 18 | + ResourcePatternTypeLiteral, |
| 19 | + ResourceTypeCluster, |
| 20 | + ResourceTypeConsumerGroup, |
| 21 | + ResourceTypeTopic, |
| 22 | + ResourceTypeTransactionalId, |
| 23 | + type Rule, |
| 24 | +} from '../../../src/components/pages/security/shared/acl-model'; |
| 25 | +import { AclPage } from '../utils/acl-page'; |
| 26 | + |
| 27 | +const initialRules: Rule[] = [ |
| 28 | + { |
| 29 | + id: 0, |
| 30 | + resourceType: ResourceTypeCluster, |
| 31 | + mode: ModeCustom, |
| 32 | + selectorType: ResourcePatternTypeLiteral, |
| 33 | + selectorValue: 'kafka-cluster', |
| 34 | + operations: { |
| 35 | + DESCRIBE: OperationTypeAllow, |
| 36 | + }, |
| 37 | + }, |
| 38 | + { |
| 39 | + id: 1, |
| 40 | + resourceType: ResourceTypeTopic, |
| 41 | + mode: ModeCustom, |
| 42 | + selectorType: ResourcePatternTypeLiteral, |
| 43 | + selectorValue: 'topic-acl2', |
| 44 | + operations: { |
| 45 | + DESCRIBE: OperationTypeAllow, |
| 46 | + READ: OperationTypeAllow, |
| 47 | + WRITE: OperationTypeAllow, |
| 48 | + }, |
| 49 | + }, |
| 50 | + { |
| 51 | + id: 2, |
| 52 | + resourceType: ResourceTypeConsumerGroup, |
| 53 | + mode: ModeCustom, |
| 54 | + selectorType: ResourcePatternTypeLiteral, |
| 55 | + selectorValue: 'cg-a', |
| 56 | + operations: { |
| 57 | + READ: OperationTypeAllow, |
| 58 | + }, |
| 59 | + }, |
| 60 | +]; |
| 61 | + |
| 62 | +const addedRule: Rule = { |
| 63 | + id: 3, |
| 64 | + resourceType: ResourceTypeTransactionalId, |
| 65 | + mode: ModeCustom, |
| 66 | + selectorType: ResourcePatternTypeLiteral, |
| 67 | + selectorValue: 'tx-1', |
| 68 | + operations: { |
| 69 | + DESCRIBE: OperationTypeAllow, |
| 70 | + }, |
| 71 | +}; |
| 72 | + |
| 73 | +test.describe('ACL edit preserves existing rules (UX-1217)', () => { |
| 74 | + test('adding a rule on edit does not wipe existing ACLs', async ({ page }) => { |
| 75 | + test.setTimeout(180_000); |
| 76 | + |
| 77 | + const principal = `edit-preserve-${Date.now()}`; |
| 78 | + const host = '*'; |
| 79 | + const aclPage = new AclPage(page); |
| 80 | + |
| 81 | + await test.step('Create initial ACL with 3 distinct rule groups', async () => { |
| 82 | + await aclPage.goto(); |
| 83 | + await aclPage.setPrincipal(principal); |
| 84 | + await aclPage.setHost(host); |
| 85 | + await aclPage.configureRules(initialRules); |
| 86 | + await aclPage.submitForm(); |
| 87 | + await aclPage.waitForDetailPage(); |
| 88 | + await aclPage.validateRulesCount(initialRules.length); |
| 89 | + }); |
| 90 | + |
| 91 | + await test.step('Navigate to edit page', async () => { |
| 92 | + await aclPage.clickUpdateButtonFromDetailPage(); |
| 93 | + await aclPage.waitForUpdatePage(); |
| 94 | + }); |
| 95 | + |
| 96 | + await test.step('Add a new rule — pre-fix this collides with the loaded id=2 rule', async () => { |
| 97 | + await aclPage.updateRules([addedRule]); |
| 98 | + await aclPage.submitForm(); |
| 99 | + await aclPage.waitForDetailPage(); |
| 100 | + }); |
| 101 | + |
| 102 | + await test.step('Verify every original rule plus the added rule is preserved', async () => { |
| 103 | + const finalRules = [...initialRules, addedRule]; |
| 104 | + await aclPage.validateRulesCount(finalRules.length); |
| 105 | + await aclPage.validateAllDetailRules(finalRules, principal, host); |
| 106 | + }); |
| 107 | + }); |
| 108 | +}); |
0 commit comments