|
| 1 | +import weaviate, { ApiKey, GroupAssignment } from '..'; |
| 2 | +import { requireAtLeast } from '../../test/version.js'; |
| 3 | + |
| 4 | +requireAtLeast(1, 32, 5).describe('Integration testing of the OIDC groups', () => { |
| 5 | + const makeClient = (key: string = 'admin-key') => |
| 6 | + weaviate.connectToLocal({ |
| 7 | + port: 8091, |
| 8 | + grpcPort: 50062, |
| 9 | + authCredentials: new ApiKey(key), |
| 10 | + }); |
| 11 | + |
| 12 | + it('should assign / get / revoke group roles', async () => { |
| 13 | + const client = await makeClient(); |
| 14 | + const groupID = './assign-group'; |
| 15 | + const roles = ['viewer', 'admin']; |
| 16 | + |
| 17 | + await client.groups.oidc.revokeRoles(groupID, roles); |
| 18 | + await expect(client.groups.oidc.getAssignedRoles(groupID)).resolves.toEqual({}); |
| 19 | + |
| 20 | + await client.groups.oidc.assignRoles(groupID, roles); |
| 21 | + const assignedRoles = await client.groups.oidc.getAssignedRoles(groupID, true); |
| 22 | + expect(Object.keys(assignedRoles)).toEqual(expect.arrayContaining(roles)); |
| 23 | + |
| 24 | + await client.groups.oidc.revokeRoles(groupID, roles); |
| 25 | + await expect(client.groups.oidc.getAssignedRoles(groupID)).resolves.toEqual({}); |
| 26 | + }); |
| 27 | + |
| 28 | + it('should get all known role groups', async () => { |
| 29 | + const client = await makeClient(); |
| 30 | + const group1 = './group-1'; |
| 31 | + const group2 = './group-2'; |
| 32 | + |
| 33 | + await client.groups.oidc.assignRoles(group1, 'viewer'); |
| 34 | + await client.groups.oidc.assignRoles(group2, 'viewer'); |
| 35 | + |
| 36 | + await expect(client.groups.oidc.getKnownGroupNames()).resolves.toEqual( |
| 37 | + expect.arrayContaining([group1, group2]) |
| 38 | + ); |
| 39 | + |
| 40 | + await client.groups.oidc.revokeRoles(group1, 'viewer'); |
| 41 | + await client.groups.oidc.revokeRoles(group2, 'viewer'); |
| 42 | + |
| 43 | + await expect(client.groups.oidc.getKnownGroupNames()).resolves.toHaveLength(0); |
| 44 | + }); |
| 45 | + |
| 46 | + it('should get group assignments', async () => { |
| 47 | + const client = await makeClient(); |
| 48 | + const roleName = 'test_group_assignements_role'; |
| 49 | + await client.roles.delete(roleName).catch((e) => {}); |
| 50 | + await client.roles.create(roleName, []).catch((e) => {}); |
| 51 | + |
| 52 | + await expect(client.roles.getGroupAssignments(roleName)).resolves.toHaveLength(0); |
| 53 | + |
| 54 | + await client.groups.oidc.assignRoles('./group-1', roleName); |
| 55 | + await client.groups.oidc.assignRoles('./group-2', roleName); |
| 56 | + await expect(client.roles.getGroupAssignments(roleName)).resolves.toEqual( |
| 57 | + expect.arrayContaining<GroupAssignment>([ |
| 58 | + { groupID: './group-1', groupType: 'oidc' }, |
| 59 | + { groupID: './group-2', groupType: 'oidc' }, |
| 60 | + ]) |
| 61 | + ); |
| 62 | + |
| 63 | + await client.groups.oidc.revokeRoles('./group-1', roleName); |
| 64 | + await client.groups.oidc.revokeRoles('./group-2', roleName); |
| 65 | + await expect(client.roles.getGroupAssignments(roleName)).resolves.toHaveLength(0); |
| 66 | + }); |
| 67 | + |
| 68 | + it('cleanup', async () => { |
| 69 | + makeClient().then((c) => { |
| 70 | + c.groups.oidc.revokeRoles('./assign-group', ['viewer', 'admin']).catch((e) => {}); |
| 71 | + c.groups.oidc.revokeRoles('./group-1', 'viewer').catch((e) => {}); |
| 72 | + c.groups.oidc.revokeRoles('./group-2', 'viewer').catch((e) => {}); |
| 73 | + }); |
| 74 | + }); |
| 75 | +}); |
0 commit comments