keycloak-admin 2.0.0 → 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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +19 -0
- data/README.md +54 -2
- data/keycloak-admin.gemspec +14 -5
- data/lib/keycloak-admin/client/client.rb +30 -11
- data/lib/keycloak-admin/client/client_authz_permission_client.rb +1 -1
- data/lib/keycloak-admin/client/client_authz_policy_client.rb +1 -1
- data/lib/keycloak-admin/client/client_authz_resource_client.rb +1 -1
- data/lib/keycloak-admin/client/client_authz_scope_client.rb +1 -1
- data/lib/keycloak-admin/client/configurable_token_client.rb +2 -1
- data/lib/keycloak-admin/client/group_client.rb +4 -6
- data/lib/keycloak-admin/client/organization_client.rb +7 -7
- data/lib/keycloak-admin/client/resource.rb +98 -0
- data/lib/keycloak-admin/client/response.rb +36 -0
- data/lib/keycloak-admin/client/role_mapper_client.rb +2 -1
- data/lib/keycloak-admin/client/user_client.rb +22 -11
- data/lib/keycloak-admin/configuration.rb +22 -0
- data/lib/keycloak-admin/error.rb +62 -0
- data/lib/keycloak-admin/version.rb +1 -1
- data/lib/keycloak-admin.rb +1 -0
- metadata +38 -53
- data/.github/workflows/Dockerfile +0 -24
- data/.github/workflows/ci.yml +0 -94
- data/.gitignore +0 -10
- data/.rspec +0 -2
- data/Dockerfile +0 -13
- data/Gemfile +0 -3
- data/Gemfile.lock +0 -52
- data/bin/console +0 -9
- data/spec/client/attack_detection_client_spec.rb +0 -102
- data/spec/client/client_authz_permission_client_spec.rb +0 -170
- data/spec/client/client_authz_policy_client_spec.rb +0 -170
- data/spec/client/client_authz_resource_client_spec.rb +0 -150
- data/spec/client/client_authz_scope_client_spec.rb +0 -134
- data/spec/client/client_client_spec.rb +0 -133
- data/spec/client/client_role_mappings_client_spec.rb +0 -82
- data/spec/client/client_scope_client_spec.rb +0 -220
- data/spec/client/client_scope_protocol_mapper_client_spec.rb +0 -230
- data/spec/client/client_spec.rb +0 -48
- data/spec/client/configurable_token_client_spec.rb +0 -34
- data/spec/client/group_client_spec.rb +0 -328
- data/spec/client/identity_provider_client_spec.rb +0 -92
- data/spec/client/organization_client_spec.rb +0 -595
- data/spec/client/realm_client_spec.rb +0 -155
- data/spec/client/role_client_spec.rb +0 -79
- data/spec/client/role_mapper_client_spec.rb +0 -113
- data/spec/client/token_client_spec.rb +0 -68
- data/spec/client/user_client_spec.rb +0 -418
- data/spec/configuration_spec.rb +0 -113
- data/spec/gemspec_spec.rb +0 -25
- data/spec/integration/client_authorization_spec.rb +0 -93
- data/spec/representation/attack_detection_representation_spec.rb +0 -16
- data/spec/representation/client_authz_permission_representation_spec.rb +0 -52
- data/spec/representation/client_authz_policy_representation_spec.rb +0 -47
- data/spec/representation/client_authz_resource_representation_spec.rb +0 -33
- data/spec/representation/client_authz_scope_representation_spec.rb +0 -19
- data/spec/representation/client_representation_spec.rb +0 -119
- data/spec/representation/client_scope_representation_spec.rb +0 -125
- data/spec/representation/credential_representation_spec.rb +0 -68
- data/spec/representation/group_representation_spec.rb +0 -22
- data/spec/representation/identity_provider_mapper_representation_spec.rb +0 -24
- data/spec/representation/identity_provider_representation_spec.rb +0 -113
- data/spec/representation/impersonation_representation_spec.rb +0 -163
- data/spec/representation/organization_representation_spec.rb +0 -64
- data/spec/representation/protocol_mapper_representation_spec.rb +0 -57
- data/spec/representation/role_representation_spec.rb +0 -37
- data/spec/representation/session_representation_spec.rb +0 -16
- data/spec/representation/user_representation_spec.rb +0 -15
- data/spec/resource/group_resource_spec.rb +0 -14
- data/spec/resource/user_resource_spec.rb +0 -14
- data/spec/spec_helper.rb +0 -29
|
@@ -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).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).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).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).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).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
|
data/spec/configuration_spec.rb
DELETED
|
@@ -1,113 +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 "#body_for_token_retrieval" do
|
|
72
|
-
before(:each) do
|
|
73
|
-
@body = @configuration.body_for_token_retrieval
|
|
74
|
-
end
|
|
75
|
-
context "when use_service_account is false" do
|
|
76
|
-
let(:use_service_account) { false }
|
|
77
|
-
it "returns a hash of 5 elements" do
|
|
78
|
-
expect(@body.size).to eq 5
|
|
79
|
-
end
|
|
80
|
-
|
|
81
|
-
it "returns a hash containing the username" do
|
|
82
|
-
expect(@body[:username]).to eq username
|
|
83
|
-
end
|
|
84
|
-
|
|
85
|
-
it "returns a hash containing the password" do
|
|
86
|
-
expect(@body[:password]).to eq password
|
|
87
|
-
end
|
|
88
|
-
|
|
89
|
-
it "returns a hash containing the grant_type 'password'" do
|
|
90
|
-
expect(@body[:grant_type]).to eq "password"
|
|
91
|
-
end
|
|
92
|
-
|
|
93
|
-
it "returns a hash containing the client_id" do
|
|
94
|
-
expect(@body[:client_id]).to eq client_id
|
|
95
|
-
end
|
|
96
|
-
|
|
97
|
-
it "returns a hash containing the client_secret" do
|
|
98
|
-
expect(@body[:client_secret]).to eq client_secret
|
|
99
|
-
end
|
|
100
|
-
end
|
|
101
|
-
|
|
102
|
-
context "when use_service_account is true" do
|
|
103
|
-
let(:use_service_account) { true }
|
|
104
|
-
it "returns a hash of 1 element" do
|
|
105
|
-
expect(@body.size).to eq 1
|
|
106
|
-
end
|
|
107
|
-
|
|
108
|
-
it "returns a hash containing the grant_type" do
|
|
109
|
-
expect(@body[:grant_type]).to eq "client_credentials"
|
|
110
|
-
end
|
|
111
|
-
end
|
|
112
|
-
end
|
|
113
|
-
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
|
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
RSpec.describe 'ClientAuthorization' do
|
|
2
|
-
|
|
3
|
-
before(:each) do
|
|
4
|
-
skip("This test requires to be run in a Github action.") unless ENV["GITHUB_ACTIONS"]
|
|
5
|
-
|
|
6
|
-
KeycloakAdmin.configure do |config|
|
|
7
|
-
config.use_service_account = false
|
|
8
|
-
config.server_url = "http://localhost:8080/"
|
|
9
|
-
config.client_id = "admin-cli"
|
|
10
|
-
config.client_realm_name = "master"
|
|
11
|
-
config.username = "admin"
|
|
12
|
-
config.password = "admin"
|
|
13
|
-
config.faraday_options = { request: { timeout: 5 }, ssl: { verify: false } }
|
|
14
|
-
end
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
after(:each) do
|
|
18
|
-
configure
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
describe "ClientAuthorization Suite" do
|
|
22
|
-
it do
|
|
23
|
-
realm_name = "dummy"
|
|
24
|
-
|
|
25
|
-
client = KeycloakAdmin.realm(realm_name).clients.find_by_client_id("dummy-client")
|
|
26
|
-
client.authorization_services_enabled = true
|
|
27
|
-
KeycloakAdmin.realm(realm_name).clients.update(client)
|
|
28
|
-
|
|
29
|
-
expect(KeycloakAdmin.realm(realm_name).authz_scopes(client.id).list.size).to eql(0)
|
|
30
|
-
expect(KeycloakAdmin.realm(realm_name).authz_resources(client.id).list.size).to eql(0)
|
|
31
|
-
expect(KeycloakAdmin.realm(realm_name).authz_policies(client.id, 'role').list.size).to eql(0)
|
|
32
|
-
|
|
33
|
-
realm_role = KeycloakAdmin.realm(realm_name).roles.get("default-roles-dummy")
|
|
34
|
-
|
|
35
|
-
scope_1 = KeycloakAdmin.realm(realm_name).authz_scopes(client.id).create!("POST_1", "POST 1 scope", "http://asdas")
|
|
36
|
-
scope_2 = KeycloakAdmin.realm(realm_name).authz_scopes(client.id).create!("POST_2", "POST 2 scope", "http://asdas")
|
|
37
|
-
expect(KeycloakAdmin.realm(realm_name).authz_scopes(client.id).search("POST").first.name).to eql("POST_1")
|
|
38
|
-
expect(KeycloakAdmin.realm(realm_name).authz_scopes(client.id).get(scope_1.id).name).to eql("POST_1")
|
|
39
|
-
|
|
40
|
-
resource = KeycloakAdmin.realm(realm_name).authz_resources(client.id).create!("Dummy Resource", "type", ["/asdf/*", "/tmp/"], true, "display_name", [], {"a": ["b", "c"]})
|
|
41
|
-
|
|
42
|
-
expect(KeycloakAdmin.realm(realm_name).authz_resources(client.id).find_by("Dummy Resource", "", "", "", "").first.name).to eql("Dummy Resource")
|
|
43
|
-
expect(KeycloakAdmin.realm(realm_name).authz_resources(client.id).find_by("", "type", "", "", "").first.name).to eql("Dummy Resource")
|
|
44
|
-
|
|
45
|
-
expect(KeycloakAdmin.realm(realm_name).authz_resources(client.id).get(resource.id).scopes.count).to eql(0)
|
|
46
|
-
expect(KeycloakAdmin.realm(realm_name).authz_resources(client.id).get(resource.id).uris.count).to eql(2)
|
|
47
|
-
KeycloakAdmin.realm(realm_name).authz_resources(client.id).update(resource.id,
|
|
48
|
-
{
|
|
49
|
-
"name": "Dummy Resource",
|
|
50
|
-
"type": "type",
|
|
51
|
-
"owner_managed_access": true,
|
|
52
|
-
"display_name": "display_name",
|
|
53
|
-
"attributes": {"a":["b","c"]},
|
|
54
|
-
"uris": [ "/asdf/*" , "/tmp/45" ],
|
|
55
|
-
"scopes":[
|
|
56
|
-
{name: scope_1.name},{name: scope_2.name}
|
|
57
|
-
],
|
|
58
|
-
"icon_uri": "https://icon.ico"
|
|
59
|
-
}
|
|
60
|
-
)
|
|
61
|
-
|
|
62
|
-
expect(KeycloakAdmin.realm(realm_name).authz_resources(client.id).get(resource.id).scopes.count).to eql(2)
|
|
63
|
-
|
|
64
|
-
policy = KeycloakAdmin.realm(realm_name).authz_policies(client.id, 'role').create!("Policy 1", "description", "role", "POSITIVE", "UNANIMOUS", true, [{id: realm_role.id, required: true}])
|
|
65
|
-
expect(KeycloakAdmin.realm(realm_name).authz_policies(client.id, 'role').find_by("Policy 1", "role").first.name).to eql("Policy 1")
|
|
66
|
-
expect(KeycloakAdmin.realm(realm_name).authz_policies(client.id, 'role').get(policy.id).name).to eql("Policy 1")
|
|
67
|
-
scope_permission = KeycloakAdmin.realm(realm_name).authz_permissions(client.id, :scope).create!("Dummy Scope Permission", "scope description", "UNANIMOUS", "POSITIVE", [resource.id], [policy.id], [scope_1.id, scope_2.id], "")
|
|
68
|
-
resource_permission = KeycloakAdmin.realm(realm_name).authz_permissions(client.id, :resource).create!("Dummy Resource Permission", "resource description", "UNANIMOUS", "POSITIVE", [resource.id], [policy.id], nil, "")
|
|
69
|
-
expect(KeycloakAdmin.realm(realm_name).authz_permissions(client.id, "", resource.id).list.size).to eql(2)
|
|
70
|
-
expect(KeycloakAdmin.realm(realm_name).authz_permissions(client.id, "resource").get(resource_permission.id).name).to eql("Dummy Resource Permission")
|
|
71
|
-
expect(KeycloakAdmin.realm(realm_name).authz_scopes(client.id, resource.id).list.size).to eql(2)
|
|
72
|
-
|
|
73
|
-
expect(KeycloakAdmin.realm(realm_name).authz_permissions(client.id, 'scope').list.size).to eql(2)
|
|
74
|
-
expect(KeycloakAdmin.realm(realm_name).authz_permissions(client.id, 'resource').list.size).to eql(2)
|
|
75
|
-
expect(KeycloakAdmin.realm(realm_name).authz_permissions(client.id, "resource").find_by(resource_permission.name, nil).first.name).to eql("Dummy Resource Permission")
|
|
76
|
-
expect(KeycloakAdmin.realm(realm_name).authz_permissions(client.id, "resource").find_by(resource_permission.name, resource.id).first.name).to eql("Dummy Resource Permission")
|
|
77
|
-
expect(KeycloakAdmin.realm(realm_name).authz_permissions(client.id, "scope").find_by(scope_permission.name, resource.id).first.name).to eql("Dummy Scope Permission")
|
|
78
|
-
expect(KeycloakAdmin.realm(realm_name).authz_permissions(client.id, "scope").find_by(scope_permission.name, resource.id, "POST_1").first.name).to eql("Dummy Scope Permission")
|
|
79
|
-
expect(KeycloakAdmin.realm(realm_name).authz_permissions(client.id, "resource").find_by(nil, resource.id).first.name).to eql("Dummy Resource Permission")
|
|
80
|
-
expect(KeycloakAdmin.realm(realm_name).authz_permissions(client.id, "scope").find_by(nil, resource.id).first.name).to eql("Dummy Scope Permission")
|
|
81
|
-
expect(KeycloakAdmin.realm(realm_name).authz_permissions(client.id, "scope").find_by(nil, resource.id, "POST_1").first.name).to eql("Dummy Scope Permission")
|
|
82
|
-
expect(KeycloakAdmin.realm(realm_name).authz_permissions(client.id, "scope").find_by(scope_permission.name, nil).first.name).to eql("Dummy Scope Permission")
|
|
83
|
-
|
|
84
|
-
KeycloakAdmin.realm(realm_name).authz_permissions(client.id, 'scope').delete(scope_permission.id)
|
|
85
|
-
KeycloakAdmin.realm(realm_name).authz_permissions(client.id, 'resource').delete(resource_permission.id)
|
|
86
|
-
KeycloakAdmin.realm(realm_name).authz_policies(client.id, 'role').delete(policy.id)
|
|
87
|
-
KeycloakAdmin.realm(realm_name).authz_resources(client.id).delete(resource.id)
|
|
88
|
-
KeycloakAdmin.realm(realm_name).authz_scopes(client.id).delete(scope_1.id)
|
|
89
|
-
KeycloakAdmin.realm(realm_name).authz_scopes(client.id).delete(scope_2.id)
|
|
90
|
-
|
|
91
|
-
end
|
|
92
|
-
end
|
|
93
|
-
end
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
RSpec.describe KeycloakAdmin::AttackDetectionRepresentation do
|
|
4
|
-
describe '.from_hash' do
|
|
5
|
-
it 'converts json response to class structure' do
|
|
6
|
-
rep = described_class.from_hash({
|
|
7
|
-
'numFailures' => 2,
|
|
8
|
-
'disabled' => true,
|
|
9
|
-
'lastIPFailure' => 12345,
|
|
10
|
-
'last_failure' => 12345678
|
|
11
|
-
})
|
|
12
|
-
expect(rep.num_failures).to eq 2
|
|
13
|
-
expect(rep).to be_a described_class
|
|
14
|
-
end
|
|
15
|
-
end
|
|
16
|
-
end
|