keycloak-admin 1.2.0 → 2.0.0
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/CHANGELOG.md +8 -0
- data/Gemfile.lock +17 -20
- data/README.md +9 -5
- data/keycloak-admin.gemspec +4 -3
- data/lib/keycloak-admin/client/attack_detection_client.rb +3 -3
- data/lib/keycloak-admin/client/client.rb +10 -6
- 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 +2 -2
- data/lib/keycloak-admin/client/group_client.rb +13 -13
- 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/role_client.rb +6 -6
- data/lib/keycloak-admin/client/role_mapper_client.rb +7 -7
- data/lib/keycloak-admin/client/token_client.rb +1 -3
- data/lib/keycloak-admin/client/user_client.rb +24 -24
- data/lib/keycloak-admin/configuration.rb +1 -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 +10 -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 +27 -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/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 +2 -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 +0 -8
- metadata +22 -7
|
@@ -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).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).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,12 @@ 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
41
|
).and_call_original
|
|
42
42
|
|
|
43
43
|
roles = @client_role_mappings_client.list_available
|
|
@@ -62,7 +62,7 @@ RSpec.describe KeycloakAdmin::ClientRoleMappingsClient do
|
|
|
62
62
|
@client_role_mappings_client = KeycloakAdmin.realm(realm_name).user(user_id).client_role_mappings(client_id)
|
|
63
63
|
|
|
64
64
|
stub_token_client
|
|
65
|
-
expect_any_instance_of(
|
|
65
|
+
expect_any_instance_of(KeycloakAdmin::Resource).to receive(:post).with(role_list.to_json, anything)
|
|
66
66
|
end
|
|
67
67
|
|
|
68
68
|
it "saves client role mappings" do
|
|
@@ -70,11 +70,11 @@ RSpec.describe KeycloakAdmin::ClientRoleMappingsClient do
|
|
|
70
70
|
end
|
|
71
71
|
|
|
72
72
|
it "passes rest client options" do
|
|
73
|
-
|
|
74
|
-
allow_any_instance_of(KeycloakAdmin::Configuration).to receive(:
|
|
73
|
+
faraday_options = {timeout: 10}
|
|
74
|
+
allow_any_instance_of(KeycloakAdmin::Configuration).to receive(:faraday_options).and_return faraday_options
|
|
75
75
|
|
|
76
|
-
expect(
|
|
77
|
-
"http://auth.service.io/auth/admin/realms/valid-realm/users/test_user/role-mappings/clients/test_client",
|
|
76
|
+
expect(KeycloakAdmin::Resource).to receive(:new).with(
|
|
77
|
+
"http://auth.service.io/auth/admin/realms/valid-realm/users/test_user/role-mappings/clients/test_client", faraday_options).and_call_original
|
|
78
78
|
|
|
79
79
|
@client_role_mappings_client.save(role_list)
|
|
80
80
|
end
|
|
@@ -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,28 @@
|
|
|
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
|
+
|
|
2
26
|
describe "#execute_http" do
|
|
3
27
|
let(:realm_name) { "valid-realm" }
|
|
4
28
|
before(:each) do
|
|
@@ -8,19 +32,15 @@ RSpec.describe KeycloakAdmin::Client do
|
|
|
8
32
|
it "handles timeout" do
|
|
9
33
|
expect do
|
|
10
34
|
@client.execute_http do
|
|
11
|
-
raise
|
|
35
|
+
raise Faraday::TimeoutError.new
|
|
12
36
|
end
|
|
13
|
-
end.to raise_error(
|
|
37
|
+
end.to raise_error(Faraday::TimeoutError)
|
|
14
38
|
end
|
|
15
39
|
|
|
16
40
|
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
41
|
expect do
|
|
22
42
|
@client.execute_http do
|
|
23
|
-
raise
|
|
43
|
+
raise Faraday::ServerError.new("boom", status: 500, body: "Server error")
|
|
24
44
|
end
|
|
25
45
|
end.to raise_error("Keycloak: The request failed with response code 500 and message: Server error")
|
|
26
46
|
end
|