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,150 +0,0 @@
1
- RSpec.describe KeycloakAdmin::ClientAuthzResourceClient do
2
- describe "#initialize" do
3
- let(:realm_name) { nil }
4
- before(:each) do
5
- @realm = KeycloakAdmin.realm(realm_name)
6
- end
7
-
8
- context "when realm_name is defined" do
9
- let(:realm_name) { "master" }
10
- it "does not raise any error" do
11
- expect { @realm.attack_detections }.to_not raise_error
12
- end
13
- end
14
- context "when realm_name is not defined" do
15
- it "raise argument error" do
16
- expect { @realm.attack_detections }.to raise_error(ArgumentError)
17
- end
18
- end
19
- end
20
-
21
- describe "#list" do
22
- let(:realm_name) { "valid-realm" }
23
- let(:client_id) { "valid-client-id" }
24
- before(:each) do
25
- @client_authz_resource = KeycloakAdmin.realm(realm_name).authz_resources(client_id)
26
- stub_token_client
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
- end
29
-
30
- it "returns list of authz scopes" do
31
- response = @client_authz_resource.list
32
- expect(response.size).to eq 2
33
- expect(response[1].id).to eq "385966a2-14b9-4cc4-9539-5f2fe1008222"
34
- expect(response[1].name).to eq "asdfasdf"
35
- expect(response[1].type).to eq "urn:delme-client-id:resources:default"
36
- expect(response[1].owner_managed_access).to be_truthy
37
- end
38
- end
39
-
40
- describe '#get' do
41
- let(:realm_name) { "valid-realm" }
42
- let(:client_id) { "valid-client-id" }
43
- let(:resource_id) { "valid-resource-id" }
44
- let(:client_authz_resource) { KeycloakAdmin.realm(realm_name).authz_resources(client_id) }
45
- before(:each) do
46
- stub_token_client
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
- end
49
-
50
- it "returns authz scope" do
51
- response = client_authz_resource.get(resource_id)
52
- expect(response.id).to eq "94643fe2-1973-4a36-8e1f-830ade186398"
53
- expect(response.name).to eq "Default Resource"
54
- expect(response.type).to eq "urn:delme-client-id:resources:default"
55
- expect(response.owner_managed_access).to be_falsey
56
- end
57
- end
58
-
59
- describe '#update' do
60
- let(:realm_name) { "valid-realm" }
61
- let(:client_id) { "valid-client-id" }
62
- let(:resource_id) { "valid-resource-id" }
63
- let(:client_authz_resource) { KeycloakAdmin.realm(realm_name).authz_resources(client_id) }
64
- before(:each) do
65
- stub_token_client
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
- end
69
-
70
- it "returns updated authz scope" do
71
- response = client_authz_resource.update(resource_id, {name: "Default Resource", type: "urn:delme-client-id:resources:default", uris: ["/tmp/*"], owner_managed_access: false, display_name: "Default Resource", scopes: []})
72
- expect(response.id).to eq "94643fe2-1973-4a36-8e1f-830ade186398"
73
- expect(response.name).to eq "Default Resource"
74
- expect(response.type).to eq "urn:delme-client-id:resources:default"
75
- expect(response.owner_managed_access).to be_falsey
76
- end
77
- end
78
-
79
- describe '#create!' do
80
- let(:realm_name) { "valid-realm" }
81
- let(:client_id) { "valid-client-id" }
82
- before(:each) do
83
- @client_authz_resource = KeycloakAdmin.realm(realm_name).authz_resources(client_id)
84
- stub_token_client
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
- end
87
-
88
- it "returns created authz scope" do
89
- response = @client_authz_resource.create!("Default Resource", "urn:delme-client-id:resources:default", ["/tmp/*"], false, "Default Resource", [])
90
- expect(response.id).to eq "94643fe2-1973-4a36-8e1f-830ade186398"
91
- expect(response.name).to eq "Default Resource"
92
- expect(response.type).to eq "urn:delme-client-id:resources:default"
93
- expect(response.owner_managed_access).to be_falsey
94
- end
95
- end
96
-
97
- describe "#find_by" do
98
- let(:realm_name) { "valid-realm" }
99
- let(:client_id) { "valid-client-id" }
100
- let(:resource_id) { "valid-resource-id" }
101
- let(:client_authz_resource) { KeycloakAdmin.realm(realm_name).authz_resources(client_id) }
102
- before(:each) do
103
- stub_token_client
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
- end
106
-
107
- it "returns list of authz scopes" do
108
- response = client_authz_resource.find_by("Default Resource", "urn:delme-client-id:resources:default", ["/tmp/*"], false, "")
109
- expect(response.size).to eq 1
110
- expect(response[0].id).to eq "94643fe2-1973-4a36-8e1f-830ade186398"
111
- expect(response[0].name).to eq "Default Resource"
112
- expect(response[0].type).to eq "urn:delme-client-id:resources:default"
113
- expect(response[0].owner_managed_access).to be_falsey
114
- end
115
- end
116
-
117
- describe "#authz_scopes_url" do
118
- let(:realm_name) { "valid-realm" }
119
- let(:client_id) { "valid-client-id" }
120
- let(:client_authz_resource){ KeycloakAdmin.realm(realm_name).authz_resources(client_id) }
121
-
122
- context 'when resource_id is nil' do
123
- it "return a proper url" do
124
- expect(client_authz_resource.authz_resources_url(client_id)).to eq "http://auth.service.io/auth/admin/realms/valid-realm/clients/valid-client-id/authz/resource-server/resource"
125
- end
126
- end
127
-
128
- context 'when resource_id is not nil' do
129
- it "return a proper url" do
130
- expect(client_authz_resource.authz_resources_url(client_id, "resource-id")).to eq "http://auth.service.io/auth/admin/realms/valid-realm/clients/valid-client-id/authz/resource-server/resource/resource-id"
131
- end
132
- end
133
- end
134
-
135
- describe "#delete" do
136
- let(:realm_name) { "valid-realm" }
137
- let(:client_id) { "valid-client-id" }
138
- let(:resource_id) { "valid-resource-id" }
139
- let(:client_authz_resource) { KeycloakAdmin.realm(realm_name).authz_resources(client_id) }
140
- before(:each) do
141
- stub_token_client
142
- allow_any_instance_of(KeycloakAdmin::Resource).to receive(:delete).and_return '{}'
143
- end
144
-
145
- it "returns true" do
146
- response = client_authz_resource.delete(resource_id)
147
- expect(response).to be_truthy
148
- end
149
- end
150
- end
@@ -1,134 +0,0 @@
1
- RSpec.describe KeycloakAdmin::ClientAuthzScopeClient do
2
- describe "#initialize" do
3
- let(:realm_name) { nil }
4
- before(:each) do
5
- @realm = KeycloakAdmin.realm(realm_name)
6
- end
7
-
8
- context "when realm_name is defined" do
9
- let(:realm_name) { "master" }
10
- it "does not raise any error" do
11
- expect { @realm.attack_detections }.to_not raise_error
12
- end
13
- end
14
- context "when realm_name is not defined" do
15
- it "raise argument error" do
16
- expect { @realm.attack_detections }.to raise_error(ArgumentError)
17
- end
18
- end
19
- end
20
-
21
- describe "#create" do
22
- let(:realm_name) { "valid-realm" }
23
- let(:client_id) { "valid-client-id" }
24
- before(:each) do
25
- @client_authz_scope = KeycloakAdmin.realm(realm_name).authz_scopes(client_id)
26
- stub_token_client
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
- end
29
-
30
- it "returns created authz scope" do
31
- response = @client_authz_scope.create!("GET", "GET authz scope", "http://asdfasd1")
32
- expect(response.id).to eq "c0779ce3-0900-4ea3-b1d6-b23e1f19c662"
33
- expect(response.name).to eq "GET"
34
- expect(response.display_name).to eq "GET authz scope"
35
- expect(response.icon_uri).to eq "http://asdfasd1"
36
- end
37
- end
38
-
39
- describe "#list" do
40
- let(:realm_name) { "valid-realm" }
41
- let(:client_id) { "valid-client-id" }
42
- before(:each) do
43
- @client_authz_scope = KeycloakAdmin.realm(realm_name).authz_scopes(client_id)
44
- stub_token_client
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
- end
47
-
48
- it "returns list of authz scopes" do
49
- response = @client_authz_scope.list
50
- expect(response.size).to eq 2
51
- expect(response.first.id).to eq "c0779ce3-0900-4ea3-b1d6-b23e1f19c662"
52
- expect(response.first.name).to eq "GET"
53
- expect(response.first.display_name).to eq "GET authz scope"
54
- expect(response.first.icon_uri).to eq "http://asdfasd1"
55
- end
56
- end
57
-
58
-
59
- describe "#delete" do
60
- let(:realm_name) { "valid-realm" }
61
- let(:client_id) { "valid-client-id" }
62
- let(:scope_id) { "valid-scope-id" }
63
- before(:each) do
64
- @client_authz_scope = KeycloakAdmin.realm(realm_name).authz_scopes(client_id)
65
- stub_token_client
66
- allow_any_instance_of(KeycloakAdmin::Resource).to receive(:delete).and_return ""
67
- end
68
-
69
- it "returns true" do
70
- response = @client_authz_scope.delete(scope_id)
71
- expect(response).to eq true
72
- end
73
- end
74
-
75
- describe '#get' do
76
- let(:realm_name) { "valid-realm" }
77
- let(:client_id) { "valid-client-id" }
78
- let(:scope_id) { "valid-scope-id" }
79
- before(:each) do
80
- @client_authz_scope = KeycloakAdmin.realm(realm_name).authz_scopes(client_id)
81
- stub_token_client
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
- end
84
-
85
- it "returns authz scope" do
86
- response = @client_authz_scope.get(scope_id)
87
- expect(response.id).to eq "c0779ce3-0900-4ea3-b1d6-b23e1f19c662"
88
- expect(response.name).to eq "GET"
89
- expect(response.display_name).to eq "GET authz scope"
90
- expect(response.icon_uri).to eq "http://asdfasd1"
91
- end
92
- end
93
-
94
- describe '#search' do
95
- let(:realm_name) { "valid-realm" }
96
- let(:client_id) { "valid-client-id" }
97
- let(:name) { "GET" }
98
- before(:each) do
99
- @client_authz_scope = KeycloakAdmin.realm(realm_name).authz_scopes(client_id)
100
- stub_token_client
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
- end
103
-
104
- it "returns list of authz scopes" do
105
- response = @client_authz_scope.search(name)
106
- expect(response.size).to eq 1
107
- expect(response.first.id).to eq "c0779ce3-0900-4ea3-b1d6-b23e1f19c662"
108
- expect(response.first.name).to eq "GET"
109
- expect(response.first.display_name).to eq "GET authz scope"
110
- expect(response.first.icon_uri).to eq "http://asdfasd1"
111
- end
112
- end
113
-
114
- describe "#authz_scopes_url" do
115
- let(:realm_name) { "valid-realm" }
116
- let(:client_id) { "valid-client-id" }
117
- let(:client_authz_scope) { KeycloakAdmin.realm(realm_name).authz_scopes(client_id) }
118
- context 'resource_id is nil and id is nil' do
119
- it "return a proper url" do
120
- expect(client_authz_scope.authz_scopes_url(client_id)).to eq "http://auth.service.io/auth/admin/realms/valid-realm/clients/valid-client-id/authz/resource-server/scope"
121
- end
122
- end
123
- context 'resource_id is not nil' do
124
- it "return a proper url" do
125
- expect(client_authz_scope.authz_scopes_url(client_id, "valid-resource-id")).to eq "http://auth.service.io/auth/admin/realms/valid-realm/clients/valid-client-id/authz/resource-server/resource/valid-resource-id/scopes"
126
- end
127
- end
128
- context 'resource_id is nil and id is not nil' do
129
- it "return a proper url" do
130
- expect(client_authz_scope.authz_scopes_url(client_id, nil, "valid-id")).to eq "http://auth.service.io/auth/admin/realms/valid-realm/clients/valid-client-id/authz/resource-server/scope/valid-id"
131
- end
132
- end
133
- end
134
- end
@@ -1,133 +0,0 @@
1
- RSpec.describe KeycloakAdmin::ClientClient do
2
- describe "#clients_url" do
3
- let(:realm_name) { "valid-realm" }
4
- let(:client_id) { nil }
5
-
6
- before(:each) do
7
- @built_url = KeycloakAdmin.realm(realm_name).clients.clients_url(client_id)
8
- end
9
-
10
- context "when client_id is not defined" do
11
- let(:client_id) { nil }
12
- it "return a proper url without client id" do
13
- expect(@built_url).to eq "http://auth.service.io/auth/admin/realms/valid-realm/clients"
14
- end
15
- end
16
-
17
- context "when client_id is defined" do
18
- let(:client_id) { "95985b21-d884-4bbd-b852-cb8cd365afc2" }
19
- it "return a proper url with the client id" do
20
- expect(@built_url).to eq "http://auth.service.io/auth/admin/realms/valid-realm/clients/95985b21-d884-4bbd-b852-cb8cd365afc2"
21
- end
22
- end
23
- end
24
-
25
- describe "#get" do
26
- let(:realm_name) { "valid-realm" }
27
- let(:id) { "test_client_id" }
28
- let(:client_name) { "test_client_name" }
29
-
30
- before(:each) do
31
- @client_client = KeycloakAdmin.realm(realm_name).clients
32
-
33
- stub_token_client
34
- allow_any_instance_of(KeycloakAdmin::Resource).to receive(:get).and_return '{"id":"test_client_id","name":"test_client_name"}'
35
- end
36
-
37
- it "finds a client" do
38
- client = @client_client.get(id)
39
- expect(client.name).to eq client_name
40
- expect(client.id).to eq id
41
- end
42
- end
43
-
44
- describe "#find_by_client_id" do
45
- let(:realm_name) { "valid-realm" }
46
- let(:client_id) { "my_client_id" }
47
- let(:client_name) { "test_client_name" }
48
-
49
- before(:each) do
50
- @client_client = KeycloakAdmin.realm(realm_name).clients
51
-
52
- stub_token_client
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
- end
55
-
56
- it "finds a client it has" do
57
- client = @client_client.find_by_client_id(client_id)
58
- expect(client.name).to eq client_name
59
- expect(client.client_id).to eq client_id
60
- end
61
-
62
- it "returns nil if it doesn't have the client" do
63
- client = @client_client.find_by_client_id("client_id_3")
64
- expect(client).to be_nil
65
- end
66
- end
67
-
68
- describe "#list" do
69
- let(:realm_name) { "valid-realm" }
70
-
71
- before(:each) do
72
- @client_client = KeycloakAdmin.realm(realm_name).clients
73
-
74
- stub_token_client
75
- allow_any_instance_of(KeycloakAdmin::Resource).to receive(:get).and_return '[{"id":"test_client_id","name":"test_client_name"}]'
76
- end
77
-
78
- it "lists clients" do
79
- clients = @client_client.list
80
- expect(clients.length).to eq 1
81
- expect(clients[0].name).to eq "test_client_name"
82
- end
83
-
84
- it "passes rest client options" do
85
- faraday_options = {timeout: 10}
86
- allow_any_instance_of(KeycloakAdmin::Configuration).to receive(:faraday_options).and_return faraday_options
87
-
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
-
91
- clients = @client_client.list
92
- expect(clients.length).to eq 1
93
- expect(clients[0].name).to eq "test_client_name"
94
- end
95
- end
96
-
97
- describe "#update" do
98
- let(:realm_name) { "valid-realm" }
99
- let(:client) { KeycloakAdmin::ClientRepresentation.from_hash({ "id" => "test_client_id", "clientId" => "my-client", "name" => "old_name" }) }
100
-
101
- before(:each) do
102
- @client_client = KeycloakAdmin.realm(realm_name).clients
103
-
104
- stub_token_client
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
- end
108
-
109
- it "updates a client" do
110
- updated_client = @client_client.update(client)
111
-
112
- expect(updated_client.name).to eq "new_name"
113
- end
114
- end
115
-
116
- describe "#delete" do
117
- let(:realm_name) { "valid-realm" }
118
-
119
- before(:each) do
120
- @client_client = KeycloakAdmin.realm(realm_name).clients
121
- stub_token_client
122
- allow_any_instance_of(KeycloakAdmin::Resource).to receive(:delete).and_return ''
123
- end
124
-
125
- it "passes rest client options" do
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
- @client_client.delete("95b45037-3980-404c-ba12-784fa1baf2c2")
131
- end
132
- end
133
- end
@@ -1,83 +0,0 @@
1
- RSpec.describe KeycloakAdmin::ClientRoleMappingsClient do
2
- describe "#available_url" do
3
- let(:realm_name) { "valid-realm" }
4
- let(:user_id) { "test_user" }
5
- let(:client_id) { "test_client" }
6
-
7
- before(:each) do
8
- @built_url = KeycloakAdmin.realm(realm_name).user(user_id).client_role_mappings(client_id).list_available_url
9
- end
10
-
11
- it "return a proper url" do
12
- expect(@built_url).to eq "http://auth.service.io/auth/admin/realms/valid-realm/users/test_user/role-mappings/clients/test_client/available"
13
- end
14
- end
15
-
16
- describe "#list_available" do
17
- let(:realm_name) { "valid-realm" }
18
- let(:user_id) { "test_user" }
19
- let(:client_id) { "test_client" }
20
-
21
- before(:each) do
22
- @client_role_mappings_client = KeycloakAdmin.realm(realm_name).user(user_id).client_role_mappings(client_id)
23
-
24
- stub_token_client
25
- allow_any_instance_of(KeycloakAdmin::Resource).to receive(:get).and_return '[{"id":"test_role_id","name":"test_role_name"}]'
26
- end
27
-
28
- it "lists roles" do
29
- roles = @client_role_mappings_client.list_available
30
- expect(roles.length).to eq 1
31
- expect(roles[0].name).to eq "test_role_name"
32
- end
33
-
34
- it "passes rest client options" do
35
- faraday_options = {timeout: 10}
36
- allow_any_instance_of(KeycloakAdmin::Configuration).to receive(:faraday_options).and_return faraday_options
37
-
38
- expect(KeycloakAdmin::Resource).to receive(:new).with(
39
- "http://auth.service.io/auth/admin/realms/valid-realm/users/test_user/role-mappings/clients/test_client/available",
40
- faraday_options,
41
- anything
42
- ).and_call_original
43
-
44
- roles = @client_role_mappings_client.list_available
45
- expect(roles.length).to eq 1
46
- expect(roles[0].name).to eq "test_role_name"
47
- end
48
- end
49
-
50
- describe "#save" do
51
- let(:realm_name) { "valid-realm" }
52
- let(:user_id) { "test_user" }
53
- let(:client_id) { "test_client" }
54
- let(:role_list) { [
55
- KeycloakAdmin::RoleRepresentation.from_hash(
56
- "name" => "test_role_name",
57
- "composite" => false,
58
- "clientRole" => false
59
- )
60
- ] }
61
-
62
- before(:each) do
63
- @client_role_mappings_client = KeycloakAdmin.realm(realm_name).user(user_id).client_role_mappings(client_id)
64
-
65
- stub_token_client
66
- expect_any_instance_of(KeycloakAdmin::Resource).to receive(:post).with(role_list.to_json, anything)
67
- end
68
-
69
- it "saves client role mappings" do
70
- @client_role_mappings_client.save(role_list)
71
- end
72
-
73
- it "passes rest client options" do
74
- faraday_options = {timeout: 10}
75
- allow_any_instance_of(KeycloakAdmin::Configuration).to receive(:faraday_options).and_return faraday_options
76
-
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
79
-
80
- @client_role_mappings_client.save(role_list)
81
- end
82
- end
83
- end