stormpath-sdk 1.3.1 → 1.4.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.
Files changed (55) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -1
  3. data/.travis.yml +3 -3
  4. data/CHANGES.md +8 -0
  5. data/lib/stormpath-sdk.rb +8 -0
  6. data/lib/stormpath-sdk/auth/create_factor.rb +64 -0
  7. data/lib/stormpath-sdk/data_store.rb +17 -1
  8. data/lib/stormpath-sdk/oauth/authenticator.rb +2 -1
  9. data/lib/stormpath-sdk/oauth/challenge_factor_grant.rb +25 -0
  10. data/lib/stormpath-sdk/oauth/challenge_factor_grant_request.rb +16 -0
  11. data/lib/stormpath-sdk/resource/account.rb +6 -0
  12. data/lib/stormpath-sdk/resource/account_link.rb +1 -1
  13. data/lib/stormpath-sdk/resource/challenge.rb +26 -0
  14. data/lib/stormpath-sdk/resource/collection.rb +0 -1
  15. data/lib/stormpath-sdk/resource/directory.rb +1 -0
  16. data/lib/stormpath-sdk/resource/factor.rb +26 -0
  17. data/lib/stormpath-sdk/resource/field.rb +20 -0
  18. data/lib/stormpath-sdk/resource/linked_account.rb +1 -1
  19. data/lib/stormpath-sdk/resource/phone.rb +21 -0
  20. data/lib/stormpath-sdk/resource/schema.rb +21 -0
  21. data/lib/stormpath-sdk/version.rb +2 -2
  22. data/spec/auth/create_factor_spec.rb +92 -0
  23. data/spec/auth/http_basic_authentication_spec.rb +3 -3
  24. data/spec/auth/http_bearer_authentication_spec.rb +3 -3
  25. data/spec/client_spec.rb +25 -25
  26. data/spec/oauth/access_token_authentication_result_spec.rb +3 -3
  27. data/spec/provider/provider_spec.rb +2 -2
  28. data/spec/resource/account_creation_policy_spec.rb +2 -2
  29. data/spec/resource/account_link_spec.rb +2 -2
  30. data/spec/resource/account_spec.rb +196 -12
  31. data/spec/resource/account_store_mapping_spec.rb +3 -3
  32. data/spec/resource/account_store_spec.rb +4 -4
  33. data/spec/resource/api_key_spec.rb +3 -3
  34. data/spec/resource/application_spec.rb +74 -33
  35. data/spec/resource/challenge_spec.rb +53 -0
  36. data/spec/resource/collection_spec.rb +6 -6
  37. data/spec/resource/custom_data_spec.rb +2 -2
  38. data/spec/resource/directory_spec.rb +27 -21
  39. data/spec/resource/email_template_spec.rb +2 -2
  40. data/spec/resource/factor_spec.rb +124 -0
  41. data/spec/resource/field_spec.rb +35 -0
  42. data/spec/resource/group_membership_spec.rb +3 -3
  43. data/spec/resource/group_spec.rb +3 -3
  44. data/spec/resource/linked_account_spec.rb +2 -2
  45. data/spec/resource/organization_spec.rb +6 -6
  46. data/spec/resource/password_policy_spec.rb +2 -2
  47. data/spec/resource/password_strength_spec.rb +2 -2
  48. data/spec/resource/phone_spec.rb +63 -0
  49. data/spec/resource/schema_spec.rb +39 -0
  50. data/spec/resource/status_spec.rb +4 -4
  51. data/spec/spec_helper.rb +6 -3
  52. data/spec/support/custom_data_storage_behavior.rb +2 -2
  53. data/spec/support/mocked_provider_accounts.rb +106 -0
  54. data/spec/support/resource_helpers.rb +20 -16
  55. metadata +16 -2
@@ -2,8 +2,8 @@ require 'spec_helper'
2
2
 
3
3
  describe Stormpath::Resource::AccountStoreMapping, :vcr do
4
4
  let(:directory_name) { 'rubysdktestdir' }
5
- let(:directory) { test_api_client.directories.create(build_directory(name: directory_name)) }
6
- let(:application) { test_api_client.applications.create(build_application) }
5
+ let(:directory) { test_api_client.directories.create(directory_attrs(name: directory_name)) }
6
+ let(:application) { test_api_client.applications.create(application_attrs) }
7
7
 
8
8
  after do
9
9
  application.delete if application
@@ -116,7 +116,7 @@ describe Stormpath::Resource::AccountStoreMapping, :vcr do
116
116
  end
117
117
 
118
118
  describe "given a group" do
119
- let(:group) { directory.groups.create(build_group) }
119
+ let(:group) { directory.groups.create(group_attrs) }
120
120
  let(:reloaded_application) { test_api_client.applications.get application.href }
121
121
 
122
122
  after do
@@ -1,10 +1,10 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Stormpath::Resource::AccountStore, :vcr do
4
- let(:application) { test_api_client.applications.create(build_application) }
5
- let(:directory) { test_api_client.directories.create(build_directory) }
6
- let(:group) { directory.groups.create(build_group) }
7
- let(:organization) { test_api_client.organizations.create(build_organization) }
4
+ let(:application) { test_api_client.applications.create(application_attrs) }
5
+ let(:directory) { test_api_client.directories.create(directory_attrs) }
6
+ let(:group) { directory.groups.create(group_attrs) }
7
+ let(:organization) { test_api_client.organizations.create(organization_attrs) }
8
8
 
9
9
  after do
10
10
  application.delete if application
@@ -1,10 +1,10 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Stormpath::Resource::ApiKey, :vcr do
4
- let(:application) { test_api_client.applications.create(build_application) }
5
- let(:directory) { test_api_client.directories.create(build_directory) }
4
+ let(:application) { test_api_client.applications.create(application_attrs) }
5
+ let(:directory) { test_api_client.directories.create(directory_attrs) }
6
6
  let(:tenant) { application.tenant }
7
- let(:account) { application.accounts.create(build_account) }
7
+ let(:account) { application.accounts.create(account_attrs) }
8
8
  let(:api_key) { account.api_keys.create({}) }
9
9
  before { map_account_store(application, directory, 1, true, false) }
10
10
 
@@ -2,9 +2,9 @@ require 'spec_helper'
2
2
  include UUIDTools
3
3
 
4
4
  describe Stormpath::Resource::Application, :vcr do
5
- let(:app) { test_api_client.applications.create(build_application) }
5
+ let(:app) { test_api_client.applications.create(application_attrs) }
6
6
  let(:application) { test_api_client.applications.get app.href }
7
- let(:directory) { test_api_client.directories.create(build_directory) }
7
+ let(:directory) { test_api_client.directories.create(directory_attrs) }
8
8
 
9
9
  before do
10
10
  map_account_store(app, directory, 1, true, true)
@@ -67,7 +67,7 @@ describe Stormpath::Resource::Application, :vcr do
67
67
  describe 'application_associations' do
68
68
 
69
69
  context '#accounts' do
70
- let(:account) { application.accounts.create(build_account) }
70
+ let(:account) { application.accounts.create(account_attrs) }
71
71
 
72
72
  after do
73
73
  account.delete if account
@@ -84,7 +84,7 @@ describe Stormpath::Resource::Application, :vcr do
84
84
  end
85
85
 
86
86
  context '#groups' do
87
- let(:group) { application.groups.create(build_group) }
87
+ let(:group) { application.groups.create(group_attrs) }
88
88
 
89
89
  after { group.delete }
90
90
 
@@ -114,7 +114,7 @@ describe Stormpath::Resource::Application, :vcr do
114
114
 
115
115
 
116
116
  describe '#create_account' do
117
- let(:account) { Stormpath::Resource::Account.new(build_account) }
117
+ let(:account) { Stormpath::Resource::Account.new(account_attrs) }
118
118
 
119
119
  context 'with registration workflow' do
120
120
  it 'creates an account with worflow enabled' do
@@ -137,7 +137,7 @@ describe Stormpath::Resource::Application, :vcr do
137
137
 
138
138
  describe '#authenticate_account' do
139
139
  let(:account) do
140
- directory.accounts.create build_account(password: 'P@$$w0rd')
140
+ directory.accounts.create account_attrs(password: 'P@$$w0rd')
141
141
  end
142
142
 
143
143
  let(:login_request) do
@@ -182,7 +182,7 @@ describe Stormpath::Resource::Application, :vcr do
182
182
  end
183
183
 
184
184
  context 'given a proper directory' do
185
- let(:account) { directory.accounts.create build_account(password: 'P@$$w0rd') }
185
+ let(:account) { directory.accounts.create account_attrs(password: 'P@$$w0rd') }
186
186
 
187
187
  let(:login_request) do
188
188
  Stormpath::Authentication::UsernamePasswordRequest.new account.username, password, account_store: directory
@@ -197,8 +197,8 @@ describe Stormpath::Resource::Application, :vcr do
197
197
  end
198
198
 
199
199
  context 'given a wrong directory' do
200
- let(:new_directory) { test_api_client.directories.create(build_directory) }
201
- let(:account) { new_directory.accounts.create build_account(password: 'P@$$w0rd') }
200
+ let(:new_directory) { test_api_client.directories.create(directory_attrs) }
201
+ let(:account) { new_directory.accounts.create account_attrs(password: 'P@$$w0rd') }
202
202
  let(:login_request) do
203
203
  Stormpath::Authentication::UsernamePasswordRequest.new account.username, password, account_store: directory
204
204
  end
@@ -213,9 +213,9 @@ describe Stormpath::Resource::Application, :vcr do
213
213
  end
214
214
 
215
215
  context 'given a group' do
216
- let(:group) {directory.groups.create(build_group) }
216
+ let(:group) {directory.groups.create(group_attrs) }
217
217
 
218
- let(:account) { directory.accounts.create build_account(password: 'P@$$w0rd') }
218
+ let(:account) { directory.accounts.create account_attrs(password: 'P@$$w0rd') }
219
219
 
220
220
  let(:login_request) do
221
221
  Stormpath::Authentication::UsernamePasswordRequest.new account.username, password, account_store: group
@@ -247,7 +247,7 @@ describe Stormpath::Resource::Application, :vcr do
247
247
  describe '#send_password_reset_email' do
248
248
  context 'given an email' do
249
249
  context 'of an existing account on the application' do
250
- let(:account) { directory.accounts.create build_account }
250
+ let(:account) { directory.accounts.create account_attrs }
251
251
 
252
252
  let(:sent_to_account) { application.send_password_reset_email account.email }
253
253
 
@@ -261,8 +261,8 @@ describe Stormpath::Resource::Application, :vcr do
261
261
  end
262
262
 
263
263
  context 'of an existing account not mapped to the application' do
264
- let(:account) { other_directory.accounts.create build_account }
265
- let(:other_directory) { test_api_client.directories.create(build_directory) }
264
+ let(:account) { other_directory.accounts.create account_attrs }
265
+ let(:other_directory) { test_api_client.directories.create(directory_attrs) }
266
266
 
267
267
  after do
268
268
  account.delete
@@ -285,7 +285,7 @@ describe Stormpath::Resource::Application, :vcr do
285
285
  end
286
286
 
287
287
  context 'of an existing account on the application with an account store href' do
288
- let(:account) { directory.accounts.create build_account }
288
+ let(:account) { directory.accounts.create account_attrs }
289
289
 
290
290
  let(:sent_to_account) do
291
291
  application.send_password_reset_email(account.email, account_store: { href: directory.href })
@@ -301,7 +301,7 @@ describe Stormpath::Resource::Application, :vcr do
301
301
  end
302
302
 
303
303
  context 'of an existing account on the application with an account store resource object' do
304
- let(:account) { directory.accounts.create build_account }
304
+ let(:account) { directory.accounts.create account_attrs }
305
305
 
306
306
  let(:sent_to_account) do
307
307
  application.send_password_reset_email(account.email, account_store: directory)
@@ -317,8 +317,8 @@ describe Stormpath::Resource::Application, :vcr do
317
317
  end
318
318
 
319
319
  context 'of an existing account not mapped to the application with an account store href' do
320
- let(:account) { directory.accounts.create build_account }
321
- let(:other_directory) { test_api_client.directories.create(build_directory) }
320
+ let(:account) { directory.accounts.create account_attrs }
321
+ let(:other_directory) { test_api_client.directories.create(directory_attrs) }
322
322
 
323
323
  after do
324
324
  account.delete
@@ -333,7 +333,7 @@ describe Stormpath::Resource::Application, :vcr do
333
333
  end
334
334
 
335
335
  context 'of an existing account on the application with a non existant account store organization namekey' do
336
- let(:account) { directory.accounts.create build_account }
336
+ let(:account) { directory.accounts.create account_attrs }
337
337
 
338
338
  after do
339
339
  account.delete
@@ -347,8 +347,8 @@ describe Stormpath::Resource::Application, :vcr do
347
347
  end
348
348
 
349
349
  context 'of an existing account on the application with a right account store organization namekey' do
350
- let(:account) { account_directory.accounts.create build_account }
351
- let(:account_directory) { test_api_client.directories.create(build_directory) }
350
+ let(:account) { account_directory.accounts.create account_attrs }
351
+ let(:account_directory) { test_api_client.directories.create(directory_attrs) }
352
352
 
353
353
  let(:reloaded_account_directory) do
354
354
  test_api_client.directories.get(account_directory.href)
@@ -386,12 +386,12 @@ describe Stormpath::Resource::Application, :vcr do
386
386
  end
387
387
 
388
388
  context 'of an existing account on the application with a right account store organization resource object' do
389
- let(:account) { account_directory.accounts.create build_account }
390
- let(:account_directory) { test_api_client.directories.create(build_directory) }
389
+ let(:account) { account_directory.accounts.create account_attrs }
390
+ let(:account_directory) { test_api_client.directories.create(directory_attrs) }
391
391
  let(:reloaded_account_directory) do
392
392
  test_api_client.directories.get(account_directory.href)
393
393
  end
394
- let(:organization) { test_api_client.organizations.create(build_organization) }
394
+ let(:organization) { test_api_client.organizations.create(organization_attrs) }
395
395
  let(:sent_to_account) do
396
396
  application.send_password_reset_email(account.email, account_store: organization)
397
397
  end
@@ -415,13 +415,13 @@ describe Stormpath::Resource::Application, :vcr do
415
415
  end
416
416
 
417
417
  context 'of an existing account on the application with a wrong account store organization namekey' do
418
- let(:account) { account_directory.accounts.create build_account }
419
- let(:account_directory) { test_api_client.directories.create(build_directory) }
418
+ let(:account) { account_directory.accounts.create account_attrs }
419
+ let(:account_directory) { test_api_client.directories.create(directory_attrs) }
420
420
  let(:reloaded_account_directory) do
421
421
  test_api_client.directories.get(account_directory.href)
422
422
  end
423
- let(:organization) { test_api_client.organizations.create(build_organization) }
424
- let(:other_organization) { test_api_client.organizations.create(build_organization) }
423
+ let(:organization) { test_api_client.organizations.create(organization_attrs) }
424
+ let(:other_organization) { test_api_client.organizations.create(organization_attrs) }
425
425
 
426
426
  after do
427
427
  account.delete
@@ -445,14 +445,14 @@ describe Stormpath::Resource::Application, :vcr do
445
445
  end
446
446
 
447
447
  describe '#verification_emails' do
448
- let(:directory_with_verification) { test_api_client.directories.create(build_directory) }
448
+ let(:directory_with_verification) { test_api_client.directories.create(directory_attrs) }
449
449
 
450
450
  before do
451
451
  map_account_store(application, directory_with_verification, 1, false, false)
452
452
  enable_email_verification(directory_with_verification)
453
453
  end
454
454
 
455
- let(:account) { directory_with_verification.accounts.create(build_account) }
455
+ let(:account) { directory_with_verification.accounts.create(account_attrs) }
456
456
  let(:verification_emails) do
457
457
  application.verification_emails.create(login: account.email)
458
458
  end
@@ -468,7 +468,7 @@ describe Stormpath::Resource::Application, :vcr do
468
468
  end
469
469
 
470
470
  describe 'create_login_attempt' do
471
- let(:account) { directory.accounts.create(build_account) }
471
+ let(:account) { directory.accounts.create(account_attrs) }
472
472
 
473
473
  context 'valid credentials' do
474
474
  let(:username_password_request) do
@@ -630,7 +630,7 @@ describe Stormpath::Resource::Application, :vcr do
630
630
  end
631
631
 
632
632
  describe '#verify_password_reset_token' do
633
- let(:account) { directory.accounts.create(build_account) }
633
+ let(:account) { directory.accounts.create(account_attrs) }
634
634
  let(:password_reset_token) do
635
635
  application.password_reset_tokens.create(email: account.email).token
636
636
  end
@@ -925,7 +925,7 @@ describe Stormpath::Resource::Application, :vcr do
925
925
  end
926
926
 
927
927
  describe '#authenticate_oauth' do
928
- let(:account_data) { build_account }
928
+ let(:account_data) { account_attrs }
929
929
  let(:password_grant_request) { Stormpath::Oauth::PasswordGrantRequest.new account_data[:email], account_data[:password] }
930
930
  let(:aquire_token) { application.authenticate_oauth(password_grant_request) }
931
931
  let(:account) { application.accounts.create account_data }
@@ -1175,6 +1175,47 @@ describe Stormpath::Resource::Application, :vcr do
1175
1175
  end
1176
1176
  end
1177
1177
 
1178
+ context 'generate access token from challenge factor grant request' do
1179
+ before do
1180
+ stub_request(:post,
1181
+ "https://#{test_api_key_id}:#{test_api_key_secret}@#{test_host}/v1/accounts/#{account.href.split('/').last}/factors?challenge=true")
1182
+ .to_return(body: Stormpath::Test.mocked_factor_response)
1183
+
1184
+ stub_request(:post,
1185
+ "https://#{test_api_key_id}:#{test_api_key_secret}@#{test_host}/v1/applications/#{application.href.split('/').last}/oauth/token")
1186
+ .to_return(body: Stormpath::Test.mocked_challenge_factor_grant_response)
1187
+ end
1188
+ let(:account_data) { account_attrs }
1189
+ let(:authenticate_oauth) { application.authenticate_oauth(challenge_factor_grant_request) }
1190
+ let(:challenge_factor_grant_request) do
1191
+ Stormpath::Oauth::ChallengeFactorGrantRequest.new(challenge, code)
1192
+ end
1193
+ let(:account) do
1194
+ application.accounts.create(account_data)
1195
+ end
1196
+ let(:factor) do
1197
+ account.create_factor(:sms,
1198
+ phone: { number: '+12025550173',
1199
+ name: 'Rspec test phone',
1200
+ description: 'This is a testing phone number' },
1201
+ challenge: { message: 'Enter code please: ' })
1202
+ end
1203
+ let(:challenge) { "https://#{test_host}/v1/challenges/29300284904" }
1204
+ let(:code) { '123456' }
1205
+
1206
+ it 'should return access token response' do
1207
+ expect(authenticate_oauth).to be_kind_of(Stormpath::Oauth::AccessTokenAuthenticationResult)
1208
+ end
1209
+
1210
+ it 'response should contain token data' do
1211
+ expect(authenticate_oauth.access_token).not_to be_empty
1212
+ expect(authenticate_oauth.refresh_token).not_to be_empty
1213
+ expect(authenticate_oauth.token_type).not_to be_empty
1214
+ expect(authenticate_oauth.expires_in).not_to be_nil
1215
+ expect(authenticate_oauth.stormpath_access_token_href).not_to be_empty
1216
+ end
1217
+ end
1218
+
1178
1219
  context 'exchange id site token for access_token with invalid jwt' do
1179
1220
  let(:invalid_jwt_token) { 'invalid_token' }
1180
1221
 
@@ -0,0 +1,53 @@
1
+ require 'spec_helper'
2
+
3
+ describe Stormpath::Resource::Challenge, :vcr do
4
+ let(:directory) { test_api_client.directories.create(directory_attrs) }
5
+ let(:account) { directory.accounts.create(account_attrs) }
6
+ let(:factor) do
7
+ account.factors.create(
8
+ type: 'SMS',
9
+ phone: {
10
+ number: '+12025550173',
11
+ name: 'test phone',
12
+ description: 'this is a testing phone number'
13
+ }
14
+ )
15
+ end
16
+
17
+ let(:challenge) { factor.challenges.create(message: 'Enter code: ${code}') }
18
+ let(:validate_challenge) { challenge.validate(code: '123456') }
19
+
20
+ before do
21
+ stub_request(:post, "#{factor.href}/challenges")
22
+ .to_return(body: Stormpath::Test.mocked_challenge)
23
+
24
+ stub_request(:post, challenge.href)
25
+ .to_return(body: Stormpath::Test.mocked_successfull_challenge)
26
+ end
27
+
28
+ after { directory.delete }
29
+
30
+ describe 'instances should respond to attribute property methods' do
31
+ it do
32
+ [:message].each do |property_accessor|
33
+ expect(challenge).to respond_to(property_accessor)
34
+ expect(challenge).to respond_to("#{property_accessor}=")
35
+ expect(challenge.send(property_accessor)).to be_a String
36
+ end
37
+
38
+ [:status, :created_at, :modified_at].each do |property_getter|
39
+ expect(challenge).to respond_to(property_getter)
40
+ expect(challenge.send(property_getter)).to be_a String
41
+ end
42
+
43
+ expect(challenge.factor).to be_a Stormpath::Resource::Factor
44
+ expect(challenge.account).to be_a Stormpath::Resource::Account
45
+ end
46
+ end
47
+
48
+ describe '#validate' do
49
+ it 'should return successfull challenge for valid code from sms' do
50
+ expect(validate_challenge.status).to eq 'SUCCESS'
51
+ end
52
+ end
53
+ end
@@ -169,7 +169,7 @@ describe Stormpath::Resource::Collection, :vcr do
169
169
 
170
170
  context 'live examples' do
171
171
  context 'testing limits and offsets' do
172
- let(:directory) { test_api_client.directories.create(build_directory) }
172
+ let(:directory) { test_api_client.directories.create(directory_attrs) }
173
173
 
174
174
  let(:groups) do
175
175
  ('A'..'Z').map do |letter|
@@ -211,7 +211,7 @@ describe Stormpath::Resource::Collection, :vcr do
211
211
  end
212
212
 
213
213
  context 'testing limits and offsets with name checking' do
214
- let(:directory) { test_api_client.directories.create(build_directory) }
214
+ let(:directory) { test_api_client.directories.create(directory_attrs) }
215
215
 
216
216
  let!(:groups) do
217
217
  ('1'..'100').map do |number|
@@ -273,7 +273,7 @@ describe Stormpath::Resource::Collection, :vcr do
273
273
  end
274
274
 
275
275
  context '#wild characters search' do
276
- let(:directory) { test_api_client.directories.create(build_directory) }
276
+ let(:directory) { test_api_client.directories.create(directory_attrs) }
277
277
 
278
278
  # !@#$%^&*()_-+=?><:]}[{'
279
279
  # 'jlpicard/!@$%^*()_-+&=?><:]}[{'
@@ -309,7 +309,7 @@ describe Stormpath::Resource::Collection, :vcr do
309
309
  end
310
310
 
311
311
  context '#asterisk search on one attribute' do
312
- let(:directory) { test_api_client.directories.create(build_directory) }
312
+ let(:directory) { test_api_client.directories.create(directory_attrs) }
313
313
 
314
314
  let!(:account) do
315
315
  directory.accounts.create username: "jlpicard",
@@ -337,7 +337,7 @@ describe Stormpath::Resource::Collection, :vcr do
337
337
  end
338
338
 
339
339
  context '#asterisk search on multiple attribute' do
340
- let(:directory) { test_api_client.directories.create(build_directory) }
340
+ let(:directory) { test_api_client.directories.create(directory_attrs) }
341
341
 
342
342
  let!(:account) do
343
343
  directory.accounts.create username: "jlpicard",
@@ -365,7 +365,7 @@ describe Stormpath::Resource::Collection, :vcr do
365
365
  end
366
366
 
367
367
  context 'search accounts by custom data' do
368
- let(:directory) { test_api_client.directories.create(build_directory) }
368
+ let(:directory) { test_api_client.directories.create(directory_attrs) }
369
369
 
370
370
  let(:account) do
371
371
  directory.accounts.create(
@@ -6,7 +6,7 @@ describe Stormpath::Resource::CustomData, :vcr do
6
6
  end
7
7
 
8
8
  context 'wuth caching regions' do
9
- let(:directory) { test_api_client.directories.create(build_directory) }
9
+ let(:directory) { test_api_client.directories.create(directory_attrs) }
10
10
 
11
11
  it_behaves_like 'account_custom_data'
12
12
  it_behaves_like 'group_custom_data'
@@ -17,7 +17,7 @@ describe Stormpath::Resource::CustomData, :vcr do
17
17
  @disabled_cache_client ||= Stormpath::Client.new({api_key: test_api_key, cache: { store: Stormpath::Cache::DisabledCacheStore }})
18
18
  end
19
19
 
20
- let(:directory) { disabled_cache_client.directories.create(build_directory) }
20
+ let(:directory) { disabled_cache_client.directories.create(directory_attrs) }
21
21
 
22
22
  it_behaves_like 'account_custom_data'
23
23
  it_behaves_like 'group_custom_data'
@@ -1,11 +1,11 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Stormpath::Resource::Directory, :vcr do
4
- let(:application) { test_api_client.applications.create(build_application) }
4
+ let(:application) { test_api_client.applications.create(application_attrs) }
5
5
  after { application.delete }
6
6
 
7
7
  describe 'instances should respond to attribute property methods' do
8
- let(:directory) { test_api_client.directories.create(build_directory) }
8
+ let(:directory) { test_api_client.directories.create(directory_attrs) }
9
9
 
10
10
  after { directory.delete }
11
11
 
@@ -31,12 +31,12 @@ describe Stormpath::Resource::Directory, :vcr do
31
31
  end
32
32
 
33
33
  describe 'directory_associations' do
34
- let(:directory) { test_api_client.directories.create(build_directory) }
34
+ let(:directory) { test_api_client.directories.create(directory_attrs) }
35
35
 
36
36
  after { directory.delete }
37
37
 
38
38
  context '#accounts' do
39
- let(:account) { directory.accounts.create(build_account) }
39
+ let(:account) { directory.accounts.create(account_attrs) }
40
40
 
41
41
  after { account.delete if account }
42
42
 
@@ -50,7 +50,7 @@ describe Stormpath::Resource::Directory, :vcr do
50
50
  end
51
51
 
52
52
  context '#groups' do
53
- let(:group) { directory.groups.create(build_group) }
53
+ let(:group) { directory.groups.create(group_attrs) }
54
54
 
55
55
  after { group.delete }
56
56
 
@@ -87,7 +87,7 @@ describe Stormpath::Resource::Directory, :vcr do
87
87
  end
88
88
 
89
89
  context '#organizations' do
90
- let(:organization) { test_api_client.organizations.create(build_organization) }
90
+ let(:organization) { test_api_client.organizations.create(organization_attrs) }
91
91
 
92
92
  let!(:organization_account_store_mappings) do
93
93
  map_organization_store(directory, organization)
@@ -109,11 +109,17 @@ describe Stormpath::Resource::Directory, :vcr do
109
109
  expect(directory.password_policy).to be_kind_of(Stormpath::Resource::PasswordPolicy)
110
110
  end
111
111
  end
112
+
113
+ context '#account_schema' do
114
+ it 'should be able to fetch the account schema' do
115
+ expect(directory.account_schema).to be_kind_of Stormpath::Resource::Schema
116
+ end
117
+ end
112
118
  end
113
119
 
114
120
  describe '#create_account' do
115
- let(:directory) { test_api_client.directories.create(build_directory) }
116
- let(:account) { Stormpath::Resource::Account.new(build_account) }
121
+ let(:directory) { test_api_client.directories.create(directory_attrs) }
122
+ let(:account) { Stormpath::Resource::Account.new(account_attrs) }
117
123
 
118
124
  after { directory.delete }
119
125
 
@@ -132,7 +138,7 @@ describe Stormpath::Resource::Directory, :vcr do
132
138
  end
133
139
 
134
140
  context 'with registration workflow' do
135
- let(:directory_with_verification) { test_api_client.directories.create(build_directory) }
141
+ let(:directory_with_verification) { test_api_client.directories.create(directory_attrs) }
136
142
 
137
143
  before do
138
144
  map_account_store(application, directory_with_verification, 1, false, false)
@@ -176,7 +182,7 @@ describe Stormpath::Resource::Directory, :vcr do
176
182
  end
177
183
 
178
184
  describe 'create account with password import MCF feature' do
179
- let(:directory) { test_api_client.directories.create(build_directory) }
185
+ let(:directory) { test_api_client.directories.create(directory_attrs) }
180
186
 
181
187
  before { map_account_store(application, directory, 0, true, true) }
182
188
 
@@ -286,12 +292,12 @@ describe Stormpath::Resource::Directory, :vcr do
286
292
 
287
293
  context 'with account data as hash' do
288
294
  let(:account_email) { 'rubysdk' }
289
- let(:account) { directory.create_account(build_account(email: account_email)) }
295
+ let(:account) { directory.create_account(account_attrs(email: account_email)) }
290
296
 
291
297
  it 'creates an account with status ENABLED' do
292
298
  expect(account.email).to eq("#{account_email}#{default_domain}")
293
- expect(account.given_name).to eq('givenname')
294
- expect(account.surname).to eq('surname')
299
+ expect(account.given_name).to eq('ruby')
300
+ expect(account.surname).to eq('ruby')
295
301
  expect(account.status).to eq('ENABLED')
296
302
  end
297
303
  end
@@ -299,7 +305,7 @@ describe Stormpath::Resource::Directory, :vcr do
299
305
 
300
306
  describe '#create_directory_with_custom_data' do
301
307
  let(:directory) do
302
- test_api_client.directories.create(build_directory(name: 'rubysdkdir',
308
+ test_api_client.directories.create(directory_attrs(name: 'rubysdkdir',
303
309
  description: 'rubysdkdir desc'))
304
310
  end
305
311
 
@@ -484,12 +490,12 @@ describe Stormpath::Resource::Directory, :vcr do
484
490
  end
485
491
 
486
492
  describe '#create_account_with_custom_data' do
487
- let(:directory) { test_api_client.directories.create(build_directory) }
493
+ let(:directory) { test_api_client.directories.create(directory_attrs) }
488
494
 
489
495
  after { directory.delete }
490
496
 
491
497
  it 'creates an account with custom data' do
492
- account = Stormpath::Resource::Account.new(build_account)
498
+ account = Stormpath::Resource::Account.new(account_attrs)
493
499
 
494
500
  account.custom_data['birth_date'] = '2305-07-13'
495
501
 
@@ -504,12 +510,12 @@ describe Stormpath::Resource::Directory, :vcr do
504
510
  end
505
511
 
506
512
  describe '#create_group' do
507
- let(:directory) { test_api_client.directories.create(build_directory) }
513
+ let(:directory) { test_api_client.directories.create(directory_attrs) }
508
514
 
509
515
  after { directory.delete }
510
516
 
511
517
  context 'given a valid group' do
512
- let(:created_group) { directory.groups.create(build_group(name: 'rubysdkgroup')) }
518
+ let(:created_group) { directory.groups.create(group_attrs(name: 'rubysdkgroup')) }
513
519
 
514
520
  after { created_group.delete }
515
521
 
@@ -521,9 +527,9 @@ describe Stormpath::Resource::Directory, :vcr do
521
527
  end
522
528
 
523
529
  describe '#delete_directory' do
524
- let(:directory) { test_api_client.directories.create(build_directory) }
525
- let!(:group) { directory.groups.create(build_group) }
526
- let!(:account) { directory.accounts.create(build_account) }
530
+ let(:directory) { test_api_client.directories.create(directory_attrs) }
531
+ let!(:group) { directory.groups.create(group_attrs) }
532
+ let!(:account) { directory.accounts.create(account_attrs) }
527
533
  let!(:account_store_mapping) { map_account_store(application, directory, 0, true, true) }
528
534
 
529
535
  after { directory.delete }