stormpath-sdk 1.3.0 → 1.3.1

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -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 name: random_directory_name }
172
+ let(:directory) { test_api_client.directories.create(build_directory) }
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 name: random_directory_name }
214
+ let(:directory) { test_api_client.directories.create(build_directory) }
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 name: random_directory_name }
276
+ let(:directory) { test_api_client.directories.create(build_directory) }
277
277
 
278
278
  # !@#$%^&*()_-+=?><:]}[{'
279
279
  # 'jlpicard/!@$%^*()_-+&=?><:]}[{'
@@ -281,7 +281,7 @@ describe Stormpath::Resource::Collection, :vcr do
281
281
 
282
282
  let!(:account) do
283
283
  directory.accounts.create username: username,
284
- email: "capt@enterprise.com",
284
+ email: "captain#{default_domain}",
285
285
  givenName: "Jean-Luc",
286
286
  surname: "Picard",
287
287
  password: "hakunaMatata179Enterprise"
@@ -300,20 +300,20 @@ describe Stormpath::Resource::Collection, :vcr do
300
300
  end
301
301
 
302
302
  it 'should search accounts by email' do
303
- expect(directory.accounts.search(email: "capt@enterprise.com").count).to eq(1)
303
+ expect(directory.accounts.search(email: "captain#{default_domain}").count).to eq(1)
304
304
  end
305
305
 
306
306
  it 'should search accounts by any column (aiming at email)' do
307
- expect(directory.accounts.search("capt@enterprise.com").count).to eq(1)
307
+ expect(directory.accounts.search("captain#{default_domain}").count).to eq(1)
308
308
  end
309
309
  end
310
310
 
311
311
  context '#asterisk search on one attribute' do
312
- let(:directory) {test_api_client.directories.create name: random_directory_name }
312
+ let(:directory) { test_api_client.directories.create(build_directory) }
313
313
 
314
314
  let!(:account) do
315
315
  directory.accounts.create username: "jlpicard",
316
- email: "capt@enterprise.com",
316
+ email: "captain#{default_domain}",
317
317
  givenName: "Jean-Luc",
318
318
  surname: "Picard",
319
319
  password: "hakunaMatata179Enterprise"
@@ -337,11 +337,11 @@ 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 name: random_directory_name }
340
+ let(:directory) { test_api_client.directories.create(build_directory) }
341
341
 
342
342
  let!(:account) do
343
343
  directory.accounts.create username: "jlpicard",
344
- email: "capt@enterprise.com",
344
+ email: "captain#{default_domain}",
345
345
  givenName: "Jean-Luc",
346
346
  surname: "Picard",
347
347
  password: "hakunaMatata179Enterprise"
@@ -352,7 +352,7 @@ describe Stormpath::Resource::Collection, :vcr do
352
352
  end
353
353
 
354
354
  it 'should search accounts by username with asterisk at the beginning' do
355
- expect(directory.accounts.search(username: "*card", email: "*enterprise.com").count).to eq(1)
355
+ expect(directory.accounts.search(username: "*card", email: "*stormpath.com").count).to eq(1)
356
356
  end
357
357
 
358
358
  it 'should search accounts by username with asterisk at the end' do
@@ -360,17 +360,17 @@ describe Stormpath::Resource::Collection, :vcr do
360
360
  end
361
361
 
362
362
  it 'should search accounts by username with asterisk at the beginning and the end' do
363
- expect(directory.accounts.search(username: "*pic*", email: "*enterprise*").count).to eq(1)
363
+ expect(directory.accounts.search(username: "*pic*", email: "*stormpath*").count).to eq(1)
364
364
  end
365
365
  end
366
366
 
367
367
  context 'search accounts by custom data' do
368
- let(:directory) { test_api_client.directories.create name: random_directory_name }
368
+ let(:directory) { test_api_client.directories.create(build_directory) }
369
369
 
370
370
  let(:account) do
371
371
  directory.accounts.create(
372
372
  username: 'jlpicard',
373
- email: 'capt@enterprise.com',
373
+ email: "capt#{default_domain}",
374
374
  givenName: 'Jean-Luc',
375
375
  surname: 'Picard',
376
376
  password: 'hakunaMatata179Enterprise'
@@ -380,7 +380,7 @@ describe Stormpath::Resource::Collection, :vcr do
380
380
  let(:account2) do
381
381
  directory.accounts.create(
382
382
  username: 'jlpicard2',
383
- email: 'capt2@enterprise.com',
383
+ email: "capt2#{default_domain}",
384
384
  givenName: 'Jean-Luc2',
385
385
  surname: 'Picard2',
386
386
  password: 'hakunaMatata179Enterprise'
@@ -402,7 +402,7 @@ describe Stormpath::Resource::Collection, :vcr do
402
402
  it 'should search accounts by custom data attribute' do
403
403
  expect(account.custom_data['targetAttribute']).to eq 'findMe'
404
404
  expect(directory.accounts.count).to eq 2
405
- sleep 1
405
+ sleep 5
406
406
  expect(directory.accounts.search('customData.targetAttribute' => 'findMe').count).to eq(2)
407
407
  end
408
408
  end
@@ -418,7 +418,7 @@ describe Stormpath::Resource::Collection, :vcr do
418
418
  it 'should be able to fetch custom data attributes with snake case' do
419
419
  expect(account.custom_data['target_attribute']).to eq 'findMe'
420
420
  expect(directory.accounts.count).to eq 2
421
- sleep 1
421
+ sleep 5
422
422
  expect(directory.accounts.search('customData.target_attribute' => 'findMe').count).to eq(2)
423
423
  end
424
424
  end
@@ -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 name: random_directory_name }
9
+ let(:directory) { test_api_client.directories.create(build_directory) }
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 name: random_directory_name }
20
+ let(:directory) { disabled_cache_client.directories.create(build_directory) }
21
21
 
22
22
  it_behaves_like 'account_custom_data'
23
23
  it_behaves_like 'group_custom_data'
@@ -1,31 +1,13 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Stormpath::Resource::Directory, :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
- describe "instances should respond to attribute property methods" do
15
- let(:app) { test_api_client.applications.create name: random_application_name, description: 'Dummy desc.' }
16
- let(:application) { test_api_client.applications.get app.href }
17
- let(:directory) { test_api_client.directories.create name: random_directory_name, description: 'description_for_some_test_directory' }
18
- let(:directory_with_verification) { test_directory_with_verification }
4
+ let(:application) { test_api_client.applications.create(build_application) }
5
+ after { application.delete }
19
6
 
20
- before do
21
- test_api_client.account_store_mappings.create({ application: app, account_store: directory_with_verification,
22
- list_index: 1, is_default_account_store: false, is_default_group_store: false })
23
- end
7
+ describe 'instances should respond to attribute property methods' do
8
+ let(:directory) { test_api_client.directories.create(build_directory) }
24
9
 
25
- after do
26
- directory.delete if directory
27
- application.delete if application
28
- end
10
+ after { directory.delete }
29
11
 
30
12
  it do
31
13
  expect(directory).to be_a Stormpath::Resource::Directory
@@ -33,12 +15,12 @@ describe Stormpath::Resource::Directory, :vcr do
33
15
  [:name, :description, :status].each do |property_accessor|
34
16
  expect(directory).to respond_to(property_accessor)
35
17
  expect(directory).to respond_to("#{property_accessor}=")
36
- expect(directory.send property_accessor).to be_a String
18
+ expect(directory.send(property_accessor)).to be_a String
37
19
  end
38
20
 
39
21
  [:created_at, :modified_at].each do |property_getter|
40
22
  expect(directory).to respond_to(property_getter)
41
- expect(directory.send property_getter).to be_a String
23
+ expect(directory.send(property_getter)).to be_a String
42
24
  end
43
25
 
44
26
  expect(directory.tenant).to be_a Stormpath::Resource::Tenant
@@ -49,34 +31,28 @@ describe Stormpath::Resource::Directory, :vcr do
49
31
  end
50
32
 
51
33
  describe 'directory_associations' do
52
- let(:directory) { test_api_client.directories.create name: random_directory_name, description: 'description_for_some_test_directory' }
34
+ let(:directory) { test_api_client.directories.create(build_directory) }
53
35
 
54
- after do
55
- directory.delete if directory
56
- end
36
+ after { directory.delete }
57
37
 
58
38
  context '#accounts' do
59
- let(:account) { directory.accounts.create build_account}
39
+ let(:account) { directory.accounts.create(build_account) }
60
40
 
61
- after do
62
- account.delete if account
63
- end
41
+ after { account.delete if account }
64
42
 
65
43
  it 'should be able to create an account' do
66
44
  expect(directory.accounts).to include(account)
67
45
  end
68
46
 
69
47
  it 'should be able to create and fetch the account' do
70
- expect(directory.accounts.get account.href).to be
48
+ expect(directory.accounts.get(account.href)).to be
71
49
  end
72
50
  end
73
51
 
74
52
  context '#groups' do
75
- let(:group) { directory.groups.create name: random_group_name }
53
+ let(:group) { directory.groups.create(build_group) }
76
54
 
77
- after do
78
- group.delete if group
79
- end
55
+ after { group.delete }
80
56
 
81
57
  it 'should be able to create a group' do
82
58
  expect(directory.groups).to include(group)
@@ -111,21 +87,13 @@ describe Stormpath::Resource::Directory, :vcr do
111
87
  end
112
88
 
113
89
  context '#organizations' do
114
- let(:organization) do
115
- test_api_client.organizations.create(name: 'Test organization name',
116
- name_key: 'test-organization-name-key')
117
- end
90
+ let(:organization) { test_api_client.organizations.create(build_organization) }
118
91
 
119
92
  let!(:organization_account_store_mappings) do
120
- test_api_client.organization_account_store_mappings.create(
121
- account_store: { href: directory.href },
122
- organization: { href: organization.href }
123
- )
93
+ map_organization_store(directory, organization)
124
94
  end
125
95
 
126
- after do
127
- organization.delete
128
- end
96
+ after { organization.delete }
129
97
 
130
98
  it 'should be able to get organizations' do
131
99
  expect(directory.organizations).to include(organization)
@@ -144,104 +112,98 @@ describe Stormpath::Resource::Directory, :vcr do
144
112
  end
145
113
 
146
114
  describe '#create_account' do
147
- let(:directory) { test_api_client.directories.create name: random_directory_name, description: 'description_for_some_test_directory' }
148
-
149
- let(:account) do
150
- Stormpath::Resource::Account.new({
151
- email: random_email,
152
- given_name: 'Ruby SDK',
153
- password: 'P@$$w0rd',
154
- surname: 'SDK',
155
- username: random_user_name
156
- })
157
- end
115
+ let(:directory) { test_api_client.directories.create(build_directory) }
116
+ let(:account) { Stormpath::Resource::Account.new(build_account) }
158
117
 
159
- after do
160
- directory.delete if directory
161
- end
118
+ after { directory.delete }
162
119
 
163
120
  context 'without registration workflow' do
121
+ let(:created_account) { directory.create_account(account) }
164
122
 
165
- let(:created_account) { directory.create_account account }
166
-
167
- after do
168
- created_account.delete if created_account
169
- end
123
+ after { created_account.delete }
170
124
 
171
125
  it 'creates an account with status ENABLED' do
172
126
  expect(created_account).to be
173
127
  expect(created_account.username).to eq(account.username)
174
128
  expect(created_account).to eq(account)
175
- expect(created_account.status).to eq("ENABLED")
129
+ expect(created_account.status).to eq('ENABLED')
176
130
  expect(created_account.email_verification_token).not_to be
177
131
  end
178
132
  end
179
133
 
180
134
  context 'with registration workflow' do
135
+ let(:directory_with_verification) { test_api_client.directories.create(build_directory) }
181
136
 
182
- let(:created_account_with_reg_workflow) { test_directory_with_verification.create_account account }
183
-
184
- after do
185
- created_account_with_reg_workflow.delete if created_account_with_reg_workflow
137
+ before do
138
+ map_account_store(application, directory_with_verification, 1, false, false)
139
+ enable_email_verification(directory_with_verification)
186
140
  end
187
141
 
188
- it 'creates an account with status UNVERIFIED' do
189
- expect(created_account_with_reg_workflow).to be
190
- expect(created_account_with_reg_workflow.username).to eq(account.username)
191
- expect(created_account_with_reg_workflow).to eq(account)
192
- expect(created_account_with_reg_workflow.status).to eq("UNVERIFIED")
193
- expect(created_account_with_reg_workflow.email_verification_token.href).to be
194
- end
142
+ after { directory_with_verification.delete }
195
143
 
196
- end
144
+ context 'enabled on account creation' do
145
+ let(:created_account_with_reg_workflow) do
146
+ directory_with_verification.create_account(account)
147
+ end
197
148
 
198
- context 'with registration workflow but set it to false on account creation' do
199
- let(:created_account_with_reg_workflow) { test_directory_with_verification.create_account account, false }
149
+ after { created_account_with_reg_workflow.delete }
200
150
 
201
- after do
202
- created_account_with_reg_workflow.delete if created_account_with_reg_workflow
151
+ it 'creates an account with status UNVERIFIED' do
152
+ expect(created_account_with_reg_workflow).to be
153
+ expect(created_account_with_reg_workflow.username).to eq(account.username)
154
+ expect(created_account_with_reg_workflow).to eq(account)
155
+ expect(created_account_with_reg_workflow.status).to eq('UNVERIFIED')
156
+ expect(created_account_with_reg_workflow.email_verification_token.href).to be
157
+ end
203
158
  end
204
159
 
205
- it 'creates an account with status ENABLED' do
206
- expect(created_account_with_reg_workflow).to be
207
- expect(created_account_with_reg_workflow.username).to eq(account.username)
208
- expect(created_account_with_reg_workflow).to eq(account)
209
- expect(created_account_with_reg_workflow.status).to eq("ENABLED")
210
- expect(created_account_with_reg_workflow.email_verification_token).not_to be
160
+ context 'disabled on account creation' do
161
+ let(:created_account_with_reg_workflow) do
162
+ directory_with_verification.create_account(account, false)
163
+ end
164
+
165
+ after { created_account_with_reg_workflow.delete }
166
+
167
+ it 'creates an account with status ENABLED' do
168
+ expect(created_account_with_reg_workflow).to be
169
+ expect(created_account_with_reg_workflow.username).to eq(account.username)
170
+ expect(created_account_with_reg_workflow).to eq(account)
171
+ expect(created_account_with_reg_workflow.status).to eq('ENABLED')
172
+ expect(created_account_with_reg_workflow.email_verification_token).not_to be
173
+ end
211
174
  end
212
175
  end
213
176
  end
214
177
 
215
178
  describe 'create account with password import MCF feature' do
216
- let(:app) { test_api_client.applications.create name: random_application_name, description: 'Dummy desc.' }
217
- let(:application) { test_api_client.applications.get app.href }
218
- let(:directory) { test_api_client.directories.create name: random_directory_name, description: 'description_for_some_test_directory' }
219
- let!(:account_store_mapping) {create_account_store_mapping(application,directory,true)}
179
+ let(:directory) { test_api_client.directories.create(build_directory) }
180
+
181
+ before { map_account_store(application, directory, 0, true, true) }
220
182
 
221
183
  after do
222
- application.delete if application
223
184
  directory.delete if directory
224
- @account.delete if @account
225
- end
226
-
227
- context "MD5 hashing algorithm" do
228
- before do
229
- account_store_mapping
230
- @account = directory.accounts.create({
231
- username: "jlucpicard",
232
- email: "captain@enterprise.com",
233
- given_name: "Jean-Luc",
234
- surname: "Picard",
235
- password: "$stormpath2$MD5$1$OGYyMmM5YzVlMDEwODEwZTg3MzM4ZTA2YjljZjMxYmE=$EuFAr2NTM83PrizVAYuOvw=="
236
- }, password_format: 'mcf')
185
+ account.delete if account
186
+ end
187
+
188
+ context 'MD5 hashing algorithm' do
189
+ let!(:account) do
190
+ directory.accounts.create(
191
+ {
192
+ username: 'jlucpicard',
193
+ email: "captain#{default_domain}",
194
+ given_name: 'Jean-Luc',
195
+ surname: 'Picard',
196
+ password: '$stormpath2$MD5$1$OGYyMmM5YzVlMDEwODEwZTg3MzM4ZTA2YjljZjMxYmE=$EuFAr2NTM83PrizVAYuOvw=='
197
+ }, password_format: 'mcf'
198
+ )
237
199
  end
238
200
 
239
201
  it 'creates an account' do
240
- expect(@account).to be_a Stormpath::Resource::Account
241
- expect(@account.username).to eq("jlucpicard")
242
- expect(@account.email).to eq("captain@enterprise.com")
243
- expect(@account.given_name).to eq("Jean-Luc")
244
- expect(@account.surname).to eq("Picard")
202
+ expect(account).to be_a Stormpath::Resource::Account
203
+ expect(account.username).to eq('jlucpicard')
204
+ expect(account.email).to eq("captain#{default_domain}")
205
+ expect(account.given_name).to eq('Jean-Luc')
206
+ expect(account.surname).to eq('Picard')
245
207
  end
246
208
 
247
209
  it 'can authenticate with the account credentials' do
@@ -250,30 +212,31 @@ describe Stormpath::Resource::Directory, :vcr do
250
212
 
251
213
  expect(auth_result).to be_a Stormpath::Authentication::AuthenticationResult
252
214
  expect(auth_result.account).to be_a Stormpath::Resource::Account
253
- expect(auth_result.account.email).to eq("captain@enterprise.com")
254
- expect(auth_result.account.given_name).to eq("Jean-Luc")
255
- expect(auth_result.account.surname).to eq("Picard")
256
- end
257
- end
258
-
259
- context "SHA-512 hashing algorithm" do
260
- before do
261
- account_store_mapping
262
- @account = directory.accounts.create({
263
- username: "jlucpicard",
264
- email: "captain@enterprise.com",
265
- given_name: "Jean-Luc",
266
- surname: "Picard",
267
- password: "$stormpath2$SHA-512$1$ZFhBRmpFSnEwVEx2ekhKS0JTMDJBNTNmcg==$Q+sGFg9e+pe9QsUdfnbJUMDtrQNf27ezTnnGllBVkQpMRc9bqH6WkyE3y0svD/7cBk8uJW9Wb3dolWwDtDLFjg=="
268
- }, password_format: 'mcf')
215
+ expect(auth_result.account.email).to eq("captain#{default_domain}")
216
+ expect(auth_result.account.given_name).to eq('Jean-Luc')
217
+ expect(auth_result.account.surname).to eq('Picard')
218
+ end
219
+ end
220
+
221
+ context 'SHA-512 hashing algorithm' do
222
+ let!(:account) do
223
+ directory.accounts.create(
224
+ {
225
+ username: 'jlucpicard',
226
+ email: "captain#{default_domain}",
227
+ given_name: 'Jean-Luc',
228
+ surname: 'Picard',
229
+ password: '$stormpath2$SHA-512$1$ZFhBRmpFSnEwVEx2ekhKS0JTMDJBNTNmcg==$Q+sGFg9e+pe9QsUdfnbJUMDtrQNf27ezTnnGllBVkQpMRc9bqH6WkyE3y0svD/7cBk8uJW9Wb3dolWwDtDLFjg=='
230
+ }, password_format: 'mcf'
231
+ )
269
232
  end
270
233
 
271
234
  it 'creates an account' do
272
- expect(@account).to be_a Stormpath::Resource::Account
273
- expect(@account.username).to eq("jlucpicard")
274
- expect(@account.email).to eq("captain@enterprise.com")
275
- expect(@account.given_name).to eq("Jean-Luc")
276
- expect(@account.surname).to eq("Picard")
235
+ expect(account).to be_a Stormpath::Resource::Account
236
+ expect(account.username).to eq('jlucpicard')
237
+ expect(account.email).to eq("captain#{default_domain}")
238
+ expect(account.given_name).to eq('Jean-Luc')
239
+ expect(account.surname).to eq('Picard')
277
240
  end
278
241
 
279
242
  it 'can authenticate with the account credentials' do
@@ -282,30 +245,31 @@ describe Stormpath::Resource::Directory, :vcr do
282
245
 
283
246
  expect(auth_result).to be_a Stormpath::Authentication::AuthenticationResult
284
247
  expect(auth_result.account).to be_a Stormpath::Resource::Account
285
- expect(auth_result.account.email).to eq("captain@enterprise.com")
286
- expect(auth_result.account.given_name).to eq("Jean-Luc")
287
- expect(auth_result.account.surname).to eq("Picard")
288
- end
289
- end
290
-
291
- context "BCrypt 2A hashing algorithm" do
292
- before do
293
- account_store_mapping
294
- @account = directory.accounts.create({
295
- username: "jlucpicard",
296
- email: "captain@enterprise.com",
297
- given_name: "Jean-Luc",
298
- surname: "Picard",
299
- password: "$2a$10$sWvxHJIvkARbp.u2yBpuJeGzNvpxYQo7AYxAJwFRH0HptXSWyqvwy"
300
- }, password_format: 'mcf')
248
+ expect(auth_result.account.email).to eq("captain#{default_domain}")
249
+ expect(auth_result.account.given_name).to eq('Jean-Luc')
250
+ expect(auth_result.account.surname).to eq('Picard')
251
+ end
252
+ end
253
+
254
+ context 'BCrypt 2A hashing algorithm' do
255
+ let!(:account) do
256
+ directory.accounts.create(
257
+ {
258
+ username: 'jlucpicard',
259
+ email: "captain#{default_domain}",
260
+ given_name: 'Jean-Luc',
261
+ surname: 'Picard',
262
+ password: '$2a$10$sWvxHJIvkARbp.u2yBpuJeGzNvpxYQo7AYxAJwFRH0HptXSWyqvwy'
263
+ }, password_format: 'mcf'
264
+ )
301
265
  end
302
266
 
303
267
  it 'creates an account' do
304
- expect(@account).to be_a Stormpath::Resource::Account
305
- expect(@account.username).to eq("jlucpicard")
306
- expect(@account.email).to eq("captain@enterprise.com")
307
- expect(@account.given_name).to eq("Jean-Luc")
308
- expect(@account.surname).to eq("Picard")
268
+ expect(account).to be_a Stormpath::Resource::Account
269
+ expect(account.username).to eq('jlucpicard')
270
+ expect(account.email).to eq("captain#{default_domain}")
271
+ expect(account.given_name).to eq('Jean-Luc')
272
+ expect(account.surname).to eq('Picard')
309
273
  end
310
274
 
311
275
  it 'can authenticate with the account credentials' do
@@ -314,55 +278,40 @@ describe Stormpath::Resource::Directory, :vcr do
314
278
 
315
279
  expect(auth_result).to be_a Stormpath::Authentication::AuthenticationResult
316
280
  expect(auth_result.account).to be_a Stormpath::Resource::Account
317
- expect(auth_result.account.email).to eq("captain@enterprise.com")
318
- expect(auth_result.account.given_name).to eq("Jean-Luc")
319
- expect(auth_result.account.surname).to eq("Picard")
281
+ expect(auth_result.account.email).to eq("captain#{default_domain}")
282
+ expect(auth_result.account.given_name).to eq('Jean-Luc')
283
+ expect(auth_result.account.surname).to eq('Picard')
320
284
  end
321
285
  end
322
286
 
323
287
  context 'with account data as hash' do
324
- let(:account_email) { random_email }
325
-
326
- let(:created_account_with_hash) do
327
- directory.create_account({
328
- email: account_email,
329
- given_name: 'Ruby SDK',
330
- password: 'P@$$w0rd',
331
- surname: 'SDK',
332
- username: random_user_name
333
- })
334
- end
335
-
336
- after do
337
- created_account_with_hash.delete if created_account_with_hash
338
- end
288
+ let(:account_email) { 'rubysdk' }
289
+ let(:account) { directory.create_account(build_account(email: account_email)) }
339
290
 
340
291
  it 'creates an account with status ENABLED' do
341
- expect(created_account_with_hash.email).to eq(account_email)
342
- expect(created_account_with_hash.given_name).to eq('Ruby SDK')
343
- expect(created_account_with_hash.surname).to eq('SDK')
344
- expect(created_account_with_hash.status).to eq("ENABLED")
292
+ expect(account.email).to eq("#{account_email}#{default_domain}")
293
+ expect(account.given_name).to eq('givenname')
294
+ expect(account.surname).to eq('surname')
295
+ expect(account.status).to eq('ENABLED')
345
296
  end
346
297
  end
347
-
348
298
  end
349
299
 
350
300
  describe '#create_directory_with_custom_data' do
351
- let(:directory_name) { random_directory_name }
352
-
353
- let(:directory) { test_api_client.directories.create name: directory_name, description: 'description_for_some_test_directory' }
354
-
355
- after do
356
- directory.delete if directory
301
+ let(:directory) do
302
+ test_api_client.directories.create(build_directory(name: 'rubysdkdir',
303
+ description: 'rubysdkdir desc'))
357
304
  end
358
305
 
306
+ after { directory.delete }
307
+
359
308
  it 'creates an directory with custom data' do
360
- directory.custom_data["category"] = "classified"
309
+ directory.custom_data['category'] = 'classified'
361
310
 
362
311
  directory.save
363
- expect(directory.name).to eq(directory_name)
364
- expect(directory.description).to eq('description_for_some_test_directory')
365
- expect(directory.custom_data["category"]).to eq("classified")
312
+ expect(directory.name).to eq('rubysdkdir')
313
+ expect(directory.description).to eq('rubysdkdir desc')
314
+ expect(directory.custom_data['category']).to eq('classified')
366
315
  end
367
316
  end
368
317
 
@@ -370,7 +319,7 @@ describe Stormpath::Resource::Directory, :vcr do
370
319
  context 'valida data' do
371
320
  let(:directory) do
372
321
  test_api_client.directories.create(
373
- name: random_directory_name,
322
+ name: 'rubysdkdir',
374
323
  description: 'description_for_some_test_directory',
375
324
  provider: {
376
325
  provider_id: "saml",
@@ -405,7 +354,7 @@ describe Stormpath::Resource::Directory, :vcr do
405
354
  it 'raises Stormpath::Error' do
406
355
  expect do
407
356
  test_api_client.directories.create(
408
- name: random_directory_name,
357
+ name: 'rubysdkdir',
409
358
  description: 'description_for_some_test_directory',
410
359
  provider: {
411
360
  provider_id: "saml",
@@ -423,7 +372,7 @@ describe Stormpath::Resource::Directory, :vcr do
423
372
  describe 'saml #provider' do
424
373
  let(:directory) do
425
374
  test_api_client.directories.create(
426
- name: random_directory_name,
375
+ name: 'rubysdkdir',
427
376
  description: 'description_for_some_test_directory',
428
377
  provider: {
429
378
  provider_id: "saml",
@@ -459,7 +408,7 @@ describe Stormpath::Resource::Directory, :vcr do
459
408
  describe 'saml #provider_metadata' do
460
409
  let(:directory) do
461
410
  test_api_client.directories.create(
462
- name: random_directory_name,
411
+ name: 'rubysdkdir',
463
412
  description: 'description_for_some_test_directory',
464
413
  provider: {
465
414
  provider_id: "saml",
@@ -495,7 +444,7 @@ describe Stormpath::Resource::Directory, :vcr do
495
444
  describe 'saml mapping rules' do
496
445
  let(:directory) do
497
446
  test_api_client.directories.create(
498
- name: random_directory_name,
447
+ name: 'rubysdkdir',
499
448
  description: 'description_for_some_test_directory',
500
449
  provider: {
501
450
  provider_id: "saml",
@@ -535,74 +484,49 @@ describe Stormpath::Resource::Directory, :vcr do
535
484
  end
536
485
 
537
486
  describe '#create_account_with_custom_data' do
538
- let(:directory) { test_api_client.directories.create name: random_directory_name, description: 'description_for_some_test_directory' }
487
+ let(:directory) { test_api_client.directories.create(build_directory) }
539
488
 
540
- after do
541
- directory.delete if directory
542
- end
489
+ after { directory.delete }
543
490
 
544
- it 'creates an account with custom data' do
545
- account = Stormpath::Resource::Account.new({
546
- email: random_email,
547
- given_name: 'Ruby SDK',
548
- password: 'P@$$w0rd',
549
- surname: 'SDK',
550
- username: random_user_name
551
- })
491
+ it 'creates an account with custom data' do
492
+ account = Stormpath::Resource::Account.new(build_account)
552
493
 
553
- account.custom_data["birth_date"] = "2305-07-13"
494
+ account.custom_data['birth_date'] = '2305-07-13'
554
495
 
555
- created_account = directory.create_account account
496
+ created_account = directory.create_account account
556
497
 
557
- expect(created_account).to be
558
- expect(created_account.username).to eq(account.username)
559
- expect(created_account).to eq(account)
560
- expect(created_account.custom_data["birth_date"]).to eq("2305-07-13")
561
- created_account.delete
498
+ expect(created_account).to be
499
+ expect(created_account.username).to eq(account.username)
500
+ expect(created_account).to eq(account)
501
+ expect(created_account.custom_data['birth_date']).to eq('2305-07-13')
502
+ created_account.delete
562
503
  end
563
504
  end
564
505
 
565
506
  describe '#create_group' do
566
- let(:directory) { test_api_client.directories.create name: random_directory_name, description: 'description_for_some_test_directory' }
507
+ let(:directory) { test_api_client.directories.create(build_directory) }
567
508
 
568
- after do
569
- directory.delete if directory
570
- end
509
+ after { directory.delete }
571
510
 
572
511
  context 'given a valid group' do
573
- let(:group_name) { "valid_test_group" }
512
+ let(:created_group) { directory.groups.create(build_group(name: 'rubysdkgroup')) }
574
513
 
575
- let(:created_group) { directory.groups.create name: group_name }
576
-
577
- after do
578
- created_group.delete if created_group
579
- end
514
+ after { created_group.delete }
580
515
 
581
516
  it 'creates a group' do
582
517
  expect(created_group).to be
583
- expect(created_group.name).to eq(group_name)
518
+ expect(created_group.name).to eq('rubysdkgroup')
584
519
  end
585
520
  end
586
521
  end
587
522
 
588
523
  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) }
527
+ let!(:account_store_mapping) { map_account_store(application, directory, 0, true, true) }
589
528
 
590
- let(:directory) { test_api_client.directories.create name: random_directory_name }
591
-
592
- let(:application) { test_api_client.applications.create name: random_application_name }
593
-
594
- let!(:group) { directory.groups.create name: 'someGroup' }
595
-
596
- let!(:account) { directory.accounts.create({ email: 'rubysdk@example.com', given_name: 'Ruby SDK', password: 'P@$$w0rd',surname: 'SDK' }) }
597
-
598
- let!(:account_store_mapping) do
599
- test_api_client.account_store_mappings.create({ application: application, account_store: directory })
600
- end
601
-
602
- after do
603
- application.delete if application
604
- directory.delete if directory
605
- end
529
+ after { directory.delete }
606
530
 
607
531
  it 'and all of its associations' do
608
532
  expect(directory.groups.count).to eq(1)