keycloak-admin 2.0.1 → 2.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (70) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +13 -0
  3. data/README.md +40 -4
  4. data/keycloak-admin.gemspec +14 -6
  5. data/lib/keycloak-admin/client/client.rb +22 -10
  6. data/lib/keycloak-admin/client/client_authz_permission_client.rb +1 -1
  7. data/lib/keycloak-admin/client/client_authz_policy_client.rb +1 -1
  8. data/lib/keycloak-admin/client/client_authz_resource_client.rb +1 -1
  9. data/lib/keycloak-admin/client/client_authz_scope_client.rb +1 -1
  10. data/lib/keycloak-admin/client/group_client.rb +2 -5
  11. data/lib/keycloak-admin/client/organization_client.rb +7 -7
  12. data/lib/keycloak-admin/client/user_client.rb +8 -4
  13. data/lib/keycloak-admin/error.rb +62 -0
  14. data/lib/keycloak-admin/version.rb +1 -1
  15. data/lib/keycloak-admin.rb +1 -0
  16. metadata +21 -56
  17. data/.github/workflows/Dockerfile +0 -24
  18. data/.github/workflows/ci.yml +0 -94
  19. data/.github/workflows/release.yml +0 -112
  20. data/.gitignore +0 -10
  21. data/.rspec +0 -2
  22. data/Dockerfile +0 -13
  23. data/Gemfile +0 -3
  24. data/Gemfile.lock +0 -54
  25. data/Rakefile +0 -6
  26. data/bin/console +0 -9
  27. data/spec/client/attack_detection_client_spec.rb +0 -102
  28. data/spec/client/client_authz_permission_client_spec.rb +0 -170
  29. data/spec/client/client_authz_policy_client_spec.rb +0 -170
  30. data/spec/client/client_authz_resource_client_spec.rb +0 -150
  31. data/spec/client/client_authz_scope_client_spec.rb +0 -134
  32. data/spec/client/client_client_spec.rb +0 -133
  33. data/spec/client/client_role_mappings_client_spec.rb +0 -83
  34. data/spec/client/client_scope_client_spec.rb +0 -220
  35. data/spec/client/client_scope_protocol_mapper_client_spec.rb +0 -230
  36. data/spec/client/client_spec.rb +0 -101
  37. data/spec/client/configurable_token_client_spec.rb +0 -34
  38. data/spec/client/group_client_spec.rb +0 -328
  39. data/spec/client/identity_provider_client_spec.rb +0 -92
  40. data/spec/client/organization_client_spec.rb +0 -595
  41. data/spec/client/realm_client_spec.rb +0 -155
  42. data/spec/client/resource_spec.rb +0 -223
  43. data/spec/client/response_spec.rb +0 -68
  44. data/spec/client/role_client_spec.rb +0 -79
  45. data/spec/client/role_mapper_client_spec.rb +0 -113
  46. data/spec/client/token_client_spec.rb +0 -68
  47. data/spec/client/user_client_spec.rb +0 -418
  48. data/spec/configuration_spec.rb +0 -150
  49. data/spec/gemspec_spec.rb +0 -25
  50. data/spec/integration/client_authorization_spec.rb +0 -93
  51. data/spec/representation/attack_detection_representation_spec.rb +0 -16
  52. data/spec/representation/client_authz_permission_representation_spec.rb +0 -52
  53. data/spec/representation/client_authz_policy_representation_spec.rb +0 -47
  54. data/spec/representation/client_authz_resource_representation_spec.rb +0 -33
  55. data/spec/representation/client_authz_scope_representation_spec.rb +0 -19
  56. data/spec/representation/client_representation_spec.rb +0 -119
  57. data/spec/representation/client_scope_representation_spec.rb +0 -125
  58. data/spec/representation/credential_representation_spec.rb +0 -68
  59. data/spec/representation/group_representation_spec.rb +0 -22
  60. data/spec/representation/identity_provider_mapper_representation_spec.rb +0 -24
  61. data/spec/representation/identity_provider_representation_spec.rb +0 -113
  62. data/spec/representation/impersonation_representation_spec.rb +0 -163
  63. data/spec/representation/organization_representation_spec.rb +0 -64
  64. data/spec/representation/protocol_mapper_representation_spec.rb +0 -57
  65. data/spec/representation/role_representation_spec.rb +0 -37
  66. data/spec/representation/session_representation_spec.rb +0 -16
  67. data/spec/representation/user_representation_spec.rb +0 -15
  68. data/spec/resource/group_resource_spec.rb +0 -14
  69. data/spec/resource/user_resource_spec.rb +0 -14
  70. data/spec/spec_helper.rb +0 -36
@@ -1,220 +0,0 @@
1
- RSpec.describe KeycloakAdmin::ClientScopeClient do
2
- let(:realm_name) { "valid-realm" }
3
- let(:client_scope_id) { "valid-scope-id" }
4
-
5
- let(:scope_json) do
6
- <<~JSON
7
- {"id":"valid-scope-id","name":"my-scope","description":"A test scope","protocol":"openid-connect","attributes":{"display.on.consent.screen":"true","include.in.token.scope":"true"}}
8
- JSON
9
- end
10
-
11
- let(:scope_with_mappers_json) do
12
- <<~JSON
13
- {"id":"valid-scope-id","name":"my-scope","description":"A test scope","protocol":"openid-connect","attributes":{},"protocolMappers":[{"id":"mapper-id","name":"my-claim","protocol":"openid-connect","protocolMapper":"oidc-hardcoded-claim-mapper","config":{"claim.name":"my_claim","claim.value":"bar","access.token.claim":"true"}}]}
14
- JSON
15
- end
16
-
17
- describe "#initialize" do
18
- context "when realm_name is defined" do
19
- it "does not raise any error" do
20
- expect { KeycloakAdmin.realm(realm_name).client_scopes }.to_not raise_error
21
- end
22
- end
23
-
24
- context "when realm_name is not defined" do
25
- it "raises an argument error" do
26
- expect { KeycloakAdmin.realm(nil).client_scopes }.to raise_error(ArgumentError)
27
- end
28
- end
29
- end
30
-
31
- describe "#list" do
32
- before(:each) do
33
- @client = KeycloakAdmin.realm(realm_name).client_scopes
34
- stub_token_client
35
- allow_any_instance_of(KeycloakAdmin::Resource).to receive(:get).and_return stub_response
36
- end
37
-
38
- context "with one scope" do
39
- let(:stub_response) { "[#{scope_json}]" }
40
-
41
- it "returns one scope" do
42
- expect(@client.list.size).to eq 1
43
- end
44
-
45
- it "returns the correct scope attributes" do
46
- expect(@client.list.first).to have_attributes(
47
- id: "valid-scope-id",
48
- name: "my-scope",
49
- description: "A test scope",
50
- protocol: "openid-connect"
51
- )
52
- end
53
-
54
- it "returns attributes map" do
55
- expect(@client.list.first.attributes).to include(
56
- "display.on.consent.screen" => "true",
57
- "include.in.token.scope" => "true"
58
- )
59
- end
60
- end
61
-
62
- context "with multiple scopes" do
63
- let(:second_scope_json) { '{"id":"other-scope-id","name":"other-scope","protocol":"openid-connect"}' }
64
- let(:stub_response) { "[#{scope_json},#{second_scope_json}]" }
65
-
66
- it "returns two scopes" do
67
- expect(@client.list.size).to eq 2
68
- end
69
-
70
- it "includes both scope names" do
71
- expect(@client.list.map(&:name)).to include("my-scope", "other-scope")
72
- end
73
- end
74
- end
75
-
76
- describe "#get" do
77
- before(:each) do
78
- @client = KeycloakAdmin.realm(realm_name).client_scopes
79
- stub_token_client
80
- allow_any_instance_of(KeycloakAdmin::Resource).to receive(:get).and_return stub_response
81
- end
82
-
83
- context "without protocol mappers" do
84
- let(:stub_response) { scope_json }
85
-
86
- it "returns the correct id" do
87
- expect(@client.get(client_scope_id).id).to eq "valid-scope-id"
88
- end
89
-
90
- it "returns the correct name" do
91
- expect(@client.get(client_scope_id).name).to eq "my-scope"
92
- end
93
-
94
- it "returns the correct description" do
95
- expect(@client.get(client_scope_id).description).to eq "A test scope"
96
- end
97
-
98
- it "returns the correct protocol" do
99
- expect(@client.get(client_scope_id).protocol).to eq "openid-connect"
100
- end
101
-
102
- it "returns an empty protocolMappers list" do
103
- expect(@client.get(client_scope_id).protocol_mappers).to eq []
104
- end
105
- end
106
-
107
- context "with protocol mappers" do
108
- let(:stub_response) { scope_with_mappers_json }
109
-
110
- it "returns protocol mappers" do
111
- expect(@client.get(client_scope_id).protocol_mappers.size).to eq 1
112
- end
113
-
114
- it "returns the correct mapper name" do
115
- expect(@client.get(client_scope_id).protocol_mappers.first.name).to eq "my-claim"
116
- end
117
- end
118
- end
119
-
120
- describe "#create!" do
121
- before(:each) do
122
- @client = KeycloakAdmin.realm(realm_name).client_scopes
123
- stub_token_client
124
- allow_any_instance_of(KeycloakAdmin::Resource).to receive(:post).and_return ""
125
- end
126
-
127
- let(:scope_representation) do
128
- scope = KeycloakAdmin::ClientScopeRepresentation.new
129
- scope.name = "my-scope"
130
- scope.description = "A test scope"
131
- scope.protocol = "openid-connect"
132
- scope.attributes = { "display.on.consent.screen" => "true", "include.in.token.scope" => "true" }
133
- scope
134
- end
135
-
136
- it "creates successfully" do
137
- expect(@client.create!(scope_representation)).to be true
138
- end
139
- end
140
-
141
- describe "#save" do
142
- before(:each) do
143
- @client = KeycloakAdmin.realm(realm_name).client_scopes
144
- stub_token_client
145
- allow_any_instance_of(KeycloakAdmin::Resource).to receive(:put).and_return ""
146
- end
147
-
148
- let(:scope_representation) { KeycloakAdmin::ClientScopeRepresentation.from_hash(JSON.parse(scope_json)) }
149
-
150
- it "calls put on the scope url" do
151
- expect_any_instance_of(KeycloakAdmin::Resource).to receive(:put).with(anything, anything)
152
- @client.save(scope_representation)
153
- end
154
-
155
- it "returns true" do
156
- expect(@client.save(scope_representation)).to be true
157
- end
158
- end
159
-
160
- describe "#search" do
161
- let(:second_scope_json) { '{"id":"other-scope-id","name":"other-scope","protocol":"openid-connect"}' }
162
-
163
- before(:each) do
164
- @client = KeycloakAdmin.realm(realm_name).client_scopes
165
- stub_token_client
166
- allow_any_instance_of(KeycloakAdmin::Resource).to receive(:get).and_return "[#{scope_json},#{second_scope_json}]"
167
- end
168
-
169
- context "when the name matches one scope" do
170
- it "returns only the matching scope" do
171
- expect(@client.search("my-scope").size).to eq 1
172
- end
173
-
174
- it "returns the correct scope" do
175
- expect(@client.search("my-scope").first).to have_attributes(id: "valid-scope-id", name: "my-scope")
176
- end
177
- end
178
-
179
- context "when the name is a partial match" do
180
- it "returns all scopes containing the substring" do
181
- expect(@client.search("scope").size).to eq 2
182
- end
183
- end
184
-
185
- context "when no scope matches" do
186
- it "returns an empty array" do
187
- expect(@client.search("unknown")).to eq []
188
- end
189
- end
190
- end
191
-
192
- describe "#delete" do
193
- before(:each) do
194
- @client = KeycloakAdmin.realm(realm_name).client_scopes
195
- stub_token_client
196
- allow_any_instance_of(KeycloakAdmin::Resource).to receive(:delete).and_return ""
197
- end
198
-
199
- it "returns true" do
200
- expect(@client.delete(client_scope_id)).to eq true
201
- end
202
- end
203
-
204
- describe "#client_scopes_url" do
205
- let(:client) { KeycloakAdmin.realm(realm_name).client_scopes }
206
- let(:base_url) { "http://auth.service.io/auth/admin/realms/valid-realm/client-scopes" }
207
-
208
- context "without a client_scope_id" do
209
- it "returns the base url" do
210
- expect(client.client_scopes_url).to eq base_url
211
- end
212
- end
213
-
214
- context "with a client_scope_id" do
215
- it "returns the url with client_scope_id appended" do
216
- expect(client.client_scopes_url(client_scope_id)).to eq "#{base_url}/valid-scope-id"
217
- end
218
- end
219
- end
220
- end
@@ -1,230 +0,0 @@
1
- RSpec.describe KeycloakAdmin::ClientScopeProtocolMapperClient do
2
- let(:realm_name) { "valid-realm" }
3
- let(:client_scope_id) { "valid-scope-id" }
4
- let(:mapper_id) { "valid-mapper-id" }
5
-
6
- let(:mapper_json) do
7
- <<~JSON
8
- {"id":"valid-mapper-id","name":"my-claim","protocol":"openid-connect","protocolMapper":"oidc-hardcoded-claim-mapper","config":{"claim.name":"my_claim","claim.value":"bar","access.token.claim":"true"}}
9
- JSON
10
- end
11
-
12
- let(:audience_mapper_json) do
13
- <<~JSON
14
- {"protocol":"openid-connect","protocolMapper":"oidc-audience-mapper","name":"audience-config-rvw-123","config":{"included.client.audience":"","included.custom.audience":"https://api.example.com","id.token.claim":"false","access.token.claim":"true","lightweight.claim":"false","introspection.token.claim":"true"}}
15
- JSON
16
- end
17
-
18
- describe "#initialize" do
19
- context "when realm_name is defined" do
20
- it "does not raise any error" do
21
- expect { KeycloakAdmin.realm(realm_name).client_scope_protocol_mappers(client_scope_id) }.to_not raise_error
22
- end
23
- end
24
-
25
- context "when realm_name is not defined" do
26
- it "raises an argument error" do
27
- expect { KeycloakAdmin.realm(nil).client_scope_protocol_mappers(client_scope_id) }.to raise_error(ArgumentError)
28
- end
29
- end
30
- end
31
-
32
- describe "#list" do
33
- before(:each) do
34
- @client = KeycloakAdmin.realm(realm_name).client_scope_protocol_mappers(client_scope_id)
35
- stub_token_client
36
- allow_any_instance_of(KeycloakAdmin::Resource).to receive(:get).and_return stub_response
37
- end
38
-
39
- context "with a hardcoded claim mapper" do
40
- let(:stub_response) { "[#{mapper_json}]" }
41
-
42
- it "returns one mapper" do
43
- expect(@client.list.size).to eq 1
44
- end
45
-
46
- it "returns the correct mapper attributes" do
47
- expect(@client.list.first).to have_attributes(id: "valid-mapper-id", name: "my-claim", protocol: "openid-connect", protocolMapper: "oidc-hardcoded-claim-mapper")
48
- end
49
- end
50
-
51
- context "with an audience mapper" do
52
- let(:stub_response) { "[#{audience_mapper_json}]" }
53
-
54
- it "returns one mapper" do
55
- expect(@client.list.size).to eq 1
56
- end
57
-
58
- it "returns the correct mapper attributes" do
59
- expect(@client.list.first).to have_attributes(name: "audience-config-rvw-123", protocol: "openid-connect", protocolMapper: "oidc-audience-mapper")
60
- end
61
- end
62
-
63
- context "with multiple mappers" do
64
- let(:stub_response) { "[#{mapper_json},#{audience_mapper_json}]" }
65
-
66
- it "returns two mappers" do
67
- expect(@client.list.size).to eq 2
68
- end
69
-
70
- it "includes both mapper names" do
71
- expect(@client.list.map(&:name)).to include("my-claim", "audience-config-rvw-123")
72
- end
73
- end
74
- end
75
-
76
- describe "#get" do
77
- before(:each) do
78
- @client = KeycloakAdmin.realm(realm_name).client_scope_protocol_mappers(client_scope_id)
79
- stub_token_client
80
- allow_any_instance_of(KeycloakAdmin::Resource).to receive(:get).and_return stub_response
81
- end
82
-
83
- context "with a hardcoded claim mapper" do
84
- let(:stub_response) { mapper_json }
85
-
86
- it "returns the correct id" do
87
- expect(@client.get(mapper_id).id).to eq "valid-mapper-id"
88
- end
89
-
90
- it "returns the correct name" do
91
- expect(@client.get(mapper_id).name).to eq "my-claim"
92
- end
93
-
94
- it "returns the correct protocol" do
95
- expect(@client.get(mapper_id).protocol).to eq "openid-connect"
96
- end
97
-
98
- it "returns the correct protocolMapper" do
99
- expect(@client.get(mapper_id).protocolMapper).to eq "oidc-hardcoded-claim-mapper"
100
- end
101
- end
102
-
103
- context "with an audience mapper" do
104
- let(:stub_response) { audience_mapper_json }
105
-
106
- it "returns the correct name" do
107
- expect(@client.get(mapper_id).name).to eq "audience-config-rvw-123"
108
- end
109
-
110
- it "returns the correct protocol" do
111
- expect(@client.get(mapper_id).protocol).to eq "openid-connect"
112
- end
113
-
114
- it "returns the correct protocolMapper" do
115
- expect(@client.get(mapper_id).protocolMapper).to eq "oidc-audience-mapper"
116
- end
117
-
118
- it "returns the correct config" do
119
- expect(@client.get(mapper_id).config).to include(
120
- "included.custom.audience" => "https://api.example.com",
121
- "access.token.claim" => "true",
122
- "introspection.token.claim" => "true",
123
- "id.token.claim" => "false"
124
- )
125
- end
126
- end
127
- end
128
-
129
- describe "#create!" do
130
- before(:each) do
131
- @client = KeycloakAdmin.realm(realm_name).client_scope_protocol_mappers(client_scope_id)
132
- stub_token_client
133
- allow_any_instance_of(KeycloakAdmin::Resource).to receive(:post).and_return stub_response
134
- end
135
-
136
- context "with a hardcoded claim mapper" do
137
- let(:stub_response) { mapper_json }
138
- let(:mapper_representation) do
139
- mapper = KeycloakAdmin::ProtocolMapperRepresentation.new
140
- mapper.name = "my-claim"
141
- mapper.protocol = "openid-connect"
142
- mapper.protocolMapper = "oidc-hardcoded-claim-mapper"
143
- mapper.config = { "claim.name" => "my_claim", "claim.value" => "bar", "access.token.claim" => "true" }
144
- mapper
145
- end
146
-
147
- it "creates successfully" do
148
- expect(@client.create!(mapper_representation)).to be true
149
- end
150
- end
151
-
152
- context "with an audience mapper" do
153
- let(:stub_response) { audience_mapper_json }
154
- let(:mapper_representation) do
155
- mapper = KeycloakAdmin::ProtocolMapperRepresentation.new
156
- mapper.name = "audience-config-rvw-123"
157
- mapper.protocol = "openid-connect"
158
- mapper.protocolMapper = "oidc-audience-mapper"
159
- mapper.config = {
160
- "included.client.audience" => "",
161
- "included.custom.audience" => "https://api.example.com",
162
- "id.token.claim" => "false",
163
- "access.token.claim" => "true",
164
- "lightweight.claim" => "false",
165
- "introspection.token.claim" => "true"
166
- }
167
- mapper
168
- end
169
-
170
- it "creates successfully" do
171
- expect(@client.create!(mapper_representation)).to be true
172
- end
173
- end
174
- end
175
-
176
- describe "#save" do
177
- before(:each) do
178
- @client = KeycloakAdmin.realm(realm_name).client_scope_protocol_mappers(client_scope_id)
179
- stub_token_client
180
- allow_any_instance_of(KeycloakAdmin::Resource).to receive(:put).and_return ""
181
- end
182
-
183
- context "with a hardcoded claim mapper" do
184
- let(:mapper_representation) { KeycloakAdmin::ProtocolMapperRepresentation.from_hash(JSON.parse(mapper_json)) }
185
-
186
- it "calls put on the mapper url" do
187
- expect_any_instance_of(KeycloakAdmin::Resource).to receive(:put).with(anything, anything)
188
- @client.save(mapper_representation)
189
- end
190
- end
191
-
192
- context "with an audience mapper" do
193
- let(:mapper_representation) { KeycloakAdmin::ProtocolMapperRepresentation.from_hash(JSON.parse(audience_mapper_json)) }
194
-
195
- it "calls put on the mapper url" do
196
- expect_any_instance_of(KeycloakAdmin::Resource).to receive(:put).with(anything, anything)
197
- @client.save(mapper_representation)
198
- end
199
- end
200
- end
201
-
202
- describe "#delete" do
203
- before(:each) do
204
- @client = KeycloakAdmin.realm(realm_name).client_scope_protocol_mappers(client_scope_id)
205
- stub_token_client
206
- allow_any_instance_of(KeycloakAdmin::Resource).to receive(:delete).and_return ""
207
- end
208
-
209
- it "returns true" do
210
- expect(@client.delete(mapper_id)).to eq true
211
- end
212
- end
213
-
214
- describe "#protocol_mappers_url" do
215
- let(:client) { KeycloakAdmin.realm(realm_name).client_scope_protocol_mappers(client_scope_id) }
216
- let(:base_url) { "http://auth.service.io/auth/admin/realms/valid-realm/client-scopes/valid-scope-id/protocol-mappers/models" }
217
-
218
- context "without a mapper_id" do
219
- it "returns the base url" do
220
- expect(client.protocol_mappers_url).to eq base_url
221
- end
222
- end
223
-
224
- context "with a mapper_id" do
225
- it "returns the url with mapper_id appended" do
226
- expect(client.protocol_mappers_url(mapper_id)).to eq "#{base_url}/valid-mapper-id"
227
- end
228
- end
229
- end
230
- end
@@ -1,101 +0,0 @@
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
-
79
- describe "#execute_http" do
80
- let(:realm_name) { "valid-realm" }
81
- before(:each) do
82
- @client = KeycloakAdmin::Client.new(KeycloakAdmin.config)
83
- end
84
-
85
- it "handles timeout" do
86
- expect do
87
- @client.execute_http do
88
- raise Faraday::TimeoutError.new
89
- end
90
- end.to raise_error(Faraday::TimeoutError)
91
- end
92
-
93
- it "handles response exception" do
94
- expect do
95
- @client.execute_http do
96
- raise Faraday::ServerError.new("boom", status: 500, body: "Server error")
97
- end
98
- end.to raise_error("Keycloak: The request failed with response code 500 and message: Server error")
99
- end
100
- end
101
- end
@@ -1,34 +0,0 @@
1
- RSpec.describe KeycloakAdmin::ConfigurableTokenClient do
2
- describe "#initialize" do
3
- context "when realm_name is defined" do
4
- let(:realm_name) { "master" }
5
- it "does not raise any error" do
6
- expect {
7
- KeycloakAdmin.realm(realm_name).configurable_token
8
- }.to_not raise_error
9
- end
10
- end
11
-
12
- context "when realm_name is not defined" do
13
- let(:realm_name) { nil }
14
- it "raises any error" do
15
- expect {
16
- KeycloakAdmin.realm(realm_name).configurable_token
17
- }.to raise_error(ArgumentError)
18
- end
19
- end
20
- end
21
-
22
- describe "#token_url" do
23
- let(:realm_name) { "valid-realm" }
24
- let(:user_id) { nil }
25
-
26
- before(:each) do
27
- @built_url = KeycloakAdmin.realm(realm_name).configurable_token.token_url
28
- end
29
-
30
- it "return a proper url with the realm name" do
31
- expect(@built_url).to eq "http://auth.service.io/auth/realms/valid-realm/configurable-token"
32
- end
33
- end
34
- end