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
|
@@ -32,7 +32,7 @@ RSpec.describe KeycloakAdmin::ClientScopeClient do
|
|
|
32
32
|
before(:each) do
|
|
33
33
|
@client = KeycloakAdmin.realm(realm_name).client_scopes
|
|
34
34
|
stub_token_client
|
|
35
|
-
allow_any_instance_of(
|
|
35
|
+
allow_any_instance_of(KeycloakAdmin::Resource).to receive(:get).and_return stub_response
|
|
36
36
|
end
|
|
37
37
|
|
|
38
38
|
context "with one scope" do
|
|
@@ -77,7 +77,7 @@ RSpec.describe KeycloakAdmin::ClientScopeClient do
|
|
|
77
77
|
before(:each) do
|
|
78
78
|
@client = KeycloakAdmin.realm(realm_name).client_scopes
|
|
79
79
|
stub_token_client
|
|
80
|
-
allow_any_instance_of(
|
|
80
|
+
allow_any_instance_of(KeycloakAdmin::Resource).to receive(:get).and_return stub_response
|
|
81
81
|
end
|
|
82
82
|
|
|
83
83
|
context "without protocol mappers" do
|
|
@@ -121,7 +121,7 @@ RSpec.describe KeycloakAdmin::ClientScopeClient do
|
|
|
121
121
|
before(:each) do
|
|
122
122
|
@client = KeycloakAdmin.realm(realm_name).client_scopes
|
|
123
123
|
stub_token_client
|
|
124
|
-
allow_any_instance_of(
|
|
124
|
+
allow_any_instance_of(KeycloakAdmin::Resource).to receive(:post).and_return ""
|
|
125
125
|
end
|
|
126
126
|
|
|
127
127
|
let(:scope_representation) do
|
|
@@ -142,13 +142,13 @@ RSpec.describe KeycloakAdmin::ClientScopeClient do
|
|
|
142
142
|
before(:each) do
|
|
143
143
|
@client = KeycloakAdmin.realm(realm_name).client_scopes
|
|
144
144
|
stub_token_client
|
|
145
|
-
allow_any_instance_of(
|
|
145
|
+
allow_any_instance_of(KeycloakAdmin::Resource).to receive(:put).and_return ""
|
|
146
146
|
end
|
|
147
147
|
|
|
148
148
|
let(:scope_representation) { KeycloakAdmin::ClientScopeRepresentation.from_hash(JSON.parse(scope_json)) }
|
|
149
149
|
|
|
150
150
|
it "calls put on the scope url" do
|
|
151
|
-
expect_any_instance_of(
|
|
151
|
+
expect_any_instance_of(KeycloakAdmin::Resource).to receive(:put).with(anything, anything)
|
|
152
152
|
@client.save(scope_representation)
|
|
153
153
|
end
|
|
154
154
|
|
|
@@ -163,7 +163,7 @@ RSpec.describe KeycloakAdmin::ClientScopeClient do
|
|
|
163
163
|
before(:each) do
|
|
164
164
|
@client = KeycloakAdmin.realm(realm_name).client_scopes
|
|
165
165
|
stub_token_client
|
|
166
|
-
allow_any_instance_of(
|
|
166
|
+
allow_any_instance_of(KeycloakAdmin::Resource).to receive(:get).and_return "[#{scope_json},#{second_scope_json}]"
|
|
167
167
|
end
|
|
168
168
|
|
|
169
169
|
context "when the name matches one scope" do
|
|
@@ -193,7 +193,7 @@ RSpec.describe KeycloakAdmin::ClientScopeClient do
|
|
|
193
193
|
before(:each) do
|
|
194
194
|
@client = KeycloakAdmin.realm(realm_name).client_scopes
|
|
195
195
|
stub_token_client
|
|
196
|
-
allow_any_instance_of(
|
|
196
|
+
allow_any_instance_of(KeycloakAdmin::Resource).to receive(:delete).and_return ""
|
|
197
197
|
end
|
|
198
198
|
|
|
199
199
|
it "returns true" do
|
|
@@ -33,7 +33,7 @@ RSpec.describe KeycloakAdmin::ClientScopeProtocolMapperClient do
|
|
|
33
33
|
before(:each) do
|
|
34
34
|
@client = KeycloakAdmin.realm(realm_name).client_scope_protocol_mappers(client_scope_id)
|
|
35
35
|
stub_token_client
|
|
36
|
-
allow_any_instance_of(
|
|
36
|
+
allow_any_instance_of(KeycloakAdmin::Resource).to receive(:get).and_return stub_response
|
|
37
37
|
end
|
|
38
38
|
|
|
39
39
|
context "with a hardcoded claim mapper" do
|
|
@@ -77,7 +77,7 @@ RSpec.describe KeycloakAdmin::ClientScopeProtocolMapperClient do
|
|
|
77
77
|
before(:each) do
|
|
78
78
|
@client = KeycloakAdmin.realm(realm_name).client_scope_protocol_mappers(client_scope_id)
|
|
79
79
|
stub_token_client
|
|
80
|
-
allow_any_instance_of(
|
|
80
|
+
allow_any_instance_of(KeycloakAdmin::Resource).to receive(:get).and_return stub_response
|
|
81
81
|
end
|
|
82
82
|
|
|
83
83
|
context "with a hardcoded claim mapper" do
|
|
@@ -130,7 +130,7 @@ RSpec.describe KeycloakAdmin::ClientScopeProtocolMapperClient do
|
|
|
130
130
|
before(:each) do
|
|
131
131
|
@client = KeycloakAdmin.realm(realm_name).client_scope_protocol_mappers(client_scope_id)
|
|
132
132
|
stub_token_client
|
|
133
|
-
allow_any_instance_of(
|
|
133
|
+
allow_any_instance_of(KeycloakAdmin::Resource).to receive(:post).and_return stub_response
|
|
134
134
|
end
|
|
135
135
|
|
|
136
136
|
context "with a hardcoded claim mapper" do
|
|
@@ -177,14 +177,14 @@ RSpec.describe KeycloakAdmin::ClientScopeProtocolMapperClient do
|
|
|
177
177
|
before(:each) do
|
|
178
178
|
@client = KeycloakAdmin.realm(realm_name).client_scope_protocol_mappers(client_scope_id)
|
|
179
179
|
stub_token_client
|
|
180
|
-
allow_any_instance_of(
|
|
180
|
+
allow_any_instance_of(KeycloakAdmin::Resource).to receive(:put).and_return ""
|
|
181
181
|
end
|
|
182
182
|
|
|
183
183
|
context "with a hardcoded claim mapper" do
|
|
184
184
|
let(:mapper_representation) { KeycloakAdmin::ProtocolMapperRepresentation.from_hash(JSON.parse(mapper_json)) }
|
|
185
185
|
|
|
186
186
|
it "calls put on the mapper url" do
|
|
187
|
-
expect_any_instance_of(
|
|
187
|
+
expect_any_instance_of(KeycloakAdmin::Resource).to receive(:put).with(anything, anything)
|
|
188
188
|
@client.save(mapper_representation)
|
|
189
189
|
end
|
|
190
190
|
end
|
|
@@ -193,7 +193,7 @@ RSpec.describe KeycloakAdmin::ClientScopeProtocolMapperClient do
|
|
|
193
193
|
let(:mapper_representation) { KeycloakAdmin::ProtocolMapperRepresentation.from_hash(JSON.parse(audience_mapper_json)) }
|
|
194
194
|
|
|
195
195
|
it "calls put on the mapper url" do
|
|
196
|
-
expect_any_instance_of(
|
|
196
|
+
expect_any_instance_of(KeycloakAdmin::Resource).to receive(:put).with(anything, anything)
|
|
197
197
|
@client.save(mapper_representation)
|
|
198
198
|
end
|
|
199
199
|
end
|
|
@@ -203,7 +203,7 @@ RSpec.describe KeycloakAdmin::ClientScopeProtocolMapperClient do
|
|
|
203
203
|
before(:each) do
|
|
204
204
|
@client = KeycloakAdmin.realm(realm_name).client_scope_protocol_mappers(client_scope_id)
|
|
205
205
|
stub_token_client
|
|
206
|
-
allow_any_instance_of(
|
|
206
|
+
allow_any_instance_of(KeycloakAdmin::Resource).to receive(:delete).and_return ""
|
|
207
207
|
end
|
|
208
208
|
|
|
209
209
|
it "returns true" do
|
data/spec/client/client_spec.rb
CHANGED
|
@@ -1,4 +1,81 @@
|
|
|
1
1
|
RSpec.describe KeycloakAdmin::Client do
|
|
2
|
+
describe "#server_url" do
|
|
3
|
+
def client_with_server_url(server_url)
|
|
4
|
+
configuration = KeycloakAdmin::Configuration.new
|
|
5
|
+
configuration.server_url = server_url
|
|
6
|
+
KeycloakAdmin::Client.new(configuration)
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
it "returns the configured url untouched when it has no trailing slash" do
|
|
10
|
+
expect(client_with_server_url("http://auth.service.io/auth").server_url).to eql "http://auth.service.io/auth"
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
it "strips a trailing slash so built paths stay normalized" do
|
|
14
|
+
expect(client_with_server_url("http://auth.service.io/auth/").server_url).to eql "http://auth.service.io/auth"
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
it "strips repeated trailing slashes" do
|
|
18
|
+
expect(client_with_server_url("http://localhost:8080///").server_url).to eql "http://localhost:8080"
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
it "returns nil when no url is configured" do
|
|
22
|
+
expect(client_with_server_url(nil).server_url).to be_nil
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
describe "#current_token" do
|
|
27
|
+
def token(expires_in)
|
|
28
|
+
KeycloakAdmin::TokenRepresentation.new(
|
|
29
|
+
"access_token", "bearer", expires_in, "refresh_token",
|
|
30
|
+
"refresh_expires_in", "id_token", "not_before_policy", "session_state"
|
|
31
|
+
)
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
it "fetches once and reuses the cached token across Client instances sharing the same configuration" do
|
|
35
|
+
configuration = KeycloakAdmin.config
|
|
36
|
+
configuration.clear_cached_token!
|
|
37
|
+
allow_any_instance_of(KeycloakAdmin::TokenClient).to receive(:get).and_return(token(3600))
|
|
38
|
+
|
|
39
|
+
first = KeycloakAdmin::Client.new(configuration).current_token
|
|
40
|
+
second = KeycloakAdmin::Client.new(configuration).current_token
|
|
41
|
+
|
|
42
|
+
expect(first).to be second
|
|
43
|
+
expect(second).to be second
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
it "fetches a new token once the cached one has expired" do
|
|
47
|
+
configuration = KeycloakAdmin.config
|
|
48
|
+
configuration.clear_cached_token!
|
|
49
|
+
# allow_any_instance_of's sequential and_return(a, b) tracks call count per instance,
|
|
50
|
+
# and a fresh TokenClient is built on every fetch, so a plain external counter is used
|
|
51
|
+
# instead to force the first fetch to be pre-expired and the second one not to be.
|
|
52
|
+
call_count = 0
|
|
53
|
+
allow_any_instance_of(KeycloakAdmin::TokenClient).to receive(:get) do
|
|
54
|
+
call_count += 1
|
|
55
|
+
call_count == 1 ? token(5) : token(3600)
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
expired_immediately = KeycloakAdmin::Client.new(configuration).current_token
|
|
59
|
+
refreshed = KeycloakAdmin::Client.new(configuration).current_token
|
|
60
|
+
|
|
61
|
+
expect(expired_immediately).to_not be refreshed
|
|
62
|
+
expect(call_count).to eq 2
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
describe "#resource" do
|
|
67
|
+
it "builds a Resource with the configuration's faraday_options and logger" do
|
|
68
|
+
configuration = KeycloakAdmin::Configuration.new
|
|
69
|
+
configuration.faraday_options = { timeout: 5 }
|
|
70
|
+
configuration.logger = Logger.new(IO::NULL)
|
|
71
|
+
client = KeycloakAdmin::Client.new(configuration)
|
|
72
|
+
|
|
73
|
+
expect(KeycloakAdmin::Resource).to receive(:new).with("http://x", { timeout: 5 }, configuration.logger)
|
|
74
|
+
|
|
75
|
+
client.send(:resource, "http://x")
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
|
|
2
79
|
describe "#execute_http" do
|
|
3
80
|
let(:realm_name) { "valid-realm" }
|
|
4
81
|
before(:each) do
|
|
@@ -8,19 +85,15 @@ RSpec.describe KeycloakAdmin::Client do
|
|
|
8
85
|
it "handles timeout" do
|
|
9
86
|
expect do
|
|
10
87
|
@client.execute_http do
|
|
11
|
-
raise
|
|
88
|
+
raise Faraday::TimeoutError.new
|
|
12
89
|
end
|
|
13
|
-
end.to raise_error(
|
|
90
|
+
end.to raise_error(Faraday::TimeoutError)
|
|
14
91
|
end
|
|
15
92
|
|
|
16
93
|
it "handles response exception" do
|
|
17
|
-
response = double
|
|
18
|
-
allow(response).to receive(:code).and_return 500
|
|
19
|
-
allow(response).to receive(:body).and_return "Server error"
|
|
20
|
-
|
|
21
94
|
expect do
|
|
22
95
|
@client.execute_http do
|
|
23
|
-
raise
|
|
96
|
+
raise Faraday::ServerError.new("boom", status: 500, body: "Server error")
|
|
24
97
|
end
|
|
25
98
|
end.to raise_error("Keycloak: The request failed with response code 500 and message: Server error")
|
|
26
99
|
end
|
|
@@ -29,7 +29,7 @@ RSpec.describe KeycloakAdmin::GroupClient do
|
|
|
29
29
|
@group_client = KeycloakAdmin.realm(realm_name).groups
|
|
30
30
|
|
|
31
31
|
stub_token_client
|
|
32
|
-
allow_any_instance_of(
|
|
32
|
+
allow_any_instance_of(KeycloakAdmin::Resource).to receive(:get).and_return '{"id":"test_group_id","name":"test_group_name"}'
|
|
33
33
|
end
|
|
34
34
|
|
|
35
35
|
it "get a group" do
|
|
@@ -39,11 +39,11 @@ RSpec.describe KeycloakAdmin::GroupClient do
|
|
|
39
39
|
end
|
|
40
40
|
|
|
41
41
|
it "passes rest client options" do
|
|
42
|
-
|
|
43
|
-
allow_any_instance_of(KeycloakAdmin::Configuration).to receive(:
|
|
42
|
+
faraday_options = {timeout: 10}
|
|
43
|
+
allow_any_instance_of(KeycloakAdmin::Configuration).to receive(:faraday_options).and_return faraday_options
|
|
44
44
|
|
|
45
|
-
expect(
|
|
46
|
-
"http://auth.service.io/auth/admin/realms/valid-realm/groups/test_group_id",
|
|
45
|
+
expect(KeycloakAdmin::Resource).to receive(:new).with(
|
|
46
|
+
"http://auth.service.io/auth/admin/realms/valid-realm/groups/test_group_id", faraday_options, anything).and_call_original
|
|
47
47
|
|
|
48
48
|
group = @group_client.get("test_group_id")
|
|
49
49
|
expect(group.id).to eq "test_group_id"
|
|
@@ -58,7 +58,7 @@ RSpec.describe KeycloakAdmin::GroupClient do
|
|
|
58
58
|
@group_client = KeycloakAdmin.realm(realm_name).groups
|
|
59
59
|
|
|
60
60
|
stub_token_client
|
|
61
|
-
allow_any_instance_of(
|
|
61
|
+
allow_any_instance_of(KeycloakAdmin::Resource).to receive(:get).and_return '[{"id":"test_group_id","name":"test_group_name"}]'
|
|
62
62
|
end
|
|
63
63
|
|
|
64
64
|
it "lists groups" do
|
|
@@ -68,11 +68,11 @@ RSpec.describe KeycloakAdmin::GroupClient do
|
|
|
68
68
|
end
|
|
69
69
|
|
|
70
70
|
it "passes rest client options" do
|
|
71
|
-
|
|
72
|
-
allow_any_instance_of(KeycloakAdmin::Configuration).to receive(:
|
|
71
|
+
faraday_options = {timeout: 10}
|
|
72
|
+
allow_any_instance_of(KeycloakAdmin::Configuration).to receive(:faraday_options).and_return faraday_options
|
|
73
73
|
|
|
74
|
-
expect(
|
|
75
|
-
"http://auth.service.io/auth/admin/realms/valid-realm/groups",
|
|
74
|
+
expect(KeycloakAdmin::Resource).to receive(:new).with(
|
|
75
|
+
"http://auth.service.io/auth/admin/realms/valid-realm/groups", faraday_options, anything).and_call_original
|
|
76
76
|
|
|
77
77
|
groups = @group_client.list
|
|
78
78
|
expect(groups.length).to eq 1
|
|
@@ -88,7 +88,7 @@ RSpec.describe KeycloakAdmin::GroupClient do
|
|
|
88
88
|
@group_client = KeycloakAdmin.realm(realm_name).groups
|
|
89
89
|
|
|
90
90
|
stub_token_client
|
|
91
|
-
allow_any_instance_of(
|
|
91
|
+
allow_any_instance_of(KeycloakAdmin::Resource).to receive(:get).and_return '[{"id":"test_group_id","name":"test_group_name"}]'
|
|
92
92
|
end
|
|
93
93
|
|
|
94
94
|
it "lists children groups" do
|
|
@@ -98,11 +98,11 @@ RSpec.describe KeycloakAdmin::GroupClient do
|
|
|
98
98
|
end
|
|
99
99
|
|
|
100
100
|
it "passes rest client options" do
|
|
101
|
-
|
|
102
|
-
allow_any_instance_of(KeycloakAdmin::Configuration).to receive(:
|
|
101
|
+
faraday_options = {timeout: 10}
|
|
102
|
+
allow_any_instance_of(KeycloakAdmin::Configuration).to receive(:faraday_options).and_return faraday_options
|
|
103
103
|
|
|
104
|
-
expect(
|
|
105
|
-
"http://auth.service.io/auth/admin/realms/valid-realm/groups/parent_group_id/children",
|
|
104
|
+
expect(KeycloakAdmin::Resource).to receive(:new).with(
|
|
105
|
+
"http://auth.service.io/auth/admin/realms/valid-realm/groups/parent_group_id/children", faraday_options, anything).and_call_original
|
|
106
106
|
|
|
107
107
|
groups = @group_client.children("parent_group_id")
|
|
108
108
|
expect(groups.length).to eq 1
|
|
@@ -130,7 +130,7 @@ RSpec.describe KeycloakAdmin::GroupClient do
|
|
|
130
130
|
{ location: 'http://auth.service.io/auth/admin/realms/valid-realm/groups/be061c48-6edd-4783-a726-1a57d4bfa22b' }
|
|
131
131
|
)
|
|
132
132
|
|
|
133
|
-
expect_any_instance_of(
|
|
133
|
+
expect_any_instance_of(KeycloakAdmin::Resource).to receive(:post).with(group.to_json, anything).and_return response
|
|
134
134
|
end
|
|
135
135
|
|
|
136
136
|
it "saves a group" do
|
|
@@ -138,11 +138,11 @@ RSpec.describe KeycloakAdmin::GroupClient do
|
|
|
138
138
|
end
|
|
139
139
|
|
|
140
140
|
it "passes rest client options" do
|
|
141
|
-
|
|
142
|
-
allow_any_instance_of(KeycloakAdmin::Configuration).to receive(:
|
|
141
|
+
faraday_options = {timeout: 10}
|
|
142
|
+
allow_any_instance_of(KeycloakAdmin::Configuration).to receive(:faraday_options).and_return faraday_options
|
|
143
143
|
|
|
144
|
-
expect(
|
|
145
|
-
"http://auth.service.io/auth/admin/realms/valid-realm/groups",
|
|
144
|
+
expect(KeycloakAdmin::Resource).to receive(:new).with(
|
|
145
|
+
"http://auth.service.io/auth/admin/realms/valid-realm/groups", faraday_options, anything).and_call_original
|
|
146
146
|
|
|
147
147
|
@group_client.save(group)
|
|
148
148
|
end
|
|
@@ -160,7 +160,7 @@ RSpec.describe KeycloakAdmin::GroupClient do
|
|
|
160
160
|
{ location: 'http://auth.service.io/auth/admin/realms/valid-realm/groups/be061c48-6edd-4783-a726-1a57d4bfa22b' }
|
|
161
161
|
)
|
|
162
162
|
|
|
163
|
-
expect_any_instance_of(
|
|
163
|
+
expect_any_instance_of(KeycloakAdmin::Resource).to receive(:put).with(group.to_json, anything).and_return response
|
|
164
164
|
end
|
|
165
165
|
|
|
166
166
|
it "saves a group" do
|
|
@@ -168,11 +168,11 @@ RSpec.describe KeycloakAdmin::GroupClient do
|
|
|
168
168
|
end
|
|
169
169
|
|
|
170
170
|
it "passes rest client options" do
|
|
171
|
-
|
|
172
|
-
allow_any_instance_of(KeycloakAdmin::Configuration).to receive(:
|
|
171
|
+
faraday_options = {timeout: 10}
|
|
172
|
+
allow_any_instance_of(KeycloakAdmin::Configuration).to receive(:faraday_options).and_return faraday_options
|
|
173
173
|
|
|
174
|
-
expect(
|
|
175
|
-
"http://auth.service.io/auth/admin/realms/valid-realm/groups/test_group_id",
|
|
174
|
+
expect(KeycloakAdmin::Resource).to receive(:new).with(
|
|
175
|
+
"http://auth.service.io/auth/admin/realms/valid-realm/groups/test_group_id", faraday_options, anything).and_call_original
|
|
176
176
|
|
|
177
177
|
@group_client.save(group)
|
|
178
178
|
end
|
|
@@ -186,22 +186,22 @@ RSpec.describe KeycloakAdmin::GroupClient do
|
|
|
186
186
|
@group_client = KeycloakAdmin.realm(realm_name).groups
|
|
187
187
|
|
|
188
188
|
stub_token_client
|
|
189
|
-
@response = double
|
|
190
|
-
|
|
191
|
-
|
|
189
|
+
@response = double(
|
|
190
|
+
headers: { location: 'http://auth.service.io/auth/admin/realms/valid-realm/groups/be061c48-6edd-4783-a726-1a57d4bfa22b' },
|
|
191
|
+
status: 201,
|
|
192
|
+
reason_phrase: 'Created'
|
|
192
193
|
)
|
|
193
|
-
allow_any_instance_of(
|
|
194
|
+
allow_any_instance_of(KeycloakAdmin::Resource).to receive(:post).and_return @response
|
|
194
195
|
end
|
|
195
196
|
|
|
196
197
|
it "creates a group" do
|
|
197
|
-
stub_net_http_res(Net::HTTPCreated, 201, 'Created')
|
|
198
|
-
|
|
199
198
|
group_id = @group_client.create!("test_group_name")
|
|
200
199
|
expect(group_id).to eq 'be061c48-6edd-4783-a726-1a57d4bfa22b'
|
|
201
200
|
end
|
|
202
201
|
|
|
203
202
|
it "detects unexpected response to create a group" do
|
|
204
|
-
|
|
203
|
+
allow(@response).to receive(:status).and_return 200
|
|
204
|
+
allow(@response).to receive(:reason_phrase).and_return 'OK'
|
|
205
205
|
|
|
206
206
|
expect{ @group_client.create!("test_group_name") }.to raise_error(
|
|
207
207
|
'Create method returned status OK (Code: 200); expected status: Created (201)'
|
|
@@ -216,15 +216,15 @@ RSpec.describe KeycloakAdmin::GroupClient do
|
|
|
216
216
|
@group_client = KeycloakAdmin.realm(realm_name).groups
|
|
217
217
|
|
|
218
218
|
stub_token_client
|
|
219
|
-
@response = double
|
|
220
|
-
location: 'http://auth.service.io/auth/admin/realms/valid-realm/groups/7686af34-204c-4515-8122-78d19febbf6e'
|
|
221
|
-
|
|
222
|
-
|
|
219
|
+
@response = double(
|
|
220
|
+
headers: { location: 'http://auth.service.io/auth/admin/realms/valid-realm/groups/7686af34-204c-4515-8122-78d19febbf6e' },
|
|
221
|
+
status: 201,
|
|
222
|
+
reason_phrase: 'Created'
|
|
223
|
+
)
|
|
224
|
+
allow_any_instance_of(KeycloakAdmin::Resource).to receive(:post).and_return @response
|
|
223
225
|
end
|
|
224
226
|
|
|
225
227
|
it "creates a subgroup" do
|
|
226
|
-
stub_net_http_res(Net::HTTPCreated, 201, 'Created')
|
|
227
|
-
|
|
228
228
|
group_id = @group_client.create_subgroup!('be061c48-6edd-4783-a726-1a57d4bfa22b', 'subgroup-name')
|
|
229
229
|
expect(group_id).to eq '7686af34-204c-4515-8122-78d19febbf6e'
|
|
230
230
|
end
|
|
@@ -237,7 +237,7 @@ RSpec.describe KeycloakAdmin::GroupClient do
|
|
|
237
237
|
@group_client = KeycloakAdmin.realm(realm_name).groups
|
|
238
238
|
|
|
239
239
|
stub_token_client
|
|
240
|
-
allow_any_instance_of(
|
|
240
|
+
allow_any_instance_of(KeycloakAdmin::Resource).to receive(:delete).and_return ''
|
|
241
241
|
end
|
|
242
242
|
|
|
243
243
|
it "deletes a group" do
|
|
@@ -246,11 +246,11 @@ RSpec.describe KeycloakAdmin::GroupClient do
|
|
|
246
246
|
end
|
|
247
247
|
|
|
248
248
|
it "raises a delete error" do
|
|
249
|
-
|
|
250
|
-
allow_any_instance_of(KeycloakAdmin::Configuration).to receive(:
|
|
249
|
+
faraday_options = {timeout: 10}
|
|
250
|
+
allow_any_instance_of(KeycloakAdmin::Configuration).to receive(:faraday_options).and_return faraday_options
|
|
251
251
|
|
|
252
|
-
expect(
|
|
253
|
-
"http://auth.service.io/auth/admin/realms/valid-realm/groups/test_group_id",
|
|
252
|
+
expect(KeycloakAdmin::Resource).to receive(:new).with(
|
|
253
|
+
"http://auth.service.io/auth/admin/realms/valid-realm/groups/test_group_id", faraday_options, anything).and_raise("error")
|
|
254
254
|
|
|
255
255
|
expect { @group_client.delete("test_group_id") }.to raise_error("error")
|
|
256
256
|
end
|
|
@@ -261,7 +261,7 @@ RSpec.describe KeycloakAdmin::GroupClient do
|
|
|
261
261
|
before(:each) do
|
|
262
262
|
@group_client = KeycloakAdmin.realm(realm_name).groups
|
|
263
263
|
stub_token_client
|
|
264
|
-
allow_any_instance_of(
|
|
264
|
+
allow_any_instance_of(KeycloakAdmin::Resource).to receive(:get).and_return '[{"id":"role-id","name":"role-name"}]'
|
|
265
265
|
end
|
|
266
266
|
|
|
267
267
|
it 'gets all realm-level roles for a group' do
|
|
@@ -279,7 +279,7 @@ RSpec.describe KeycloakAdmin::GroupClient do
|
|
|
279
279
|
@group_client = KeycloakAdmin.realm(realm_name).groups
|
|
280
280
|
|
|
281
281
|
stub_token_client
|
|
282
|
-
allow_any_instance_of(
|
|
282
|
+
allow_any_instance_of(KeycloakAdmin::Resource).to receive(:post).and_return ''
|
|
283
283
|
end
|
|
284
284
|
|
|
285
285
|
it 'adds a realm-level role to a group' do
|
|
@@ -302,7 +302,7 @@ RSpec.describe KeycloakAdmin::GroupClient do
|
|
|
302
302
|
@group_client = KeycloakAdmin.realm(realm_name).groups
|
|
303
303
|
|
|
304
304
|
stub_token_client
|
|
305
|
-
allow(
|
|
305
|
+
allow(KeycloakAdmin::Resource).to receive(:execute).and_return ''
|
|
306
306
|
end
|
|
307
307
|
|
|
308
308
|
it 'deletes a realm-level role from a group' do
|
|
@@ -315,7 +315,7 @@ RSpec.describe KeycloakAdmin::GroupClient do
|
|
|
315
315
|
|
|
316
316
|
result = @group_client.remove_realm_level_role_name!('test-group-id', 'test-role-name')
|
|
317
317
|
expect(result).to be(true)
|
|
318
|
-
expect(
|
|
318
|
+
expect(KeycloakAdmin::Resource).to have_received(:execute).with(
|
|
319
319
|
hash_including(
|
|
320
320
|
url: "http://auth.service.io/auth/admin/realms/valid-realm/groups/test-group-id/role-mappings/realm",
|
|
321
321
|
method: :delete,
|
|
@@ -68,7 +68,7 @@ RSpec.describe KeycloakAdmin::IdentityProviderClient do
|
|
|
68
68
|
@identity_provider_client = KeycloakAdmin.realm(realm_name).identity_providers
|
|
69
69
|
|
|
70
70
|
stub_token_client
|
|
71
|
-
allow_any_instance_of(
|
|
71
|
+
allow_any_instance_of(KeycloakAdmin::Resource).to receive(:get).and_return json_response
|
|
72
72
|
end
|
|
73
73
|
|
|
74
74
|
it "lists identity providers" do
|
|
@@ -78,11 +78,11 @@ RSpec.describe KeycloakAdmin::IdentityProviderClient do
|
|
|
78
78
|
end
|
|
79
79
|
|
|
80
80
|
it "passes rest client options" do
|
|
81
|
-
|
|
82
|
-
allow_any_instance_of(KeycloakAdmin::Configuration).to receive(:
|
|
81
|
+
faraday_options = {timeout: 10}
|
|
82
|
+
allow_any_instance_of(KeycloakAdmin::Configuration).to receive(:faraday_options).and_return faraday_options
|
|
83
83
|
|
|
84
|
-
expect(
|
|
85
|
-
"http://auth.service.io/auth/admin/realms/valid-realm/identity-provider/instances",
|
|
84
|
+
expect(KeycloakAdmin::Resource).to receive(:new).with(
|
|
85
|
+
"http://auth.service.io/auth/admin/realms/valid-realm/identity-provider/instances", faraday_options, anything).and_call_original
|
|
86
86
|
|
|
87
87
|
identity_providers = @identity_provider_client.list
|
|
88
88
|
expect(identity_providers.length).to eq 1
|