forked from keycloak/keycloak-nodejs-admin-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
clients.spec.ts
1271 lines (1083 loc) Β· 35 KB
/
clients.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// tslint:disable:no-unused-expression
import * as chai from 'chai';
import {KeycloakAdminClient} from '../src/client';
import {credentials} from './constants';
import faker from 'faker';
import ClientRepresentation from '../src/defs/clientRepresentation';
import ProtocolMapperRepresentation from '../src/defs/protocolMapperRepresentation';
import ClientScopeRepresentation from '../src/defs/clientScopeRepresentation';
import ScopeRepresentation from '../src/defs/scopeRepresentation';
import ResourceRepresentation from '../src/defs/resourceRepresentation';
import UserRepresentation from '../src/defs/userRepresentation';
import PolicyRepresentation, {Logic} from '../src/defs/policyRepresentation';
const expect = chai.expect;
describe('Clients', () => {
let kcAdminClient: KeycloakAdminClient;
let currentClient: ClientRepresentation;
let currentClientScope: ClientScopeRepresentation;
let currentRoleName: string;
before(async () => {
kcAdminClient = new KeycloakAdminClient();
await kcAdminClient.auth(credentials);
// create client and also test it
// NOTICE: to be clear, clientId stands for the property `clientId` of client
// clientUniqueId stands for property `id` of client
const clientId = faker.internet.userName();
const createdClient = await kcAdminClient.clients.create({
clientId,
});
expect(createdClient.id).to.be.ok;
const client = await kcAdminClient.clients.findOne({
id: createdClient.id,
});
expect(client).to.be.ok;
currentClient = client!;
});
after(async () => {
// delete the current one
await kcAdminClient.clients.del({
id: currentClient.id!,
});
});
it('list clients', async () => {
const clients = await kcAdminClient.clients.find();
expect(clients).to.be.ok;
});
it('get single client', async () => {
const clientUniqueId = currentClient.id!;
const client = await kcAdminClient.clients.findOne({
id: clientUniqueId,
});
// not sure why entity from list api will not have property: authorizationServicesEnabled
expect(client).to.deep.include(currentClient);
});
it('update single client', async () => {
const {clientId, id: clientUniqueId} = currentClient;
await kcAdminClient.clients.update(
{id: clientUniqueId!},
{
// clientId is required in client update. no idea why...
clientId,
description: 'test',
},
);
const client = await kcAdminClient.clients.findOne({
id: clientUniqueId!,
});
expect(client).to.include({
description: 'test',
});
});
it('delete single client', async () => {
// create another one for delete test
const clientId = faker.internet.userName();
const {id} = await kcAdminClient.clients.create({
clientId,
});
// delete it
await kcAdminClient.clients.del({
id,
});
const delClient = await kcAdminClient.clients.findOne({
id,
});
expect(delClient).to.be.null;
});
/**
* client roles
*/
describe('client roles', () => {
before(async () => {
const roleName = faker.internet.userName();
// create a client role
const {roleName: createdRoleName} =
await kcAdminClient.clients.createRole({
id: currentClient.id,
name: roleName,
});
expect(createdRoleName).to.be.equal(roleName);
// assign currentClientRole
currentRoleName = roleName;
});
after(async () => {
// delete client role
await kcAdminClient.clients.delRole({
id: currentClient.id!,
roleName: currentRoleName,
});
});
it('list the client roles', async () => {
const roles = await kcAdminClient.clients.listRoles({
id: currentClient.id!,
});
expect(roles[0]).to.include({
name: currentRoleName,
});
});
it('find the client role', async () => {
const role = await kcAdminClient.clients.findRole({
id: currentClient.id!,
roleName: currentRoleName,
});
expect(role).to.include({
name: currentRoleName,
clientRole: true,
containerId: currentClient.id,
});
});
it('update the client role', async () => {
// NOTICE: roleName MUST be in the payload, no idea why...
const delta = {
name: currentRoleName,
description: 'test',
};
await kcAdminClient.clients.updateRole(
{
id: currentClient.id!,
roleName: currentRoleName,
},
delta,
);
// check the change
const role = await kcAdminClient.clients.findRole({
id: currentClient.id!,
roleName: currentRoleName,
});
expect(role).to.include(delta);
});
it('delete a client role', async () => {
const roleName = faker.internet.userName();
// create a client role
await kcAdminClient.clients.createRole({
id: currentClient.id,
name: roleName,
});
// delete
await kcAdminClient.clients.delRole({
id: currentClient.id!,
roleName,
});
// check it's null
const role = await kcAdminClient.clients.findRole({
id: currentClient.id!,
roleName,
});
expect(role).to.be.null;
});
});
describe('client secret', () => {
before(async () => {
const {clientId, id: clientUniqueId} = currentClient;
// update with serviceAccountsEnabled: true
await kcAdminClient.clients.update(
{
id: clientUniqueId!,
},
{
clientId,
serviceAccountsEnabled: true,
},
);
});
it('get client secret', async () => {
const credential = await kcAdminClient.clients.getClientSecret({
id: currentClient.id!,
});
expect(credential).to.have.all.keys('type', 'value');
});
it('generate new client secret', async () => {
const newCredential = await kcAdminClient.clients.generateNewClientSecret(
{
id: currentClient.id!,
},
);
const credential = await kcAdminClient.clients.getClientSecret({
id: currentClient.id!,
});
expect(newCredential).to.be.eql(credential);
});
it('generate new registration access token', async () => {
const newRegistrationAccessToken =
await kcAdminClient.clients.generateRegistrationAccessToken({
id: currentClient.id!,
});
expect(newRegistrationAccessToken).to.be.ok;
});
it('get installation providers', async () => {
const installationProvider =
await kcAdminClient.clients.getInstallationProviders({
id: currentClient.id!,
providerId: 'keycloak-oidc-jboss-subsystem',
});
expect(installationProvider).to.be.ok;
expect(typeof installationProvider).to.be.equal('string');
});
it('get service account user', async () => {
const serviceAccountUser =
await kcAdminClient.clients.getServiceAccountUser({
id: currentClient.id!,
});
expect(serviceAccountUser).to.be.ok;
});
});
describe('default client scopes', () => {
let dummyClientScope: ClientScopeRepresentation;
beforeEach(async () => {
dummyClientScope = {
name: 'does-anyone-read-this',
description: 'Oh - seems like you are reading Hey there!',
protocol: 'openid-connect',
};
// setup dummy client scope
await kcAdminClient.clientScopes.create(dummyClientScope);
currentClientScope = (await kcAdminClient.clientScopes.findOneByName({
name: dummyClientScope.name!,
}))!;
});
afterEach(async () => {
// cleanup default scopes
try {
const {id} = currentClient;
const {id: clientScopeId} = currentClientScope;
await kcAdminClient.clients.delDefaultClientScope({
clientScopeId: clientScopeId!,
id: id!,
});
} catch (e) {
// ignore
}
// cleanup client scopes
try {
await kcAdminClient.clientScopes.delByName({
name: dummyClientScope.name!,
});
} catch (e) {
// ignore
}
});
it('list default client scopes', async () => {
const defaultClientScopes =
await kcAdminClient.clients.listDefaultClientScopes({
id: currentClient.id!,
});
expect(defaultClientScopes).to.be.ok;
});
it('add default client scope', async () => {
const {id} = currentClient;
const {id: clientScopeId} = currentClientScope;
await kcAdminClient.clients.addDefaultClientScope({
id: id!,
clientScopeId: clientScopeId!,
});
const defaultScopes = await kcAdminClient.clients.listDefaultClientScopes(
{id: id!},
);
expect(defaultScopes).to.be.ok;
const clientScope = defaultScopes.find(
(scope) => scope.id === clientScopeId,
);
expect(clientScope).to.be.ok;
});
it('delete default client scope', async () => {
const {id} = currentClient;
const {id: clientScopeId} = currentClientScope;
await kcAdminClient.clients.addDefaultClientScope({
id: id!,
clientScopeId: clientScopeId!,
});
await kcAdminClient.clients.delDefaultClientScope({
id: id!,
clientScopeId: clientScopeId!,
});
const defaultScopes = await kcAdminClient.clients.listDefaultClientScopes(
{id: id!},
);
const clientScope = defaultScopes.find(
(scope) => scope.id === clientScopeId,
);
expect(clientScope).not.to.be.ok;
});
});
describe('optional client scopes', () => {
let dummyClientScope: ClientScopeRepresentation;
beforeEach(async () => {
dummyClientScope = {
name: 'i-hope-your-well',
description: 'Everyone has that one friend.',
protocol: 'openid-connect',
};
// setup dummy client scope
await kcAdminClient.clientScopes.create(dummyClientScope);
currentClientScope = (await kcAdminClient.clientScopes.findOneByName({
name: dummyClientScope.name!,
}))!;
});
afterEach(async () => {
// cleanup optional scopes
try {
const {id} = currentClient;
const {id: clientScopeId} = currentClientScope;
await kcAdminClient.clients.delOptionalClientScope({
clientScopeId: clientScopeId!,
id: id!,
});
} catch (e) {
// ignore
}
// cleanup client scopes
try {
await kcAdminClient.clientScopes.delByName({
name: dummyClientScope.name!,
});
} catch (e) {
// ignore
}
});
it('list optional client scopes', async () => {
const optionalClientScopes =
await kcAdminClient.clients.listOptionalClientScopes({
id: currentClient.id!,
});
expect(optionalClientScopes).to.be.ok;
});
it('add optional client scope', async () => {
const {id} = currentClient;
const {id: clientScopeId} = currentClientScope;
await kcAdminClient.clients.addOptionalClientScope({
id: id!,
clientScopeId: clientScopeId!,
});
const optionalScopes =
await kcAdminClient.clients.listOptionalClientScopes({id: id!});
expect(optionalScopes).to.be.ok;
const clientScope = optionalScopes.find(
(scope) => scope.id === clientScopeId,
);
expect(clientScope).to.be.ok;
});
it('delete optional client scope', async () => {
const {id} = currentClient;
const {id: clientScopeId} = currentClientScope;
await kcAdminClient.clients.addOptionalClientScope({
id: id!,
clientScopeId: clientScopeId!,
});
await kcAdminClient.clients.delOptionalClientScope({
id: id!,
clientScopeId: clientScopeId!,
});
const optionalScopes =
await kcAdminClient.clients.listOptionalClientScopes({id: id!});
const clientScope = optionalScopes.find(
(scope) => scope.id === clientScopeId,
);
expect(clientScope).not.to.be.ok;
});
});
describe('protocol mappers', () => {
let dummyMapper: ProtocolMapperRepresentation;
beforeEach(() => {
dummyMapper = {
name: 'become-a-farmer',
protocol: 'openid-connect',
protocolMapper: 'oidc-role-name-mapper',
config: {
role: 'admin',
'new.role.name': 'farmer',
},
};
});
afterEach(async () => {
try {
const {id: clientUniqueId} = currentClient;
const {id: mapperId} =
(await kcAdminClient.clients.findProtocolMapperByName({
id: clientUniqueId!,
name: dummyMapper.name!,
}))!;
await kcAdminClient.clients.delProtocolMapper({
id: clientUniqueId!,
mapperId: mapperId!,
});
} catch (e) {
// ignore
}
});
it('list protocol mappers', async () => {
const {id} = currentClient;
const mapperList = await kcAdminClient.clients.listProtocolMappers({
id: id!,
});
expect(mapperList).to.be.ok;
});
it('add multiple protocol mappers', async () => {
const {id} = currentClient;
await kcAdminClient.clients.addMultipleProtocolMappers({id: id!}, [
dummyMapper,
]);
const mapper = (await kcAdminClient.clients.findProtocolMapperByName({
id: id!,
name: dummyMapper.name!,
}))!;
expect(mapper).to.be.ok;
expect(mapper.protocol).to.eq(dummyMapper.protocol);
expect(mapper.protocolMapper).to.eq(dummyMapper.protocolMapper);
});
it('add single protocol mapper', async () => {
const {id} = currentClient;
await kcAdminClient.clients.addProtocolMapper({id: id!}, dummyMapper);
const mapper = (await kcAdminClient.clients.findProtocolMapperByName({
id: id!,
name: dummyMapper.name!,
}))!;
expect(mapper).to.be.ok;
expect(mapper.protocol).to.eq(dummyMapper.protocol);
expect(mapper.protocolMapper).to.eq(dummyMapper.protocolMapper);
});
it('find protocol mapper by id', async () => {
const {id} = currentClient;
await kcAdminClient.clients.addProtocolMapper({id: id!}, dummyMapper);
const {id: mapperId} =
(await kcAdminClient.clients.findProtocolMapperByName({
id: id!,
name: dummyMapper.name!,
}))!;
const mapper = await kcAdminClient.clients.findProtocolMapperById({
mapperId: mapperId!,
id: id!,
});
expect(mapper).to.be.ok;
expect(mapper.id).to.eql(mapperId);
});
it('find protocol mapper by name', async () => {
const {id} = currentClient;
await kcAdminClient.clients.addProtocolMapper({id: id!}, dummyMapper);
const mapper = (await kcAdminClient.clients.findProtocolMapperByName({
id: id!,
name: dummyMapper.name!,
}))!;
expect(mapper).to.be.ok;
expect(mapper.name).to.eql(dummyMapper.name);
});
it('find protocol mappers by protocol', async () => {
const {id} = currentClient;
await kcAdminClient.clients.addProtocolMapper({id: id!}, dummyMapper);
const mapperList =
await kcAdminClient.clients.findProtocolMappersByProtocol({
id: id!,
protocol: dummyMapper.protocol!,
});
expect(mapperList).to.be.ok;
expect(mapperList.length).to.be.gte(1);
const mapper = mapperList.find((item) => item.name === dummyMapper.name);
expect(mapper).to.be.ok;
});
it('update protocol mapper', async () => {
const {id} = currentClient;
dummyMapper.config = {'access.token.claim': 'true'};
await kcAdminClient.clients.addProtocolMapper({id: id!}, dummyMapper);
const mapper = (await kcAdminClient.clients.findProtocolMapperByName({
id: id!,
name: dummyMapper.name!,
}))!;
expect(mapper.config!['access.token.claim']).to.eq('true');
mapper.config = {'access.token.claim': 'false'};
await kcAdminClient.clients.updateProtocolMapper(
{id: id!, mapperId: mapper.id!},
mapper,
);
const updatedMapper =
(await kcAdminClient.clients.findProtocolMapperByName({
id: id!,
name: dummyMapper.name!,
}))!;
expect(updatedMapper.config!['access.token.claim']).to.eq('false');
});
it('delete protocol mapper', async () => {
const {id} = currentClient;
await kcAdminClient.clients.addProtocolMapper({id: id!}, dummyMapper);
const {id: mapperId} =
(await kcAdminClient.clients.findProtocolMapperByName({
id: id!,
name: dummyMapper.name!,
}))!;
await kcAdminClient.clients.delProtocolMapper({
id: id!,
mapperId: mapperId!,
});
const mapper = await kcAdminClient.clients.findProtocolMapperByName({
id: id!,
name: dummyMapper.name!,
});
expect(mapper).not.to.be.ok;
});
});
describe('scope mappings', () => {
it('list client and realm scope mappings', async () => {
const {id} = currentClient;
const scopes = await kcAdminClient.clients.listScopeMappings({
id: id!,
});
expect(scopes).to.be.ok;
});
describe('client', () => {
const dummyRoleName = 'clientScopeMappingsRole-dummy';
beforeEach(async () => {
const {id} = currentClient;
await kcAdminClient.clients.createRole({
id,
name: dummyRoleName,
});
});
afterEach(async () => {
try {
const {id} = currentClient;
await kcAdminClient.clients.delRole({
id: id!,
roleName: dummyRoleName,
});
} catch (e) {
// ignore
}
});
it('add scope mappings', async () => {
const {id: clientUniqueId} = currentClient;
const availableRoles =
await kcAdminClient.clients.listAvailableClientScopeMappings({
id: clientUniqueId!,
client: clientUniqueId!,
});
await kcAdminClient.clients.addClientScopeMappings(
{
id: clientUniqueId!,
client: clientUniqueId!,
},
availableRoles,
);
const roles = await kcAdminClient.clients.listClientScopeMappings({
id: clientUniqueId!,
client: clientUniqueId!,
});
expect(roles).to.be.ok;
expect(roles).to.be.eql(availableRoles);
});
it('list scope mappings', async () => {
const {id: clientUniqueId} = currentClient;
const roles = await kcAdminClient.clients.listClientScopeMappings({
id: clientUniqueId!,
client: clientUniqueId!,
});
expect(roles).to.be.ok;
});
it('list available scope mappings', async () => {
const {id: clientUniqueId} = currentClient;
const roles =
await kcAdminClient.clients.listAvailableClientScopeMappings({
id: clientUniqueId!,
client: clientUniqueId!,
});
expect(roles).to.be.ok;
});
it('list composite scope mappings', async () => {
const {id: clientUniqueId} = currentClient;
const roles =
await kcAdminClient.clients.listCompositeClientScopeMappings({
id: clientUniqueId!,
client: clientUniqueId!,
});
expect(roles).to.be.ok;
});
it('delete scope mappings', async () => {
const {id: clientUniqueId} = currentClient;
const rolesBefore = await kcAdminClient.clients.listClientScopeMappings(
{
id: clientUniqueId!,
client: clientUniqueId!,
},
);
await kcAdminClient.clients.delClientScopeMappings(
{
id: clientUniqueId!,
client: clientUniqueId!,
},
rolesBefore,
);
const rolesAfter = await kcAdminClient.clients.listClientScopeMappings({
id: clientUniqueId!,
client: clientUniqueId!,
});
expect(rolesAfter).to.be.ok;
expect(rolesAfter).to.eql([]);
});
it('get effective scope mapping of all roles for a specific container', async () => {
const {id: clientUniqueId} = currentClient;
const roles = await kcAdminClient.clients.evaluatePermission({
id: clientUniqueId!,
roleContainer: 'master',
type: 'granted',
scope: 'openid',
});
expect(roles).to.be.ok;
expect(roles.length).to.be.eq(5);
});
it('get list of all protocol mappers', async () => {
const {id: clientUniqueId} = currentClient;
const protocolMappers =
await kcAdminClient.clients.evaluateListProtocolMapper({
id: clientUniqueId!,
scope: 'openid',
});
expect(protocolMappers).to.be.ok;
expect(protocolMappers.length).to.be.gt(10);
});
it('get JSON with payload of example access token', async () => {
const {id: clientUniqueId} = currentClient;
const username = faker.internet.userName();
const user = await kcAdminClient.users.create({
username,
});
const accessToken =
await kcAdminClient.clients.evaluateGenerateAccessToken({
id: clientUniqueId!,
userId: user.id,
scope: 'openid',
});
expect(accessToken).to.be.ok;
await kcAdminClient.users.del({id: user.id});
});
});
describe('realm', () => {
const dummyRoleName = 'realmScopeMappingsRole-dummy';
beforeEach(async () => {
await kcAdminClient.roles.create({
name: dummyRoleName,
});
});
afterEach(async () => {
try {
await kcAdminClient.roles.delByName({
name: dummyRoleName,
});
} catch (e) {
// ignore
}
});
it('add scope mappings', async () => {
const {id} = currentClient;
const availableRoles =
await kcAdminClient.clients.listAvailableRealmScopeMappings({
id: id!,
});
await kcAdminClient.clients.addRealmScopeMappings(
{id: id!},
availableRoles,
);
const roles = await kcAdminClient.clients.listRealmScopeMappings({
id: id!,
});
expect(roles).to.be.ok;
expect(roles).to.deep.members(availableRoles);
});
it('list scope mappings', async () => {
const {id} = currentClient;
const roles = await kcAdminClient.clients.listRealmScopeMappings({
id: id!,
});
expect(roles).to.be.ok;
});
it('list available scope mappings', async () => {
const {id} = currentClient;
const roles =
await kcAdminClient.clients.listAvailableRealmScopeMappings({
id: id!,
});
expect(roles).to.be.ok;
});
it('list composite scope mappings', async () => {
const {id} = currentClient;
const roles =
await kcAdminClient.clients.listCompositeRealmScopeMappings({
id: id!,
});
expect(roles).to.be.ok;
});
it('delete scope mappings', async () => {
const {id} = currentClient;
const rolesBefore = await kcAdminClient.clients.listRealmScopeMappings({
id: id!,
});
await kcAdminClient.clients.delRealmScopeMappings(
{id: id!},
rolesBefore,
);
const rolesAfter = await kcAdminClient.clients.listRealmScopeMappings({
id: id!,
});
expect(rolesAfter).to.be.ok;
expect(rolesAfter).to.eql([]);
});
});
});
describe('sessions', () => {
it('list clients user sessions', async () => {
const clientUniqueId = currentClient.id;
const userSessions = await kcAdminClient.clients.listSessions({
id: clientUniqueId!,
});
expect(userSessions).to.be.ok;
});
it('list clients offline user sessions', async () => {
const clientUniqueId = currentClient.id;
const userSessions = await kcAdminClient.clients.listOfflineSessions({
id: clientUniqueId!,
});
expect(userSessions).to.be.ok;
});
it('list clients user session count', async () => {
const clientUniqueId = currentClient.id;
const userSessions = await kcAdminClient.clients.getSessionCount({
id: clientUniqueId!,
});
expect(userSessions).to.be.ok;
});
it('list clients offline user session count', async () => {
const clientUniqueId = currentClient.id;
const userSessions = await kcAdminClient.clients.getOfflineSessionCount({
id: clientUniqueId!,
});
expect(userSessions).to.be.ok;
});
});
describe('nodes', () => {
const host = '127.0.0.1';
it('register a node manually', async () => {
await kcAdminClient.clients.addClusterNode({
id: currentClient.id!,
node: host,
});
const client = (await kcAdminClient.clients.findOne({
id: currentClient.id!,
}))!;
expect(Object.keys(client.registeredNodes!)).to.be.eql([host]);
});
it('remove registered host', async () => {
await kcAdminClient.clients.deleteClusterNode({
id: currentClient.id!,
node: host,
});
const client = (await kcAdminClient.clients.findOne({
id: currentClient.id!,
}))!;
expect(client.registeredNodes).to.be.undefined;
});
});
describe('client attribute certificate', () => {
const keystoreConfig = {
format: 'JKS',
keyAlias: 'new',
keyPassword: 'password',
realmAlias: 'master',
realmCertificate: false,
storePassword: 'password',
};
const attr = 'jwt.credential';
it('generate and download keys', async () => {
const result = await kcAdminClient.clients.generateAndDownloadKey(
{id: currentClient.id!, attr},
keystoreConfig,
);
expect(result).to.be.ok;
});
it('generate key and updated info', async () => {
const certificate = await kcAdminClient.clients.generateKey({
id: currentClient.id!,
attr,
});
expect(certificate).to.be.ok;
expect(certificate.certificate).to.be.ok;
const info = await kcAdminClient.clients.getKeyInfo({
id: currentClient.id!,
attr,
});
expect(info).to.be.eql(certificate);
});
it('download key', async () => {
const result = await kcAdminClient.clients.downloadKey(
{id: currentClient.id!, attr},
keystoreConfig,
);
expect(result).to.be.ok;
});
});
describe('authorization', async () => {
const resourceConfig = {
name: 'testResourceName',
type: 'testResourceType',
scopeNames: ['testScopeA', 'testScopeB', 'testScopeC'],
};
const policyConfig = {
name: 'testPolicyName',
type: 'user',
logic: Logic.POSITIVE,
};
const permissionConfig = {
name: 'testPermissionName',
type: 'scope',
logic: Logic.POSITIVE,
};
let scopes: ScopeRepresentation[];
let resource: ResourceRepresentation;
let policy: PolicyRepresentation;
let permission: PolicyRepresentation;
let user: UserRepresentation;
before('enable authorization services', async () => {
await kcAdminClient.clients.update(
{id: currentClient.id!},
{
clientId: currentClient.clientId,
authorizationServicesEnabled: true,
serviceAccountsEnabled: true,
},
);
});