keycloak-admin 1.2.0 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +4 -2
- data/.github/workflows/release.yml +112 -0
- data/CHANGELOG.md +14 -0
- data/Gemfile.lock +19 -20
- data/README.md +25 -5
- data/Rakefile +6 -0
- data/keycloak-admin.gemspec +5 -3
- data/lib/keycloak-admin/client/attack_detection_client.rb +3 -3
- data/lib/keycloak-admin/client/client.rb +18 -7
- data/lib/keycloak-admin/client/client_authz_permission_client.rb +7 -7
- data/lib/keycloak-admin/client/client_authz_policy_client.rb +5 -5
- data/lib/keycloak-admin/client/client_authz_resource_client.rb +6 -6
- data/lib/keycloak-admin/client/client_authz_scope_client.rb +5 -5
- data/lib/keycloak-admin/client/client_client.rb +6 -6
- data/lib/keycloak-admin/client/client_role_client.rb +1 -1
- data/lib/keycloak-admin/client/client_role_mappings_client.rb +2 -2
- data/lib/keycloak-admin/client/client_scope_client.rb +5 -5
- data/lib/keycloak-admin/client/client_scope_protocol_mapper_client.rb +5 -5
- data/lib/keycloak-admin/client/configurable_token_client.rb +4 -3
- data/lib/keycloak-admin/client/group_client.rb +15 -14
- data/lib/keycloak-admin/client/identity_provider_client.rb +4 -4
- data/lib/keycloak-admin/client/organization_client.rb +18 -18
- data/lib/keycloak-admin/client/realm_client.rb +4 -4
- data/lib/keycloak-admin/client/resource.rb +98 -0
- data/lib/keycloak-admin/client/response.rb +36 -0
- data/lib/keycloak-admin/client/role_client.rb +6 -6
- data/lib/keycloak-admin/client/role_mapper_client.rb +9 -8
- data/lib/keycloak-admin/client/token_client.rb +1 -3
- data/lib/keycloak-admin/client/user_client.rb +38 -31
- data/lib/keycloak-admin/configuration.rb +23 -1
- data/lib/keycloak-admin/version.rb +1 -1
- data/lib/keycloak-admin.rb +3 -1
- data/spec/client/attack_detection_client_spec.rb +3 -3
- data/spec/client/client_authz_permission_client_spec.rb +5 -5
- data/spec/client/client_authz_policy_client_spec.rb +5 -5
- data/spec/client/client_authz_resource_client_spec.rb +7 -7
- data/spec/client/client_authz_scope_client_spec.rb +5 -5
- data/spec/client/client_client_spec.rb +14 -14
- data/spec/client/client_role_mappings_client_spec.rb +11 -10
- data/spec/client/client_scope_client_spec.rb +7 -7
- data/spec/client/client_scope_protocol_mapper_client_spec.rb +7 -7
- data/spec/client/client_spec.rb +80 -7
- data/spec/client/group_client_spec.rb +47 -47
- data/spec/client/identity_provider_client_spec.rb +5 -5
- data/spec/client/organization_client_spec.rb +31 -31
- data/spec/client/realm_client_spec.rb +20 -20
- data/spec/client/resource_spec.rb +223 -0
- data/spec/client/response_spec.rb +68 -0
- data/spec/client/role_client_spec.rb +10 -10
- data/spec/client/role_mapper_client_spec.rb +10 -10
- data/spec/client/token_client_spec.rb +5 -5
- data/spec/client/user_client_spec.rb +29 -29
- data/spec/configuration_spec.rb +39 -2
- data/spec/gemspec_spec.rb +25 -0
- data/spec/integration/client_authorization_spec.rb +4 -4
- data/spec/representation/client_authz_policy_representation_spec.rb +1 -1
- data/spec/spec_helper.rb +8 -9
- metadata +42 -7
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
require "rest-client"
|
|
2
|
-
|
|
3
1
|
module KeycloakAdmin
|
|
4
2
|
class TokenClient < Client
|
|
5
3
|
def initialize(configuration, realm_client)
|
|
@@ -18,7 +16,7 @@ module KeycloakAdmin
|
|
|
18
16
|
|
|
19
17
|
def get
|
|
20
18
|
response = execute_http do
|
|
21
|
-
|
|
19
|
+
resource(token_url).post(
|
|
22
20
|
@configuration.body_for_token_retrieval,
|
|
23
21
|
@configuration.headers_for_token_retrieval
|
|
24
22
|
)
|
|
@@ -13,7 +13,7 @@ module KeycloakAdmin
|
|
|
13
13
|
|
|
14
14
|
def save(user_representation)
|
|
15
15
|
execute_http do
|
|
16
|
-
|
|
16
|
+
resource(users_url).post(
|
|
17
17
|
create_payload(user_representation), headers
|
|
18
18
|
)
|
|
19
19
|
end
|
|
@@ -23,40 +23,43 @@ module KeycloakAdmin
|
|
|
23
23
|
# pay attention that, since Keycloak 24.0.4, partial updates of attributes are not authorized anymore
|
|
24
24
|
def update(user_id, user_representation_body)
|
|
25
25
|
raise ArgumentError.new("user_id must be defined") if user_id.nil?
|
|
26
|
-
|
|
27
|
-
@configuration.
|
|
26
|
+
Resource.execute(
|
|
27
|
+
@configuration.faraday_options.merge(
|
|
28
28
|
method: :put,
|
|
29
29
|
url: users_url(user_id),
|
|
30
30
|
payload: create_payload(user_representation_body),
|
|
31
|
-
headers: headers
|
|
31
|
+
headers: headers,
|
|
32
|
+
logger: @configuration.logger
|
|
32
33
|
)
|
|
33
34
|
)
|
|
34
35
|
end
|
|
35
36
|
|
|
36
37
|
def add_group(user_id, group_id)
|
|
37
|
-
|
|
38
|
-
@configuration.
|
|
38
|
+
Resource.execute(
|
|
39
|
+
@configuration.faraday_options.merge(
|
|
39
40
|
method: :put,
|
|
40
41
|
url: "#{users_url(user_id)}/groups/#{group_id}",
|
|
41
42
|
payload: create_payload({}),
|
|
42
|
-
headers: headers
|
|
43
|
+
headers: headers,
|
|
44
|
+
logger: @configuration.logger
|
|
43
45
|
)
|
|
44
46
|
)
|
|
45
47
|
end
|
|
46
48
|
|
|
47
49
|
def remove_group(user_id, group_id)
|
|
48
|
-
|
|
49
|
-
@configuration.
|
|
50
|
+
Resource.execute(
|
|
51
|
+
@configuration.faraday_options.merge(
|
|
50
52
|
method: :delete,
|
|
51
53
|
url: "#{users_url(user_id)}/groups/#{group_id}",
|
|
52
|
-
headers: headers
|
|
54
|
+
headers: headers,
|
|
55
|
+
logger: @configuration.logger
|
|
53
56
|
)
|
|
54
57
|
)
|
|
55
58
|
end
|
|
56
59
|
|
|
57
60
|
def add_client_roles_on_user(user_id, client_id, role_representations)
|
|
58
61
|
execute_http do
|
|
59
|
-
|
|
62
|
+
resource(user_client_role_mappings_url(user_id, client_id)).post(
|
|
60
63
|
create_payload(role_representations), headers
|
|
61
64
|
)
|
|
62
65
|
end
|
|
@@ -64,7 +67,7 @@ module KeycloakAdmin
|
|
|
64
67
|
|
|
65
68
|
def get(user_id)
|
|
66
69
|
response = execute_http do
|
|
67
|
-
|
|
70
|
+
resource(users_url(user_id)).get(headers)
|
|
68
71
|
end
|
|
69
72
|
UserRepresentation.from_hash(JSON.parse(response))
|
|
70
73
|
end
|
|
@@ -86,7 +89,7 @@ module KeycloakAdmin
|
|
|
86
89
|
end
|
|
87
90
|
|
|
88
91
|
response = execute_http do
|
|
89
|
-
|
|
92
|
+
resource(users_url).get(derived_headers)
|
|
90
93
|
end
|
|
91
94
|
JSON.parse(response).map { |user_as_hash| UserRepresentation.from_hash(user_as_hash) }
|
|
92
95
|
end
|
|
@@ -97,26 +100,27 @@ module KeycloakAdmin
|
|
|
97
100
|
|
|
98
101
|
def delete(user_id)
|
|
99
102
|
execute_http do
|
|
100
|
-
|
|
103
|
+
resource(users_url(user_id)).delete(headers)
|
|
101
104
|
end
|
|
102
105
|
true
|
|
103
106
|
end
|
|
104
107
|
|
|
105
108
|
def groups(user_id)
|
|
106
109
|
response = execute_http do
|
|
107
|
-
|
|
110
|
+
resource(groups_url(user_id)).get(headers)
|
|
108
111
|
end
|
|
109
112
|
JSON.parse(response).map { |group_as_hash| GroupRepresentation.from_hash(group_as_hash) }
|
|
110
113
|
end
|
|
111
114
|
|
|
112
115
|
def update_password(user_id, new_password)
|
|
113
116
|
execute_http do
|
|
114
|
-
|
|
115
|
-
@configuration.
|
|
117
|
+
Resource.execute(
|
|
118
|
+
@configuration.faraday_options.merge(
|
|
116
119
|
method: :put,
|
|
117
120
|
url: reset_password_url(user_id),
|
|
118
121
|
payload: { type: "password", value: new_password, temporary: false }.to_json,
|
|
119
|
-
headers: headers
|
|
122
|
+
headers: headers,
|
|
123
|
+
logger: @configuration.logger
|
|
120
124
|
)
|
|
121
125
|
)
|
|
122
126
|
end
|
|
@@ -125,7 +129,7 @@ module KeycloakAdmin
|
|
|
125
129
|
|
|
126
130
|
def credentials(user_id)
|
|
127
131
|
response = execute_http do
|
|
128
|
-
|
|
132
|
+
resource(credentials_url(user_id)).get(headers)
|
|
129
133
|
end
|
|
130
134
|
JSON.parse(response).map { |group_as_hash| CredentialRepresentation.from_hash(group_as_hash) }
|
|
131
135
|
end
|
|
@@ -140,7 +144,7 @@ module KeycloakAdmin
|
|
|
140
144
|
lifespan_param = lifespan.nil? ? "" : "&lifespan=#{lifespan.seconds}"
|
|
141
145
|
redirect_uri_param = redirect_uri.nil? ? "" : "&redirect_uri=#{redirect_uri}"
|
|
142
146
|
client_id_param = client_id.nil? ? "" : "client_id=#{client_id}"
|
|
143
|
-
|
|
147
|
+
Resource.put("#{execute_actions_email_url(user_id)}?#{client_id_param}#{redirect_uri_param}#{lifespan_param}", create_payload(actions), headers, @configuration.logger)
|
|
144
148
|
end
|
|
145
149
|
user_id
|
|
146
150
|
end
|
|
@@ -148,12 +152,13 @@ module KeycloakAdmin
|
|
|
148
152
|
def impersonate(user_id)
|
|
149
153
|
impersonation = get_redirect_impersonation(user_id)
|
|
150
154
|
response = execute_http do
|
|
151
|
-
|
|
152
|
-
@configuration.
|
|
155
|
+
Resource.execute(
|
|
156
|
+
@configuration.faraday_options.merge(
|
|
153
157
|
method: :post,
|
|
154
158
|
url: impersonation.impersonation_url,
|
|
155
159
|
payload: impersonation.body.to_json,
|
|
156
|
-
headers: impersonation.headers
|
|
160
|
+
headers: impersonation.headers,
|
|
161
|
+
logger: @configuration.logger
|
|
157
162
|
)
|
|
158
163
|
)
|
|
159
164
|
end
|
|
@@ -164,7 +169,7 @@ module KeycloakAdmin
|
|
|
164
169
|
raise ArgumentError.new("user_id must be defined") if user_id.nil?
|
|
165
170
|
|
|
166
171
|
response = execute_http do
|
|
167
|
-
|
|
172
|
+
resource("#{users_url(user_id)}/sessions").get(headers)
|
|
168
173
|
end
|
|
169
174
|
JSON.parse(response).map { |session_as_hash| SessionRepresentation.from_hash(session_as_hash) }
|
|
170
175
|
end
|
|
@@ -173,11 +178,12 @@ module KeycloakAdmin
|
|
|
173
178
|
raise ArgumentError.new("user_id must be defined") if user_id.nil?
|
|
174
179
|
|
|
175
180
|
execute_http do
|
|
176
|
-
|
|
177
|
-
@configuration.
|
|
181
|
+
Resource.execute(
|
|
182
|
+
@configuration.faraday_options.merge(
|
|
178
183
|
method: :post,
|
|
179
184
|
url: logout_url(user_id),
|
|
180
|
-
headers: headers
|
|
185
|
+
headers: headers,
|
|
186
|
+
logger: @configuration.logger
|
|
181
187
|
)
|
|
182
188
|
)
|
|
183
189
|
end
|
|
@@ -195,12 +201,13 @@ module KeycloakAdmin
|
|
|
195
201
|
fed_id_rep.identity_provider = idp_id
|
|
196
202
|
|
|
197
203
|
execute_http do
|
|
198
|
-
|
|
199
|
-
@configuration.
|
|
204
|
+
Resource.execute(
|
|
205
|
+
@configuration.faraday_options.merge(
|
|
200
206
|
method: :post,
|
|
201
207
|
url: federated_identity_url(user_id, idp_id),
|
|
202
208
|
payload: fed_id_rep.to_json,
|
|
203
|
-
headers: headers
|
|
209
|
+
headers: headers,
|
|
210
|
+
logger: @configuration.logger
|
|
204
211
|
)
|
|
205
212
|
)
|
|
206
213
|
end
|
|
@@ -208,7 +215,7 @@ module KeycloakAdmin
|
|
|
208
215
|
|
|
209
216
|
def unlink_idp(user_id, idp_id)
|
|
210
217
|
execute_http do
|
|
211
|
-
|
|
218
|
+
resource(federated_identity_url(user_id, idp_id)).delete(headers)
|
|
212
219
|
end
|
|
213
220
|
end
|
|
214
221
|
|
|
@@ -2,7 +2,29 @@ require "base64"
|
|
|
2
2
|
|
|
3
3
|
module KeycloakAdmin
|
|
4
4
|
class Configuration
|
|
5
|
-
attr_accessor :server_url, :server_domain, :client_id, :client_secret, :client_realm_name, :use_service_account, :username, :password, :logger, :
|
|
5
|
+
attr_accessor :server_url, :server_domain, :client_id, :client_secret, :client_realm_name, :use_service_account, :username, :password, :logger, :faraday_options
|
|
6
|
+
|
|
7
|
+
# Treat a cached token as expired this many seconds before its real expiry, so it
|
|
8
|
+
# cannot go stale between the check below and the request that relies on it.
|
|
9
|
+
TOKEN_EXPIRY_SAFETY_MARGIN_SECONDS = 10
|
|
10
|
+
|
|
11
|
+
# Returns the cached TokenRepresentation, or nil if there is none or it is (about to be) expired.
|
|
12
|
+
def cached_token
|
|
13
|
+
return nil if @token_expires_at.nil? || Time.now >= @token_expires_at
|
|
14
|
+
@cached_token
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def cache_token(token_representation)
|
|
18
|
+
return token_representation unless token_representation.expires_in.is_a?(Numeric)
|
|
19
|
+
@cached_token = token_representation
|
|
20
|
+
@token_expires_at = Time.now + token_representation.expires_in - TOKEN_EXPIRY_SAFETY_MARGIN_SECONDS
|
|
21
|
+
token_representation
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def clear_cached_token!
|
|
25
|
+
@cached_token = nil
|
|
26
|
+
@token_expires_at = nil
|
|
27
|
+
end
|
|
6
28
|
|
|
7
29
|
def body_for_token_retrieval
|
|
8
30
|
if use_service_account
|
data/lib/keycloak-admin.rb
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
require "logger"
|
|
2
2
|
|
|
3
3
|
require_relative "keycloak-admin/configuration"
|
|
4
|
+
require_relative "keycloak-admin/client/response"
|
|
5
|
+
require_relative "keycloak-admin/client/resource"
|
|
4
6
|
require_relative "keycloak-admin/client/client"
|
|
5
7
|
require_relative "keycloak-admin/client/client_client"
|
|
6
8
|
require_relative "keycloak-admin/client/client_role_client"
|
|
@@ -83,7 +85,7 @@ module KeycloakAdmin
|
|
|
83
85
|
config.use_service_account = true
|
|
84
86
|
config.username = nil
|
|
85
87
|
config.password = nil
|
|
86
|
-
config.
|
|
88
|
+
config.faraday_options = {}
|
|
87
89
|
end
|
|
88
90
|
end
|
|
89
91
|
|
|
@@ -25,7 +25,7 @@ RSpec.describe KeycloakAdmin::AttackDetectionClient do
|
|
|
25
25
|
before(:each) do
|
|
26
26
|
@attack_detections = KeycloakAdmin.realm(realm_name).attack_detections
|
|
27
27
|
stub_token_client
|
|
28
|
-
allow_any_instance_of(
|
|
28
|
+
allow_any_instance_of(KeycloakAdmin::Resource).to receive(:get).and_return '{"numFailures":1,"disabled":true, "lastFailure":123456}'
|
|
29
29
|
end
|
|
30
30
|
|
|
31
31
|
context "when user_id is defined" do
|
|
@@ -49,7 +49,7 @@ RSpec.describe KeycloakAdmin::AttackDetectionClient do
|
|
|
49
49
|
before(:each) do
|
|
50
50
|
@attack_detections = KeycloakAdmin.realm(realm_name).attack_detections
|
|
51
51
|
stub_token_client
|
|
52
|
-
allow_any_instance_of(
|
|
52
|
+
allow_any_instance_of(KeycloakAdmin::Resource).to receive(:delete)
|
|
53
53
|
end
|
|
54
54
|
|
|
55
55
|
context "when user_id is defined" do
|
|
@@ -72,7 +72,7 @@ RSpec.describe KeycloakAdmin::AttackDetectionClient do
|
|
|
72
72
|
before(:each) do
|
|
73
73
|
@attack_detections = KeycloakAdmin.realm(realm_name).attack_detections
|
|
74
74
|
stub_token_client
|
|
75
|
-
allow_any_instance_of(
|
|
75
|
+
allow_any_instance_of(KeycloakAdmin::Resource).to receive(:delete)
|
|
76
76
|
end
|
|
77
77
|
it "returns true" do
|
|
78
78
|
expect(@attack_detections.unlock_users).to be_truthy
|
|
@@ -42,7 +42,7 @@ RSpec.describe KeycloakAdmin::ClientAuthzPermissionClient do
|
|
|
42
42
|
let(:client_authz_permission) { KeycloakAdmin.realm(realm_name).authz_permissions(client_id, "resource") }
|
|
43
43
|
before(:each) do
|
|
44
44
|
stub_token_client
|
|
45
|
-
allow_any_instance_of(
|
|
45
|
+
allow_any_instance_of(KeycloakAdmin::Resource).to receive(:delete).and_return 'true'
|
|
46
46
|
end
|
|
47
47
|
|
|
48
48
|
it "deletes a permission" do
|
|
@@ -56,7 +56,7 @@ RSpec.describe KeycloakAdmin::ClientAuthzPermissionClient do
|
|
|
56
56
|
let(:client_authz_permission) { KeycloakAdmin.realm(realm_name).authz_permissions(client_id, "resource") }
|
|
57
57
|
before(:each) do
|
|
58
58
|
stub_token_client
|
|
59
|
-
allow_any_instance_of(
|
|
59
|
+
allow_any_instance_of(KeycloakAdmin::Resource).to receive(:get).and_return '[{"id":"245ce612-ccdc-4426-8ea7-e0e29a718033","name":"Default Permission","description":"A permission that applies to the default resource type","type":"resource","logic":"POSITIVE","decisionStrategy":"UNANIMOUS","resourceType":"urn:dummy-client:resources:default"},{"id":"06a21e38-4e92-466d-8647-ffcd9c7b51c3","name":"delme policy","description":"delme polidy ","type":"resource","logic":"POSITIVE","decisionStrategy":"UNANIMOUS","resourceType":"asdfasdf"}]'
|
|
60
60
|
end
|
|
61
61
|
|
|
62
62
|
it "finds permissions" do
|
|
@@ -72,7 +72,7 @@ RSpec.describe KeycloakAdmin::ClientAuthzPermissionClient do
|
|
|
72
72
|
let(:client_authz_permission) { KeycloakAdmin.realm(realm_name).authz_permissions(client_id, "resource") }
|
|
73
73
|
before(:each) do
|
|
74
74
|
stub_token_client
|
|
75
|
-
allow_any_instance_of(
|
|
75
|
+
allow_any_instance_of(KeycloakAdmin::Resource).to receive(:post).and_return '{"id":"245ce612-ccdc-4426-8ea7-e0e29a718033","name":"Default Permission","description":"A permission that applies to the default resource type","type":"resource","logic":"POSITIVE","decisionStrategy":"UNANIMOUS","resourceType":"urn:dummy-client:resources:default"}'
|
|
76
76
|
end
|
|
77
77
|
|
|
78
78
|
it "creates a permission" do
|
|
@@ -92,7 +92,7 @@ RSpec.describe KeycloakAdmin::ClientAuthzPermissionClient do
|
|
|
92
92
|
before(:each) do
|
|
93
93
|
@client_authz_permission = KeycloakAdmin.realm(realm_name).authz_permissions(client_id, "resource")
|
|
94
94
|
stub_token_client
|
|
95
|
-
allow_any_instance_of(
|
|
95
|
+
allow_any_instance_of(KeycloakAdmin::Resource).to receive(:get).and_return '[{"id":"245ce612-ccdc-4426-8ea7-e0e29a718033","name":"Default Permission","description":"A permission that applies to the default resource type","type":"resource","logic":"POSITIVE","decisionStrategy":"UNANIMOUS","resourceType":"urn:dummy-client:resources:default"},{"id":"06a21e38-4e92-466d-8647-ffcd9c7b51c3","name":"delme policy","description":"delme polidy ","type":"resource","logic":"POSITIVE","decisionStrategy":"UNANIMOUS","resourceType":"asdfasdf"}]'
|
|
96
96
|
|
|
97
97
|
end
|
|
98
98
|
|
|
@@ -114,7 +114,7 @@ RSpec.describe KeycloakAdmin::ClientAuthzPermissionClient do
|
|
|
114
114
|
let(:client_authz_permission) { KeycloakAdmin.realm(realm_name).authz_permissions(client_id, "resource") }
|
|
115
115
|
before(:each) do
|
|
116
116
|
stub_token_client
|
|
117
|
-
allow_any_instance_of(
|
|
117
|
+
allow_any_instance_of(KeycloakAdmin::Resource).to receive(:get).and_return '{"id":"245ce612-ccdc-4426-8ea7-e0e29a718033","name":"Default Permission","description":"A permission that applies to the default resource type","type":"resource","logic":"POSITIVE","decisionStrategy":"UNANIMOUS","resourceType":"urn:dummy-client:resources:default"}'
|
|
118
118
|
end
|
|
119
119
|
|
|
120
120
|
it "gets a permission" do
|
|
@@ -50,7 +50,7 @@ RSpec.describe KeycloakAdmin::ClientAuthzPolicyClient do
|
|
|
50
50
|
|
|
51
51
|
before(:each) do
|
|
52
52
|
stub_token_client
|
|
53
|
-
allow_any_instance_of(
|
|
53
|
+
allow_any_instance_of(KeycloakAdmin::Resource).to receive(:post).and_return '{"id":"234f6f33-ef03-4f3f-a8c0-ad7bca27b720","name":"policy name","description":"policy description","type":"role","logic":"POSITIVE","decisionStrategy":"UNANIMOUS","config":{"roles":"[{\"id\":\"1d305dbe-6379-4900-8e63-96541006160a\",\"required\":false}]"}}'
|
|
54
54
|
end
|
|
55
55
|
|
|
56
56
|
it "creates a new authz policy" do
|
|
@@ -72,7 +72,7 @@ RSpec.describe KeycloakAdmin::ClientAuthzPolicyClient do
|
|
|
72
72
|
let(:client_authz_policy){ KeycloakAdmin.realm(realm_name).authz_policies(client_id, type) }
|
|
73
73
|
before(:each) do
|
|
74
74
|
stub_token_client
|
|
75
|
-
allow_any_instance_of(
|
|
75
|
+
allow_any_instance_of(KeycloakAdmin::Resource).to receive(:get).and_return '{"id":"234f6f33-ef03-4f3f-a8c0-ad7bca27b720","name":"policy name","description":"policy description","type":"role","logic":"POSITIVE","decisionStrategy":"UNANIMOUS","config":{"roles":"[{\"id\":\"1d305dbe-6379-4900-8e63-96541006160a\",\"required\":false}]"}}'
|
|
76
76
|
end
|
|
77
77
|
|
|
78
78
|
it "returns an authz policy" do
|
|
@@ -94,7 +94,7 @@ RSpec.describe KeycloakAdmin::ClientAuthzPolicyClient do
|
|
|
94
94
|
let(:client_authz_policy){ KeycloakAdmin.realm(realm_name).authz_policies(client_id, type) }
|
|
95
95
|
before(:each) do
|
|
96
96
|
stub_token_client
|
|
97
|
-
allow_any_instance_of(
|
|
97
|
+
allow_any_instance_of(KeycloakAdmin::Resource).to receive(:get).and_return '[{"id":"234f6f33-ef03-4f3f-a8c0-ad7bca27b720","name":"policy name","description":"policy description","type":"role","logic":"POSITIVE","decisionStrategy":"UNANIMOUS","config":{"roles":"[{\"id\":\"1d305dbe-6379-4900-8e63-96541006160a\",\"required\":false}]"}}]'
|
|
98
98
|
end
|
|
99
99
|
|
|
100
100
|
it "returns list of authz policies" do
|
|
@@ -117,7 +117,7 @@ RSpec.describe KeycloakAdmin::ClientAuthzPolicyClient do
|
|
|
117
117
|
before(:each) do
|
|
118
118
|
@client_authz_policy = KeycloakAdmin.realm(realm_name).authz_policies(client_id, type)
|
|
119
119
|
stub_token_client
|
|
120
|
-
allow_any_instance_of(
|
|
120
|
+
allow_any_instance_of(KeycloakAdmin::Resource).to receive(:delete).and_return 'true'
|
|
121
121
|
end
|
|
122
122
|
|
|
123
123
|
it "deletes an authz policy" do
|
|
@@ -133,7 +133,7 @@ RSpec.describe KeycloakAdmin::ClientAuthzPolicyClient do
|
|
|
133
133
|
before(:each) do
|
|
134
134
|
@client_authz_policy = KeycloakAdmin.realm(realm_name).authz_policies(client_id, type)
|
|
135
135
|
stub_token_client
|
|
136
|
-
allow_any_instance_of(
|
|
136
|
+
allow_any_instance_of(KeycloakAdmin::Resource).to receive(:get).and_return '[{"id":"234f6f33-ef03-4f3f-a8c0-ad7bca27b720","name":"policy name","description":"policy description","type":"role","logic":"POSITIVE","decisionStrategy":"UNANIMOUS","config":{"roles":"[{\"id\":\"1d305dbe-6379-4900-8e63-96541006160a\",\"required\":false}]"}}]'
|
|
137
137
|
end
|
|
138
138
|
|
|
139
139
|
it "returns list of authz policies" do
|
|
@@ -24,7 +24,7 @@ RSpec.describe KeycloakAdmin::ClientAuthzResourceClient do
|
|
|
24
24
|
before(:each) do
|
|
25
25
|
@client_authz_resource = KeycloakAdmin.realm(realm_name).authz_resources(client_id)
|
|
26
26
|
stub_token_client
|
|
27
|
-
allow_any_instance_of(
|
|
27
|
+
allow_any_instance_of(KeycloakAdmin::Resource).to receive(:get).and_return '[{"name":"Default Resource","type":"urn:delme-client-id:resources:default","owner":{"id":"d259b451-371b-432a-a526-3508f3a36f3b","name":"delme-client-id"},"ownerManagedAccess":false,"_id":"94643fe2-1973-4a36-8e1f-830ade186398","uris":["/*"]},{"name":"asdfasdf","type":"urn:delme-client-id:resources:default","owner":{"id":"d259b451-371b-432a-a526-3508f3a36f3b","name":"delme-client-id"},"ownerManagedAccess":true,"displayName":"asdfasdfasdfa","_id":"385966a2-14b9-4cc4-9539-5f2fe1008222","uris":["/*"],"icon_uri":"http://icon"}]'
|
|
28
28
|
end
|
|
29
29
|
|
|
30
30
|
it "returns list of authz scopes" do
|
|
@@ -44,7 +44,7 @@ RSpec.describe KeycloakAdmin::ClientAuthzResourceClient do
|
|
|
44
44
|
let(:client_authz_resource) { KeycloakAdmin.realm(realm_name).authz_resources(client_id) }
|
|
45
45
|
before(:each) do
|
|
46
46
|
stub_token_client
|
|
47
|
-
allow_any_instance_of(
|
|
47
|
+
allow_any_instance_of(KeycloakAdmin::Resource).to receive(:get).and_return '{"name":"Default Resource","type":"urn:delme-client-id:resources:default","owner":{"id":"d259b451-371b-432a-a526-3508f3a36f3b","name":"delme-client-id"},"ownerManagedAccess":false,"_id":"94643fe2-1973-4a36-8e1f-830ade186398","uris":["/*"]}'
|
|
48
48
|
end
|
|
49
49
|
|
|
50
50
|
it "returns authz scope" do
|
|
@@ -63,8 +63,8 @@ RSpec.describe KeycloakAdmin::ClientAuthzResourceClient do
|
|
|
63
63
|
let(:client_authz_resource) { KeycloakAdmin.realm(realm_name).authz_resources(client_id) }
|
|
64
64
|
before(:each) do
|
|
65
65
|
stub_token_client
|
|
66
|
-
allow_any_instance_of(
|
|
67
|
-
allow_any_instance_of(
|
|
66
|
+
allow_any_instance_of(KeycloakAdmin::Resource).to receive(:get).and_return '{"name":"Default Resource","type":"urn:delme-client-id:resources:default","owner":{"id":"d259b451-371b-432a-a526-3508f3a36f3b","name":"delme-client-id"},"ownerManagedAccess":false,"_id":"94643fe2-1973-4a36-8e1f-830ade186398","uris":["/*"]}'
|
|
67
|
+
allow_any_instance_of(KeycloakAdmin::Resource).to receive(:put).and_return '{"name":"Default Resource","type":"urn:delme-client-id:resources:default","owner":{"id":"d259b451-371b-432a-a526-3508f3a36f3b","name":"delme-client-id"},"ownerManagedAccess":false,"_id":"94643fe2-1973-4a36-8e1f-830ade186398","uris":["/*"]}'
|
|
68
68
|
end
|
|
69
69
|
|
|
70
70
|
it "returns updated authz scope" do
|
|
@@ -82,7 +82,7 @@ RSpec.describe KeycloakAdmin::ClientAuthzResourceClient do
|
|
|
82
82
|
before(:each) do
|
|
83
83
|
@client_authz_resource = KeycloakAdmin.realm(realm_name).authz_resources(client_id)
|
|
84
84
|
stub_token_client
|
|
85
|
-
allow_any_instance_of(
|
|
85
|
+
allow_any_instance_of(KeycloakAdmin::Resource).to receive(:post).and_return '{"name":"Default Resource","type":"urn:delme-client-id:resources:default","owner":{"id":"d259b451-371b-432a-a526-3508f3a36f3b","name":"delme-client-id"},"ownerManagedAccess":false,"_id":"94643fe2-1973-4a36-8e1f-830ade186398","uris":["/*"]}'
|
|
86
86
|
end
|
|
87
87
|
|
|
88
88
|
it "returns created authz scope" do
|
|
@@ -101,7 +101,7 @@ RSpec.describe KeycloakAdmin::ClientAuthzResourceClient do
|
|
|
101
101
|
let(:client_authz_resource) { KeycloakAdmin.realm(realm_name).authz_resources(client_id) }
|
|
102
102
|
before(:each) do
|
|
103
103
|
stub_token_client
|
|
104
|
-
allow_any_instance_of(
|
|
104
|
+
allow_any_instance_of(KeycloakAdmin::Resource).to receive(:get).and_return '[{"name":"Default Resource","type":"urn:delme-client-id:resources:default","owner":{"id":"d259b451-371b-432a-a526-3508f3a36f3b","name":"delme-client-id"},"ownerManagedAccess":false,"_id":"94643fe2-1973-4a36-8e1f-830ade186398","uris":["/*"]}]'
|
|
105
105
|
end
|
|
106
106
|
|
|
107
107
|
it "returns list of authz scopes" do
|
|
@@ -139,7 +139,7 @@ RSpec.describe KeycloakAdmin::ClientAuthzResourceClient do
|
|
|
139
139
|
let(:client_authz_resource) { KeycloakAdmin.realm(realm_name).authz_resources(client_id) }
|
|
140
140
|
before(:each) do
|
|
141
141
|
stub_token_client
|
|
142
|
-
allow_any_instance_of(
|
|
142
|
+
allow_any_instance_of(KeycloakAdmin::Resource).to receive(:delete).and_return '{}'
|
|
143
143
|
end
|
|
144
144
|
|
|
145
145
|
it "returns true" do
|
|
@@ -24,7 +24,7 @@ RSpec.describe KeycloakAdmin::ClientAuthzScopeClient do
|
|
|
24
24
|
before(:each) do
|
|
25
25
|
@client_authz_scope = KeycloakAdmin.realm(realm_name).authz_scopes(client_id)
|
|
26
26
|
stub_token_client
|
|
27
|
-
allow_any_instance_of(
|
|
27
|
+
allow_any_instance_of(KeycloakAdmin::Resource).to receive(:post).and_return '{"id":"c0779ce3-0900-4ea3-b1d6-b23e1f19c662","name":"GET","iconUri":"http://asdfasd1","displayName":"GET authz scope"}'
|
|
28
28
|
end
|
|
29
29
|
|
|
30
30
|
it "returns created authz scope" do
|
|
@@ -42,7 +42,7 @@ RSpec.describe KeycloakAdmin::ClientAuthzScopeClient do
|
|
|
42
42
|
before(:each) do
|
|
43
43
|
@client_authz_scope = KeycloakAdmin.realm(realm_name).authz_scopes(client_id)
|
|
44
44
|
stub_token_client
|
|
45
|
-
allow_any_instance_of(
|
|
45
|
+
allow_any_instance_of(KeycloakAdmin::Resource).to receive(:get).and_return '[{"id":"c0779ce3-0900-4ea3-b1d6-b23e1f19c662","name":"GET","iconUri":"http://asdfasd1","displayName":"GET authz scope"},{"id":"d0779ce3-0900-4ea3-b1d6-b23e1f19c662","name":"POST","iconUri":"http://asdfasd2","displayName":"POST authz scope"}]'
|
|
46
46
|
end
|
|
47
47
|
|
|
48
48
|
it "returns list of authz scopes" do
|
|
@@ -63,7 +63,7 @@ RSpec.describe KeycloakAdmin::ClientAuthzScopeClient do
|
|
|
63
63
|
before(:each) do
|
|
64
64
|
@client_authz_scope = KeycloakAdmin.realm(realm_name).authz_scopes(client_id)
|
|
65
65
|
stub_token_client
|
|
66
|
-
allow_any_instance_of(
|
|
66
|
+
allow_any_instance_of(KeycloakAdmin::Resource).to receive(:delete).and_return ""
|
|
67
67
|
end
|
|
68
68
|
|
|
69
69
|
it "returns true" do
|
|
@@ -79,7 +79,7 @@ RSpec.describe KeycloakAdmin::ClientAuthzScopeClient do
|
|
|
79
79
|
before(:each) do
|
|
80
80
|
@client_authz_scope = KeycloakAdmin.realm(realm_name).authz_scopes(client_id)
|
|
81
81
|
stub_token_client
|
|
82
|
-
allow_any_instance_of(
|
|
82
|
+
allow_any_instance_of(KeycloakAdmin::Resource).to receive(:get).and_return '{"id":"c0779ce3-0900-4ea3-b1d6-b23e1f19c662","name":"GET","iconUri":"http://asdfasd1","displayName":"GET authz scope"}'
|
|
83
83
|
end
|
|
84
84
|
|
|
85
85
|
it "returns authz scope" do
|
|
@@ -98,7 +98,7 @@ RSpec.describe KeycloakAdmin::ClientAuthzScopeClient do
|
|
|
98
98
|
before(:each) do
|
|
99
99
|
@client_authz_scope = KeycloakAdmin.realm(realm_name).authz_scopes(client_id)
|
|
100
100
|
stub_token_client
|
|
101
|
-
allow_any_instance_of(
|
|
101
|
+
allow_any_instance_of(KeycloakAdmin::Resource).to receive(:get).and_return '[{"id":"c0779ce3-0900-4ea3-b1d6-b23e1f19c662","name":"GET","iconUri":"http://asdfasd1","displayName":"GET authz scope"}]'
|
|
102
102
|
end
|
|
103
103
|
|
|
104
104
|
it "returns list of authz scopes" do
|
|
@@ -31,7 +31,7 @@ RSpec.describe KeycloakAdmin::ClientClient do
|
|
|
31
31
|
@client_client = KeycloakAdmin.realm(realm_name).clients
|
|
32
32
|
|
|
33
33
|
stub_token_client
|
|
34
|
-
allow_any_instance_of(
|
|
34
|
+
allow_any_instance_of(KeycloakAdmin::Resource).to receive(:get).and_return '{"id":"test_client_id","name":"test_client_name"}'
|
|
35
35
|
end
|
|
36
36
|
|
|
37
37
|
it "finds a client" do
|
|
@@ -50,7 +50,7 @@ RSpec.describe KeycloakAdmin::ClientClient do
|
|
|
50
50
|
@client_client = KeycloakAdmin.realm(realm_name).clients
|
|
51
51
|
|
|
52
52
|
stub_token_client
|
|
53
|
-
allow_any_instance_of(
|
|
53
|
+
allow_any_instance_of(KeycloakAdmin::Resource).to receive(:get).and_return '[{"id":"test_client_id","clientId": "my_client_id","name":"test_client_name"},{"id":"test_client_id_2","clientId":"client_id_2","name":"test_client_name_2"}]'
|
|
54
54
|
end
|
|
55
55
|
|
|
56
56
|
it "finds a client it has" do
|
|
@@ -72,7 +72,7 @@ RSpec.describe KeycloakAdmin::ClientClient do
|
|
|
72
72
|
@client_client = KeycloakAdmin.realm(realm_name).clients
|
|
73
73
|
|
|
74
74
|
stub_token_client
|
|
75
|
-
allow_any_instance_of(
|
|
75
|
+
allow_any_instance_of(KeycloakAdmin::Resource).to receive(:get).and_return '[{"id":"test_client_id","name":"test_client_name"}]'
|
|
76
76
|
end
|
|
77
77
|
|
|
78
78
|
it "lists clients" do
|
|
@@ -82,11 +82,11 @@ RSpec.describe KeycloakAdmin::ClientClient do
|
|
|
82
82
|
end
|
|
83
83
|
|
|
84
84
|
it "passes rest client options" do
|
|
85
|
-
|
|
86
|
-
allow_any_instance_of(KeycloakAdmin::Configuration).to receive(:
|
|
85
|
+
faraday_options = {timeout: 10}
|
|
86
|
+
allow_any_instance_of(KeycloakAdmin::Configuration).to receive(:faraday_options).and_return faraday_options
|
|
87
87
|
|
|
88
|
-
expect(
|
|
89
|
-
"http://auth.service.io/auth/admin/realms/valid-realm/clients",
|
|
88
|
+
expect(KeycloakAdmin::Resource).to receive(:new).with(
|
|
89
|
+
"http://auth.service.io/auth/admin/realms/valid-realm/clients", faraday_options, anything).and_call_original
|
|
90
90
|
|
|
91
91
|
clients = @client_client.list
|
|
92
92
|
expect(clients.length).to eq 1
|
|
@@ -102,8 +102,8 @@ RSpec.describe KeycloakAdmin::ClientClient do
|
|
|
102
102
|
@client_client = KeycloakAdmin.realm(realm_name).clients
|
|
103
103
|
|
|
104
104
|
stub_token_client
|
|
105
|
-
allow_any_instance_of(
|
|
106
|
-
allow_any_instance_of(
|
|
105
|
+
allow_any_instance_of(KeycloakAdmin::Resource).to receive(:put).and_return ''
|
|
106
|
+
allow_any_instance_of(KeycloakAdmin::Resource).to receive(:get).and_return '{"id":"test_client_id", "clientId": "my-client","name":"new_name"}'
|
|
107
107
|
end
|
|
108
108
|
|
|
109
109
|
it "updates a client" do
|
|
@@ -119,14 +119,14 @@ RSpec.describe KeycloakAdmin::ClientClient do
|
|
|
119
119
|
before(:each) do
|
|
120
120
|
@client_client = KeycloakAdmin.realm(realm_name).clients
|
|
121
121
|
stub_token_client
|
|
122
|
-
allow_any_instance_of(
|
|
122
|
+
allow_any_instance_of(KeycloakAdmin::Resource).to receive(:delete).and_return ''
|
|
123
123
|
end
|
|
124
124
|
|
|
125
125
|
it "passes rest client options" do
|
|
126
|
-
|
|
127
|
-
allow_any_instance_of(KeycloakAdmin::Configuration).to receive(:
|
|
128
|
-
expect(
|
|
129
|
-
"http://auth.service.io/auth/admin/realms/valid-realm/clients/95b45037-3980-404c-ba12-784fa1baf2c2",
|
|
126
|
+
faraday_options = {timeout: 10}
|
|
127
|
+
allow_any_instance_of(KeycloakAdmin::Configuration).to receive(:faraday_options).and_return faraday_options
|
|
128
|
+
expect(KeycloakAdmin::Resource).to receive(:new).with(
|
|
129
|
+
"http://auth.service.io/auth/admin/realms/valid-realm/clients/95b45037-3980-404c-ba12-784fa1baf2c2", faraday_options, anything).and_call_original
|
|
130
130
|
@client_client.delete("95b45037-3980-404c-ba12-784fa1baf2c2")
|
|
131
131
|
end
|
|
132
132
|
end
|
|
@@ -22,7 +22,7 @@ RSpec.describe KeycloakAdmin::ClientRoleMappingsClient do
|
|
|
22
22
|
@client_role_mappings_client = KeycloakAdmin.realm(realm_name).user(user_id).client_role_mappings(client_id)
|
|
23
23
|
|
|
24
24
|
stub_token_client
|
|
25
|
-
allow_any_instance_of(
|
|
25
|
+
allow_any_instance_of(KeycloakAdmin::Resource).to receive(:get).and_return '[{"id":"test_role_id","name":"test_role_name"}]'
|
|
26
26
|
end
|
|
27
27
|
|
|
28
28
|
it "lists roles" do
|
|
@@ -32,12 +32,13 @@ RSpec.describe KeycloakAdmin::ClientRoleMappingsClient do
|
|
|
32
32
|
end
|
|
33
33
|
|
|
34
34
|
it "passes rest client options" do
|
|
35
|
-
|
|
36
|
-
allow_any_instance_of(KeycloakAdmin::Configuration).to receive(:
|
|
35
|
+
faraday_options = {timeout: 10}
|
|
36
|
+
allow_any_instance_of(KeycloakAdmin::Configuration).to receive(:faraday_options).and_return faraday_options
|
|
37
37
|
|
|
38
|
-
expect(
|
|
38
|
+
expect(KeycloakAdmin::Resource).to receive(:new).with(
|
|
39
39
|
"http://auth.service.io/auth/admin/realms/valid-realm/users/test_user/role-mappings/clients/test_client/available",
|
|
40
|
-
|
|
40
|
+
faraday_options,
|
|
41
|
+
anything
|
|
41
42
|
).and_call_original
|
|
42
43
|
|
|
43
44
|
roles = @client_role_mappings_client.list_available
|
|
@@ -62,7 +63,7 @@ RSpec.describe KeycloakAdmin::ClientRoleMappingsClient do
|
|
|
62
63
|
@client_role_mappings_client = KeycloakAdmin.realm(realm_name).user(user_id).client_role_mappings(client_id)
|
|
63
64
|
|
|
64
65
|
stub_token_client
|
|
65
|
-
expect_any_instance_of(
|
|
66
|
+
expect_any_instance_of(KeycloakAdmin::Resource).to receive(:post).with(role_list.to_json, anything)
|
|
66
67
|
end
|
|
67
68
|
|
|
68
69
|
it "saves client role mappings" do
|
|
@@ -70,11 +71,11 @@ RSpec.describe KeycloakAdmin::ClientRoleMappingsClient do
|
|
|
70
71
|
end
|
|
71
72
|
|
|
72
73
|
it "passes rest client options" do
|
|
73
|
-
|
|
74
|
-
allow_any_instance_of(KeycloakAdmin::Configuration).to receive(:
|
|
74
|
+
faraday_options = {timeout: 10}
|
|
75
|
+
allow_any_instance_of(KeycloakAdmin::Configuration).to receive(:faraday_options).and_return faraday_options
|
|
75
76
|
|
|
76
|
-
expect(
|
|
77
|
-
"http://auth.service.io/auth/admin/realms/valid-realm/users/test_user/role-mappings/clients/test_client",
|
|
77
|
+
expect(KeycloakAdmin::Resource).to receive(:new).with(
|
|
78
|
+
"http://auth.service.io/auth/admin/realms/valid-realm/users/test_user/role-mappings/clients/test_client", faraday_options, anything).and_call_original
|
|
78
79
|
|
|
79
80
|
@client_role_mappings_client.save(role_list)
|
|
80
81
|
end
|