keycloak-admin 2.0.1 → 2.0.2

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.
Files changed (70) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +13 -0
  3. data/README.md +40 -4
  4. data/keycloak-admin.gemspec +14 -6
  5. data/lib/keycloak-admin/client/client.rb +22 -10
  6. data/lib/keycloak-admin/client/client_authz_permission_client.rb +1 -1
  7. data/lib/keycloak-admin/client/client_authz_policy_client.rb +1 -1
  8. data/lib/keycloak-admin/client/client_authz_resource_client.rb +1 -1
  9. data/lib/keycloak-admin/client/client_authz_scope_client.rb +1 -1
  10. data/lib/keycloak-admin/client/group_client.rb +2 -5
  11. data/lib/keycloak-admin/client/organization_client.rb +7 -7
  12. data/lib/keycloak-admin/client/user_client.rb +8 -4
  13. data/lib/keycloak-admin/error.rb +62 -0
  14. data/lib/keycloak-admin/version.rb +1 -1
  15. data/lib/keycloak-admin.rb +1 -0
  16. metadata +21 -56
  17. data/.github/workflows/Dockerfile +0 -24
  18. data/.github/workflows/ci.yml +0 -94
  19. data/.github/workflows/release.yml +0 -112
  20. data/.gitignore +0 -10
  21. data/.rspec +0 -2
  22. data/Dockerfile +0 -13
  23. data/Gemfile +0 -3
  24. data/Gemfile.lock +0 -54
  25. data/Rakefile +0 -6
  26. data/bin/console +0 -9
  27. data/spec/client/attack_detection_client_spec.rb +0 -102
  28. data/spec/client/client_authz_permission_client_spec.rb +0 -170
  29. data/spec/client/client_authz_policy_client_spec.rb +0 -170
  30. data/spec/client/client_authz_resource_client_spec.rb +0 -150
  31. data/spec/client/client_authz_scope_client_spec.rb +0 -134
  32. data/spec/client/client_client_spec.rb +0 -133
  33. data/spec/client/client_role_mappings_client_spec.rb +0 -83
  34. data/spec/client/client_scope_client_spec.rb +0 -220
  35. data/spec/client/client_scope_protocol_mapper_client_spec.rb +0 -230
  36. data/spec/client/client_spec.rb +0 -101
  37. data/spec/client/configurable_token_client_spec.rb +0 -34
  38. data/spec/client/group_client_spec.rb +0 -328
  39. data/spec/client/identity_provider_client_spec.rb +0 -92
  40. data/spec/client/organization_client_spec.rb +0 -595
  41. data/spec/client/realm_client_spec.rb +0 -155
  42. data/spec/client/resource_spec.rb +0 -223
  43. data/spec/client/response_spec.rb +0 -68
  44. data/spec/client/role_client_spec.rb +0 -79
  45. data/spec/client/role_mapper_client_spec.rb +0 -113
  46. data/spec/client/token_client_spec.rb +0 -68
  47. data/spec/client/user_client_spec.rb +0 -418
  48. data/spec/configuration_spec.rb +0 -150
  49. data/spec/gemspec_spec.rb +0 -25
  50. data/spec/integration/client_authorization_spec.rb +0 -93
  51. data/spec/representation/attack_detection_representation_spec.rb +0 -16
  52. data/spec/representation/client_authz_permission_representation_spec.rb +0 -52
  53. data/spec/representation/client_authz_policy_representation_spec.rb +0 -47
  54. data/spec/representation/client_authz_resource_representation_spec.rb +0 -33
  55. data/spec/representation/client_authz_scope_representation_spec.rb +0 -19
  56. data/spec/representation/client_representation_spec.rb +0 -119
  57. data/spec/representation/client_scope_representation_spec.rb +0 -125
  58. data/spec/representation/credential_representation_spec.rb +0 -68
  59. data/spec/representation/group_representation_spec.rb +0 -22
  60. data/spec/representation/identity_provider_mapper_representation_spec.rb +0 -24
  61. data/spec/representation/identity_provider_representation_spec.rb +0 -113
  62. data/spec/representation/impersonation_representation_spec.rb +0 -163
  63. data/spec/representation/organization_representation_spec.rb +0 -64
  64. data/spec/representation/protocol_mapper_representation_spec.rb +0 -57
  65. data/spec/representation/role_representation_spec.rb +0 -37
  66. data/spec/representation/session_representation_spec.rb +0 -16
  67. data/spec/representation/user_representation_spec.rb +0 -15
  68. data/spec/resource/group_resource_spec.rb +0 -14
  69. data/spec/resource/user_resource_spec.rb +0 -14
  70. data/spec/spec_helper.rb +0 -36
@@ -1,68 +0,0 @@
1
- RSpec.describe KeycloakAdmin::TokenClient do
2
- describe "#initialize" do
3
- let(:realm_name) { nil }
4
- before(:each) do
5
- @realm = KeycloakAdmin.realm(realm_name)
6
- end
7
-
8
- context "when realm_name is defined" do
9
- let(:realm_name) { "master" }
10
- it "does not raise any error" do
11
- expect {
12
- @realm.token
13
- }.to_not raise_error
14
- end
15
- end
16
-
17
- context "when realm_name is not defined" do
18
- let(:realm_name) { nil }
19
- it "raises any error" do
20
- expect {
21
- @realm.token
22
- }.to raise_error(ArgumentError)
23
- end
24
- end
25
- end
26
-
27
- describe "#token_url" do
28
- let(:realm_name) { "valid-realm" }
29
- before(:each) do
30
- @built_url = KeycloakAdmin.realm(realm_name).token.token_url
31
- end
32
-
33
- it "returns a proper url" do
34
- expect(@built_url).to eq "http://auth.service.io/auth/realms/valid-realm/protocol/openid-connect/token"
35
- end
36
- end
37
-
38
- describe "#get" do
39
- let(:realm_name) { "valid-realm" }
40
- before(:each) do
41
- @token_client = KeycloakAdmin.realm(realm_name).token
42
- end
43
-
44
- it "parses the response" do
45
- stub_post
46
-
47
- token = @token_client.get
48
- expect(token.access_token).to eq 'test_access_token'
49
- end
50
-
51
- it "passes rest client options" do
52
- faraday_options = {timeout: 10}
53
- allow_any_instance_of(KeycloakAdmin::Configuration).to receive(:faraday_options).and_return faraday_options
54
- stub_post
55
-
56
- expect(KeycloakAdmin::Resource).to receive(:new).with(
57
- "http://auth.service.io/auth/realms/valid-realm/protocol/openid-connect/token", faraday_options, anything).and_call_original
58
-
59
- @token_client.get
60
- end
61
-
62
- def stub_post
63
- response = double
64
- allow(response).to receive(:body).and_return '{"access_token":"test_access_token"}'
65
- allow_any_instance_of(KeycloakAdmin::Resource).to receive(:post).and_return response
66
- end
67
- end
68
- end
@@ -1,418 +0,0 @@
1
- RSpec.describe KeycloakAdmin::TokenClient do
2
- describe "#initialize" do
3
- let(:realm_name) { nil }
4
- before(:each) do
5
- @realm = KeycloakAdmin.realm(realm_name)
6
- end
7
-
8
- context "when realm_name is defined" do
9
- let(:realm_name) { "master" }
10
- it "does not raise any error" do
11
- expect {
12
- @realm.users
13
- }.to_not raise_error
14
- end
15
- end
16
-
17
- context "when realm_name is not defined" do
18
- let(:realm_name) { nil }
19
- it "raises any error" do
20
- expect {
21
- @realm.users
22
- }.to raise_error(ArgumentError)
23
- end
24
- end
25
- end
26
-
27
- describe "#users_url" do
28
- let(:realm_name) { "valid-realm" }
29
- let(:user_id) { nil }
30
-
31
- before(:each) do
32
- @built_url = KeycloakAdmin.realm(realm_name).users.users_url(user_id)
33
- end
34
-
35
- context "when user_id is not defined" do
36
- let(:user_id) { nil }
37
- it "return a proper url without user id" do
38
- expect(@built_url).to eq "http://auth.service.io/auth/admin/realms/valid-realm/users"
39
- end
40
- end
41
-
42
- context "when user_id is defined" do
43
- let(:user_id) { "95985b21-d884-4bbd-b852-cb8cd365afc2" }
44
- it "return a proper url with the user id" do
45
- expect(@built_url).to eq "http://auth.service.io/auth/admin/realms/valid-realm/users/95985b21-d884-4bbd-b852-cb8cd365afc2"
46
- end
47
- end
48
- end
49
-
50
- describe "#reset_password_url" do
51
- let(:realm_name) { "valid-realm" }
52
- let(:user_id) { nil }
53
-
54
- before(:each) do
55
- @client = KeycloakAdmin.realm(realm_name).users
56
- end
57
-
58
- context "when user_id is not defined" do
59
- let(:user_id) { nil }
60
- it "raises an error" do
61
- expect {
62
- @client.reset_password_url(user_id)
63
- }.to raise_error(ArgumentError)
64
- end
65
- end
66
-
67
- context "when user_id is defined" do
68
- let(:user_id) { 42 }
69
- it "return a proper url" do
70
- expect(@client.reset_password_url(user_id)).to eq "http://auth.service.io/auth/admin/realms/valid-realm/users/42/reset-password"
71
- end
72
- end
73
- end
74
-
75
- describe "#execute_actions_email_url" do
76
- let(:realm_name) { "valid-realm" }
77
- let(:user_id) { nil }
78
-
79
- before(:each) do
80
- @client = KeycloakAdmin.realm(realm_name).users
81
- end
82
-
83
- context "when user_id is not defined" do
84
- let(:user_id) { nil }
85
- it "raises an error" do
86
- expect {
87
- @client.execute_actions_email_url(user_id)
88
- }.to raise_error(ArgumentError)
89
- end
90
- end
91
-
92
- context "when user_id is defined" do
93
- let(:user_id) { 42 }
94
- it "return a proper url" do
95
- expect(@client.execute_actions_email_url(user_id)).to eq "http://auth.service.io/auth/admin/realms/valid-realm/users/42/execute-actions-email"
96
- end
97
- end
98
- end
99
-
100
- describe "#impersonation_url" do
101
- let(:realm_name) { "valid-realm" }
102
- let(:user_id) { nil }
103
-
104
- before(:each) do
105
- @client = KeycloakAdmin.realm(realm_name).users
106
- end
107
-
108
- context "when user_id is not defined" do
109
- let(:user_id) { nil }
110
- it "raises an error" do
111
- expect {
112
- @client.impersonation_url(user_id)
113
- }.to raise_error(ArgumentError)
114
- end
115
- end
116
-
117
- context "when user_id is defined" do
118
- let(:user_id) { 42 }
119
- it "return a proper url" do
120
- expect(@client.impersonation_url(user_id)).to eq "http://auth.service.io/auth/admin/realms/valid-realm/users/42/impersonation"
121
- end
122
- end
123
- end
124
-
125
- describe "#save" do
126
- let(:realm_name) { "valid-realm" }
127
- let(:user) { KeycloakAdmin::UserRepresentation.from_hash(
128
- "username" => "test_username",
129
- "createdTimestamp" => Time.now.to_i,
130
- )}
131
-
132
- before(:each) do
133
- @user_client = KeycloakAdmin.realm(realm_name).users
134
-
135
- stub_token_client
136
- allow_any_instance_of(KeycloakAdmin::Resource).to receive(:post)
137
- end
138
-
139
- it "saves a user" do
140
- expect(@user_client.save(user)).to eq user
141
- end
142
-
143
- it "passes rest client options" do
144
- faraday_options = {timeout: 10}
145
- allow_any_instance_of(KeycloakAdmin::Configuration).to receive(:faraday_options).and_return faraday_options
146
-
147
- expect(KeycloakAdmin::Resource).to receive(:new).with(
148
- "http://auth.service.io/auth/admin/realms/valid-realm/users", faraday_options, anything).and_call_original
149
-
150
- expect(@user_client.save(user)).to eq user
151
- end
152
- end
153
-
154
- describe "#get" do
155
- let(:realm_name) { "valid-realm" }
156
-
157
- before(:each) do
158
- @user_client = KeycloakAdmin.realm(realm_name).users
159
-
160
- stub_token_client
161
- allow_any_instance_of(KeycloakAdmin::Resource).to receive(:get).and_return '{"username":"test_username","createdTimestamp":1559347200, "requiredActions":["CONFIGURE_TOTP"], "totp": true}'
162
- end
163
-
164
- it "parses the response" do
165
- user = @user_client.get('test_user_id')
166
- expect(user.username).to eq 'test_username'
167
- end
168
-
169
- it "passes rest client options" do
170
- faraday_options = {timeout: 10}
171
- allow_any_instance_of(KeycloakAdmin::Configuration).to receive(:faraday_options).and_return faraday_options
172
-
173
- expect(KeycloakAdmin::Resource).to receive(:new).with(
174
- "http://auth.service.io/auth/admin/realms/valid-realm/users/test_user_id", faraday_options, anything).and_call_original
175
-
176
- user = @user_client.get('test_user_id')
177
- expect(user.username).to eq 'test_username'
178
- expect(user.totp).to be true
179
- expect(user.required_actions).to eq ["CONFIGURE_TOTP"]
180
- end
181
- end
182
-
183
- describe "#search" do
184
- let(:realm_name) { "valid-realm" }
185
- let(:user) { KeycloakAdmin::UserRepresentation.from_hash(
186
- "username" => "test_username",
187
- "createdTimestamp" => Time.now.to_i,
188
- )}
189
-
190
- before(:each) do
191
- @user_client = KeycloakAdmin.realm(realm_name).users
192
-
193
- stub_token_client
194
- allow_any_instance_of(KeycloakAdmin::Resource).to receive(:get).and_return '[{"username":"test_username","createdTimestamp":1559347200}]'
195
- end
196
-
197
- it "finds a user using a string" do
198
- users = @user_client.search("test_username")
199
- expect(users.length).to eq 1
200
- expect(users[0].username).to eq "test_username"
201
- end
202
-
203
- it "finds a user using nil does not fail" do
204
- users = @user_client.search(nil)
205
- expect(users.length).to eq 1
206
- expect(users[0].username).to eq "test_username"
207
- end
208
-
209
- it "finds a user using a hash" do
210
- users = @user_client.search({ search: "test_username"})
211
- expect(users.length).to eq 1
212
- expect(users[0].username).to eq "test_username"
213
- end
214
-
215
- it "passes rest client options" do
216
- faraday_options = {timeout: 10}
217
- allow_any_instance_of(KeycloakAdmin::Configuration).to receive(:faraday_options).and_return faraday_options
218
-
219
- expect(KeycloakAdmin::Resource).to receive(:new).with(
220
- "http://auth.service.io/auth/admin/realms/valid-realm/users", faraday_options, anything).and_call_original
221
-
222
- users = @user_client.search("test_username")
223
- expect(users.length).to eq 1
224
- expect(users[0].username).to eq "test_username"
225
- end
226
- end
227
-
228
- describe "#list" do
229
- let(:realm_name) { "valid-realm" }
230
- let(:user) { KeycloakAdmin::UserRepresentation.from_hash(
231
- "username" => "test_username",
232
- "createdTimestamp" => Time.now.to_i,
233
- )}
234
-
235
- before(:each) do
236
- @user_client = KeycloakAdmin.realm(realm_name).users
237
-
238
- stub_token_client
239
- allow_any_instance_of(KeycloakAdmin::Resource).to receive(:get).and_return '[{"username":"test_username","createdTimestamp":1559347200}]'
240
- end
241
-
242
- it "lists users" do
243
- users = @user_client.list
244
- expect(users.length).to eq 1
245
- expect(users[0].username).to eq "test_username"
246
- end
247
-
248
- it "passes rest client options" do
249
- faraday_options = {timeout: 10}
250
- allow_any_instance_of(KeycloakAdmin::Configuration).to receive(:faraday_options).and_return faraday_options
251
-
252
- expect(KeycloakAdmin::Resource).to receive(:new).with(
253
- "http://auth.service.io/auth/admin/realms/valid-realm/users", faraday_options, anything).and_call_original
254
-
255
- users = @user_client.list
256
- expect(users.length).to eq 1
257
- expect(users[0].username).to eq "test_username"
258
- end
259
- end
260
-
261
- describe "#delete" do
262
- let(:realm_name) { "valid-realm" }
263
-
264
- before(:each) do
265
- @user_client = KeycloakAdmin.realm(realm_name).users
266
-
267
- stub_token_client
268
- allow_any_instance_of(KeycloakAdmin::Resource).to receive(:delete)
269
- end
270
-
271
- it "does not fail" do
272
- expect(@user_client.delete('test_user_id')).to be_truthy
273
- end
274
-
275
- it "passes rest client options" do
276
- faraday_options = {timeout: 10}
277
- allow_any_instance_of(KeycloakAdmin::Configuration).to receive(:faraday_options).and_return faraday_options
278
-
279
- expect(KeycloakAdmin::Resource).to receive(:new).with(
280
- "http://auth.service.io/auth/admin/realms/valid-realm/users/test_user_id", faraday_options, anything).and_call_original
281
-
282
- @user_client.delete('test_user_id')
283
- end
284
- end
285
-
286
- describe '#update' do
287
- let(:realm_name) { 'valid-realm' }
288
- before(:each) do
289
- @user_client = KeycloakAdmin.realm(realm_name).users
290
-
291
- stub_token_client
292
- allow(KeycloakAdmin::Resource).to receive(:execute).and_return "write a better test"
293
- end
294
-
295
- context 'when user_id is defined' do
296
- let(:user_id) { '95985b21-d884-4bbd-b852-cb8cd365afc2' }
297
-
298
- it 'updates the user details' do
299
- ## TODO use this expected payload to check whether it has been sent or not
300
- expected_payload = {
301
- method: :put,
302
- url: "http://auth.service.io/auth/admin/realms/valid-realm/users/95985b21-d884-4bbd-b852-cb8cd365afc2",
303
- payload: '{"firstName":"Test","enabled":false}',
304
- headers: {
305
- Authorization: "Bearer test_access_token",
306
- content_type: :json,
307
- accept: :json
308
- }
309
- }
310
- response = @user_client.update(user_id, { firstName: 'Test', enabled: false })
311
- expect(response).to eq "write a better test"
312
- end
313
- end
314
-
315
- context 'when user_id is not defined' do
316
- let(:user_id) { '95985b21-d884-4bbd-b852-cb8cd365afc2' }
317
-
318
- let(:user_id) { nil }
319
- it 'raise argument error' do
320
- expect { @user_client.update(user_id, { firstName: 'Test', enabled: false }) }.to raise_error(ArgumentError)
321
- end
322
- end
323
- end
324
-
325
- describe '#sessions' do
326
- let(:realm_name) { "valid-realm" }
327
-
328
- before(:each) do
329
- @user_client = KeycloakAdmin.realm(realm_name).users
330
- stub_token_client
331
- allow_any_instance_of(KeycloakAdmin::Resource).to receive(:get).and_return '[{"id":"95985b21-d884-4bbd-b852-dsfsdfsd","username":"test_username", "ip_address":"0.0.0.0"}]'
332
- end
333
-
334
- context 'when user_id is defined' do
335
- let(:user_id) { '95985b21-d884-4bbd-b852-cb8cd365afc2' }
336
- it 'returns list of active sessions' do
337
- response = @user_client.sessions(user_id)
338
- expect(response[0].id).to eq '95985b21-d884-4bbd-b852-dsfsdfsd'
339
- end
340
- end
341
-
342
- context 'when user_id is not defined' do
343
- let(:user_id) { nil }
344
- it 'raise argument error' do
345
- expect { @user_client.sessions(user_id) }.to raise_error(ArgumentError)
346
- end
347
- end
348
- end
349
-
350
- describe '#logout' do
351
- let(:realm_name) { 'valid-realm' }
352
-
353
- before(:each) do
354
- @user_client = KeycloakAdmin.realm(realm_name).users
355
- stub_token_client
356
- allow(KeycloakAdmin::Resource).to receive(:execute)
357
- end
358
-
359
- context 'when user_id is defined' do
360
- let(:user_id) { '95985b21-d884-4bbd-b852-cb8cd365afc2' }
361
- it 'logout user and return true' do
362
- expect(@user_client.logout(user_id)).to be_truthy
363
- end
364
- end
365
-
366
- context 'when user_id is not defined' do
367
- let(:user_id) { nil }
368
- it 'raise argument error' do
369
- expect { @user_client.logout(user_id) }.to raise_error(ArgumentError)
370
- end
371
- end
372
- end
373
-
374
- describe '#credentials' do
375
- let(:realm_name) { "valid-realm" }
376
-
377
- before(:each) do
378
- @user_client = KeycloakAdmin.realm(realm_name).users
379
- stub_token_client
380
- json_payload = <<-'payload'
381
- [
382
- {
383
- "id": "2ff4b4d0-fd72-4c6e-9684-02ab337687c2",
384
- "type": "password",
385
- "userLabel": "My password",
386
- "createdDate": 1767604673211,
387
- "credentialData": "{\"hashIterations\":5,\"algorithm\":\"argon2\",\"additionalParameters\":{\"hashLength\":[\"32\"],\"memory\":[\"7168\"],\"type\":[\"id\"],\"version\":[\"1.3\"],\"parallelism\":[\"1\"]}}"
388
- },
389
- {
390
- "id": "34389672-9356-4154-9ed6-6c212b869010",
391
- "type": "otp",
392
- "userLabel": "Smartphone",
393
- "createdDate": 1767605202060,
394
- "credentialData": "{\"subType\":\"totp\",\"digits\":6,\"counter\":0,\"period\":30,\"algorithm\":\"HmacSHA1\"}"
395
- }
396
- ]
397
- payload
398
- allow_any_instance_of(KeycloakAdmin::Resource).to receive(:get).and_return json_payload
399
- end
400
-
401
- context 'when user_id is defined' do
402
- let(:user_id) { '95985b21-d884-4bbd-b852-cb8cd365afc2' }
403
- it 'returns list of credentials' do
404
- response = @user_client.credentials(user_id)
405
- expect(response.size).to eq 2
406
- expect(response[0].id).to eq "2ff4b4d0-fd72-4c6e-9684-02ab337687c2"
407
- expect(response[1].id).to eq "34389672-9356-4154-9ed6-6c212b869010"
408
- end
409
- end
410
-
411
- context 'when user_id is not defined' do
412
- let(:user_id) { nil }
413
- it 'raise argument error' do
414
- expect { @user_client.credentials(user_id) }.to raise_error(ArgumentError)
415
- end
416
- end
417
- end
418
- end
@@ -1,150 +0,0 @@
1
- RSpec.describe KeycloakAdmin::RealmClient do
2
-
3
- let(:client_id) { "admin-cli" }
4
- let(:client_secret) { "aaaaaaaa" }
5
- let(:client_realm_name) { "master2" }
6
- let(:use_service_account) { true }
7
- let(:username) { "a" }
8
- let(:password) { "b" }
9
- let(:faraday_options) { {timeout: 10 } }
10
-
11
- before(:each) do
12
- @configuration = KeycloakAdmin::Configuration.new
13
- @configuration.server_url = "http://auth.service.io/auth"
14
- @configuration.server_domain = "auth.service.io"
15
- @configuration.client_id = client_id
16
- @configuration.client_secret = client_secret
17
- @configuration.client_realm_name = client_realm_name
18
- @configuration.use_service_account = use_service_account
19
- @configuration.username = username
20
- @configuration.password = password
21
- @configuration.faraday_options = faraday_options
22
- end
23
-
24
- describe "#headers_for_token_retrieval" do
25
- before(:each) do
26
- @headers = @configuration.headers_for_token_retrieval
27
- end
28
-
29
- context "when use_service_account is false" do
30
- let(:use_service_account) { false }
31
- it "returns an empty hash" do
32
- expect(@headers).to be_empty
33
- end
34
- end
35
-
36
- context "when use_service_account is true" do
37
- let(:use_service_account) { true }
38
- it "returns a single element" do
39
- expect(@headers.size).to eq 1
40
- end
41
-
42
- it "returns the Authorization Key" do
43
- expect(@headers.has_key?(:Authorization)).to be true
44
- end
45
-
46
- it "returns a Basic Authorization Key" do
47
- expect(@headers[:Authorization]).to start_with "Basic"
48
- end
49
-
50
- context "client_id='a' and client_secret='b'" do
51
- let(:client_id) { "a" }
52
- let(:client_secret) { "b" }
53
-
54
- it "returns a Basic Authorization = 'Basic YTpi'" do
55
- expect(@headers[:Authorization]).to eq "Basic YTpi"
56
- end
57
- end
58
-
59
- context "client_id='365e3c66-fd0f-11e7-8be5-0ed5f89f718b' and client_secret='411e6f9a-fd0f-11e7-8be5-0ed5f89f718b'" do
60
- let(:client_id) { "365e3c66-fd0f-11e7-8be5-0ed5f89f718b" }
61
- let(:client_secret) { "411e6f9a-fd0f-11e7-8be5-0ed5f89f718b" }
62
-
63
- it "returns a Basic Authorization = 'Basic MzY1ZTNjNjYtZmQwZi0xMWU3LThiZTUtMGVkNWY4OWY3MThiOjQxMWU2ZjlhLWZkMGYtMTFlNy04YmU1LTBlZDVmODlmNzE4Yg=='" do
64
- expect(@headers[:Authorization]).to eq "Basic MzY1ZTNjNjYtZmQwZi0xMWU3LThiZTUtMGVkNWY4OWY3MThiOjQxMWU2ZjlhLWZkMGYtMTFlNy04YmU1LTBlZDVmODlmNzE4Yg=="
65
- end
66
- end
67
-
68
- end
69
- end
70
-
71
- describe "#cached_token / #cache_token / #clear_cached_token!" do
72
- def token(expires_in)
73
- KeycloakAdmin::TokenRepresentation.new(
74
- "access_token", "bearer", expires_in, "refresh_token",
75
- "refresh_expires_in", "id_token", "not_before_policy", "session_state"
76
- )
77
- end
78
-
79
- it "has no cached token initially" do
80
- expect(@configuration.cached_token).to be_nil
81
- end
82
-
83
- it "returns the token it was given, while it is still within its expiry" do
84
- cached = @configuration.cache_token(token(3600))
85
- expect(cached.access_token).to eq "access_token"
86
- expect(@configuration.cached_token).to eq cached
87
- end
88
-
89
- it "treats a token as expired a bit before its real expiry, not just after" do
90
- # expires_in: 5, minus the 10s safety margin, is already in the past the moment it is cached.
91
- @configuration.cache_token(token(5))
92
- expect(@configuration.cached_token).to be_nil
93
- end
94
-
95
- it "does not cache a token with a non-numeric expires_in, but still returns it" do
96
- returned = @configuration.cache_token(token("not-a-number"))
97
- expect(returned.access_token).to eq "access_token"
98
- expect(@configuration.cached_token).to be_nil
99
- end
100
-
101
- it "clears the cache" do
102
- @configuration.cache_token(token(3600))
103
- @configuration.clear_cached_token!
104
- expect(@configuration.cached_token).to be_nil
105
- end
106
- end
107
-
108
- describe "#body_for_token_retrieval" do
109
- before(:each) do
110
- @body = @configuration.body_for_token_retrieval
111
- end
112
- context "when use_service_account is false" do
113
- let(:use_service_account) { false }
114
- it "returns a hash of 5 elements" do
115
- expect(@body.size).to eq 5
116
- end
117
-
118
- it "returns a hash containing the username" do
119
- expect(@body[:username]).to eq username
120
- end
121
-
122
- it "returns a hash containing the password" do
123
- expect(@body[:password]).to eq password
124
- end
125
-
126
- it "returns a hash containing the grant_type 'password'" do
127
- expect(@body[:grant_type]).to eq "password"
128
- end
129
-
130
- it "returns a hash containing the client_id" do
131
- expect(@body[:client_id]).to eq client_id
132
- end
133
-
134
- it "returns a hash containing the client_secret" do
135
- expect(@body[:client_secret]).to eq client_secret
136
- end
137
- end
138
-
139
- context "when use_service_account is true" do
140
- let(:use_service_account) { true }
141
- it "returns a hash of 1 element" do
142
- expect(@body.size).to eq 1
143
- end
144
-
145
- it "returns a hash containing the grant_type" do
146
- expect(@body[:grant_type]).to eq "client_credentials"
147
- end
148
- end
149
- end
150
- end
data/spec/gemspec_spec.rb DELETED
@@ -1,25 +0,0 @@
1
- RSpec.describe "keycloak-admin.gemspec" do
2
- let(:gemspec_path) { File.expand_path("../keycloak-admin.gemspec", __dir__) }
3
- let(:gemspec) { Gem::Specification.load(gemspec_path) }
4
-
5
- it "loads" do
6
- expect(gemspec).to be_a(Gem::Specification)
7
- expect(gemspec.name).to eq "keycloak-admin"
8
- end
9
-
10
- it "declares Ruby 3.1 as the minimum supported version" do
11
- expect(gemspec.required_ruby_version.to_s).to eq ">= 3.1"
12
- end
13
-
14
- # The CI matrix runs the oldest supported Ruby. If `required_ruby_version` is
15
- # ever raised without widening that matrix, or the matrix drops below what the
16
- # gemspec promises, this fails on the offending job instead of silently
17
- # shipping a gem that cannot install.
18
- it "is installable on the Ruby running this suite" do
19
- running_ruby = Gem::Version.new(RUBY_VERSION)
20
-
21
- expect(gemspec.required_ruby_version.satisfied_by?(running_ruby)).to be(true),
22
- "gemspec requires Ruby #{gemspec.required_ruby_version}, " \
23
- "but the suite is running on #{RUBY_VERSION}"
24
- end
25
- end