keycloak-admin 1.1.4 → 1.1.6
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/.github/workflows/Dockerfile +24 -24
- data/.github/workflows/ci.yml +80 -80
- data/.gitignore +9 -9
- data/.rspec +2 -2
- data/CHANGELOG.md +23 -0
- data/Dockerfile +12 -12
- data/Gemfile +3 -3
- data/Gemfile.lock +1 -1
- data/MIT-LICENSE +20 -20
- data/README.md +20 -1
- data/bin/console +9 -9
- data/keycloak-admin.gemspec +24 -24
- data/lib/keycloak-admin/client/attack_detection_client.rb +41 -41
- data/lib/keycloak-admin/client/client.rb +56 -56
- data/lib/keycloak-admin/client/client_authz_permission_client.rb +80 -80
- data/lib/keycloak-admin/client/client_authz_policy_client.rb +75 -75
- data/lib/keycloak-admin/client/client_authz_resource_client.rb +92 -92
- data/lib/keycloak-admin/client/client_authz_scope_client.rb +70 -70
- data/lib/keycloak-admin/client/client_client.rb +71 -71
- data/lib/keycloak-admin/client/client_role_client.rb +20 -20
- data/lib/keycloak-admin/client/client_role_mappings_client.rb +32 -32
- data/lib/keycloak-admin/client/configurable_token_client.rb +35 -35
- data/lib/keycloak-admin/client/group_client.rb +148 -148
- data/lib/keycloak-admin/client/identity_provider_client.rb +51 -51
- data/lib/keycloak-admin/client/organization_client.rb +245 -0
- data/lib/keycloak-admin/client/realm_client.rb +126 -122
- data/lib/keycloak-admin/client/role_client.rb +59 -59
- data/lib/keycloak-admin/client/role_mapper_client.rb +47 -47
- data/lib/keycloak-admin/client/token_client.rb +29 -29
- data/lib/keycloak-admin/client/user_client.rb +278 -266
- data/lib/keycloak-admin/configuration.rb +52 -52
- data/lib/keycloak-admin/representation/attack_detection_representation.rb +17 -17
- data/lib/keycloak-admin/representation/camel_json.rb +12 -12
- data/lib/keycloak-admin/representation/client_authz_permission_representation.rb +33 -33
- data/lib/keycloak-admin/representation/client_authz_policy_config_representation.rb +14 -14
- data/lib/keycloak-admin/representation/client_authz_policy_representation.rb +26 -26
- data/lib/keycloak-admin/representation/client_authz_resource_representation.rb +25 -25
- data/lib/keycloak-admin/representation/client_authz_scope_representation.rb +16 -16
- data/lib/keycloak-admin/representation/client_representation.rb +71 -71
- data/lib/keycloak-admin/representation/credential_representation.rb +71 -38
- data/lib/keycloak-admin/representation/federated_identity_representation.rb +15 -15
- data/lib/keycloak-admin/representation/group_representation.rb +21 -21
- data/lib/keycloak-admin/representation/identity_provider_mapper_representation.rb +19 -19
- data/lib/keycloak-admin/representation/identity_provider_representation.rb +71 -67
- data/lib/keycloak-admin/representation/impersonation_redirection_representation.rb +16 -16
- data/lib/keycloak-admin/representation/impersonation_representation.rb +43 -43
- data/lib/keycloak-admin/representation/member_representation.rb +11 -0
- data/lib/keycloak-admin/representation/organization_domain_representation.rb +18 -0
- data/lib/keycloak-admin/representation/organization_representation.rb +30 -0
- data/lib/keycloak-admin/representation/protocol_mapper_representation.rb +19 -19
- data/lib/keycloak-admin/representation/realm_representation.rb +14 -14
- data/lib/keycloak-admin/representation/representation.rb +23 -23
- data/lib/keycloak-admin/representation/role_representation.rb +19 -19
- data/lib/keycloak-admin/representation/session_representation.rb +22 -22
- data/lib/keycloak-admin/representation/token_representation.rb +39 -39
- data/lib/keycloak-admin/representation/user_representation.rb +47 -47
- data/lib/keycloak-admin/resource/base_role_containing_resource.rb +28 -28
- data/lib/keycloak-admin/resource/group_resource.rb +11 -11
- data/lib/keycloak-admin/resource/user_resource.rb +7 -7
- data/lib/keycloak-admin/version.rb +3 -3
- data/lib/keycloak-admin.rb +88 -84
- data/spec/client/attack_detection_client_spec.rb +102 -102
- data/spec/client/client_authz_permission_client_spec.rb +170 -170
- data/spec/client/client_authz_policy_client_spec.rb +169 -169
- data/spec/client/client_authz_resource_client_spec.rb +150 -150
- data/spec/client/client_authz_scope_client_spec.rb +133 -133
- data/spec/client/client_client_spec.rb +133 -133
- data/spec/client/client_role_mappings_client_spec.rb +82 -82
- data/spec/client/client_spec.rb +28 -28
- data/spec/client/configurable_token_client_spec.rb +34 -34
- data/spec/client/group_client_spec.rb +328 -328
- data/spec/client/identity_provider_client_spec.rb +92 -92
- data/spec/client/organization_client_spec.rb +595 -0
- data/spec/client/realm_client_spec.rb +155 -155
- data/spec/client/role_client_spec.rb +79 -79
- data/spec/client/role_mapper_client_spec.rb +113 -113
- data/spec/client/token_client_spec.rb +68 -68
- data/spec/client/user_client_spec.rb +418 -373
- data/spec/configuration_spec.rb +113 -113
- data/spec/integration/client_authorization_spec.rb +93 -93
- data/spec/representation/attack_detection_representation_spec.rb +15 -15
- data/spec/representation/client_authz_permission_representation_spec.rb +52 -52
- data/spec/representation/client_authz_policy_representation_spec.rb +46 -46
- data/spec/representation/client_authz_resource_representation_spec.rb +33 -33
- data/spec/representation/client_authz_scope_representation_spec.rb +18 -18
- data/spec/representation/client_representation_spec.rb +119 -119
- data/spec/representation/credential_representation_spec.rb +68 -0
- data/spec/representation/group_representation_spec.rb +22 -22
- data/spec/representation/identity_provider_mapper_representation_spec.rb +24 -24
- data/spec/representation/identity_provider_representation_spec.rb +113 -113
- data/spec/representation/impersonation_representation_spec.rb +163 -163
- data/spec/representation/organization_representation_spec.rb +64 -0
- data/spec/representation/protocol_mapper_representation_spec.rb +57 -57
- data/spec/representation/role_representation_spec.rb +37 -37
- data/spec/representation/session_representation_spec.rb +15 -15
- data/spec/representation/user_representation_spec.rb +15 -15
- data/spec/resource/group_resource_spec.rb +14 -14
- data/spec/resource/user_resource_spec.rb +14 -14
- data/spec/spec_helper.rb +37 -37
- metadata +13 -6
|
@@ -0,0 +1,595 @@
|
|
|
1
|
+
RSpec.describe KeycloakAdmin::OrganizationClient do
|
|
2
|
+
describe "#organization_url" do
|
|
3
|
+
let(:realm_name) { "valid-realm" }
|
|
4
|
+
let(:organization_id) { nil }
|
|
5
|
+
|
|
6
|
+
before(:each) do
|
|
7
|
+
@built_url = KeycloakAdmin.realm(realm_name).organizations.organization_url(organization_id)
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
context "when organization_id is defined" do
|
|
11
|
+
let(:organization_id) { "95985b21-d884-4bbd-b852-cb8cd365afc2" }
|
|
12
|
+
it "return a proper url with the organization id" do
|
|
13
|
+
expect(@built_url).to eq "http://auth.service.io/auth/admin/realms/valid-realm/organizations/95985b21-d884-4bbd-b852-cb8cd365afc2"
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
describe "#list" do
|
|
19
|
+
let(:realm_name) { "valid-realm" }
|
|
20
|
+
|
|
21
|
+
before(:each) do
|
|
22
|
+
@organization_client = KeycloakAdmin.realm(realm_name).organizations
|
|
23
|
+
stub_token_client
|
|
24
|
+
json_payload = <<-'payload'
|
|
25
|
+
[
|
|
26
|
+
{
|
|
27
|
+
"id": "8f6e474e-e688-4bec-99ba-5dc862594f4b",
|
|
28
|
+
"name": "My organization",
|
|
29
|
+
"alias": "myorg",
|
|
30
|
+
"enabled": true,
|
|
31
|
+
"description": "A single organization",
|
|
32
|
+
"domains": [
|
|
33
|
+
{
|
|
34
|
+
"name": "hello.com",
|
|
35
|
+
"verified": false
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
"name": "gmail.com",
|
|
39
|
+
"verified": true
|
|
40
|
+
}
|
|
41
|
+
]
|
|
42
|
+
}
|
|
43
|
+
]
|
|
44
|
+
payload
|
|
45
|
+
allow_any_instance_of(RestClient::Resource).to receive(:get).and_return json_payload
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
it "lists organizations" do
|
|
49
|
+
organizations = @organization_client.list
|
|
50
|
+
expect(organizations.length).to eq 1
|
|
51
|
+
expect(organizations[0].id).to eq "8f6e474e-e688-4bec-99ba-5dc862594f4b"
|
|
52
|
+
expect(organizations[0].name).to eq "My organization"
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
it "passes rest client options" do
|
|
56
|
+
rest_client_options = {timeout: 10}
|
|
57
|
+
allow_any_instance_of(KeycloakAdmin::Configuration).to receive(:rest_client_options).and_return rest_client_options
|
|
58
|
+
|
|
59
|
+
expect(RestClient::Resource).to receive(:new).with(
|
|
60
|
+
"http://auth.service.io/auth/admin/realms/valid-realm/organizations?briefRepresentation=true", rest_client_options).and_call_original
|
|
61
|
+
|
|
62
|
+
organizations = @organization_client.list
|
|
63
|
+
expect(organizations.length).to eq 1
|
|
64
|
+
expect(organizations[0]).to be_a KeycloakAdmin::OrganizationRepresentation
|
|
65
|
+
expect(organizations[0].id).to eq "8f6e474e-e688-4bec-99ba-5dc862594f4b"
|
|
66
|
+
expect(organizations[0].name).to eq "My organization"
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
describe "#count" do
|
|
71
|
+
let(:realm_name) { "valid-realm" }
|
|
72
|
+
|
|
73
|
+
before(:each) do
|
|
74
|
+
@organization_client = KeycloakAdmin.realm(realm_name).organizations
|
|
75
|
+
stub_token_client
|
|
76
|
+
json_payload = "2"
|
|
77
|
+
allow_any_instance_of(RestClient::Resource).to receive(:get).and_return json_payload
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
it "count organizations" do
|
|
81
|
+
count = @organization_client.count(false, nil, "test")
|
|
82
|
+
expect(count).to eq 2
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
context "when building the count url" do
|
|
86
|
+
let(:exact) { nil }
|
|
87
|
+
let(:query) { nil }
|
|
88
|
+
let(:search) { nil }
|
|
89
|
+
|
|
90
|
+
before(:each) do
|
|
91
|
+
@count_url = @organization_client.count_url(exact, query, search)
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
context "with everything null" do
|
|
95
|
+
it "return a proper url" do
|
|
96
|
+
expect(@count_url).to eq "http://auth.service.io/auth/admin/realms/valid-realm/organizations/count?"
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
context "with exact=false" do
|
|
101
|
+
let(:exact) { false }
|
|
102
|
+
it "return a proper url" do
|
|
103
|
+
expect(@count_url).to eq "http://auth.service.io/auth/admin/realms/valid-realm/organizations/count?exact=false"
|
|
104
|
+
end
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
context "with exact=true" do
|
|
108
|
+
let(:exact) { true }
|
|
109
|
+
it "return a proper url" do
|
|
110
|
+
expect(@count_url).to eq "http://auth.service.io/auth/admin/realms/valid-realm/organizations/count?exact=true"
|
|
111
|
+
end
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
context "with query=test" do
|
|
115
|
+
let(:query) { "test" }
|
|
116
|
+
it "return a proper url" do
|
|
117
|
+
expect(@count_url).to eq "http://auth.service.io/auth/admin/realms/valid-realm/organizations/count?q=test"
|
|
118
|
+
end
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
context "with search=nameoforg" do
|
|
122
|
+
let(:search) { "nameoforg" }
|
|
123
|
+
it "return a proper url" do
|
|
124
|
+
expect(@count_url).to eq "http://auth.service.io/auth/admin/realms/valid-realm/organizations/count?search=nameoforg"
|
|
125
|
+
end
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
context "with every argument setup" do
|
|
129
|
+
let(:exact) { true }
|
|
130
|
+
let(:query) { "a query" }
|
|
131
|
+
let(:search) { "a name" }
|
|
132
|
+
it "return a proper url" do
|
|
133
|
+
expect(@count_url).to eq "http://auth.service.io/auth/admin/realms/valid-realm/organizations/count?exact=true&q=a query&search=a name"
|
|
134
|
+
end
|
|
135
|
+
end
|
|
136
|
+
end
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
describe "#associated_with_member" do
|
|
140
|
+
let(:realm_name) { "valid-realm" }
|
|
141
|
+
|
|
142
|
+
before(:each) do
|
|
143
|
+
@organization_client = KeycloakAdmin.realm(realm_name).organizations
|
|
144
|
+
stub_token_client
|
|
145
|
+
json_payload = <<-'payload'
|
|
146
|
+
[
|
|
147
|
+
{
|
|
148
|
+
"id": "8f6e474e-e688-4bec-99ba-5dc862594f4b",
|
|
149
|
+
"name": "My organization",
|
|
150
|
+
"alias": "myorg",
|
|
151
|
+
"enabled": true,
|
|
152
|
+
"description": "A single organization",
|
|
153
|
+
"domains": [
|
|
154
|
+
{
|
|
155
|
+
"name": "hello.com",
|
|
156
|
+
"verified": false
|
|
157
|
+
},
|
|
158
|
+
{
|
|
159
|
+
"name": "gmail.com",
|
|
160
|
+
"verified": true
|
|
161
|
+
}
|
|
162
|
+
]
|
|
163
|
+
}
|
|
164
|
+
]
|
|
165
|
+
payload
|
|
166
|
+
allow_any_instance_of(RestClient::Resource).to receive(:get).and_return json_payload
|
|
167
|
+
end
|
|
168
|
+
|
|
169
|
+
it "list organizations of members organizations" do
|
|
170
|
+
organizations = @organization_client.associated_with_member("648ebe7f-e4ba-4d82-a87d-c585c866d0e7")
|
|
171
|
+
expect(organizations.size).to eq 1
|
|
172
|
+
expect(organizations[0]).to be_a KeycloakAdmin::OrganizationRepresentation
|
|
173
|
+
expect(organizations[0].id).to eq "8f6e474e-e688-4bec-99ba-5dc862594f4b"
|
|
174
|
+
end
|
|
175
|
+
end
|
|
176
|
+
|
|
177
|
+
describe "#delete" do
|
|
178
|
+
let(:realm_name) { "valid-realm" }
|
|
179
|
+
|
|
180
|
+
before(:each) do
|
|
181
|
+
@organization_client = KeycloakAdmin.realm(realm_name).organizations
|
|
182
|
+
stub_token_client
|
|
183
|
+
allow_any_instance_of(RestClient::Resource).to receive(:delete).and_return ""
|
|
184
|
+
end
|
|
185
|
+
|
|
186
|
+
it "deletes an organization" do
|
|
187
|
+
result = @organization_client.delete("2904e1a1-e5f4-4143-8725-003e54cc8b58")
|
|
188
|
+
expect(result).to be(true)
|
|
189
|
+
end
|
|
190
|
+
|
|
191
|
+
it "raises a delete error" do
|
|
192
|
+
rest_client_options = {timeout: 10}
|
|
193
|
+
allow_any_instance_of(KeycloakAdmin::Configuration).to receive(:rest_client_options).and_return rest_client_options
|
|
194
|
+
|
|
195
|
+
expect(RestClient::Resource).to receive(:new).with(
|
|
196
|
+
"http://auth.service.io/auth/admin/realms/valid-realm/organizations/2904e1a1-e5f4-4143-8725-003e54cc8b58", rest_client_options).and_raise("error")
|
|
197
|
+
|
|
198
|
+
expect { @organization_client.delete("2904e1a1-e5f4-4143-8725-003e54cc8b58") }.to raise_error("error")
|
|
199
|
+
end
|
|
200
|
+
end
|
|
201
|
+
|
|
202
|
+
describe "#identity_providers" do
|
|
203
|
+
let(:realm_name) { "valid-realm" }
|
|
204
|
+
|
|
205
|
+
before(:each) do
|
|
206
|
+
@organization_client = KeycloakAdmin.realm(realm_name).organizations
|
|
207
|
+
stub_token_client
|
|
208
|
+
json_payload = <<-'payload'
|
|
209
|
+
[
|
|
210
|
+
{
|
|
211
|
+
"alias": "google",
|
|
212
|
+
"displayName": "",
|
|
213
|
+
"internalId": "59b28b03-07db-4281-b637-4040368df082",
|
|
214
|
+
"providerId": "google",
|
|
215
|
+
"enabled": true,
|
|
216
|
+
"updateProfileFirstLoginMode": "on",
|
|
217
|
+
"trustEmail": false,
|
|
218
|
+
"storeToken": false,
|
|
219
|
+
"addReadTokenRoleOnCreate": false,
|
|
220
|
+
"authenticateByDefault": false,
|
|
221
|
+
"linkOnly": false,
|
|
222
|
+
"hideOnLogin": true,
|
|
223
|
+
"organizationId": "8f6e474e-e688-4bec-99ba-5dc862594f4b",
|
|
224
|
+
"config": {
|
|
225
|
+
"syncMode": "LEGACY",
|
|
226
|
+
"clientSecret": "**********",
|
|
227
|
+
"clientId": "test",
|
|
228
|
+
"kc.org.broker.redirect.mode.email-matches": "false"
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
]
|
|
232
|
+
payload
|
|
233
|
+
allow_any_instance_of(RestClient::Resource).to receive(:get).and_return json_payload
|
|
234
|
+
end
|
|
235
|
+
|
|
236
|
+
it "get identity providers" do
|
|
237
|
+
identity_providers = @organization_client.identity_providers("8f6e474e-e688-4bec-99ba-5dc862594f4b")
|
|
238
|
+
expect(identity_providers.size).to eq 1
|
|
239
|
+
expect(identity_providers[0]).to be_a KeycloakAdmin::IdentityProviderRepresentation
|
|
240
|
+
expect(identity_providers[0].alias).to eq "google"
|
|
241
|
+
expect(identity_providers[0].organization_id).to eq "8f6e474e-e688-4bec-99ba-5dc862594f4b"
|
|
242
|
+
end
|
|
243
|
+
end
|
|
244
|
+
|
|
245
|
+
describe "#add_identity_provider" do
|
|
246
|
+
let(:realm_name) { "valid-realm" }
|
|
247
|
+
|
|
248
|
+
before(:each) do
|
|
249
|
+
@organization_client = KeycloakAdmin.realm(realm_name).organizations
|
|
250
|
+
stub_token_client
|
|
251
|
+
allow_any_instance_of(RestClient::Resource).to receive(:post).and_return ""
|
|
252
|
+
end
|
|
253
|
+
|
|
254
|
+
it "adds one identity provider" do
|
|
255
|
+
@organization_client.add_identity_provider("8f6e474e-e688-4bec-99ba-5dc862594f4b", "google")
|
|
256
|
+
end
|
|
257
|
+
end
|
|
258
|
+
|
|
259
|
+
describe "#get_identity_provider" do
|
|
260
|
+
let(:realm_name) { "valid-realm" }
|
|
261
|
+
|
|
262
|
+
before(:each) do
|
|
263
|
+
@organization_client = KeycloakAdmin.realm(realm_name).organizations
|
|
264
|
+
json_payload = <<-'payload'
|
|
265
|
+
{
|
|
266
|
+
"alias": "google",
|
|
267
|
+
"displayName": "",
|
|
268
|
+
"internalId": "59b28b03-07db-4281-b637-4040368df082",
|
|
269
|
+
"providerId": "google",
|
|
270
|
+
"enabled": true,
|
|
271
|
+
"updateProfileFirstLoginMode": "on",
|
|
272
|
+
"trustEmail": false,
|
|
273
|
+
"storeToken": false,
|
|
274
|
+
"addReadTokenRoleOnCreate": false,
|
|
275
|
+
"authenticateByDefault": false,
|
|
276
|
+
"linkOnly": false,
|
|
277
|
+
"hideOnLogin": true,
|
|
278
|
+
"organizationId": "8f6e474e-e688-4bec-99ba-5dc862594f4b",
|
|
279
|
+
"config": {
|
|
280
|
+
"syncMode": "LEGACY",
|
|
281
|
+
"clientSecret": "**********",
|
|
282
|
+
"clientId": "test",
|
|
283
|
+
"kc.org.broker.redirect.mode.email-matches": "false"
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
payload
|
|
287
|
+
stub_token_client
|
|
288
|
+
allow_any_instance_of(RestClient::Resource).to receive(:get).and_return json_payload
|
|
289
|
+
end
|
|
290
|
+
|
|
291
|
+
it "get identity provider" do
|
|
292
|
+
idp = @organization_client.get_identity_provider("8f6e474e-e688-4bec-99ba-5dc862594f4b", "google")
|
|
293
|
+
expect(idp).to be_a KeycloakAdmin::IdentityProviderRepresentation
|
|
294
|
+
expect(idp.alias).to eq "google"
|
|
295
|
+
end
|
|
296
|
+
end
|
|
297
|
+
|
|
298
|
+
describe "#get" do
|
|
299
|
+
let(:realm_name) { "valid-realm" }
|
|
300
|
+
|
|
301
|
+
before(:each) do
|
|
302
|
+
@organization_client = KeycloakAdmin.realm(realm_name).organizations
|
|
303
|
+
stub_token_client
|
|
304
|
+
json_payload = <<-'payload'
|
|
305
|
+
{
|
|
306
|
+
"id": "8f6e474e-e688-4bec-99ba-5dc862594f4b",
|
|
307
|
+
"name": "My organization",
|
|
308
|
+
"alias": "myorg",
|
|
309
|
+
"enabled": true,
|
|
310
|
+
"description": "A single organization",
|
|
311
|
+
"domains": [
|
|
312
|
+
{
|
|
313
|
+
"name": "hello.com",
|
|
314
|
+
"verified": false
|
|
315
|
+
},
|
|
316
|
+
{
|
|
317
|
+
"name": "gmail.com",
|
|
318
|
+
"verified": true
|
|
319
|
+
}
|
|
320
|
+
]
|
|
321
|
+
}
|
|
322
|
+
payload
|
|
323
|
+
allow_any_instance_of(RestClient::Resource).to receive(:get).and_return json_payload
|
|
324
|
+
end
|
|
325
|
+
|
|
326
|
+
it "get organization" do
|
|
327
|
+
organization = @organization_client.get("8f6e474e-e688-4bec-99ba-5dc862594f4b")
|
|
328
|
+
expect(organization).to be
|
|
329
|
+
expect(organization).to be_a KeycloakAdmin::OrganizationRepresentation
|
|
330
|
+
expect(organization.id).to eq "8f6e474e-e688-4bec-99ba-5dc862594f4b"
|
|
331
|
+
expect(organization.name).to eq "My organization"
|
|
332
|
+
end
|
|
333
|
+
|
|
334
|
+
it "passes rest client options" do
|
|
335
|
+
rest_client_options = {timeout: 10}
|
|
336
|
+
allow_any_instance_of(KeycloakAdmin::Configuration).to receive(:rest_client_options).and_return rest_client_options
|
|
337
|
+
|
|
338
|
+
expect(RestClient::Resource).to receive(:new).with(
|
|
339
|
+
"http://auth.service.io/auth/admin/realms/valid-realm/organizations/8f6e474e-e688-4bec-99ba-5dc862594f4b", rest_client_options).and_call_original
|
|
340
|
+
|
|
341
|
+
organization = @organization_client.get("8f6e474e-e688-4bec-99ba-5dc862594f4b")
|
|
342
|
+
expect(organization).to be
|
|
343
|
+
expect(organization).to be_a KeycloakAdmin::OrganizationRepresentation
|
|
344
|
+
expect(organization.id).to eq "8f6e474e-e688-4bec-99ba-5dc862594f4b"
|
|
345
|
+
end
|
|
346
|
+
end
|
|
347
|
+
|
|
348
|
+
describe "#members_count" do
|
|
349
|
+
let(:realm_name) { "valid-realm" }
|
|
350
|
+
|
|
351
|
+
before(:each) do
|
|
352
|
+
@organization_client = KeycloakAdmin.realm(realm_name).organizations
|
|
353
|
+
stub_token_client
|
|
354
|
+
allow_any_instance_of(RestClient::Resource).to receive(:get).and_return "2"
|
|
355
|
+
end
|
|
356
|
+
|
|
357
|
+
it "get count of members" do
|
|
358
|
+
count = @organization_client.members_count("8f6e474e-e688-4bec-99ba-5dc862594f4b")
|
|
359
|
+
expect(count).to eq 2
|
|
360
|
+
end
|
|
361
|
+
end
|
|
362
|
+
|
|
363
|
+
describe "#members" do
|
|
364
|
+
let(:realm_name) { "valid-realm" }
|
|
365
|
+
|
|
366
|
+
before(:each) do
|
|
367
|
+
@organization_client = KeycloakAdmin.realm(realm_name).organizations
|
|
368
|
+
json_payload = <<-'payload'
|
|
369
|
+
[
|
|
370
|
+
{
|
|
371
|
+
"id": "648ebe7f-e4ba-4d82-a87d-c585c866d0e7",
|
|
372
|
+
"username": "admin",
|
|
373
|
+
"emailVerified": false,
|
|
374
|
+
"attributes": {
|
|
375
|
+
"is_temporary_admin": [
|
|
376
|
+
"true"
|
|
377
|
+
]
|
|
378
|
+
},
|
|
379
|
+
"enabled": true,
|
|
380
|
+
"createdTimestamp": 1767600090489,
|
|
381
|
+
"totp": false,
|
|
382
|
+
"disableableCredentialTypes": [],
|
|
383
|
+
"requiredActions": [],
|
|
384
|
+
"notBefore": 0,
|
|
385
|
+
"membershipType": "UNMANAGED"
|
|
386
|
+
},
|
|
387
|
+
{
|
|
388
|
+
"id": "2167481a-6a08-44f3-aa9a-42e33afa6834",
|
|
389
|
+
"username": "client",
|
|
390
|
+
"emailVerified": true,
|
|
391
|
+
"enabled": true,
|
|
392
|
+
"createdTimestamp": 1767601626861,
|
|
393
|
+
"totp": false,
|
|
394
|
+
"disableableCredentialTypes": [],
|
|
395
|
+
"requiredActions": [],
|
|
396
|
+
"notBefore": 0,
|
|
397
|
+
"membershipType": "MANAGED"
|
|
398
|
+
}
|
|
399
|
+
]
|
|
400
|
+
payload
|
|
401
|
+
stub_token_client
|
|
402
|
+
allow_any_instance_of(RestClient::Resource).to receive(:get).and_return json_payload
|
|
403
|
+
end
|
|
404
|
+
|
|
405
|
+
it "get members" do
|
|
406
|
+
members = @organization_client.members("8f6e474e-e688-4bec-99ba-5dc862594f4b")
|
|
407
|
+
expect(members.size).to eq 2
|
|
408
|
+
expect(members[0]).to be_a KeycloakAdmin::MemberRepresentation
|
|
409
|
+
expect(members[0].id).to eq "648ebe7f-e4ba-4d82-a87d-c585c866d0e7"
|
|
410
|
+
expect(members[0].membership_type).to eq "UNMANAGED"
|
|
411
|
+
expect(members[1]).to be_a KeycloakAdmin::MemberRepresentation
|
|
412
|
+
expect(members[1].id).to eq "2167481a-6a08-44f3-aa9a-42e33afa6834"
|
|
413
|
+
expect(members[1].membership_type).to eq "MANAGED"
|
|
414
|
+
end
|
|
415
|
+
end
|
|
416
|
+
|
|
417
|
+
describe "#invite_existing_user" do
|
|
418
|
+
let(:realm_name) { "valid-realm" }
|
|
419
|
+
|
|
420
|
+
before(:each) do
|
|
421
|
+
@organization_client = KeycloakAdmin.realm(realm_name).organizations
|
|
422
|
+
stub_token_client
|
|
423
|
+
allow_any_instance_of(RestClient::Resource).to receive(:post).and_return ""
|
|
424
|
+
end
|
|
425
|
+
|
|
426
|
+
it "invites an existing user" do
|
|
427
|
+
@organization_client.invite_existing_user("8f6e474e-e688-4bec-99ba-5dc862594f4b", "9a2ff47d-759c-4126-a281-8e4a7c6465e4")
|
|
428
|
+
end
|
|
429
|
+
end
|
|
430
|
+
|
|
431
|
+
describe "#invite_user" do
|
|
432
|
+
let(:realm_name) { "valid-realm" }
|
|
433
|
+
|
|
434
|
+
before(:each) do
|
|
435
|
+
@organization_client = KeycloakAdmin.realm(realm_name).organizations
|
|
436
|
+
stub_token_client
|
|
437
|
+
allow_any_instance_of(RestClient::Resource).to receive(:post).and_return ""
|
|
438
|
+
end
|
|
439
|
+
|
|
440
|
+
it "invites an existing user" do
|
|
441
|
+
@organization_client.invite_user("8f6e474e-e688-4bec-99ba-5dc862594f4b", "hello@acme.com", "John", "Doe")
|
|
442
|
+
end
|
|
443
|
+
end
|
|
444
|
+
|
|
445
|
+
describe "#delete_member" do
|
|
446
|
+
let(:realm_name) { "valid-realm" }
|
|
447
|
+
|
|
448
|
+
before(:each) do
|
|
449
|
+
@organization_client = KeycloakAdmin.realm(realm_name).organizations
|
|
450
|
+
stub_token_client
|
|
451
|
+
allow_any_instance_of(RestClient::Resource).to receive(:delete).and_return ""
|
|
452
|
+
end
|
|
453
|
+
|
|
454
|
+
it "deletes a member" do
|
|
455
|
+
result = @organization_client.delete_member("8f6e474e-e688-4bec-99ba-5dc862594f4b", "e226d9d3-868e-453b-9bfc-d9d9cc534526")
|
|
456
|
+
expect(result).to be(true)
|
|
457
|
+
end
|
|
458
|
+
end
|
|
459
|
+
|
|
460
|
+
describe "#get_member" do
|
|
461
|
+
let(:realm_name) { "valid-realm" }
|
|
462
|
+
|
|
463
|
+
before(:each) do
|
|
464
|
+
@organization_client = KeycloakAdmin.realm(realm_name).organizations
|
|
465
|
+
json_payload = <<-'payload'
|
|
466
|
+
{
|
|
467
|
+
"id": "9a2ff47d-759c-4126-a281-8e4a7c6465e4",
|
|
468
|
+
"username": "hello",
|
|
469
|
+
"email": "hello@gmail.com",
|
|
470
|
+
"emailVerified": true,
|
|
471
|
+
"enabled": true,
|
|
472
|
+
"createdTimestamp": 1767608088024,
|
|
473
|
+
"totp": false,
|
|
474
|
+
"disableableCredentialTypes": [],
|
|
475
|
+
"requiredActions": [],
|
|
476
|
+
"notBefore": 0,
|
|
477
|
+
"membershipType": "UNMANAGED"
|
|
478
|
+
}
|
|
479
|
+
payload
|
|
480
|
+
stub_token_client
|
|
481
|
+
allow_any_instance_of(RestClient::Resource).to receive(:get).and_return json_payload
|
|
482
|
+
end
|
|
483
|
+
|
|
484
|
+
it "gets a member" do
|
|
485
|
+
member = @organization_client.get_member("8f6e474e-e688-4bec-99ba-5dc862594f4b", "9a2ff47d-759c-4126-a281-8e4a7c6465e4")
|
|
486
|
+
expect(member).to be
|
|
487
|
+
expect(member).to be_a KeycloakAdmin::MemberRepresentation
|
|
488
|
+
expect(member.id).to eq "9a2ff47d-759c-4126-a281-8e4a7c6465e4"
|
|
489
|
+
expect(member.membership_type).to eq "UNMANAGED"
|
|
490
|
+
end
|
|
491
|
+
end
|
|
492
|
+
|
|
493
|
+
describe "#add_member" do
|
|
494
|
+
let(:realm_name) { "valid-realm" }
|
|
495
|
+
|
|
496
|
+
before(:each) do
|
|
497
|
+
@organization_client = KeycloakAdmin.realm(realm_name).organizations
|
|
498
|
+
stub_token_client
|
|
499
|
+
allow_any_instance_of(RestClient::Resource).to receive(:post).and_return ""
|
|
500
|
+
end
|
|
501
|
+
|
|
502
|
+
it "creates a member from an existing user" do
|
|
503
|
+
result = @organization_client.add_member("8f6e474e-e688-4bec-99ba-5dc862594f4b", "9a2ff47d-759c-4126-a281-8e4a7c6465e4")
|
|
504
|
+
expect(result).to be true
|
|
505
|
+
end
|
|
506
|
+
end
|
|
507
|
+
|
|
508
|
+
describe "#add_member" do
|
|
509
|
+
let(:realm_name) { "valid-realm" }
|
|
510
|
+
|
|
511
|
+
before(:each) do
|
|
512
|
+
@organization_client = KeycloakAdmin.realm(realm_name).organizations
|
|
513
|
+
stub_token_client
|
|
514
|
+
allow_any_instance_of(RestClient::Resource).to receive(:post).and_return ""
|
|
515
|
+
end
|
|
516
|
+
|
|
517
|
+
it "creates a member from an existing user" do
|
|
518
|
+
result = @organization_client.add_member("8f6e474e-e688-4bec-99ba-5dc862594f4b", "9a2ff47d-759c-4126-a281-8e4a7c6465e4")
|
|
519
|
+
expect(result).to be true
|
|
520
|
+
end
|
|
521
|
+
end
|
|
522
|
+
|
|
523
|
+
describe "#update" do
|
|
524
|
+
let(:realm_name) { "valid-realm" }
|
|
525
|
+
let(:json_payload) do
|
|
526
|
+
<<-'payload'
|
|
527
|
+
{
|
|
528
|
+
"id": "8f6e474e-e688-4bec-99ba-5dc862594f4b",
|
|
529
|
+
"name": "Company",
|
|
530
|
+
"alias": "company",
|
|
531
|
+
"enabled": true,
|
|
532
|
+
"description": "A test organization",
|
|
533
|
+
"redirectUrl": "https://myapp.acme.com/redirect",
|
|
534
|
+
"attributes": {
|
|
535
|
+
"hello": [
|
|
536
|
+
"yes"
|
|
537
|
+
]
|
|
538
|
+
},
|
|
539
|
+
"domains": [
|
|
540
|
+
{
|
|
541
|
+
"name": "hello.com",
|
|
542
|
+
"verified": false
|
|
543
|
+
},
|
|
544
|
+
{
|
|
545
|
+
"name": "help.com",
|
|
546
|
+
"verified": false
|
|
547
|
+
}
|
|
548
|
+
]
|
|
549
|
+
}
|
|
550
|
+
payload
|
|
551
|
+
end
|
|
552
|
+
|
|
553
|
+
before(:each) do
|
|
554
|
+
@organization_client = KeycloakAdmin.realm(realm_name).organizations
|
|
555
|
+
stub_token_client
|
|
556
|
+
allow_any_instance_of(RestClient::Resource).to receive(:put).and_return ""
|
|
557
|
+
allow_any_instance_of(RestClient::Resource).to receive(:get).and_return json_payload
|
|
558
|
+
end
|
|
559
|
+
|
|
560
|
+
it "updates an organization" do
|
|
561
|
+
organization = KeycloakAdmin::OrganizationRepresentation.from_json(json_payload)
|
|
562
|
+
updated_organization = @organization_client.update(organization)
|
|
563
|
+
expect(updated_organization).to be
|
|
564
|
+
expect(updated_organization).to be_a KeycloakAdmin::OrganizationRepresentation
|
|
565
|
+
expect(updated_organization.id).to eq "8f6e474e-e688-4bec-99ba-5dc862594f4b"
|
|
566
|
+
end
|
|
567
|
+
end
|
|
568
|
+
|
|
569
|
+
describe "#create!" do
|
|
570
|
+
let(:realm_name) { "valid-realm" }
|
|
571
|
+
before(:each) do
|
|
572
|
+
@organization_client = KeycloakAdmin.realm(realm_name).organizations
|
|
573
|
+
stub_token_client
|
|
574
|
+
allow_any_instance_of(RestClient::Resource).to receive(:post).and_return ""
|
|
575
|
+
end
|
|
576
|
+
|
|
577
|
+
it "creates an organization" do
|
|
578
|
+
@organization_client.create!(
|
|
579
|
+
"new name",
|
|
580
|
+
"alias_name",
|
|
581
|
+
"enabled",
|
|
582
|
+
"description",
|
|
583
|
+
"http://redirect_url",
|
|
584
|
+
[
|
|
585
|
+
KeycloakAdmin::OrganizationDomainRepresentation.new("acme.com", true),
|
|
586
|
+
KeycloakAdmin::OrganizationDomainRepresentation.new("doe.com", false)
|
|
587
|
+
],
|
|
588
|
+
{
|
|
589
|
+
"advanced": ["yes", "no"],
|
|
590
|
+
"hello": ["maybe"]
|
|
591
|
+
}
|
|
592
|
+
)
|
|
593
|
+
end
|
|
594
|
+
end
|
|
595
|
+
end
|