stormpath-sdk 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. data/Gemfile +4 -0
  2. data/README.md +24 -0
  3. data/Rakefile +16 -0
  4. data/lib/stormpath-sdk.rb +49 -0
  5. data/lib/stormpath-sdk/auth/authentication_result.rb +17 -0
  6. data/lib/stormpath-sdk/auth/basic_authenticator.rb +42 -0
  7. data/lib/stormpath-sdk/auth/basic_login_attempt.rb +30 -0
  8. data/lib/stormpath-sdk/auth/username_password_request.rb +43 -0
  9. data/lib/stormpath-sdk/client/api_key.rb +18 -0
  10. data/lib/stormpath-sdk/client/client.rb +23 -0
  11. data/lib/stormpath-sdk/client/client_builder.rb +291 -0
  12. data/lib/stormpath-sdk/ds/data_store.rb +150 -0
  13. data/lib/stormpath-sdk/ds/resource_factory.rb +22 -0
  14. data/lib/stormpath-sdk/http/authc/sauthc1_signer.rb +216 -0
  15. data/lib/stormpath-sdk/http/http_client_request_executor.rb +69 -0
  16. data/lib/stormpath-sdk/http/request.rb +83 -0
  17. data/lib/stormpath-sdk/http/response.rb +35 -0
  18. data/lib/stormpath-sdk/resource/account.rb +110 -0
  19. data/lib/stormpath-sdk/resource/account_list.rb +17 -0
  20. data/lib/stormpath-sdk/resource/application.rb +95 -0
  21. data/lib/stormpath-sdk/resource/application_list.rb +17 -0
  22. data/lib/stormpath-sdk/resource/collection_resource.rb +76 -0
  23. data/lib/stormpath-sdk/resource/directory.rb +76 -0
  24. data/lib/stormpath-sdk/resource/directory_list.rb +15 -0
  25. data/lib/stormpath-sdk/resource/email_verification_token.rb +11 -0
  26. data/lib/stormpath-sdk/resource/error.rb +42 -0
  27. data/lib/stormpath-sdk/resource/group.rb +73 -0
  28. data/lib/stormpath-sdk/resource/group_list.rb +18 -0
  29. data/lib/stormpath-sdk/resource/group_membership.rb +55 -0
  30. data/lib/stormpath-sdk/resource/group_membership_list.rb +17 -0
  31. data/lib/stormpath-sdk/resource/instance_resource.rb +13 -0
  32. data/lib/stormpath-sdk/resource/password_reset_token.rb +27 -0
  33. data/lib/stormpath-sdk/resource/resource.rb +173 -0
  34. data/lib/stormpath-sdk/resource/resource_error.rb +32 -0
  35. data/lib/stormpath-sdk/resource/status.rb +19 -0
  36. data/lib/stormpath-sdk/resource/tenant.rb +55 -0
  37. data/lib/stormpath-sdk/resource/utils.rb +16 -0
  38. data/lib/stormpath-sdk/util/assert.rb +26 -0
  39. data/lib/stormpath-sdk/util/hash.rb +17 -0
  40. data/lib/stormpath-sdk/util/request_utils.rb +57 -0
  41. data/lib/stormpath-sdk/version.rb +4 -0
  42. data/stormpath-sdk.gemspec +29 -0
  43. data/test/client/client.yml +16 -0
  44. data/test/client/clientbuilder_spec.rb +176 -0
  45. data/test/client/read_spec.rb +243 -0
  46. data/test/client/write_spec.rb +315 -0
  47. metadata +226 -0
@@ -0,0 +1,243 @@
1
+ require "stormpath-sdk"
2
+
3
+ include Stormpath::Client
4
+ include Stormpath::Resource
5
+
6
+ describe "READ Operations" do
7
+
8
+ before(:all) do
9
+ apiKey = ApiKey.new 'myApkiKeyId', 'myApkiKeySecret'
10
+ @client = Client.new apiKey
11
+ @tenant = @client.current_tenant
12
+ @data_store = @client.data_store
13
+ end
14
+
15
+ it "client should be created from api_key" do
16
+ @client.should be_instance_of Client
17
+ end
18
+
19
+ it "tenant's properties must come complete'" do
20
+
21
+ @tenant.should be_kind_of Tenant
22
+
23
+ key = @tenant.get_key
24
+ name = @tenant.get_name
25
+
26
+ key.should be_kind_of String
27
+ name.should be_kind_of String
28
+
29
+ applications = @tenant.get_applications
30
+
31
+ applications.should be_kind_of ApplicationList
32
+
33
+ # checking the tenant's' applications
34
+ applications.each { |app|
35
+
36
+ app.should be_kind_of Application
37
+
38
+ appName = app.get_name
39
+
40
+ # just checking that at least one
41
+ # application property can be read from here
42
+ appName.should be_kind_of String
43
+ }
44
+
45
+ directories = @tenant.get_directories
46
+
47
+ directories.should be_kind_of DirectoryList
48
+
49
+ # checking the tenant's' directories
50
+ directories.each { |dir|
51
+
52
+ dir.should be_kind_of Directory
53
+
54
+ dirName = dir.get_name
55
+
56
+ # just checking that at least one
57
+ # directory property can be read from here
58
+ dirName.should be_kind_of String
59
+ }
60
+
61
+ end
62
+
63
+ it "application's properties must come complete'" do
64
+
65
+ href = 'applications/fzyWJ5V_SDORGPk4fT2jhA'
66
+ application = @data_store.get_resource href, Application
67
+
68
+ application.should be_kind_of Application
69
+
70
+ name = application.get_name
71
+ status = application.get_status
72
+ description = application.get_description
73
+ tenant = application.get_tenant
74
+ accounts = application.get_accounts
75
+ password_reset_tokens = application.get_password_reset_token
76
+
77
+ name.should be_kind_of String
78
+ status.should be_kind_of String
79
+ description.should be_kind_of String
80
+ tenant.should be_kind_of Tenant
81
+ accounts.should be_kind_of AccountList
82
+ password_reset_tokens.should be_kind_of PasswordResetToken
83
+
84
+ accounts.each { |acc|
85
+
86
+ acc.should be_kind_of Account
87
+
88
+ acc_name = acc.get_username
89
+
90
+ # just checking that at least one
91
+ # account property can be read from here
92
+ acc_name.should be_kind_of String
93
+ }
94
+
95
+
96
+ end
97
+
98
+ it "directory's properties must come complete'" do
99
+
100
+ href = 'directories/wDTY5jppTLS2uZEAcqaL5A'
101
+ directory = @data_store.get_resource href, Directory
102
+
103
+ directory.should be_kind_of Directory
104
+
105
+ name = directory.get_name
106
+ status = directory.get_status
107
+ description = directory.get_description
108
+ tenant = directory.get_tenant
109
+ accounts = directory.get_accounts
110
+ groups = directory.get_groups
111
+
112
+ name.should be_kind_of String
113
+ status.should be_kind_of String
114
+ description.should be_kind_of String
115
+ tenant.should be_kind_of Tenant
116
+ accounts.should be_kind_of AccountList
117
+ groups.should be_kind_of GroupList
118
+
119
+ accounts.each { |acc|
120
+
121
+ acc.should be_kind_of Account
122
+
123
+ acc_name = acc.get_username
124
+
125
+ # just checking that at least one
126
+ # account property can be read from here
127
+ acc_name.should be_kind_of String
128
+ }
129
+
130
+ groups.each { |group|
131
+
132
+ group.should be_kind_of Group
133
+
134
+ group_name = group.get_name
135
+
136
+ # just checking that at least one
137
+ # group property can be read from here
138
+ group_name.should be_kind_of String
139
+ }
140
+
141
+
142
+ end
143
+
144
+ it "group's properties must come complete'" do
145
+
146
+ href = 'groups/mCidbrAcSF-VpkNfOVvJkQ'
147
+ group = @data_store.get_resource href, Group
148
+
149
+ group.should be_kind_of Group
150
+
151
+ name = group.get_name
152
+ status = group.get_status
153
+ description = group.get_description
154
+ tenant = group.get_tenant
155
+ accounts = group.get_accounts
156
+ directory = group.get_directory
157
+
158
+ name.should be_kind_of String
159
+ status.should be_kind_of String
160
+ description.should be_kind_of String
161
+ tenant.should be_kind_of Tenant
162
+ accounts.should be_kind_of AccountList
163
+ directory.should be_kind_of Directory
164
+
165
+ accounts.each { |acc|
166
+
167
+ acc.should be_kind_of Account
168
+
169
+ acc_name = acc.get_username
170
+
171
+ # just checking that at least one
172
+ # account property can be read from here
173
+ acc_name.should be_kind_of String
174
+ }
175
+
176
+
177
+ end
178
+
179
+ it "account's properties must come complete'" do
180
+
181
+ href = 'accounts/ije9hUEKTZ29YcGhdG5s2A'
182
+ account = @data_store.get_resource href, Account
183
+
184
+ account.should be_kind_of Account
185
+
186
+ username = account.get_username
187
+ status = account.get_status
188
+ email = account.get_email
189
+ given_name = account.get_given_name
190
+ middle_name = account.get_middle_name
191
+ surname = account.get_surname
192
+ groups = account.get_groups
193
+ directory = account.get_directory
194
+ email_verification_token = account.get_email_verification_token
195
+ group_memberships = account.get_group_memberships
196
+
197
+ username.should be_kind_of String
198
+ status.should be_kind_of String
199
+ email.should be_kind_of String
200
+ given_name.should be_kind_of String
201
+ # middle_name is optional
202
+ #middle_name.should be_kind_of String
203
+ surname.should be_kind_of String
204
+ groups.should be_kind_of GroupList
205
+ directory.should be_kind_of Directory
206
+ email_verification_token.should be_kind_of EmailVerificationToken
207
+ group_memberships.should be_kind_of GroupMembershipList
208
+
209
+ groups.each { |group|
210
+
211
+ group.should be_kind_of Group
212
+
213
+ group_name = group.get_name
214
+
215
+ # just checking that at least one
216
+ # group property can be read from here
217
+ group_name.should be_kind_of String
218
+ }
219
+
220
+ group_memberships.each { |groupMembership|
221
+
222
+ groupMembership.should be_kind_of GroupMembership
223
+
224
+ group = groupMembership.get_group
225
+
226
+ if (!group.nil?)
227
+
228
+ group_name = group.get_name
229
+
230
+ # just checking that at least one
231
+ # group property can be read from here
232
+ group_name.should be_kind_of String
233
+
234
+ end
235
+ }
236
+
237
+
238
+ end
239
+
240
+ end
241
+
242
+
243
+
@@ -0,0 +1,315 @@
1
+ require "stormpath-sdk"
2
+
3
+ include Stormpath::Authentication
4
+
5
+ describe "WRITE Operations" do
6
+
7
+ before(:all) do
8
+ apiKey = ApiKey.new 'myApkiKeyId', 'myApkiKeySecret'
9
+ @client = Client.new apiKey
10
+ @data_store = @client.data_store
11
+ @create_account = false
12
+ @update_account = false
13
+ @update_application = false
14
+ @update_directory = false
15
+ @update_group = false
16
+ @create_application = false
17
+ @verify_email = false
18
+ @create_password_reset_token = false
19
+ @verify_password_reset_token = false
20
+ @create_group_membership_from_account = false
21
+ @create_group_membership_from_group = false
22
+ @update_group_membership_with_deletion = false
23
+ end
24
+
25
+ it "application should be able to authenticate" do
26
+
27
+ href = 'applications/fzyWJ5V_SDORGPk4fT2jhA'
28
+ application = @data_store.get_resource href, Application
29
+
30
+ result = application.authenticate UsernamePasswordRequest.new 'tootertest', 'super_P4ss', nil
31
+
32
+ result.should be_kind_of Account
33
+ end
34
+
35
+ it "application should NOT be able to authenticate and catch the error" do
36
+
37
+ begin
38
+
39
+ href = 'applications/fzyWJ5V_SDORGPk4fT2jhA'
40
+ application = @data_store.get_resource href, Application
41
+ result = application.authenticate UsernamePasswordRequest.new 'tootertest', 'WRONG_PASS', nil
42
+
43
+ rescue ResourceError => re
44
+ p '** Authentication Error **'
45
+ p 'Message: ' + re.message
46
+ p 'HTTP Status: ' + re.get_status.to_s
47
+ p 'Developer Message: ' + re.get_developer_message
48
+ p 'More Information: ' + re.get_more_info
49
+ p 'Error Code: ' + re.get_code.to_s
50
+ end
51
+
52
+ result.should_not be_kind_of Account
53
+ end
54
+
55
+ it "directory should be able to create account" do
56
+
57
+ if (@create_account)
58
+
59
+ href = 'directories/wDTY5jppTLS2uZEAcqaL5A'
60
+ directory = @data_store.get_resource href, Directory
61
+
62
+ account = @data_store.instantiate Account, nil
63
+ account.set_email 'rubysdk@email.com'
64
+ account.set_given_name 'Ruby'
65
+ account.set_password 'super_P4ss'
66
+ account.set_surname 'Sdk'
67
+ account.set_username 'rubysdk'
68
+
69
+ result = directory.create_account account
70
+
71
+ result.should be_kind_of Account
72
+
73
+ end
74
+
75
+ end
76
+
77
+ it "account should be updated" do
78
+
79
+ if (@update_account)
80
+
81
+ href = 'accounts/ije9hUEKTZ29YcGhdG5s2A'
82
+ account = @data_store.get_resource href, Account
83
+
84
+ mod_value = 'Modified at: ' + Time.now.to_s
85
+ account.set_middle_name mod_value
86
+ account.set_status Status::ENABLED
87
+
88
+ account.save
89
+
90
+ account.get_middle_name.should == mod_value
91
+
92
+ end
93
+
94
+ end
95
+
96
+ it "application should be updated" do
97
+
98
+ if (@update_application)
99
+
100
+ href = 'applications/fzyWJ5V_SDORGPk4fT2jhA'
101
+ application = @data_store.get_resource href, Application
102
+
103
+ application.set_name application.get_name + ' Modified'
104
+ application.set_status Status::ENABLED
105
+
106
+ application.save
107
+
108
+ application.get_name.should be_kind_of String
109
+
110
+ end
111
+
112
+ end
113
+
114
+ it "directory should be updated" do
115
+
116
+ if (@update_directory)
117
+
118
+ href = 'directories/wDTY5jppTLS2uZEAcqaL5A'
119
+ directory = @data_store.get_resource href, Directory
120
+
121
+ directory.set_name directory.get_name + ' Modified'
122
+ directory.set_status Status::ENABLED
123
+
124
+ directory.save
125
+
126
+ directory.get_name.should be_kind_of String
127
+
128
+ end
129
+
130
+ end
131
+
132
+ it "group should be updated" do
133
+
134
+ if (@update_group)
135
+
136
+ href = 'groups/mCidbrAcSF-VpkNfOVvJkQ'
137
+ group = @data_store.get_resource href, Group
138
+
139
+ group.set_name group.get_description + ' Modified'
140
+ group.set_status Status::ENABLED
141
+
142
+ group.save
143
+
144
+ group.get_name.should be_kind_of String
145
+
146
+ end
147
+
148
+ end
149
+
150
+ it "application should be created" do
151
+
152
+ if (@create_application)
153
+
154
+ tenant = @client.current_tenant
155
+
156
+ application = @data_store.instantiate Application, nil
157
+ application.set_name 'Test Application Creation'
158
+ application.set_description 'Test Application Description'
159
+
160
+ result = tenant.create_application application
161
+
162
+ result.should be_kind_of Application
163
+
164
+ end
165
+
166
+ end
167
+
168
+ it "email should get verified" do
169
+
170
+ if (@verify_email)
171
+
172
+ verification_token = 'ujhNWAIVT2Wtfk-no3ajtw'
173
+
174
+ tenant = @client.current_tenant
175
+
176
+ result = tenant.verify_account_email verification_token
177
+
178
+ result.should be_kind_of Account
179
+
180
+ end
181
+
182
+ end
183
+
184
+ it "password reset token should be created" do
185
+
186
+ if (@create_password_reset_token)
187
+
188
+ href = 'applications/fzyWJ5V_SDORGPk4fT2jhA'
189
+ application = @data_store.get_resource href, Application
190
+
191
+ password_reset_token = application.create_password_reset_token 'rubysdk@email.com'
192
+
193
+ password_reset_token.should be_kind_of PasswordResetToken
194
+
195
+ end
196
+
197
+ end
198
+
199
+ it "password reset token should be verified" do
200
+
201
+ if (@verify_password_reset_token)
202
+
203
+ href = 'applications/fzyWJ5V_SDORGPk4fT2jhA'
204
+ application = @data_store.get_resource href, Application
205
+
206
+ password_reset_token = application.verify_password_reset_token 'XW1AAKnlT-6sX0KEvLAbDg'
207
+
208
+ password_reset_token.should be_kind_of PasswordResetToken
209
+
210
+ end
211
+
212
+ end
213
+
214
+ it "account should be linked to specified group" do
215
+
216
+ if (@create_group_membership_from_account)
217
+
218
+ group_href = 'groups/mCidbrAcSF-VpkNfOVvJkQ'
219
+ group = @data_store.get_resource group_href, Group
220
+
221
+ account_href = 'accounts/ije9hUEKTZ29YcGhdG5s2A'
222
+ account = @data_store.get_resource account_href, Account
223
+
224
+ account.add_group group
225
+
226
+ group_linked = false
227
+ account.get_group_memberships.each { |group_membership|
228
+
229
+ group = group_membership.get_group
230
+
231
+ if (!group.nil? and group.get_href.include? group_href)
232
+ group_linked = true
233
+ break
234
+ end
235
+ }
236
+
237
+ group_linked.should == true
238
+
239
+ end
240
+
241
+ end
242
+
243
+
244
+ it "group should be linked to specified account" do
245
+
246
+ if (@create_group_membership_from_group)
247
+
248
+ group_href = 'groups/mCidbrAcSF-VpkNfOVvJkQ'
249
+ group = @data_store.get_resource group_href, Group
250
+
251
+ account_href = 'accounts/ije9hUEKTZ29YcGhdG5s2A'
252
+ account = @data_store.get_resource account_href, Account
253
+
254
+ group.add_account account
255
+
256
+ accountLinked = false
257
+ group.get_accounts.each { |tmpAccount|
258
+
259
+ if (tmpAccount.get_href.include? account_href)
260
+ accountLinked = true
261
+ break
262
+ end
263
+ }
264
+
265
+ accountLinked.should == true
266
+
267
+ end
268
+
269
+ end
270
+
271
+ it "group membership should be updated with deletion/creation" do
272
+
273
+ if (@update_group_membership_with_deletion)
274
+
275
+ group_href = 'groups/mCidbrAcSF-VpkNfOVvJkQ'
276
+ group = @data_store.get_resource group_href, Group
277
+
278
+ account_href = 'accounts/ije9hUEKTZ29YcGhdG5s2A'
279
+ account = @data_store.get_resource account_href, Account
280
+
281
+ group_linked = false
282
+ group_membership = nil
283
+ account.get_group_memberships.each { |tmp_group_membership|
284
+
285
+ group_membership = tmp_group_membership
286
+ tmp_group = group_membership.get_group
287
+
288
+ if (!tmp_group.nil? and tmp_group.get_href.include? group_href)
289
+ group_linked = true
290
+ break
291
+ end
292
+ }
293
+
294
+ if (!group_linked)
295
+ group_membership.delete
296
+ group.add_account account
297
+ end
298
+
299
+ account.get_group_memberships.each { |tmp_group_membership|
300
+
301
+ tmp_group = tmp_group_membership.get_group
302
+
303
+ if (!tmp_group.nil? and tmp_group.get_href.include? group_href)
304
+ group_membership = tmp_group_membership
305
+ break
306
+ end
307
+ }
308
+
309
+ group_membership.get_group.get_href.should include group_href
310
+
311
+ end
312
+
313
+ end
314
+
315
+ end