keycloak-admin 0.7.0 → 0.7.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +2 -1
  3. data/CHANGELOG.md +70 -0
  4. data/Dockerfile +1 -1
  5. data/Gemfile.lock +7 -5
  6. data/README.md +149 -3
  7. data/lib/keycloak-admin.rb +13 -0
  8. data/lib/keycloak-admin/client/client.rb +11 -3
  9. data/lib/keycloak-admin/client/client_client.rb +24 -0
  10. data/lib/keycloak-admin/client/client_role_mappings_client.rb +32 -0
  11. data/lib/keycloak-admin/client/group_client.rb +46 -0
  12. data/lib/keycloak-admin/client/realm_client.rb +54 -0
  13. data/lib/keycloak-admin/client/role_client.rb +32 -0
  14. data/lib/keycloak-admin/client/role_mapper_client.rb +20 -0
  15. data/lib/keycloak-admin/client/user_client.rb +44 -2
  16. data/lib/keycloak-admin/representation/camel_json.rb +1 -1
  17. data/lib/keycloak-admin/representation/client_representation.rb +16 -0
  18. data/lib/keycloak-admin/representation/federated_identity_representation.rb +15 -0
  19. data/lib/keycloak-admin/representation/group_representation.rb +15 -0
  20. data/lib/keycloak-admin/representation/realm_representation.rb +14 -0
  21. data/lib/keycloak-admin/representation/representation.rb +5 -1
  22. data/lib/keycloak-admin/representation/role_representation.rb +17 -0
  23. data/lib/keycloak-admin/representation/user_representation.rb +21 -14
  24. data/lib/keycloak-admin/resource/base_role_containing_resource.rb +26 -0
  25. data/lib/keycloak-admin/resource/group_resource.rb +7 -0
  26. data/lib/keycloak-admin/resource/user_resource.rb +7 -0
  27. data/lib/keycloak-admin/version.rb +1 -1
  28. data/spec/client/client_client_spec.rb +53 -0
  29. data/spec/client/client_role_mappings_client_spec.rb +82 -0
  30. data/spec/client/group_client_spec.rb +125 -0
  31. data/spec/client/realm_client_spec.rb +108 -0
  32. data/spec/client/role_client_spec.rb +83 -0
  33. data/spec/client/role_mapper_client_spec.rb +47 -0
  34. data/spec/client/user_client_spec.rb +105 -14
  35. data/spec/representation/user_representation_spec.rb +15 -0
  36. data/spec/resource/group_resource_spec.rb +14 -0
  37. data/spec/resource/user_resource_spec.rb +14 -0
  38. data/spec/spec_helper.rb +7 -0
  39. metadata +25 -4
@@ -97,15 +97,42 @@ RSpec.describe KeycloakAdmin::TokenClient do
97
97
  end
98
98
  end
99
99
 
100
+ describe "#save" do
101
+ let(:realm_name) { "valid-realm" }
102
+ let(:user) { KeycloakAdmin::UserRepresentation.from_hash(
103
+ "username" => "test_username",
104
+ "createdTimestamp" => Time.now.to_i,
105
+ )}
106
+
107
+ before(:each) do
108
+ @user_client = KeycloakAdmin.realm(realm_name).users
109
+
110
+ stub_token_client
111
+ allow_any_instance_of(RestClient::Resource).to receive(:post)
112
+ end
113
+
114
+ it "saves a user" do
115
+ expect(@user_client.save(user)).to eq user
116
+ end
117
+
118
+ it "passes rest client options" do
119
+ rest_client_options = {verify_ssl: OpenSSL::SSL::VERIFY_NONE}
120
+ allow_any_instance_of(KeycloakAdmin::Configuration).to receive(:rest_client_options).and_return rest_client_options
121
+
122
+ expect(RestClient::Resource).to receive(:new).with(
123
+ "http://auth.service.io/auth/admin/realms/valid-realm/users", rest_client_options).and_call_original
124
+
125
+ expect(@user_client.save(user)).to eq user
126
+ end
127
+ end
128
+
100
129
  describe "#get" do
101
130
  let(:realm_name) { "valid-realm" }
131
+
102
132
  before(:each) do
103
- @user_client = KeycloakAdmin.realm("a_realm").users
133
+ @user_client = KeycloakAdmin.realm(realm_name).users
104
134
 
105
- allow_any_instance_of(KeycloakAdmin::TokenClient).to receive(:get).and_return KeycloakAdmin::TokenRepresentation.new(
106
- 'test_access_token', 'token_type', 'expires_in', 'refresh_token',
107
- 'refresh_expires_in', 'id_token', 'not_before_policy', 'session_state'
108
- )
135
+ stub_token_client
109
136
  allow_any_instance_of(RestClient::Resource).to receive(:get).and_return '{"username":"test_username","createdTimestamp":1559347200}'
110
137
  end
111
138
 
@@ -119,27 +146,91 @@ RSpec.describe KeycloakAdmin::TokenClient do
119
146
  allow_any_instance_of(KeycloakAdmin::Configuration).to receive(:rest_client_options).and_return rest_client_options
120
147
 
121
148
  expect(RestClient::Resource).to receive(:new).with(
122
- "http://auth.service.io/auth/admin/realms/a_realm/users/test_user_id", rest_client_options).and_call_original
149
+ "http://auth.service.io/auth/admin/realms/valid-realm/users/test_user_id", rest_client_options).and_call_original
123
150
 
124
151
  user = @user_client.get('test_user_id')
125
152
  expect(user.username).to eq 'test_username'
126
153
  end
127
154
  end
128
155
 
156
+ describe "#search" do
157
+ let(:realm_name) { "valid-realm" }
158
+ let(:user) { KeycloakAdmin::UserRepresentation.from_hash(
159
+ "username" => "test_username",
160
+ "createdTimestamp" => Time.now.to_i,
161
+ )}
162
+
163
+ before(:each) do
164
+ @user_client = KeycloakAdmin.realm(realm_name).users
165
+
166
+ stub_token_client
167
+ allow_any_instance_of(RestClient::Resource).to receive(:get).and_return '[{"username":"test_username","createdTimestamp":1559347200}]'
168
+ end
169
+
170
+ it "finds a user" do
171
+ users = @user_client.search("test_username")
172
+ expect(users.length).to eq 1
173
+ expect(users[0].username).to eq "test_username"
174
+ end
175
+
176
+ it "passes rest client options" do
177
+ rest_client_options = {verify_ssl: OpenSSL::SSL::VERIFY_NONE}
178
+ allow_any_instance_of(KeycloakAdmin::Configuration).to receive(:rest_client_options).and_return rest_client_options
179
+
180
+ expect(RestClient::Resource).to receive(:new).with(
181
+ "http://auth.service.io/auth/admin/realms/valid-realm/users", rest_client_options).and_call_original
182
+
183
+ users = @user_client.search("test_username")
184
+ expect(users.length).to eq 1
185
+ expect(users[0].username).to eq "test_username"
186
+ end
187
+ end
188
+
189
+ describe "#list" do
190
+ let(:realm_name) { "valid-realm" }
191
+ let(:user) { KeycloakAdmin::UserRepresentation.from_hash(
192
+ "username" => "test_username",
193
+ "createdTimestamp" => Time.now.to_i,
194
+ )}
195
+
196
+ before(:each) do
197
+ @user_client = KeycloakAdmin.realm(realm_name).users
198
+
199
+ stub_token_client
200
+ allow_any_instance_of(RestClient::Resource).to receive(:get).and_return '[{"username":"test_username","createdTimestamp":1559347200}]'
201
+ end
202
+
203
+ it "lists users" do
204
+ users = @user_client.list
205
+ expect(users.length).to eq 1
206
+ expect(users[0].username).to eq "test_username"
207
+ end
208
+
209
+ it "passes rest client options" do
210
+ rest_client_options = {verify_ssl: OpenSSL::SSL::VERIFY_NONE}
211
+ allow_any_instance_of(KeycloakAdmin::Configuration).to receive(:rest_client_options).and_return rest_client_options
212
+
213
+ expect(RestClient::Resource).to receive(:new).with(
214
+ "http://auth.service.io/auth/admin/realms/valid-realm/users", rest_client_options).and_call_original
215
+
216
+ users = @user_client.list
217
+ expect(users.length).to eq 1
218
+ expect(users[0].username).to eq "test_username"
219
+ end
220
+ end
221
+
129
222
  describe "#delete" do
130
223
  let(:realm_name) { "valid-realm" }
224
+
131
225
  before(:each) do
132
- @user_client = KeycloakAdmin.realm("a_realm").users
226
+ @user_client = KeycloakAdmin.realm(realm_name).users
133
227
 
134
- allow_any_instance_of(KeycloakAdmin::TokenClient).to receive(:get).and_return KeycloakAdmin::TokenRepresentation.new(
135
- 'test_access_token', 'token_type', 'expires_in', 'refresh_token',
136
- 'refresh_expires_in', 'id_token', 'not_before_policy', 'session_state'
137
- )
228
+ stub_token_client
138
229
  allow_any_instance_of(RestClient::Resource).to receive(:delete)
139
230
  end
140
231
 
141
- it "parses the response" do
142
- @user_client.delete('test_user_id')
232
+ it "does not fail" do
233
+ expect(@user_client.delete('test_user_id')).to be_truthy
143
234
  end
144
235
 
145
236
  it "passes rest client options" do
@@ -147,7 +238,7 @@ RSpec.describe KeycloakAdmin::TokenClient do
147
238
  allow_any_instance_of(KeycloakAdmin::Configuration).to receive(:rest_client_options).and_return rest_client_options
148
239
 
149
240
  expect(RestClient::Resource).to receive(:new).with(
150
- "http://auth.service.io/auth/admin/realms/a_realm/users/test_user_id", rest_client_options).and_call_original
241
+ "http://auth.service.io/auth/admin/realms/valid-realm/users/test_user_id", rest_client_options).and_call_original
151
242
 
152
243
  @user_client.delete('test_user_id')
153
244
  end
@@ -0,0 +1,15 @@
1
+ RSpec.describe KeycloakAdmin::UserRepresentation do
2
+ describe "#to_json" do
3
+ before(:each) do
4
+ @user = KeycloakAdmin::UserRepresentation.from_hash(
5
+ "username" => "test_username",
6
+ "createdTimestamp" => Time.at(1559836000).to_i,
7
+ "enabled" => true
8
+ )
9
+ end
10
+
11
+ it "can convert to json" do
12
+ expect(@user.to_json).to eq '{"id":null,"createdTimestamp":1559836000,"origin":null,"username":"test_username","email":null,"enabled":true,"emailVerified":null,"firstName":null,"lastName":null,"attributes":null,"credentials":[],"federatedIdentities":[]}'
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,14 @@
1
+ RSpec.describe KeycloakAdmin::GroupResource do
2
+ describe "#resource_url" do
3
+ let(:realm_name) { "valid-realm" }
4
+ let(:group_id) { "95985b21-d884-4bbd-b852-cb8cd365afc2" }
5
+
6
+ before(:each) do
7
+ @built_url = KeycloakAdmin.realm(realm_name).group(group_id).resource_url
8
+ end
9
+
10
+ it "return a proper url" do
11
+ expect(@built_url).to eq "http://auth.service.io/auth/admin/realms/valid-realm/groups/95985b21-d884-4bbd-b852-cb8cd365afc2"
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,14 @@
1
+ RSpec.describe KeycloakAdmin::UserResource do
2
+ describe "#resource_url" do
3
+ let(:realm_name) { "valid-realm" }
4
+ let(:user_id) { "95985b21-d884-4bbd-b852-cb8cd365afc2" }
5
+
6
+ before(:each) do
7
+ @built_url = KeycloakAdmin.realm(realm_name).user(user_id).resource_url
8
+ end
9
+
10
+ it "return a proper url" do
11
+ expect(@built_url).to eq "http://auth.service.io/auth/admin/realms/valid-realm/users/95985b21-d884-4bbd-b852-cb8cd365afc2"
12
+ end
13
+ end
14
+ end
@@ -20,3 +20,10 @@ RSpec.configure do |config|
20
20
 
21
21
  configure
22
22
  end
23
+
24
+ def stub_token_client
25
+ allow_any_instance_of(KeycloakAdmin::TokenClient).to receive(:get).and_return KeycloakAdmin::TokenRepresentation.new(
26
+ 'test_access_token', 'token_type', 'expires_in', 'refresh_token',
27
+ 'refresh_expires_in', 'id_token', 'not_before_policy', 'session_state'
28
+ )
29
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: keycloak-admin
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.7.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lorent Lempereur
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-06-06 00:00:00.000000000 Z
11
+ date: 2020-03-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: http-cookie
@@ -81,6 +81,7 @@ extra_rdoc_files: []
81
81
  files:
82
82
  - ".gitignore"
83
83
  - ".rspec"
84
+ - CHANGELOG.md
84
85
  - Dockerfile
85
86
  - Gemfile
86
87
  - Gemfile.lock
@@ -89,26 +90,47 @@ files:
89
90
  - keycloak-admin.gemspec
90
91
  - lib/keycloak-admin.rb
91
92
  - lib/keycloak-admin/client/client.rb
93
+ - lib/keycloak-admin/client/client_client.rb
94
+ - lib/keycloak-admin/client/client_role_mappings_client.rb
92
95
  - lib/keycloak-admin/client/configurable_token_client.rb
96
+ - lib/keycloak-admin/client/group_client.rb
93
97
  - lib/keycloak-admin/client/realm_client.rb
98
+ - lib/keycloak-admin/client/role_client.rb
99
+ - lib/keycloak-admin/client/role_mapper_client.rb
94
100
  - lib/keycloak-admin/client/token_client.rb
95
101
  - lib/keycloak-admin/client/user_client.rb
96
102
  - lib/keycloak-admin/configuration.rb
97
103
  - lib/keycloak-admin/representation/camel_json.rb
104
+ - lib/keycloak-admin/representation/client_representation.rb
98
105
  - lib/keycloak-admin/representation/credential_representation.rb
106
+ - lib/keycloak-admin/representation/federated_identity_representation.rb
107
+ - lib/keycloak-admin/representation/group_representation.rb
99
108
  - lib/keycloak-admin/representation/impersonation_redirection_representation.rb
100
109
  - lib/keycloak-admin/representation/impersonation_representation.rb
110
+ - lib/keycloak-admin/representation/realm_representation.rb
101
111
  - lib/keycloak-admin/representation/representation.rb
112
+ - lib/keycloak-admin/representation/role_representation.rb
102
113
  - lib/keycloak-admin/representation/token_representation.rb
103
114
  - lib/keycloak-admin/representation/user_representation.rb
115
+ - lib/keycloak-admin/resource/base_role_containing_resource.rb
116
+ - lib/keycloak-admin/resource/group_resource.rb
117
+ - lib/keycloak-admin/resource/user_resource.rb
104
118
  - lib/keycloak-admin/version.rb
119
+ - spec/client/client_client_spec.rb
120
+ - spec/client/client_role_mappings_client_spec.rb
105
121
  - spec/client/client_spec.rb
106
122
  - spec/client/configurable_token_client_spec.rb
123
+ - spec/client/group_client_spec.rb
107
124
  - spec/client/realm_client_spec.rb
125
+ - spec/client/role_client_spec.rb
126
+ - spec/client/role_mapper_client_spec.rb
108
127
  - spec/client/token_client_spec.rb
109
128
  - spec/client/user_client_spec.rb
110
129
  - spec/configuration_spec.rb
111
130
  - spec/representation/impersonation_representation_spec.rb
131
+ - spec/representation/user_representation_spec.rb
132
+ - spec/resource/group_resource_spec.rb
133
+ - spec/resource/user_resource_spec.rb
112
134
  - spec/spec_helper.rb
113
135
  homepage: https://github.com/looorent/keycloak-admin-ruby
114
136
  licenses:
@@ -129,8 +151,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
129
151
  - !ruby/object:Gem::Version
130
152
  version: '0'
131
153
  requirements: []
132
- rubyforge_project:
133
- rubygems_version: 2.6.4
154
+ rubygems_version: 3.0.3
134
155
  signing_key:
135
156
  specification_version: 4
136
157
  summary: Keycloak Admin REST API client written in Ruby