|
| 1 | +export type RbacUser = { |
| 2 | + username: string; |
| 3 | + firstName: string; |
| 4 | + lastName: string; |
| 5 | + email: string; |
| 6 | + password: string; |
| 7 | + groups: string[]; |
| 8 | +}; |
| 9 | + |
| 10 | +export type RBACGroup = { |
| 11 | + name: string; |
| 12 | + keycloak?: boolean; |
| 13 | +}; |
| 14 | + |
| 15 | +/** |
| 16 | + * Users created in Keycloak for RBAC e2e tests. |
| 17 | + * Each key describes the scenario the user serves. |
| 18 | + * |
| 19 | + * - rbacAdmin: RBAC plugin admin; configured as admin in app-config. |
| 20 | + * - noAccess: No permissions; verifies RBAC sidebar hidden and direct nav blocked. |
| 21 | + * - tara: Fixture member used when constructing roles via the UI. |
| 22 | + * - jonathon: Fixture member used when editing role membership via the UI. |
| 23 | + * - currentUserOwner: Member of rhdh-qe-2-team. Tests $currentUser: can unregister own |
| 24 | + * components but not group-owned ones. |
| 25 | + * - conditionalManager: Gets conditional RBAC manage permission via rbac-ownership-role |
| 26 | + * (catalog_reader in CSV). Used in the serial IsOwner suite. |
| 27 | + * - allowAllowUser: catalog_reader. Both static allow AND conditional IS_ENTITY_OWNER |
| 28 | + * allow read — tests policyDecisionPrecedence allow+allow case. |
| 29 | + * - conditionalAllowUser: Has static deny (all_resource_denier) but conditional policy allows |
| 30 | + * read — tests conditional overrides deny. |
| 31 | + * - conditionalDenyUser: Has static allow but conditional deny wins — sees empty catalog. |
| 32 | + * - conditionalDenier: all_resource_reader + conditional_denier roles — conditional deny |
| 33 | + * overrides static allow. |
| 34 | + */ |
| 35 | +export const RBAC_DESCRIPTIVE_USERS: Record<string, RbacUser> = { |
| 36 | + rbacAdmin: { |
| 37 | + username: "rbac-admin", |
| 38 | + firstName: "RBAC", |
| 39 | + lastName: "Admin", |
| 40 | + email: "rbac-admin@example.com", |
| 41 | + password: |
| 42 | + process.env.RBAC_ADMIN_PASSWORD ?? |
| 43 | + crypto.randomUUID().substring(0, 21).replaceAll("-", "0"), |
| 44 | + groups: [], |
| 45 | + }, |
| 46 | + noAccess: { |
| 47 | + username: "no-access", |
| 48 | + firstName: "No", |
| 49 | + lastName: "Access", |
| 50 | + email: "no-access@example.com", |
| 51 | + password: crypto.randomUUID().substring(0, 21).replaceAll("-", "0"), |
| 52 | + groups: [], |
| 53 | + }, |
| 54 | + tara: { |
| 55 | + username: "tara", |
| 56 | + firstName: "Tara", |
| 57 | + lastName: "MacGovern", |
| 58 | + email: "tara@example.com", |
| 59 | + password: crypto.randomUUID().substring(0, 21).replaceAll("-", "0"), |
| 60 | + groups: [], |
| 61 | + }, |
| 62 | + jonathon: { |
| 63 | + username: "jonathon", |
| 64 | + firstName: "Jonathon", |
| 65 | + lastName: "Page", |
| 66 | + email: "jonathon@example.com", |
| 67 | + password: crypto.randomUUID().substring(0, 21).replaceAll("-", "0"), |
| 68 | + groups: [], |
| 69 | + }, |
| 70 | + currentUserOwner: { |
| 71 | + username: "current-user-owner", |
| 72 | + firstName: "Current", |
| 73 | + lastName: "User-Owner", |
| 74 | + email: "current-user-owner@example.com", |
| 75 | + password: crypto.randomUUID().substring(0, 21).replaceAll("-", "0"), |
| 76 | + groups: ["rhdh-qe-2-team"], |
| 77 | + }, |
| 78 | + conditionalManager: { |
| 79 | + username: "conditional-manager", |
| 80 | + firstName: "Conditional", |
| 81 | + lastName: "Manager", |
| 82 | + email: "conditional-manager@example.com", |
| 83 | + password: crypto.randomUUID().substring(0, 21).replaceAll("-", "0"), |
| 84 | + groups: [], |
| 85 | + }, |
| 86 | + allowAllowUser: { |
| 87 | + username: "allow-allow-user", |
| 88 | + firstName: "Allow", |
| 89 | + lastName: "Allow-User", |
| 90 | + email: "allow-allow-user@example.com", |
| 91 | + password: crypto.randomUUID().substring(0, 21).replaceAll("-", "0"), |
| 92 | + groups: [], |
| 93 | + }, |
| 94 | + conditionalAllowUser: { |
| 95 | + username: "conditional-allow-user", |
| 96 | + firstName: "Conditional", |
| 97 | + lastName: "Allow-User", |
| 98 | + email: "conditional-allow-user@example.com", |
| 99 | + password: crypto.randomUUID().substring(0, 21).replaceAll("-", "0"), |
| 100 | + groups: [], |
| 101 | + }, |
| 102 | + conditionalDenyUser: { |
| 103 | + username: "conditional-deny-user", |
| 104 | + firstName: "Conditional", |
| 105 | + lastName: "Deny-User", |
| 106 | + email: "conditional-deny-user@example.com", |
| 107 | + password: crypto.randomUUID().substring(0, 21).replaceAll("-", "0"), |
| 108 | + groups: [], |
| 109 | + }, |
| 110 | + conditionalDenier: { |
| 111 | + username: "conditional-denier", |
| 112 | + firstName: "Conditional", |
| 113 | + lastName: "Denier", |
| 114 | + email: "conditional-denier@example.com", |
| 115 | + password: crypto.randomUUID().substring(0, 21).replaceAll("-", "0"), |
| 116 | + groups: [], |
| 117 | + }, |
| 118 | + childGroupMember: { |
| 119 | + username: "child-group-member", |
| 120 | + firstName: "Child", |
| 121 | + lastName: "Group-Member", |
| 122 | + email: "child-group-member@example.com", |
| 123 | + password: crypto.randomUUID().substring(0, 21).replaceAll("-", "0"), |
| 124 | + groups: [], |
| 125 | + }, |
| 126 | + subChildGroupMember: { |
| 127 | + username: "sub-child-group-member", |
| 128 | + firstName: "Sub-Child", |
| 129 | + lastName: "Group-Member", |
| 130 | + email: "sub-child-group-member@example.com", |
| 131 | + password: crypto.randomUUID().substring(0, 21).replaceAll("-", "0"), |
| 132 | + groups: [], |
| 133 | + }, |
| 134 | +}; |
| 135 | + |
| 136 | +/** |
| 137 | + * Groups created in Keycloak for RBAC e2e tests. |
| 138 | + * The transitive parent/child/sub-child groups are not created via Keycloak |
| 139 | + * (configureForRHDH does not support sub-group membership); they are managed |
| 140 | + * separately in the catalog config. |
| 141 | + */ |
| 142 | +export const RBAC_GROUPS: Record<string, RBACGroup> = { |
| 143 | + backstage: { name: "backstage", keycloak: true }, |
| 144 | + currentUserOwnerTeam: { name: "rhdh-qe-2-team", keycloak: true }, |
| 145 | + rhdhParentTeam: { name: "rhdh-qe-parent-team" }, |
| 146 | + rhdhChildTeam: { name: "rhdh-qe-child-team" }, |
| 147 | + rhdhSubChildTeam: { name: "rhdh-qe-sub-child-team" }, |
| 148 | +}; |
| 149 | + |
| 150 | +/** |
| 151 | + * Returns the UI display name for a user in RBAC_DESCRIPTIVE_USERS. |
| 152 | + * Used when selecting members from the role creation/edit form dropdowns. |
| 153 | + */ |
| 154 | +export const displayName = (key: keyof typeof RBAC_DESCRIPTIVE_USERS): string => |
| 155 | + `${RBAC_DESCRIPTIVE_USERS[key].firstName} ${RBAC_DESCRIPTIVE_USERS[key].lastName}`; |
| 156 | + |
| 157 | +export const userEntityRef = (user: RbacUser): string => |
| 158 | + `user:default/${user.username}`; |
0 commit comments