keycloak-api-manager 3.2.1 → 4.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.env.example +27 -0
- package/Handlers/clientsHandler.js +240 -30
- package/Handlers/groupsHandler.js +16 -1
- package/Handlers/httpApiHelper.js +87 -0
- package/Handlers/realmsHandler.js +26 -4
- package/Handlers/usersHandler.js +43 -10
- package/README.md +341 -10
- package/index.js +159 -29
- package/package.json +3 -14
- package/test/.mocharc.json +4 -0
- package/test/TESTING.md +327 -0
- package/test/config/CONFIGURATION.md +170 -0
- package/test/config/default.json +36 -0
- package/test/config/local.json.example +7 -0
- package/test/config/secrets.json.example +7 -0
- package/test/diagnostic-protocol-mappers.js +189 -0
- package/test/docker-keycloak/DEPLOYMENT_GUIDE.md +262 -0
- package/test/docker-keycloak/certs/.gitkeep +7 -0
- package/test/docker-keycloak/docker-compose-https.yml +50 -0
- package/test/docker-keycloak/docker-compose.yml +59 -0
- package/test/docker-keycloak/setup-keycloak.js +501 -0
- package/test/enableServerFeatures.js +315 -0
- package/test/helpers/config.js +218 -0
- package/test/helpers/docker-helpers.js +513 -0
- package/test/helpers/setup.js +186 -0
- package/test/package.json +18 -0
- package/test/setup.js +194 -0
- package/test/specs/authenticationManagement.test.js +224 -0
- package/test/specs/clientCredentials.test.js +76 -0
- package/test/specs/clientScopes.test.js +388 -0
- package/test/specs/clients.test.js +791 -0
- package/test/specs/components.test.js +151 -0
- package/test/specs/debugClientLibrary.test.js +88 -0
- package/test/specs/groups.test.js +362 -0
- package/test/specs/identityProviders.test.js +292 -0
- package/test/specs/realms.test.js +390 -0
- package/test/specs/roles.test.js +322 -0
- package/test/specs/users.test.js +445 -0
- package/test/testConfig.js +69 -0
- package/.mocharc.json +0 -7
- package/docker-compose.yml +0 -27
- package/test/authenticationManagement.test.js +0 -329
- package/test/clientScopes.test.js +0 -256
- package/test/clients.test.js +0 -284
- package/test/components.test.js +0 -122
- package/test/config.js +0 -137
- package/test/docker-helpers.js +0 -111
- package/test/groups.test.js +0 -284
- package/test/identityProviders.test.js +0 -197
- package/test/mocha.env.js +0 -55
- package/test/realms.test.js +0 -349
- package/test/roles.test.js +0 -215
- package/test/users.test.js +0 -405
package/test/realms.test.js
DELETED
|
@@ -1,349 +0,0 @@
|
|
|
1
|
-
const { expect } = require('chai');
|
|
2
|
-
const { getAdminClient } = require('./config');
|
|
3
|
-
|
|
4
|
-
describe('Realms Handler', function () {
|
|
5
|
-
this.timeout(15000);
|
|
6
|
-
let client;
|
|
7
|
-
let testRealmName;
|
|
8
|
-
let testGroupId;
|
|
9
|
-
|
|
10
|
-
before(function () {
|
|
11
|
-
client = getAdminClient();
|
|
12
|
-
testRealmName = `test-realm-${Date.now()}`;
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
// ==================== REALM CRUD ====================
|
|
16
|
-
describe('CRUD Operations', function () {
|
|
17
|
-
describe('create', function () {
|
|
18
|
-
it('should create a realm with minimal representation', async function () {
|
|
19
|
-
const result = await client.realms.create({
|
|
20
|
-
realm: testRealmName,
|
|
21
|
-
enabled: true,
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
expect(result).to.have.property('id');
|
|
25
|
-
expect(result.realm).to.equal(testRealmName);
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
it('should fail creating duplicate realm', async function () {
|
|
29
|
-
try {
|
|
30
|
-
await client.realms.create({
|
|
31
|
-
realm: testRealmName,
|
|
32
|
-
enabled: true,
|
|
33
|
-
});
|
|
34
|
-
expect.fail('Should have thrown an error for duplicate realm');
|
|
35
|
-
} catch (err) {
|
|
36
|
-
expect(err).to.exist;
|
|
37
|
-
}
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
it('should fail with missing realm name', async function () {
|
|
41
|
-
try {
|
|
42
|
-
await client.realms.create({
|
|
43
|
-
displayName: 'Invalid',
|
|
44
|
-
});
|
|
45
|
-
expect.fail('Should have thrown an error');
|
|
46
|
-
} catch (err) {
|
|
47
|
-
expect(err).to.exist;
|
|
48
|
-
}
|
|
49
|
-
});
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
describe('find', function () {
|
|
53
|
-
it('should list all realms', async function () {
|
|
54
|
-
const realms = await client.realms.find();
|
|
55
|
-
|
|
56
|
-
expect(realms).to.be.an('array');
|
|
57
|
-
expect(realms.length).to.be.greaterThan(0);
|
|
58
|
-
expect(realms.some((r) => r.realm === testRealmName)).to.be.true;
|
|
59
|
-
});
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
describe('findOne', function () {
|
|
63
|
-
it('should find a specific realm by name', async function () {
|
|
64
|
-
const realm = await client.realms.findOne({ realm: testRealmName });
|
|
65
|
-
|
|
66
|
-
expect(realm).to.exist;
|
|
67
|
-
expect(realm.realm).to.equal(testRealmName);
|
|
68
|
-
expect(realm.enabled).to.be.true;
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
it('should return null for non-existent realm', async function () {
|
|
72
|
-
try {
|
|
73
|
-
await client.realms.findOne({ realm: 'non-existent-realm-xyz' });
|
|
74
|
-
expect.fail('Should have thrown an error');
|
|
75
|
-
} catch (err) {
|
|
76
|
-
expect(err).to.exist;
|
|
77
|
-
}
|
|
78
|
-
});
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
describe('update', function () {
|
|
82
|
-
it('should update realm configuration', async function () {
|
|
83
|
-
const updateRep = {
|
|
84
|
-
displayName: 'Updated Display Name',
|
|
85
|
-
loginTheme: 'keycloak',
|
|
86
|
-
accessCodeLifespan: 60,
|
|
87
|
-
};
|
|
88
|
-
|
|
89
|
-
await client.realms.update({ realm: testRealmName }, updateRep);
|
|
90
|
-
|
|
91
|
-
const updated = await client.realms.findOne({ realm: testRealmName });
|
|
92
|
-
expect(updated.displayName).to.equal('Updated Display Name');
|
|
93
|
-
expect(updated.loginTheme).to.equal('keycloak');
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
it('should update realm enabled status', async function () {
|
|
97
|
-
await client.realms.update({ realm: testRealmName }, { enabled: false });
|
|
98
|
-
|
|
99
|
-
const updated = await client.realms.findOne({ realm: testRealmName });
|
|
100
|
-
expect(updated.enabled).to.be.false;
|
|
101
|
-
});
|
|
102
|
-
});
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
// ==================== REALM CONFIGURATION ====================
|
|
106
|
-
describe('Configuration Operations', function () {
|
|
107
|
-
describe('export', function () {
|
|
108
|
-
it('should export realm configuration', async function () {
|
|
109
|
-
const exported = await client.realms.export({
|
|
110
|
-
realm: testRealmName,
|
|
111
|
-
exportClients: true,
|
|
112
|
-
exportGroupsAndRoles: true,
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
expect(exported).to.be.an('object');
|
|
116
|
-
expect(exported.realm).to.equal(testRealmName);
|
|
117
|
-
});
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
describe('getKeys', function () {
|
|
121
|
-
it('should retrieve realm keys', async function () {
|
|
122
|
-
const keys = await client.realms.getKeys({ realm: testRealmName });
|
|
123
|
-
|
|
124
|
-
expect(keys).to.be.an('object');
|
|
125
|
-
expect(keys).to.have.property('keys');
|
|
126
|
-
expect(keys.keys).to.be.an('array');
|
|
127
|
-
});
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
describe('getClientSessionStats', function () {
|
|
131
|
-
it('should retrieve client session statistics', async function () {
|
|
132
|
-
const stats = await client.realms.getClientSessionStats({ realm: testRealmName });
|
|
133
|
-
|
|
134
|
-
expect(stats).to.be.an('array');
|
|
135
|
-
});
|
|
136
|
-
});
|
|
137
|
-
});
|
|
138
|
-
|
|
139
|
-
// ==================== EVENT CONFIGURATION ====================
|
|
140
|
-
describe('Event Management', function () {
|
|
141
|
-
describe('getConfigEvents', function () {
|
|
142
|
-
it('should retrieve event configuration', async function () {
|
|
143
|
-
const config = await client.realms.getConfigEvents({ realm: testRealmName });
|
|
144
|
-
|
|
145
|
-
expect(config).to.be.an('object');
|
|
146
|
-
});
|
|
147
|
-
});
|
|
148
|
-
|
|
149
|
-
describe('updateConfigEvents', function () {
|
|
150
|
-
it('should update event configuration', async function () {
|
|
151
|
-
const eventConfig = {
|
|
152
|
-
eventsEnabled: true,
|
|
153
|
-
eventsListeners: ['jboss-logging'],
|
|
154
|
-
enabledEventTypes: ['LOGIN', 'LOGOUT'],
|
|
155
|
-
};
|
|
156
|
-
|
|
157
|
-
await client.realms.updateConfigEvents({ realm: testRealmName }, eventConfig);
|
|
158
|
-
|
|
159
|
-
const updated = await client.realms.getConfigEvents({ realm: testRealmName });
|
|
160
|
-
expect(updated.eventsEnabled).to.be.true;
|
|
161
|
-
});
|
|
162
|
-
});
|
|
163
|
-
|
|
164
|
-
describe('findEvents', function () {
|
|
165
|
-
it('should retrieve realm events', async function () {
|
|
166
|
-
const events = await client.realms.findEvents({
|
|
167
|
-
realm: testRealmName,
|
|
168
|
-
max: 10,
|
|
169
|
-
});
|
|
170
|
-
|
|
171
|
-
expect(events).to.be.an('array');
|
|
172
|
-
});
|
|
173
|
-
});
|
|
174
|
-
|
|
175
|
-
describe('findAdminEvents', function () {
|
|
176
|
-
it('should retrieve admin events', async function () {
|
|
177
|
-
const events = await client.realms.findAdminEvents({
|
|
178
|
-
realm: testRealmName,
|
|
179
|
-
max: 10,
|
|
180
|
-
});
|
|
181
|
-
|
|
182
|
-
expect(events).to.be.an('array');
|
|
183
|
-
});
|
|
184
|
-
});
|
|
185
|
-
|
|
186
|
-
describe('clearEvents', function () {
|
|
187
|
-
it('should clear events for realm', async function () {
|
|
188
|
-
await client.realms.clearEvents({ realm: testRealmName });
|
|
189
|
-
// Verify no error thrown
|
|
190
|
-
});
|
|
191
|
-
});
|
|
192
|
-
|
|
193
|
-
describe('clearAdminEvents', function () {
|
|
194
|
-
it('should clear admin events for realm', async function () {
|
|
195
|
-
await client.realms.clearAdminEvents({ realm: testRealmName });
|
|
196
|
-
// Verify no error thrown
|
|
197
|
-
});
|
|
198
|
-
});
|
|
199
|
-
});
|
|
200
|
-
|
|
201
|
-
// ==================== DEFAULT GROUPS ====================
|
|
202
|
-
describe('Default Groups Management', function () {
|
|
203
|
-
before(async function () {
|
|
204
|
-
// Create a test group first
|
|
205
|
-
const group = await client.groups.create(
|
|
206
|
-
{ realm: testRealmName },
|
|
207
|
-
{ name: 'test-default-group' }
|
|
208
|
-
);
|
|
209
|
-
testGroupId = group.id;
|
|
210
|
-
});
|
|
211
|
-
|
|
212
|
-
describe('getDefaultGroups', function () {
|
|
213
|
-
it('should retrieve default groups for realm', async function () {
|
|
214
|
-
const groups = await client.realms.getDefaultGroups({
|
|
215
|
-
realm: testRealmName,
|
|
216
|
-
});
|
|
217
|
-
|
|
218
|
-
expect(groups).to.be.an('array');
|
|
219
|
-
});
|
|
220
|
-
});
|
|
221
|
-
|
|
222
|
-
describe('addDefaultGroup', function () {
|
|
223
|
-
it('should add a group to default groups', async function () {
|
|
224
|
-
await client.realms.addDefaultGroup({
|
|
225
|
-
realm: testRealmName,
|
|
226
|
-
id: testGroupId,
|
|
227
|
-
});
|
|
228
|
-
|
|
229
|
-
const defaultGroups = await client.realms.getDefaultGroups({
|
|
230
|
-
realm: testRealmName,
|
|
231
|
-
});
|
|
232
|
-
|
|
233
|
-
expect(defaultGroups.some((g) => g.id === testGroupId)).to.be.true;
|
|
234
|
-
});
|
|
235
|
-
});
|
|
236
|
-
|
|
237
|
-
describe('removeDefaultGroup', function () {
|
|
238
|
-
it('should remove a group from default groups', async function () {
|
|
239
|
-
await client.realms.removeDefaultGroup({
|
|
240
|
-
realm: testRealmName,
|
|
241
|
-
id: testGroupId,
|
|
242
|
-
});
|
|
243
|
-
|
|
244
|
-
const defaultGroups = await client.realms.getDefaultGroups({
|
|
245
|
-
realm: testRealmName,
|
|
246
|
-
});
|
|
247
|
-
|
|
248
|
-
expect(defaultGroups.some((g) => g.id === testGroupId)).to.be.false;
|
|
249
|
-
});
|
|
250
|
-
});
|
|
251
|
-
|
|
252
|
-
describe('getGroupByPath', function () {
|
|
253
|
-
it('should retrieve group by path', async function () {
|
|
254
|
-
const group = await client.realms.getGroupByPath({
|
|
255
|
-
realm: testRealmName,
|
|
256
|
-
path: '/test-default-group',
|
|
257
|
-
});
|
|
258
|
-
|
|
259
|
-
expect(group).to.exist;
|
|
260
|
-
expect(group.name).to.equal('test-default-group');
|
|
261
|
-
});
|
|
262
|
-
});
|
|
263
|
-
});
|
|
264
|
-
|
|
265
|
-
// ==================== CLIENT REGISTRATION ====================
|
|
266
|
-
describe('Client Registration', function () {
|
|
267
|
-
let initialAccessTokenId;
|
|
268
|
-
|
|
269
|
-
describe('createClientsInitialAccess', function () {
|
|
270
|
-
it('should create initial access token for client registration', async function () {
|
|
271
|
-
const result = await client.realms.createClientsInitialAccess(
|
|
272
|
-
{ realm: testRealmName },
|
|
273
|
-
{ count: 1, expiration: 3600 }
|
|
274
|
-
);
|
|
275
|
-
|
|
276
|
-
expect(result).to.have.property('token');
|
|
277
|
-
initialAccessTokenId = result.id;
|
|
278
|
-
});
|
|
279
|
-
});
|
|
280
|
-
|
|
281
|
-
describe('getClientsInitialAccess', function () {
|
|
282
|
-
it('should list all initial access tokens', async function () {
|
|
283
|
-
const tokens = await client.realms.getClientsInitialAccess({
|
|
284
|
-
realm: testRealmName,
|
|
285
|
-
});
|
|
286
|
-
|
|
287
|
-
expect(tokens).to.be.an('array');
|
|
288
|
-
expect(tokens.some((t) => t.id === initialAccessTokenId)).to.be.true;
|
|
289
|
-
});
|
|
290
|
-
});
|
|
291
|
-
|
|
292
|
-
describe('delClientsInitialAccess', function () {
|
|
293
|
-
it('should delete an initial access token', async function () {
|
|
294
|
-
await client.realms.delClientsInitialAccess({
|
|
295
|
-
realm: testRealmName,
|
|
296
|
-
id: initialAccessTokenId,
|
|
297
|
-
});
|
|
298
|
-
|
|
299
|
-
const tokens = await client.realms.getClientsInitialAccess({
|
|
300
|
-
realm: testRealmName,
|
|
301
|
-
});
|
|
302
|
-
|
|
303
|
-
expect(tokens.some((t) => t.id === initialAccessTokenId)).to.be.false;
|
|
304
|
-
});
|
|
305
|
-
});
|
|
306
|
-
|
|
307
|
-
describe('getClientRegistrationPolicyProviders', function () {
|
|
308
|
-
it('should retrieve client registration policy providers', async function () {
|
|
309
|
-
const providers = await client.realms.getClientRegistrationPolicyProviders({
|
|
310
|
-
realm: testRealmName,
|
|
311
|
-
});
|
|
312
|
-
|
|
313
|
-
expect(providers).to.be.an('array');
|
|
314
|
-
});
|
|
315
|
-
});
|
|
316
|
-
});
|
|
317
|
-
|
|
318
|
-
// ==================== REALM MANAGEMENT ====================
|
|
319
|
-
describe('Realm Management', function () {
|
|
320
|
-
describe('logoutAll', function () {
|
|
321
|
-
it('should logout all users in realm', async function () {
|
|
322
|
-
await client.realms.logoutAll({ realm: testRealmName });
|
|
323
|
-
// Verify no error thrown
|
|
324
|
-
});
|
|
325
|
-
});
|
|
326
|
-
|
|
327
|
-
describe('pushRevocation', function () {
|
|
328
|
-
it('should push revocation policy to realm', async function () {
|
|
329
|
-
await client.realms.pushRevocation({ realm: testRealmName });
|
|
330
|
-
// Verify no error thrown
|
|
331
|
-
});
|
|
332
|
-
});
|
|
333
|
-
});
|
|
334
|
-
|
|
335
|
-
// ==================== CLEANUP ====================
|
|
336
|
-
after(async function () {
|
|
337
|
-
try {
|
|
338
|
-
// Cleanup test group
|
|
339
|
-
if (testGroupId) {
|
|
340
|
-
await client.groups.del({ realm: testRealmName, id: testGroupId });
|
|
341
|
-
}
|
|
342
|
-
// Delete test realm
|
|
343
|
-
await client.realms.del({ realm: testRealmName });
|
|
344
|
-
} catch (err) {
|
|
345
|
-
// Ignore if not found
|
|
346
|
-
console.error('Cleanup error:', err.message);
|
|
347
|
-
}
|
|
348
|
-
});
|
|
349
|
-
});
|
package/test/roles.test.js
DELETED
|
@@ -1,215 +0,0 @@
|
|
|
1
|
-
const { expect } = require('chai');
|
|
2
|
-
const { getAdminClient } = require('./config');
|
|
3
|
-
|
|
4
|
-
describe('Roles Handler', function () {
|
|
5
|
-
this.timeout(15000);
|
|
6
|
-
let client;
|
|
7
|
-
let testRoleId;
|
|
8
|
-
let testRoleName;
|
|
9
|
-
let compositeRoleId;
|
|
10
|
-
|
|
11
|
-
before(async function () {
|
|
12
|
-
client = getAdminClient();
|
|
13
|
-
testRoleName = `test-role-${Date.now()}`;
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
// ==================== ROLE CRUD ====================
|
|
17
|
-
describe('CRUD Operations', function () {
|
|
18
|
-
describe('create', function () {
|
|
19
|
-
it('should create a realm role with valid representation', async function () {
|
|
20
|
-
const roleRep = {
|
|
21
|
-
name: testRoleName,
|
|
22
|
-
displayName: 'Test Role Display',
|
|
23
|
-
description: 'Test role for integration',
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
const result = await client.roles.create(
|
|
27
|
-
{ realm: 'test-realm' },
|
|
28
|
-
roleRep
|
|
29
|
-
);
|
|
30
|
-
|
|
31
|
-
expect(result).to.have.property('id');
|
|
32
|
-
testRoleId = result.id;
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
it('should fail creating duplicate role name', async function () {
|
|
36
|
-
try {
|
|
37
|
-
await client.roles.create(
|
|
38
|
-
{ realm: 'test-realm' },
|
|
39
|
-
{ name: testRoleName }
|
|
40
|
-
);
|
|
41
|
-
expect.fail('Should have thrown error for duplicate role');
|
|
42
|
-
} catch (err) {
|
|
43
|
-
expect(err).to.exist;
|
|
44
|
-
}
|
|
45
|
-
});
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
describe('find', function () {
|
|
49
|
-
it('should list all realm roles', async function () {
|
|
50
|
-
const roles = await client.roles.find({ realm: 'test-realm' });
|
|
51
|
-
|
|
52
|
-
expect(roles).to.be.an('array');
|
|
53
|
-
expect(roles.length).to.be.greaterThan(0);
|
|
54
|
-
expect(roles.some((r) => r.name === testRoleName)).to.be.true;
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
it('should support pagination parameters', async function () {
|
|
58
|
-
const roles = await client.roles.find({
|
|
59
|
-
realm: 'test-realm',
|
|
60
|
-
first: 0,
|
|
61
|
-
max: 5,
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
expect(roles).to.be.an('array');
|
|
65
|
-
expect(roles.length).to.be.lessThanOrEqual(5);
|
|
66
|
-
});
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
describe('findOneByName', function () {
|
|
70
|
-
it('should find a specific role by name', async function () {
|
|
71
|
-
const role = await client.roles.findOneByName({
|
|
72
|
-
realm: 'test-realm',
|
|
73
|
-
name: testRoleName,
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
expect(role).to.exist;
|
|
77
|
-
expect(role.name).to.equal(testRoleName);
|
|
78
|
-
});
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
describe('findOneById', function () {
|
|
82
|
-
it('should find a specific role by id', async function () {
|
|
83
|
-
const role = await client.roles.findOneById({
|
|
84
|
-
realm: 'test-realm',
|
|
85
|
-
id: testRoleId,
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
expect(role).to.exist;
|
|
89
|
-
expect(role.id).to.equal(testRoleId);
|
|
90
|
-
});
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
describe('update', function () {
|
|
94
|
-
describe('updateByName', function () {
|
|
95
|
-
it('should update role by name', async function () {
|
|
96
|
-
const updateRep = {
|
|
97
|
-
displayName: 'Updated Display Name',
|
|
98
|
-
description: 'Updated description',
|
|
99
|
-
};
|
|
100
|
-
|
|
101
|
-
await client.roles.updateByName(
|
|
102
|
-
{ realm: 'test-realm', name: testRoleName },
|
|
103
|
-
updateRep
|
|
104
|
-
);
|
|
105
|
-
|
|
106
|
-
const updated = await client.roles.findOneByName({
|
|
107
|
-
realm: 'test-realm',
|
|
108
|
-
name: testRoleName,
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
expect(updated.displayName).to.equal('Updated Display Name');
|
|
112
|
-
});
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
describe('updateById', function () {
|
|
116
|
-
it('should update role by id', async function () {
|
|
117
|
-
const updateRep = {
|
|
118
|
-
description: 'Updated by ID',
|
|
119
|
-
};
|
|
120
|
-
|
|
121
|
-
await client.roles.updateById(
|
|
122
|
-
{ realm: 'test-realm', id: testRoleId },
|
|
123
|
-
updateRep
|
|
124
|
-
);
|
|
125
|
-
|
|
126
|
-
const updated = await client.roles.findOneById({
|
|
127
|
-
realm: 'test-realm',
|
|
128
|
-
id: testRoleId,
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
expect(updated.description).to.equal('Updated by ID');
|
|
132
|
-
});
|
|
133
|
-
});
|
|
134
|
-
});
|
|
135
|
-
});
|
|
136
|
-
|
|
137
|
-
// ==================== COMPOSITE ROLES ====================
|
|
138
|
-
describe('Composite Roles', function () {
|
|
139
|
-
before(async function () {
|
|
140
|
-
// Create a composite role
|
|
141
|
-
const compositeRep = {
|
|
142
|
-
name: `composite-role-${Date.now()}`,
|
|
143
|
-
composite: true,
|
|
144
|
-
};
|
|
145
|
-
|
|
146
|
-
const result = await client.roles.create(
|
|
147
|
-
{ realm: 'test-realm' },
|
|
148
|
-
compositeRep
|
|
149
|
-
);
|
|
150
|
-
compositeRoleId = result.id;
|
|
151
|
-
});
|
|
152
|
-
|
|
153
|
-
describe('createComposite', function () {
|
|
154
|
-
it('should create composite role with child roles', async function () {
|
|
155
|
-
const childRole = await client.roles.findOneByName({
|
|
156
|
-
realm: 'test-realm',
|
|
157
|
-
name: testRoleName,
|
|
158
|
-
});
|
|
159
|
-
|
|
160
|
-
await client.roles.createComposite(
|
|
161
|
-
{ realm: 'test-realm', name: `composite-role-${Date.now()}` },
|
|
162
|
-
[childRole]
|
|
163
|
-
);
|
|
164
|
-
|
|
165
|
-
// Verify composite created
|
|
166
|
-
});
|
|
167
|
-
});
|
|
168
|
-
|
|
169
|
-
describe('getCompositeRoles', function () {
|
|
170
|
-
it('should retrieve composite roles', async function () {
|
|
171
|
-
const composites = await client.roles.getCompositeRoles({
|
|
172
|
-
realm: 'test-realm',
|
|
173
|
-
id: compositeRoleId,
|
|
174
|
-
});
|
|
175
|
-
|
|
176
|
-
expect(composites).to.be.an('array');
|
|
177
|
-
});
|
|
178
|
-
});
|
|
179
|
-
|
|
180
|
-
describe('getCompositeRolesForRealm', function () {
|
|
181
|
-
it('should retrieve composite roles for realm', async function () {
|
|
182
|
-
const composites = await client.roles.getCompositeRolesForRealm({
|
|
183
|
-
realm: 'test-realm',
|
|
184
|
-
id: compositeRoleId,
|
|
185
|
-
});
|
|
186
|
-
|
|
187
|
-
expect(composites).to.be.an('array');
|
|
188
|
-
});
|
|
189
|
-
});
|
|
190
|
-
});
|
|
191
|
-
|
|
192
|
-
// ==================== CLEANUP ====================
|
|
193
|
-
after(async function () {
|
|
194
|
-
try {
|
|
195
|
-
if (testRoleId) {
|
|
196
|
-
await client.roles.delByName({ realm: 'test-realm', name: testRoleName });
|
|
197
|
-
}
|
|
198
|
-
if (compositeRoleId) {
|
|
199
|
-
// Delete composite role
|
|
200
|
-
const compositeRole = await client.roles.findOneById({
|
|
201
|
-
realm: 'test-realm',
|
|
202
|
-
id: compositeRoleId,
|
|
203
|
-
});
|
|
204
|
-
if (compositeRole) {
|
|
205
|
-
await client.roles.delByName({
|
|
206
|
-
realm: 'test-realm',
|
|
207
|
-
name: compositeRole.name,
|
|
208
|
-
});
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
} catch (err) {
|
|
212
|
-
console.error('Cleanup error:', err.message);
|
|
213
|
-
}
|
|
214
|
-
});
|
|
215
|
-
});
|