keycloak-api-manager 3.1.0 → 3.2.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.
@@ -0,0 +1,329 @@
1
+ const { expect } = require('chai');
2
+ const { getAdminClient } = require('./config');
3
+
4
+ describe('Authentication Management Handler', function () {
5
+ this.timeout(20000);
6
+ let client;
7
+ let testFlowId;
8
+ let testFlowAlias;
9
+ let testExecutionId;
10
+ let testRequiredActionAlias;
11
+
12
+ before(function () {
13
+ client = getAdminClient();
14
+ testFlowAlias = `test-flow-${Date.now()}`;
15
+ });
16
+
17
+ // ==================== AUTHENTICATION FLOWS ====================
18
+ describe('Authentication Flows', function () {
19
+ describe('getFlows', function () {
20
+ it('should list all authentication flows', async function () {
21
+ const flows = await client.authenticationManagement.getFlows({
22
+ realm: 'test-realm',
23
+ });
24
+
25
+ expect(flows).to.be.an('array');
26
+ expect(flows.length).to.be.greaterThan(0);
27
+ });
28
+ });
29
+
30
+ describe('createFlow', function () {
31
+ it('should create an authentication flow', async function () {
32
+ const flowRep = {
33
+ alias: testFlowAlias,
34
+ description: 'Test Flow Description',
35
+ flowType: 'basic-flow',
36
+ builtIn: false,
37
+ };
38
+
39
+ const result = await client.authenticationManagement.createFlow(
40
+ { realm: 'test-realm' },
41
+ flowRep
42
+ );
43
+
44
+ expect(result).to.have.property('id');
45
+ testFlowId = result.id;
46
+ });
47
+ });
48
+
49
+ describe('getFlow', function () {
50
+ it('should retrieve a specific flow', async function () {
51
+ if (testFlowId) {
52
+ const flow = await client.authenticationManagement.getFlow({
53
+ realm: 'test-realm',
54
+ id: testFlowId,
55
+ });
56
+
57
+ expect(flow).to.exist;
58
+ expect(flow.id).to.equal(testFlowId);
59
+ }
60
+ });
61
+ });
62
+
63
+ describe('updateFlow', function () {
64
+ it('should update flow configuration', async function () {
65
+ if (testFlowId) {
66
+ const updateRep = {
67
+ description: 'Updated Description',
68
+ };
69
+
70
+ await client.authenticationManagement.updateFlow(
71
+ { realm: 'test-realm', id: testFlowId },
72
+ updateRep
73
+ );
74
+
75
+ const updated = await client.authenticationManagement.getFlow({
76
+ realm: 'test-realm',
77
+ id: testFlowId,
78
+ });
79
+
80
+ expect(updated.description).to.equal('Updated Description');
81
+ }
82
+ });
83
+ });
84
+
85
+ describe('copyFlow', function () {
86
+ it('should copy an authentication flow', async function () {
87
+ if (testFlowId) {
88
+ try {
89
+ const flowCopy = await client.authenticationManagement.copyFlow(
90
+ { realm: 'test-realm', id: testFlowId },
91
+ { newName: `copied-${testFlowAlias}` }
92
+ );
93
+
94
+ expect(flowCopy).to.exist;
95
+ } catch (err) {
96
+ // Copy might not be supported in all versions
97
+ }
98
+ }
99
+ });
100
+ });
101
+ });
102
+
103
+ // ==================== FLOW EXECUTIONS ====================
104
+ describe('Flow Executions', function () {
105
+ describe('getExecutions', function () {
106
+ it('should retrieve flow executions', async function () {
107
+ if (testFlowId) {
108
+ const executions = await client.authenticationManagement.getExecutions({
109
+ realm: 'test-realm',
110
+ flowAlias: testFlowAlias,
111
+ });
112
+
113
+ expect(executions).to.be.an('array');
114
+ }
115
+ });
116
+ });
117
+
118
+ describe('addExecutionToFlow', function () {
119
+ it('should add an execution to a flow', async function () {
120
+ if (testFlowId) {
121
+ try {
122
+ const execution = await client.authenticationManagement.addExecutionToFlow(
123
+ { realm: 'test-realm', flowAlias: testFlowAlias },
124
+ { provider: 'auth-cookie' }
125
+ );
126
+
127
+ expect(execution).to.exist;
128
+ testExecutionId = execution.id;
129
+ } catch (err) {
130
+ // Execution might not be allowed
131
+ }
132
+ }
133
+ });
134
+ });
135
+
136
+ describe('updateExecution', function () {
137
+ it('should update an execution', async function () {
138
+ if (testExecutionId && testFlowAlias) {
139
+ try {
140
+ const updateRep = {
141
+ requirement: 'CONDITIONAL',
142
+ };
143
+
144
+ await client.authenticationManagement.updateExecution(
145
+ { realm: 'test-realm', flowAlias: testFlowAlias },
146
+ updateRep
147
+ );
148
+
149
+ // Verify no error thrown
150
+ } catch (err) {
151
+ // Update might fail for some providers
152
+ }
153
+ }
154
+ });
155
+ });
156
+
157
+ describe('raisePriorityExecution', function () {
158
+ it('should raise execution priority', async function () {
159
+ if (testExecutionId && testFlowAlias) {
160
+ try {
161
+ await client.authenticationManagement.raisePriorityExecution({
162
+ realm: 'test-realm',
163
+ flowAlias: testFlowAlias,
164
+ executionId: testExecutionId,
165
+ });
166
+
167
+ // Verify no error thrown
168
+ } catch (err) {
169
+ // Priority adjust might not be supported
170
+ }
171
+ }
172
+ });
173
+ });
174
+
175
+ describe('lowerPriorityExecution', function () {
176
+ it('should lower execution priority', async function () {
177
+ if (testExecutionId && testFlowAlias) {
178
+ try {
179
+ await client.authenticationManagement.lowerPriorityExecution({
180
+ realm: 'test-realm',
181
+ flowAlias: testFlowAlias,
182
+ executionId: testExecutionId,
183
+ });
184
+
185
+ // Verify no error thrown
186
+ } catch (err) {
187
+ // Priority adjust might not be supported
188
+ }
189
+ }
190
+ });
191
+ });
192
+ });
193
+
194
+ // ==================== REQUIRED ACTIONS ====================
195
+ describe('Required Actions', function () {
196
+ describe('getRequiredActions', function () {
197
+ it('should list all required actions', async function () {
198
+ const actions = await client.authenticationManagement.getRequiredActions();
199
+
200
+ expect(actions).to.be.an('array');
201
+ expect(actions.length).to.be.greaterThan(0);
202
+ });
203
+ });
204
+
205
+ describe('getUnregisteredRequiredActions', function () {
206
+ it('should list unregistered required actions', async function () {
207
+ const unregistered = await client.authenticationManagement.getUnregisteredRequiredActions();
208
+
209
+ expect(unregistered).to.be.an('array');
210
+ });
211
+ });
212
+
213
+ describe('getRequiredActionForAlias', function () {
214
+ it('should retrieve a required action by alias', async function () {
215
+ const actions = await client.authenticationManagement.getRequiredActions();
216
+ if (actions.length > 0) {
217
+ const action = await client.authenticationManagement.getRequiredActionForAlias({
218
+ alias: actions[0].alias,
219
+ });
220
+
221
+ expect(action).to.exist;
222
+ testRequiredActionAlias = action.alias;
223
+ }
224
+ });
225
+ });
226
+
227
+ describe('updateRequiredAction', function () {
228
+ it('should update a required action', async function () {
229
+ if (testRequiredActionAlias) {
230
+ try {
231
+ const updateRep = {
232
+ enabled: true,
233
+ };
234
+
235
+ await client.authenticationManagement.updateRequiredAction(
236
+ { alias: testRequiredActionAlias },
237
+ updateRep
238
+ );
239
+
240
+ // Verify no error thrown
241
+ } catch (err) {
242
+ // Update might not be allowed
243
+ }
244
+ }
245
+ });
246
+ });
247
+
248
+ describe('raiseRequiredActionPriority', function () {
249
+ it('should raise required action priority', async function () {
250
+ if (testRequiredActionAlias) {
251
+ try {
252
+ await client.authenticationManagement.raiseRequiredActionPriority({
253
+ alias: testRequiredActionAlias,
254
+ });
255
+
256
+ // Verify no error thrown
257
+ } catch (err) {
258
+ // Priority adjust might not be supported
259
+ }
260
+ }
261
+ });
262
+ });
263
+
264
+ describe('lowerRequiredActionPriority', function () {
265
+ it('should lower required action priority', async function () {
266
+ if (testRequiredActionAlias) {
267
+ try {
268
+ await client.authenticationManagement.lowerRequiredActionPriority({
269
+ alias: testRequiredActionAlias,
270
+ });
271
+
272
+ // Verify no error thrown
273
+ } catch (err) {
274
+ // Priority adjust might not be supported
275
+ }
276
+ }
277
+ });
278
+ });
279
+ });
280
+
281
+ // ==================== PROVIDER INFORMATION ====================
282
+ describe('Authenticator Providers', function () {
283
+ describe('getAuthenticatorProviders', function () {
284
+ it('should retrieve authenticator providers', async function () {
285
+ const providers = await client.authenticationManagement.getAuthenticatorProviders();
286
+
287
+ expect(providers).to.be.an('array');
288
+ });
289
+ });
290
+
291
+ describe('getClientAuthenticatorProviders', function () {
292
+ it('should retrieve client authenticator providers', async function () {
293
+ const providers = await client.authenticationManagement.getClientAuthenticatorProviders();
294
+
295
+ expect(providers).to.be.an('array');
296
+ });
297
+ });
298
+
299
+ describe('getFormProviders', function () {
300
+ it('should retrieve form providers', async function () {
301
+ const providers = await client.authenticationManagement.getFormProviders();
302
+
303
+ expect(providers).to.be.an('array');
304
+ });
305
+ });
306
+
307
+ describe('getFormActionProviders', function () {
308
+ it('should retrieve form action providers', async function () {
309
+ const providers = await client.authenticationManagement.getFormActionProviders();
310
+
311
+ expect(providers).to.be.an('array');
312
+ });
313
+ });
314
+ });
315
+
316
+ // ==================== CLEANUP ====================
317
+ after(async function () {
318
+ try {
319
+ if (testFlowId) {
320
+ await client.authenticationManagement.deleteFlow({
321
+ realm: 'test-realm',
322
+ id: testFlowId,
323
+ });
324
+ }
325
+ } catch (err) {
326
+ console.error('Cleanup error:', err.message);
327
+ }
328
+ });
329
+ });
@@ -0,0 +1,256 @@
1
+ const { expect } = require('chai');
2
+ const { getAdminClient } = require('./config');
3
+
4
+ describe('Client Scopes Handler', function () {
5
+ this.timeout(15000);
6
+ let client;
7
+ let testScopeId;
8
+ let testScopeName;
9
+
10
+ before(function () {
11
+ client = getAdminClient();
12
+ testScopeName = `test-scope-${Date.now()}`;
13
+ });
14
+
15
+ // ==================== CLIENT SCOPE CRUD ====================
16
+ describe('CRUD Operations', function () {
17
+ describe('create', function () {
18
+ it('should create a client scope with valid representation', async function () {
19
+ const scopeRep = {
20
+ name: testScopeName,
21
+ displayName: 'Test Scope Display',
22
+ protocol: 'openid-connect',
23
+ description: 'Test scope for integration',
24
+ };
25
+
26
+ const result = await client.clientScopes.create(
27
+ { realm: 'test-realm' },
28
+ scopeRep
29
+ );
30
+
31
+ expect(result).to.have.property('id');
32
+ testScopeId = result.id;
33
+ });
34
+ });
35
+
36
+ describe('find', function () {
37
+ it('should list all client scopes', async function () {
38
+ const scopes = await client.clientScopes.find({ realm: 'test-realm' });
39
+
40
+ expect(scopes).to.be.an('array');
41
+ expect(scopes.length).to.be.greaterThan(0);
42
+ expect(scopes.some((s) => s.name === testScopeName)).to.be.true;
43
+ });
44
+ });
45
+
46
+ describe('findOne', function () {
47
+ it('should find a specific scope by id', async function () {
48
+ const scope = await client.clientScopes.findOne({
49
+ realm: 'test-realm',
50
+ id: testScopeId,
51
+ });
52
+
53
+ expect(scope).to.exist;
54
+ expect(scope.name).to.equal(testScopeName);
55
+ });
56
+ });
57
+
58
+ describe('findOneByName', function () {
59
+ it('should find a specific scope by name', async function () {
60
+ const scope = await client.clientScopes.findOneByName({
61
+ realm: 'test-realm',
62
+ name: testScopeName,
63
+ });
64
+
65
+ expect(scope).to.exist;
66
+ expect(scope.name).to.equal(testScopeName);
67
+ });
68
+ });
69
+
70
+ describe('update', function () {
71
+ it('should update scope attributes', async function () {
72
+ const updateRep = {
73
+ displayName: 'Updated Scope Display',
74
+ description: 'Updated description',
75
+ };
76
+
77
+ await client.clientScopes.update(
78
+ { realm: 'test-realm', id: testScopeId },
79
+ updateRep
80
+ );
81
+
82
+ const updated = await client.clientScopes.findOne({
83
+ realm: 'test-realm',
84
+ id: testScopeId,
85
+ });
86
+
87
+ expect(updated.displayName).to.equal('Updated Scope Display');
88
+ });
89
+ });
90
+
91
+ describe('delByName', function () {
92
+ it('should delete scope by name', async function () {
93
+ // Create temp scope for deletion test
94
+ const tempScope = await client.clientScopes.create(
95
+ { realm: 'test-realm' },
96
+ { name: `temp-scope-${Date.now()}` }
97
+ );
98
+
99
+ await client.clientScopes.delByName({
100
+ realm: 'test-realm',
101
+ name: tempScope.name,
102
+ });
103
+
104
+ // Verify deleted
105
+ });
106
+ });
107
+ });
108
+
109
+ // ==================== DEFAULT CLIENT SCOPES ====================
110
+ describe('Default Client Scopes', function () {
111
+ describe('listDefaultClientScopes', function () {
112
+ it('should list default client scopes', async function () {
113
+ const scopes = await client.clientScopes.listDefaultClientScopes({
114
+ realm: 'test-realm',
115
+ });
116
+
117
+ expect(scopes).to.be.an('array');
118
+ });
119
+ });
120
+
121
+ describe('addDefaultClientScope', function () {
122
+ it('should add a client scope to defaults', async function () {
123
+ await client.clientScopes.addDefaultClientScope({
124
+ realm: 'test-realm',
125
+ id: testScopeId,
126
+ });
127
+
128
+ const defaults = await client.clientScopes.listDefaultClientScopes({
129
+ realm: 'test-realm',
130
+ });
131
+
132
+ expect(defaults.some((s) => s.id === testScopeId)).to.be.true;
133
+ });
134
+ });
135
+
136
+ describe('delDefaultClientScope', function () {
137
+ it('should remove client scope from defaults', async function () {
138
+ await client.clientScopes.delDefaultClientScope({
139
+ realm: 'test-realm',
140
+ id: testScopeId,
141
+ });
142
+
143
+ const defaults = await client.clientScopes.listDefaultClientScopes({
144
+ realm: 'test-realm',
145
+ });
146
+
147
+ expect(defaults.some((s) => s.id === testScopeId)).to.be.false;
148
+ });
149
+ });
150
+ });
151
+
152
+ // ==================== DEFAULT OPTIONAL CLIENT SCOPES ====================
153
+ describe('Default Optional Client Scopes', function () {
154
+ describe('listDefaultOptionalClientScopes', function () {
155
+ it('should list default optional client scopes', async function () {
156
+ const scopes = await client.clientScopes.listDefaultOptionalClientScopes({
157
+ realm: 'test-realm',
158
+ });
159
+
160
+ expect(scopes).to.be.an('array');
161
+ });
162
+ });
163
+
164
+ describe('addDefaultOptionalClientScope', function () {
165
+ it('should add scope to default optional', async function () {
166
+ await client.clientScopes.addDefaultOptionalClientScope({
167
+ realm: 'test-realm',
168
+ id: testScopeId,
169
+ });
170
+
171
+ const optionals = await client.clientScopes.listDefaultOptionalClientScopes({
172
+ realm: 'test-realm',
173
+ });
174
+
175
+ expect(optionals.some((s) => s.id === testScopeId)).to.be.true;
176
+ });
177
+ });
178
+
179
+ describe('delDefaultOptionalClientScope', function () {
180
+ it('should remove scope from default optional', async function () {
181
+ await client.clientScopes.delDefaultOptionalClientScope({
182
+ realm: 'test-realm',
183
+ id: testScopeId,
184
+ });
185
+
186
+ const optionals = await client.clientScopes.listDefaultOptionalClientScopes({
187
+ realm: 'test-realm',
188
+ });
189
+
190
+ expect(optionals.some((s) => s.id === testScopeId)).to.be.false;
191
+ });
192
+ });
193
+ });
194
+
195
+ // ==================== PROTOCOL MAPPERS ====================
196
+ describe('Protocol Mappers', function () {
197
+ describe('listProtocolMappers', function () {
198
+ it('should list protocol mappers for scope', async function () {
199
+ const mappers = await client.clientScopes.listProtocolMappers({
200
+ realm: 'test-realm',
201
+ id: testScopeId,
202
+ });
203
+
204
+ expect(mappers).to.be.an('array');
205
+ });
206
+ });
207
+
208
+ describe('findProtocolMappersByProtocol', function () {
209
+ it('should find protocol mappers by protocol', async function () {
210
+ const mappers = await client.clientScopes.findProtocolMappersByProtocol({
211
+ realm: 'test-realm',
212
+ id: testScopeId,
213
+ protocol: 'openid-connect',
214
+ });
215
+
216
+ expect(mappers).to.be.an('array');
217
+ });
218
+ });
219
+ });
220
+
221
+ // ==================== SCOPE MAPPINGS ====================
222
+ describe('Scope Mappings', function () {
223
+ describe('listScopeMappings', function () {
224
+ it('should list all scope mappings', async function () {
225
+ const mappings = await client.clientScopes.listScopeMappings({
226
+ realm: 'test-realm',
227
+ id: testScopeId,
228
+ });
229
+
230
+ expect(mappings).to.be.an('object');
231
+ });
232
+ });
233
+
234
+ describe('listRealmScopeMappings', function () {
235
+ it('should list realm scope mappings', async function () {
236
+ const mappings = await client.clientScopes.listRealmScopeMappings({
237
+ realm: 'test-realm',
238
+ id: testScopeId,
239
+ });
240
+
241
+ expect(mappings).to.be.an('array');
242
+ });
243
+ });
244
+ });
245
+
246
+ // ==================== CLEANUP ====================
247
+ after(async function () {
248
+ try {
249
+ if (testScopeId) {
250
+ await client.clientScopes.del({ realm: 'test-realm', id: testScopeId });
251
+ }
252
+ } catch (err) {
253
+ console.error('Cleanup error:', err.message);
254
+ }
255
+ });
256
+ });