stormpath-sdk 1.3.0 → 1.3.1

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 (42) hide show
  1. checksums.yaml +4 -4
  2. data/.rspec +1 -0
  3. data/.travis.yml +0 -3
  4. data/CHANGES.md +9 -0
  5. data/README.md +8 -21
  6. data/Rakefile +1 -15
  7. data/lib/stormpath-sdk/oauth/error.rb +21 -0
  8. data/lib/stormpath-sdk/oauth/local_access_token_verification.rb +2 -2
  9. data/lib/stormpath-sdk/oauth/remote_access_token_verification.rb +2 -2
  10. data/lib/stormpath-sdk/version.rb +2 -2
  11. data/spec/auth/http_basic_authentication_spec.rb +6 -21
  12. data/spec/auth/http_bearer_authentication_spec.rb +11 -24
  13. data/spec/client_spec.rb +116 -258
  14. data/spec/oauth/access_token_authentication_result_spec.rb +14 -14
  15. data/spec/provider/provider_spec.rb +32 -40
  16. data/spec/resource/account_creation_policy_spec.rb +8 -13
  17. data/spec/resource/account_link_spec.rb +4 -17
  18. data/spec/resource/account_spec.rb +37 -81
  19. data/spec/resource/account_store_mapping_spec.rb +20 -32
  20. data/spec/resource/account_store_spec.rb +8 -31
  21. data/spec/resource/api_key_spec.rb +11 -14
  22. data/spec/resource/application_spec.rb +39 -168
  23. data/spec/resource/collection_spec.rb +17 -17
  24. data/spec/resource/custom_data_spec.rb +2 -2
  25. data/spec/resource/directory_spec.rb +164 -240
  26. data/spec/resource/email_template_spec.rb +21 -24
  27. data/spec/resource/group_membership_spec.rb +9 -12
  28. data/spec/resource/group_spec.rb +17 -31
  29. data/spec/resource/linked_account_spec.rb +4 -17
  30. data/spec/resource/organization_spec.rb +38 -110
  31. data/spec/resource/password_policy_spec.rb +13 -16
  32. data/spec/resource/password_strength_spec.rb +15 -18
  33. data/spec/resource/status_spec.rb +32 -35
  34. data/spec/spec_helper.rb +8 -139
  35. data/spec/support/api_key_helpers.rb +34 -0
  36. data/spec/support/custom_data_storage_behavior.rb +139 -156
  37. data/spec/support/env_names_warning.rb +59 -0
  38. data/spec/support/resource_helpers.rb +84 -0
  39. data/spec/support/resource_matchers.rb +6 -0
  40. data/stormpath-sdk.gemspec +1 -0
  41. metadata +20 -3
  42. data/support/api.rb +0 -55
@@ -1,22 +1,9 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Stormpath::Resource::AccountStoreMapping, :vcr do
4
-
5
- def create_account_store_mapping(application, account_store, options={})
6
- test_api_client.account_store_mappings.create({
7
- application: application,
8
- account_store: account_store,
9
- list_index: options[:list_index] || 0,
10
- is_default_account_store: options[:is_default_account_store] || false,
11
- is_default_group_store: options[:is_default_group_store] || false
12
- })
13
- end
14
-
15
- let(:directory_name) { random_directory_name }
16
-
17
- let(:directory) { test_api_client.directories.create name: directory_name, description: 'testDirectory for AccountStoreMappings' }
18
-
19
- let(:application) { test_api_client.applications.create name: random_application_name, description: 'testApplication for AccountStoreMappings' }
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) }
20
7
 
21
8
  after do
22
9
  application.delete if application
@@ -24,7 +11,9 @@ describe Stormpath::Resource::AccountStoreMapping, :vcr do
24
11
  end
25
12
 
26
13
  describe "instances" do
27
- let(:account_store_mapping) {create_account_store_mapping(application,directory, is_default_account_store: true)}
14
+ let!(:account_store_mapping) do
15
+ map_account_store(application, directory, 0, true, false)
16
+ end
28
17
 
29
18
  it do
30
19
  [:list_index, :is_default_account_store, :is_default_group_store, :default_account_store, :default_group_store ].each do |prop_accessor|
@@ -51,7 +40,7 @@ describe Stormpath::Resource::AccountStoreMapping, :vcr do
51
40
 
52
41
 
53
42
  describe 'given an application' do
54
- let(:reloaded_application) { test_api_client.applications.get application.href}
43
+ let(:reloaded_application) { test_api_client.applications.get application.href }
55
44
 
56
45
  context 'on application creation' do
57
46
  it 'there should be no default account/group store' do
@@ -61,33 +50,33 @@ describe Stormpath::Resource::AccountStoreMapping, :vcr do
61
50
  end
62
51
 
63
52
  it 'should retrive a default account store mapping one is created' do
64
- account_store_mapping = create_account_store_mapping(application,directory, is_default_account_store: true, is_default_group_store: true)
53
+ account_store_mapping = map_account_store(application, directory, 0, true, true)
65
54
  expect(reloaded_application.default_account_store_mapping).to eq(account_store_mapping)
66
55
  end
67
56
 
68
57
  it 'should retrive a default group store mapping when one is created' do
69
- account_store_mapping = create_account_store_mapping(application,directory, is_default_account_store: true, is_default_group_store: true)
58
+ account_store_mapping = map_account_store(application, directory, 0, true, true)
70
59
  expect(reloaded_application.default_group_store_mapping).to eq(account_store_mapping)
71
60
  end
72
61
 
73
62
  it 'change the default account store mapping, the application needs to be reloaded' do
74
- account_store_mapping = create_account_store_mapping(application,directory, is_default_account_store: true)
63
+ account_store_mapping = map_account_store(application, directory, 0, true, false)
75
64
  expect(application.default_account_store_mapping).to eq(nil)
76
65
  expect(reloaded_application.default_account_store_mapping).to eq(account_store_mapping)
77
66
  end
78
67
 
79
68
  it 'change the default group store mapping, the application needs to be reloaded' do
80
- account_store_mapping = create_account_store_mapping(application,directory, is_default_account_store: true, is_default_group_store: true)
69
+ account_store_mapping = map_account_store(application, directory, 0, true, true)
81
70
  expect(application.default_group_store_mapping).to eq(nil)
82
71
  expect(reloaded_application.default_group_store_mapping).to eq(account_store_mapping)
83
72
  end
84
73
 
85
74
  context 'remove the added default account/group store mapping' do
86
- let(:re_reloaded_application) { test_api_client.applications.get application.href}
75
+ let(:re_reloaded_application) { test_api_client.applications.get application.href }
87
76
 
88
77
  it 'there should not be a default account store mapping in the beginning and the end' do
89
78
  expect(application.default_account_store_mapping).to eq(nil)
90
- account_store_mapping = create_account_store_mapping(application,directory, is_default_account_store: true)
79
+ account_store_mapping = map_account_store(application, directory, 0, true, false)
91
80
 
92
81
  expect(application.default_account_store_mapping).to eq(nil)
93
82
  expect(reloaded_application.default_account_store_mapping).to eq(account_store_mapping)
@@ -102,7 +91,7 @@ describe Stormpath::Resource::AccountStoreMapping, :vcr do
102
91
 
103
92
  it 'there should not be a default group store mapping in the beginning and the end' do
104
93
  expect(application.default_account_store_mapping).to eq(nil)
105
- account_store_mapping = create_account_store_mapping(application,directory, is_default_group_store: true)
94
+ account_store_mapping = map_account_store(application, directory, 0, false, true)
106
95
 
107
96
  expect(application.default_group_store_mapping).to eq(nil)
108
97
  expect(reloaded_application.default_group_store_mapping).to eq(account_store_mapping)
@@ -119,7 +108,7 @@ describe Stormpath::Resource::AccountStoreMapping, :vcr do
119
108
  end
120
109
 
121
110
  describe "given a directory" do
122
- before { create_account_store_mapping(application, directory) }
111
+ before { map_account_store(application, directory, 0, false, false) }
123
112
 
124
113
  it 'add an account store mapping' do
125
114
  expect(application.account_store_mappings.count).to eq(1)
@@ -127,7 +116,7 @@ describe Stormpath::Resource::AccountStoreMapping, :vcr do
127
116
  end
128
117
 
129
118
  describe "given a group" do
130
- let(:group) { directory.groups.create name: 'testGroup', description: 'testGroup for AccountStoreMappings' }
119
+ let(:group) { directory.groups.create(build_group) }
131
120
  let(:reloaded_application) { test_api_client.applications.get application.href }
132
121
 
133
122
  after do
@@ -136,7 +125,7 @@ describe Stormpath::Resource::AccountStoreMapping, :vcr do
136
125
 
137
126
  context 'add an account store mapping' do
138
127
  it 'being a default account store' do
139
- account_store_mapping = create_account_store_mapping(application, group, is_default_account_store: true)
128
+ account_store_mapping = map_account_store(application, group, 0, true, false)
140
129
  expect(application.default_account_store_mapping).to eq(nil)
141
130
  expect(application.account_store_mappings.count).to eq(1)
142
131
  expect(reloaded_application.default_account_store_mapping).to eq(account_store_mapping)
@@ -144,7 +133,7 @@ describe Stormpath::Resource::AccountStoreMapping, :vcr do
144
133
 
145
134
  it 'being a default group store, should raise an error' do
146
135
  expect do
147
- create_account_store_mapping(application, group, is_default_group_store: true)
136
+ map_account_store(application, group, 0, false, true)
148
137
  end.to raise_error Stormpath::Error
149
138
  end
150
139
 
@@ -153,7 +142,7 @@ describe Stormpath::Resource::AccountStoreMapping, :vcr do
153
142
  end
154
143
 
155
144
  describe "update attribute default_group_store" do
156
- let(:account_store_mapping) { create_account_store_mapping(application, directory, is_default_account_store: true) }
145
+ let(:account_store_mapping) { map_account_store(application, directory, 0, true, false) }
157
146
  let(:reloaded_mapping){ application.account_store_mappings.get account_store_mapping.href }
158
147
 
159
148
  it 'should go from true to false' do
@@ -165,7 +154,7 @@ describe Stormpath::Resource::AccountStoreMapping, :vcr do
165
154
  end
166
155
 
167
156
  describe "given a mapping" do
168
- let!(:account_store_mapping) { create_account_store_mapping(application, directory, is_default_account_store: true) }
157
+ let!(:account_store_mapping) { map_account_store(application, directory, 0, true, false) }
169
158
  let(:reloaded_application) { test_api_client.applications.get application.href}
170
159
 
171
160
  it 'function delete should destroy it' do
@@ -183,5 +172,4 @@ describe Stormpath::Resource::AccountStoreMapping, :vcr do
183
172
  end
184
173
  end
185
174
  end
186
-
187
175
  end
@@ -1,33 +1,10 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Stormpath::Resource::AccountStore, :vcr do
4
- def create_account_store_mapping(application, account_store, is_default_group_store = false)
5
- test_api_client.account_store_mappings.create(
6
- application: application,
7
- account_store: account_store,
8
- list_index: 0,
9
- is_default_account_store: true,
10
- is_default_group_store: is_default_group_store
11
- )
12
- end
13
-
14
- let(:application) do
15
- test_api_client.applications.create name: random_application_name,
16
- description: 'testApplication for AccountStoreMappings'
17
- end
18
-
19
- let(:directory) do
20
- test_api_client.directories.create name: random_directory_name,
21
- description: 'testDirectory for AccountStoreMappings'
22
- end
23
-
24
- let(:group) do
25
- directory.groups.create name: 'testGroup', description: 'testGroup for AccountStoreMappings'
26
- end
27
-
28
- let(:organization) do
29
- test_api_client.organizations.create name: 'testOrganization', name_key: 'test-organization'
30
- end
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) }
31
8
 
32
9
  after do
33
10
  application.delete if application
@@ -37,7 +14,7 @@ describe Stormpath::Resource::AccountStore, :vcr do
37
14
  end
38
15
 
39
16
  describe 'given an account_store_mapping and a directory' do
40
- let!(:account_store_mapping) { create_account_store_mapping(application, directory, true) }
17
+ let!(:account_store_mapping) { map_account_store(application, directory, 0, true, true) }
41
18
  let(:reloaded_mapping) { application.account_store_mappings.get account_store_mapping.href }
42
19
 
43
20
  it 'should return a directory' do
@@ -47,7 +24,7 @@ describe Stormpath::Resource::AccountStore, :vcr do
47
24
  end
48
25
 
49
26
  describe 'given an account_store_mapping and a group' do
50
- let!(:account_store_mapping) { create_account_store_mapping(application, group) }
27
+ let!(:account_store_mapping) { map_account_store(application, group, 0, true, false) }
51
28
  let(:reloaded_mapping) { application.account_store_mappings.get account_store_mapping.href }
52
29
 
53
30
  it 'should return a group' do
@@ -57,7 +34,7 @@ describe Stormpath::Resource::AccountStore, :vcr do
57
34
  end
58
35
 
59
36
  describe 'given an account_store_mapping and an organization' do
60
- let!(:account_store_mapping) { create_account_store_mapping(application, organization) }
37
+ let!(:account_store_mapping) { map_account_store(application, organization, 0, true, false) }
61
38
  let(:reloaded_mapping) { application.account_store_mappings.get account_store_mapping.href }
62
39
 
63
40
  it 'should return an organization' do
@@ -69,7 +46,7 @@ describe Stormpath::Resource::AccountStore, :vcr do
69
46
  describe 'given an undefined account_store_mapping' do
70
47
  it 'should raise an error' do
71
48
  expect do
72
- create_account_store_mapping(application, 'undefined')
49
+ map_account_store(application, 'undefined', 0, true, false)
73
50
  end.to raise_error
74
51
  end
75
52
  end
@@ -1,23 +1,20 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Stormpath::Resource::ApiKey, :vcr do
4
- let(:application) { test_application }
4
+ let(:application) { test_api_client.applications.create(build_application) }
5
+ let(:directory) { test_api_client.directories.create(build_directory) }
5
6
  let(:tenant) { application.tenant }
6
-
7
- let(:account) do
8
- application.accounts.create(
9
- email: 'test@example.com',
10
- given_name: 'Ruby SDK',
11
- password: 'P@$$w0rd',
12
- surname: 'SDK'
13
- )
14
- end
15
-
7
+ let(:account) { application.accounts.create(build_account) }
16
8
  let(:api_key) { account.api_keys.create({}) }
9
+ before { map_account_store(application, directory, 1, true, false) }
17
10
 
18
- after { account.delete }
11
+ after do
12
+ application.delete
13
+ directory.delete
14
+ account.delete
15
+ end
19
16
 
20
- describe "instances should respond to attribute property methods" do
17
+ describe 'instances should respond to attribute property methods' do
21
18
  it do
22
19
  [:name, :description, :status].each do |property_accessor|
23
20
  expect(api_key).to respond_to(property_accessor)
@@ -26,7 +23,7 @@ describe Stormpath::Resource::ApiKey, :vcr do
26
23
 
27
24
  [:id, :secret].each do |property_getter|
28
25
  expect(api_key).to respond_to(property_getter)
29
- expect(api_key.send property_getter).to be_a String
26
+ expect(api_key.send(property_getter)).to be_a String
30
27
  end
31
28
 
32
29
  expect(api_key.tenant).to be_a Stormpath::Resource::Tenant
@@ -2,14 +2,12 @@ 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 name: random_application_name, description: 'Dummy desc.' }
5
+ let(:app) { test_api_client.applications.create(build_application) }
6
6
  let(:application) { test_api_client.applications.get app.href }
7
- let(:directory) { test_api_client.directories.create name: random_directory_name }
8
- let(:directory_with_verification) { test_directory_with_verification }
7
+ let(:directory) { test_api_client.directories.create(build_directory) }
9
8
 
10
9
  before do
11
- test_api_client.account_store_mappings.create({ application: app, account_store: directory,
12
- list_index: 1, is_default_account_store: true, is_default_group_store: true })
10
+ map_account_store(app, directory, 1, true, true)
13
11
  end
14
12
 
15
13
  after do
@@ -69,7 +67,7 @@ describe Stormpath::Resource::Application, :vcr do
69
67
  describe 'application_associations' do
70
68
 
71
69
  context '#accounts' do
72
- let(:account) { application.accounts.create build_account}
70
+ let(:account) { application.accounts.create(build_account) }
73
71
 
74
72
  after do
75
73
  account.delete if account
@@ -86,11 +84,9 @@ describe Stormpath::Resource::Application, :vcr do
86
84
  end
87
85
 
88
86
  context '#groups' do
89
- let(:group) { application.groups.create name: random_group_name }
87
+ let(:group) { application.groups.create(build_group) }
90
88
 
91
- after do
92
- group.delete if group
93
- end
89
+ after { group.delete }
94
90
 
95
91
  it 'should be able to create a group' do
96
92
  expect(application.groups).to include(group)
@@ -118,15 +114,7 @@ describe Stormpath::Resource::Application, :vcr do
118
114
 
119
115
 
120
116
  describe '#create_account' do
121
- let(:account) do
122
- Stormpath::Resource::Account.new({
123
- email: random_email,
124
- given_name: 'Ruby SDK',
125
- password: 'P@$$w0rd',
126
- surname: 'SDK',
127
- username: random_user_name
128
- })
129
- end
117
+ let(:account) { Stormpath::Resource::Account.new(build_account) }
130
118
 
131
119
  context 'with registration workflow' do
132
120
  it 'creates an account with worflow enabled' do
@@ -209,10 +197,8 @@ describe Stormpath::Resource::Application, :vcr do
209
197
  end
210
198
 
211
199
  context 'given a wrong directory' do
212
- let(:new_directory) { test_api_client.directories.create name: random_directory_name('new') }
213
-
200
+ let(:new_directory) { test_api_client.directories.create(build_directory) }
214
201
  let(:account) { new_directory.accounts.create build_account(password: 'P@$$w0rd') }
215
-
216
202
  let(:login_request) do
217
203
  Stormpath::Authentication::UsernamePasswordRequest.new account.username, password, account_store: directory
218
204
  end
@@ -227,7 +213,7 @@ describe Stormpath::Resource::Application, :vcr do
227
213
  end
228
214
 
229
215
  context 'given a group' do
230
- let(:group) {directory.groups.create name: random_group_name }
216
+ let(:group) {directory.groups.create(build_group) }
231
217
 
232
218
  let(:account) { directory.accounts.create build_account(password: 'P@$$w0rd') }
233
219
 
@@ -236,7 +222,7 @@ describe Stormpath::Resource::Application, :vcr do
236
222
  end
237
223
 
238
224
  before do
239
- test_api_client.account_store_mappings.create({ application: application, account_store: group })
225
+ map_account_store(application, group, 0, true, false)
240
226
  end
241
227
 
242
228
  after do
@@ -276,12 +262,7 @@ describe Stormpath::Resource::Application, :vcr do
276
262
 
277
263
  context 'of an existing account not mapped to the application' do
278
264
  let(:account) { other_directory.accounts.create build_account }
279
-
280
- let(:other_directory) do
281
- test_api_client.directories.create(
282
- name: random_directory_name('password_reset_account_store_href')
283
- )
284
- end
265
+ let(:other_directory) { test_api_client.directories.create(build_directory) }
285
266
 
286
267
  after do
287
268
  account.delete
@@ -337,13 +318,7 @@ describe Stormpath::Resource::Application, :vcr do
337
318
 
338
319
  context 'of an existing account not mapped to the application with an account store href' do
339
320
  let(:account) { directory.accounts.create build_account }
340
-
341
- let(:other_directory) do
342
- test_api_client.directories.create(
343
- name: random_directory_name('password_reset_account_store_href'),
344
- description: 'abc'
345
- )
346
- end
321
+ let(:other_directory) { test_api_client.directories.create(build_directory) }
347
322
 
348
323
  after do
349
324
  account.delete
@@ -373,22 +348,17 @@ describe Stormpath::Resource::Application, :vcr do
373
348
 
374
349
  context 'of an existing account on the application with a right account store organization namekey' do
375
350
  let(:account) { account_directory.accounts.create build_account }
376
-
377
- let(:account_directory) do
378
- test_api_client.directories.create(
379
- name: random_directory_name('password_reset_account_store_href')
380
- )
381
- end
351
+ let(:account_directory) { test_api_client.directories.create(build_directory) }
382
352
 
383
353
  let(:reloaded_account_directory) do
384
354
  test_api_client.directories.get(account_directory.href)
385
355
  end
386
356
 
387
- let(:organization_name_key) { "#{random_string}-org-name-key" }
357
+ let(:organization_name_key) { 'ruby-test-org-name-key' }
388
358
 
389
359
  let(:organization) do
390
360
  test_api_client.organizations.create(
391
- name: "#{random_string}_organization_name",
361
+ name: "ruby_test_organization_name",
392
362
  name_key: organization_name_key
393
363
  )
394
364
  end
@@ -404,12 +374,8 @@ describe Stormpath::Resource::Application, :vcr do
404
374
  end
405
375
 
406
376
  before do
407
- test_api_client.organization_account_store_mappings.create(
408
- account_store: { href: account_directory.href },
409
- organization: { href: organization.href }
410
- )
411
-
412
- test_api_client.account_store_mappings.create(application: application, account_store: organization)
377
+ map_organization_store(account_directory, organization)
378
+ map_account_store(application, organization, 0, true, true)
413
379
  end
414
380
 
415
381
  it 'sends a password reset request of the account' do
@@ -421,26 +387,11 @@ describe Stormpath::Resource::Application, :vcr do
421
387
 
422
388
  context 'of an existing account on the application with a right account store organization resource object' do
423
389
  let(:account) { account_directory.accounts.create build_account }
424
-
425
- let(:account_directory) do
426
- test_api_client.directories.create(
427
- name: random_directory_name('password_reset_account_store_href')
428
- )
429
- end
430
-
390
+ let(:account_directory) { test_api_client.directories.create(build_directory) }
431
391
  let(:reloaded_account_directory) do
432
392
  test_api_client.directories.get(account_directory.href)
433
393
  end
434
-
435
- let(:organization_name_key) { "#{random_string}-org-name-key" }
436
-
437
- let(:organization) do
438
- test_api_client.organizations.create(
439
- name: "#{random_string}_organization_name",
440
- name_key: organization_name_key
441
- )
442
- end
443
-
394
+ let(:organization) { test_api_client.organizations.create(build_organization) }
444
395
  let(:sent_to_account) do
445
396
  application.send_password_reset_email(account.email, account_store: organization)
446
397
  end
@@ -452,12 +403,8 @@ describe Stormpath::Resource::Application, :vcr do
452
403
  end
453
404
 
454
405
  before do
455
- test_api_client.organization_account_store_mappings.create(
456
- account_store: { href: account_directory.href },
457
- organization: { href: organization.href }
458
- )
459
-
460
- test_api_client.account_store_mappings.create(application: application, account_store: organization)
406
+ map_organization_store(account_directory, organization)
407
+ map_account_store(application, organization, 0, true, true)
461
408
  end
462
409
 
463
410
  it 'sends a password reset request of the account' do
@@ -469,34 +416,12 @@ describe Stormpath::Resource::Application, :vcr do
469
416
 
470
417
  context 'of an existing account on the application with a wrong account store organization namekey' do
471
418
  let(:account) { account_directory.accounts.create build_account }
472
-
473
- let(:account_directory) do
474
- test_api_client.directories.create(
475
- name: random_directory_name('password_reset_account_store_href')
476
- )
477
- end
478
-
419
+ let(:account_directory) { test_api_client.directories.create(build_directory) }
479
420
  let(:reloaded_account_directory) do
480
421
  test_api_client.directories.get(account_directory.href)
481
422
  end
482
-
483
- let(:organization_name_key) { "#{random_string}-org-name-key" }
484
-
485
- let(:other_organization_name_key) { "#{random_string}-other-org-name-key" }
486
-
487
- let(:organization) do
488
- test_api_client.organizations.create(
489
- name: "#{random_string}_organization_name",
490
- name_key: organization_name_key
491
- )
492
- end
493
-
494
- let(:other_organization) do
495
- test_api_client.organizations.create(
496
- name: "#{random_string}_other_organization_name",
497
- name_key: other_organization_name_key
498
- )
499
- end
423
+ let(:organization) { test_api_client.organizations.create(build_organization) }
424
+ let(:other_organization) { test_api_client.organizations.create(build_organization) }
500
425
 
501
426
  after do
502
427
  account.delete
@@ -506,12 +431,8 @@ describe Stormpath::Resource::Application, :vcr do
506
431
  end
507
432
 
508
433
  before do
509
- test_api_client.organization_account_store_mappings.create(
510
- account_store: { href: account_directory.href },
511
- organization: { href: organization.href }
512
- )
513
-
514
- test_api_client.account_store_mappings.create(application: application, account_store: organization)
434
+ map_organization_store(account_directory, organization)
435
+ map_account_store(application, organization, 0, true, true)
515
436
  end
516
437
 
517
438
  it 'sends a password reset request of the account' do
@@ -524,29 +445,21 @@ describe Stormpath::Resource::Application, :vcr do
524
445
  end
525
446
 
526
447
  describe '#verification_emails' do
527
- let(:directory_with_verification) { test_directory_with_verification }
448
+ let(:directory_with_verification) { test_api_client.directories.create(build_directory) }
528
449
 
529
450
  before do
530
- test_api_client.account_store_mappings.create({ application: app, account_store: directory_with_verification,
531
- list_index: 1, is_default_account_store: false, is_default_group_store: false })
532
- end
533
-
534
- let(:account) do
535
- directory_with_verification.accounts.create({
536
- email: random_email,
537
- given_name: 'Ruby SDK',
538
- password: 'P@$$w0rd',
539
- surname: 'SDK',
540
- username: random_user_name
541
- })
451
+ map_account_store(application, directory_with_verification, 1, false, false)
452
+ enable_email_verification(directory_with_verification)
542
453
  end
543
454
 
455
+ let(:account) { directory_with_verification.accounts.create(build_account) }
544
456
  let(:verification_emails) do
545
457
  application.verification_emails.create(login: account.email)
546
458
  end
547
459
 
548
460
  after do
549
461
  account.delete if account
462
+ directory_with_verification.delete
550
463
  end
551
464
 
552
465
  it 'returns verification email' do
@@ -555,15 +468,7 @@ describe Stormpath::Resource::Application, :vcr do
555
468
  end
556
469
 
557
470
  describe 'create_login_attempt' do
558
- let(:account) do
559
- directory.accounts.create({
560
- email: random_email,
561
- given_name: 'Ruby SDK',
562
- password: 'P@$$w0rd',
563
- surname: 'SDK',
564
- username: random_user_name
565
- })
566
- end
471
+ let(:account) { directory.accounts.create(build_account) }
567
472
 
568
473
  context 'valid credentials' do
569
474
  let(:username_password_request) do
@@ -585,30 +490,16 @@ describe Stormpath::Resource::Application, :vcr do
585
490
  end
586
491
 
587
492
  context 'with organization as account store option' do
588
- def create_organization_account_store_mapping(organization, account_store)
589
- test_api_client.organization_account_store_mappings.create({
590
- account_store: { href: account_store.href },
591
- organization: { href: organization.href }
592
- })
593
- end
594
-
595
- def create_application_account_store_mapping(application, account_store)
596
- test_api_client.account_store_mappings.create(
597
- application: application,
598
- account_store: account_store
599
- )
600
- end
601
-
602
493
  let(:organization) do
603
- test_api_client.organizations.create name: 'test_organization',
604
- name_key: "testorganization"
494
+ test_api_client.organizations.create(name: 'test_organization',
495
+ name_key: 'testorganization')
605
496
  end
606
497
 
607
498
  let(:auth_request) { application.authenticate_account(username_password_request) }
608
499
 
609
500
  before do
610
- create_organization_account_store_mapping(organization, directory)
611
- create_application_account_store_mapping(application, organization)
501
+ map_organization_store(directory, organization)
502
+ map_account_store(application, organization, 0, true, false)
612
503
  end
613
504
 
614
505
  after do
@@ -739,20 +630,10 @@ describe Stormpath::Resource::Application, :vcr do
739
630
  end
740
631
 
741
632
  describe '#verify_password_reset_token' do
742
- let(:account) do
743
- directory.accounts.create({
744
- email: random_email,
745
- given_name: 'Ruby SDK',
746
- password: 'P@$$w0rd',
747
- surname: 'SDK',
748
- username: random_user_name
749
- })
750
- end
751
-
633
+ let(:account) { directory.accounts.create(build_account) }
752
634
  let(:password_reset_token) do
753
635
  application.password_reset_tokens.create(email: account.email).token
754
636
  end
755
-
756
637
  let(:reset_password_account) do
757
638
  application.verify_password_reset_token password_reset_token
758
639
  end
@@ -785,8 +666,6 @@ describe Stormpath::Resource::Application, :vcr do
785
666
  Stormpath::Authentication::UsernamePasswordRequest.new account.username, new_password
786
667
  end
787
668
 
788
- let(:expected_email) { 'test2@example.com' }
789
-
790
669
  let(:authentication_result) do
791
670
  application.authenticate_account login_request
792
671
  end
@@ -1095,16 +974,8 @@ describe Stormpath::Resource::Application, :vcr do
1095
974
  end
1096
975
 
1097
976
  before do
1098
- test_api_client.account_store_mappings.create(
1099
- application: application,
1100
- account_store: organization
1101
- )
1102
-
1103
- test_api_client.organization_account_store_mappings.create(
1104
- account_store: { href: account_directory.href },
1105
- organization: { href: organization.href }
1106
- )
1107
-
977
+ map_account_store(application, organization, 0, true, true)
978
+ map_organization_store(account_directory, organization)
1108
979
  account_directory.accounts.create account_data
1109
980
  end
1110
981