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.
- checksums.yaml +4 -4
- data/.gitignore +1 -1
- data/.travis.yml +3 -3
- data/CHANGES.md +8 -0
- data/lib/stormpath-sdk.rb +8 -0
- data/lib/stormpath-sdk/auth/create_factor.rb +64 -0
- data/lib/stormpath-sdk/data_store.rb +17 -1
- data/lib/stormpath-sdk/oauth/authenticator.rb +2 -1
- data/lib/stormpath-sdk/oauth/challenge_factor_grant.rb +25 -0
- data/lib/stormpath-sdk/oauth/challenge_factor_grant_request.rb +16 -0
- data/lib/stormpath-sdk/resource/account.rb +6 -0
- data/lib/stormpath-sdk/resource/account_link.rb +1 -1
- data/lib/stormpath-sdk/resource/challenge.rb +26 -0
- data/lib/stormpath-sdk/resource/collection.rb +0 -1
- data/lib/stormpath-sdk/resource/directory.rb +1 -0
- data/lib/stormpath-sdk/resource/factor.rb +26 -0
- data/lib/stormpath-sdk/resource/field.rb +20 -0
- data/lib/stormpath-sdk/resource/linked_account.rb +1 -1
- data/lib/stormpath-sdk/resource/phone.rb +21 -0
- data/lib/stormpath-sdk/resource/schema.rb +21 -0
- data/lib/stormpath-sdk/version.rb +2 -2
- data/spec/auth/create_factor_spec.rb +92 -0
- data/spec/auth/http_basic_authentication_spec.rb +3 -3
- data/spec/auth/http_bearer_authentication_spec.rb +3 -3
- data/spec/client_spec.rb +25 -25
- data/spec/oauth/access_token_authentication_result_spec.rb +3 -3
- data/spec/provider/provider_spec.rb +2 -2
- data/spec/resource/account_creation_policy_spec.rb +2 -2
- data/spec/resource/account_link_spec.rb +2 -2
- data/spec/resource/account_spec.rb +196 -12
- data/spec/resource/account_store_mapping_spec.rb +3 -3
- data/spec/resource/account_store_spec.rb +4 -4
- data/spec/resource/api_key_spec.rb +3 -3
- data/spec/resource/application_spec.rb +74 -33
- data/spec/resource/challenge_spec.rb +53 -0
- data/spec/resource/collection_spec.rb +6 -6
- data/spec/resource/custom_data_spec.rb +2 -2
- data/spec/resource/directory_spec.rb +27 -21
- data/spec/resource/email_template_spec.rb +2 -2
- data/spec/resource/factor_spec.rb +124 -0
- data/spec/resource/field_spec.rb +35 -0
- data/spec/resource/group_membership_spec.rb +3 -3
- data/spec/resource/group_spec.rb +3 -3
- data/spec/resource/linked_account_spec.rb +2 -2
- data/spec/resource/organization_spec.rb +6 -6
- data/spec/resource/password_policy_spec.rb +2 -2
- data/spec/resource/password_strength_spec.rb +2 -2
- data/spec/resource/phone_spec.rb +63 -0
- data/spec/resource/schema_spec.rb +39 -0
- data/spec/resource/status_spec.rb +4 -4
- data/spec/spec_helper.rb +6 -3
- data/spec/support/custom_data_storage_behavior.rb +2 -2
- data/spec/support/mocked_provider_accounts.rb +106 -0
- data/spec/support/resource_helpers.rb +20 -16
- metadata +16 -2
@@ -1,9 +1,9 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe 'HttpBasicAuthentication', vcr: true do
|
4
|
-
let(:application) { test_api_client.applications.create(
|
5
|
-
let(:directory) { test_api_client.directories.create(
|
6
|
-
let(:account) { application.accounts.create(
|
4
|
+
let(:application) { test_api_client.applications.create(application_attrs) }
|
5
|
+
let(:directory) { test_api_client.directories.create(directory_attrs) }
|
6
|
+
let(:account) { application.accounts.create(account_attrs) }
|
7
7
|
let(:api_key) { account.api_keys.create({}) }
|
8
8
|
let(:api_key_id) { api_key.id }
|
9
9
|
let(:api_key_secret) { api_key.secret }
|
@@ -1,8 +1,8 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe 'HttpBearerAuthentication', vcr: true do
|
4
|
-
let(:application) { test_api_client.applications.create(
|
5
|
-
let(:directory) { test_api_client.directories.create(
|
4
|
+
let(:application) { test_api_client.applications.create(application_attrs) }
|
5
|
+
let(:directory) { test_api_client.directories.create(directory_attrs) }
|
6
6
|
let(:password_grant_request) do
|
7
7
|
Stormpath::Oauth::PasswordGrantRequest.new("test#{default_domain}", 'P@$$w0rd')
|
8
8
|
end
|
@@ -19,7 +19,7 @@ describe 'HttpBearerAuthentication', vcr: true do
|
|
19
19
|
end
|
20
20
|
before { map_account_store(application, directory, 1, true, true) }
|
21
21
|
let!(:account) do
|
22
|
-
application.accounts.create(
|
22
|
+
application.accounts.create(account_attrs(email: 'test', password: 'P@$$w0rd'))
|
23
23
|
end
|
24
24
|
|
25
25
|
after do
|
data/spec/client_spec.rb
CHANGED
@@ -275,7 +275,7 @@ properties
|
|
275
275
|
context 'by default' do
|
276
276
|
let(:applications) { test_api_client.applications }
|
277
277
|
|
278
|
-
let(:application) { applications.create(
|
278
|
+
let(:application) { applications.create(application_attrs) }
|
279
279
|
|
280
280
|
it 'returns the collection' do
|
281
281
|
expect(applications).to be_kind_of(Stormpath::Resource::Collection)
|
@@ -290,7 +290,7 @@ properties
|
|
290
290
|
context 'pagination' do
|
291
291
|
let!(:applications) do
|
292
292
|
(0..2).to_a.map do |index|
|
293
|
-
test_api_client.applications.create(
|
293
|
+
test_api_client.applications.create(application_attrs(name: "ruby-sdk-test-#{index}"))
|
294
294
|
end
|
295
295
|
end
|
296
296
|
|
@@ -309,9 +309,9 @@ properties
|
|
309
309
|
let(:accounts_cache_summary) { cache_manager.get_cache('accounts').stats.summary }
|
310
310
|
let(:directories_cache_summary) { cache_manager.get_cache('directories').stats.summary }
|
311
311
|
let(:groups_cache_summary) { cache_manager.get_cache('groups').stats.summary }
|
312
|
-
let(:directory) { client.directories.create(
|
313
|
-
let(:group) { directory.groups.create(
|
314
|
-
let(:account) { directory.accounts.create(
|
312
|
+
let(:directory) { client.directories.create(directory_attrs) }
|
313
|
+
let(:group) { directory.groups.create(group_attrs) }
|
314
|
+
let(:account) { directory.accounts.create(account_attrs) }
|
315
315
|
|
316
316
|
before { group.add_account(account) }
|
317
317
|
|
@@ -338,7 +338,7 @@ properties
|
|
338
338
|
let(:cached_account) do
|
339
339
|
client.accounts.get account.href, Stormpath::Resource::Expansion.new('groups')
|
340
340
|
end
|
341
|
-
let(:group) { directory.groups.create(
|
341
|
+
let(:group) { directory.groups.create(group_attrs) }
|
342
342
|
|
343
343
|
before { client.data_store.initialize_cache({}) }
|
344
344
|
|
@@ -352,8 +352,8 @@ properties
|
|
352
352
|
context 'search' do
|
353
353
|
let!(:applications) do
|
354
354
|
[
|
355
|
-
test_api_client.applications.create(
|
356
|
-
test_api_client.applications.create(
|
355
|
+
test_api_client.applications.create(application_attrs(name: 'rubytestapp1')),
|
356
|
+
test_api_client.applications.create(application_attrs(name: 'rubytestapp2'))
|
357
357
|
]
|
358
358
|
end
|
359
359
|
|
@@ -413,7 +413,7 @@ properties
|
|
413
413
|
let(:options) { { createDirectory: true } }
|
414
414
|
let!(:account) do
|
415
415
|
application.accounts.create(
|
416
|
-
|
416
|
+
account_attrs(username: 'johnsmith2', password: '4P@$$w0rd!')
|
417
417
|
)
|
418
418
|
end
|
419
419
|
let(:auth_request) do
|
@@ -496,7 +496,7 @@ properties
|
|
496
496
|
describe '#directories' do
|
497
497
|
context 'given a collection' do
|
498
498
|
let(:directories) { test_api_client.directories }
|
499
|
-
let(:directory) { directories.create(
|
499
|
+
let(:directory) { directories.create(directory_attrs) }
|
500
500
|
|
501
501
|
it 'returns the collection' do
|
502
502
|
expect(directories).to be_kind_of(Stormpath::Resource::Collection)
|
@@ -507,8 +507,8 @@ properties
|
|
507
507
|
end
|
508
508
|
|
509
509
|
context 'given a collection with a limit' do
|
510
|
-
let!(:directory_1) { test_api_client.directories.create(
|
511
|
-
let!(:directory_2) { test_api_client.directories.create(
|
510
|
+
let!(:directory_1) { test_api_client.directories.create(directory_attrs) }
|
511
|
+
let!(:directory_2) { test_api_client.directories.create(directory_attrs) }
|
512
512
|
|
513
513
|
after do
|
514
514
|
directory_1.delete
|
@@ -522,7 +522,7 @@ properties
|
|
522
522
|
|
523
523
|
describe '.create' do
|
524
524
|
let(:directory) do
|
525
|
-
test_api_client.directories.create(
|
525
|
+
test_api_client.directories.create(directory_attrs(name: 'ruby', description: 'ruby'))
|
526
526
|
end
|
527
527
|
|
528
528
|
it 'creates that application' do
|
@@ -538,7 +538,7 @@ properties
|
|
538
538
|
describe '#organization' do
|
539
539
|
context 'search' do
|
540
540
|
let!(:organization) do
|
541
|
-
test_api_client.organizations.create(
|
541
|
+
test_api_client.organizations.create(organization_attrs(name: 'ruby-org'))
|
542
542
|
end
|
543
543
|
|
544
544
|
context 'by any attribute' do
|
@@ -563,7 +563,7 @@ properties
|
|
563
563
|
end
|
564
564
|
|
565
565
|
context 'given a collection' do
|
566
|
-
let(:organization) { test_api_client.organizations.create(
|
566
|
+
let(:organization) { test_api_client.organizations.create(organization_attrs) }
|
567
567
|
|
568
568
|
it 'returns the collection' do
|
569
569
|
expect(test_api_client.organizations).to be_kind_of(Stormpath::Resource::Collection)
|
@@ -574,8 +574,8 @@ properties
|
|
574
574
|
end
|
575
575
|
|
576
576
|
context 'given a collection with a limit' do
|
577
|
-
let!(:organization_1) { test_api_client.organizations.create(
|
578
|
-
let!(:organization_2) { test_api_client.organizations.create(
|
577
|
+
let!(:organization_1) { test_api_client.organizations.create(organization_attrs) }
|
578
|
+
let!(:organization_2) { test_api_client.organizations.create(organization_attrs) }
|
579
579
|
|
580
580
|
after do
|
581
581
|
organization_1.delete
|
@@ -589,7 +589,7 @@ properties
|
|
589
589
|
|
590
590
|
describe '.create' do
|
591
591
|
let(:organization) do
|
592
|
-
test_api_client.organizations.create(
|
592
|
+
test_api_client.organizations.create(organization_attrs(name: 'ruby',
|
593
593
|
name_key: 'ruby-org',
|
594
594
|
description: 'ruby-org'))
|
595
595
|
end
|
@@ -606,8 +606,8 @@ properties
|
|
606
606
|
end
|
607
607
|
|
608
608
|
describe '#organization_account_store_mappings' do
|
609
|
-
let(:organization) { test_api_client.organizations.create(
|
610
|
-
let(:directory) { test_api_client.directories.create(
|
609
|
+
let(:organization) { test_api_client.organizations.create(organization_attrs) }
|
610
|
+
let(:directory) { test_api_client.directories.create(directory_attrs) }
|
611
611
|
|
612
612
|
let(:organization_account_store_mappings) { map_organization_store(directory, organization) }
|
613
613
|
|
@@ -627,9 +627,9 @@ properties
|
|
627
627
|
|
628
628
|
describe '#accounts.verify_account_email' do
|
629
629
|
context 'given a verfication token of an account' do
|
630
|
-
let(:application) { test_api_client.applications.create(
|
630
|
+
let(:application) { test_api_client.applications.create(application_attrs) }
|
631
631
|
let(:directory_with_verification) do
|
632
|
-
test_api_client.directories.create(
|
632
|
+
test_api_client.directories.create(directory_attrs(description: 'verification enabled'))
|
633
633
|
end
|
634
634
|
|
635
635
|
before do
|
@@ -644,7 +644,7 @@ properties
|
|
644
644
|
end
|
645
645
|
|
646
646
|
let(:account) do
|
647
|
-
directory_with_verification.create_account(Stormpath::Resource::Account.new(
|
647
|
+
directory_with_verification.create_account(Stormpath::Resource::Account.new(account_attrs))
|
648
648
|
end
|
649
649
|
let(:verification_token) { account.email_verification_token.token }
|
650
650
|
|
@@ -675,10 +675,10 @@ properties
|
|
675
675
|
end
|
676
676
|
|
677
677
|
let!(:account1) do
|
678
|
-
directory1.accounts.create(
|
678
|
+
directory1.accounts.create(account_attrs(email: 'jekyll', username: 'jekyll'))
|
679
679
|
end
|
680
680
|
let!(:account2) do
|
681
|
-
directory2.accounts.create(
|
681
|
+
directory2.accounts.create(account_attrs(email: 'hyde', username: 'hyde'))
|
682
682
|
end
|
683
683
|
|
684
684
|
let(:link_accounts) do
|
@@ -1,11 +1,11 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Stormpath::Oauth::AccessTokenAuthenticationResult, :vcr do
|
4
|
-
let(:application) { test_api_client.applications.create(
|
5
|
-
let(:directory) { test_api_client.directories.create(
|
4
|
+
let(:application) { test_api_client.applications.create(application_attrs) }
|
5
|
+
let(:directory) { test_api_client.directories.create(directory_attrs) }
|
6
6
|
before { map_account_store(application, directory, 1, true, false) }
|
7
7
|
let!(:account) do
|
8
|
-
application.accounts.create(
|
8
|
+
application.accounts.create(account_attrs(email: 'ruby25', password: 'P@$$w0rd'))
|
9
9
|
end
|
10
10
|
let(:password_grant_request) do
|
11
11
|
Stormpath::Oauth::PasswordGrantRequest.new("ruby25#{default_domain}", 'P@$$w0rd')
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Stormpath::Provider::Provider, :vcr do
|
4
|
-
let(:application) { test_api_client.applications.create(
|
4
|
+
let(:application) { test_api_client.applications.create(application_attrs) }
|
5
5
|
let(:account_store_mapping) { map_account_store(application, directory, 0, false, false) }
|
6
6
|
let(:directory) { test_api_client.directories.create(directory_hash) }
|
7
7
|
|
@@ -96,7 +96,7 @@ describe Stormpath::Provider::Provider, :vcr do
|
|
96
96
|
it_behaves_like 'a provider directory'
|
97
97
|
|
98
98
|
it 'should be able to retrieve provider data from a regular account' do
|
99
|
-
account = directory.accounts.create(
|
99
|
+
account = directory.accounts.create(account_attrs)
|
100
100
|
|
101
101
|
expect(account.provider_data).to be_kind_of(Stormpath::Provider::ProviderData)
|
102
102
|
expect(account.provider_data.provider_id).to eq(provider_id)
|
@@ -2,8 +2,8 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Stormpath::Resource::AccountCreationPolicy, :vcr do
|
4
4
|
describe 'instances should respond to attribute property methods' do
|
5
|
-
let(:application) { test_api_client.applications.create(
|
6
|
-
let(:directory) { test_api_client.directories.create(
|
5
|
+
let(:application) { test_api_client.applications.create(application_attrs) }
|
6
|
+
let(:directory) { test_api_client.directories.create(directory_attrs) }
|
7
7
|
let(:account_creation_policy) { directory.account_creation_policy }
|
8
8
|
let(:create_valid_account) do
|
9
9
|
directory.accounts.create(
|
@@ -17,10 +17,10 @@ describe Stormpath::Resource::AccountLink, :vcr do
|
|
17
17
|
end
|
18
18
|
|
19
19
|
let!(:account1) do
|
20
|
-
directory1.accounts.create(
|
20
|
+
directory1.accounts.create(account_attrs(email: 'jekyll', username: 'jekyll'))
|
21
21
|
end
|
22
22
|
let!(:account2) do
|
23
|
-
directory2.accounts.create(
|
23
|
+
directory2.accounts.create(account_attrs(email: 'hyde', username: 'hyde'))
|
24
24
|
end
|
25
25
|
|
26
26
|
let!(:account_link) do
|
@@ -2,9 +2,9 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Stormpath::Resource::Account, :vcr do
|
4
4
|
describe 'instances should respond to attribute property methods' do
|
5
|
-
let(:directory) { test_api_client.directories.create(
|
5
|
+
let(:directory) { test_api_client.directories.create(directory_attrs) }
|
6
6
|
let(:account) do
|
7
|
-
directory.accounts.create(
|
7
|
+
directory.accounts.create(account_attrs(email: 'ruby',
|
8
8
|
given_name: 'ruby',
|
9
9
|
surname: 'ruby',
|
10
10
|
middle_name: 'ruby'))
|
@@ -39,13 +39,15 @@ describe Stormpath::Resource::Account, :vcr do
|
|
39
39
|
expect(account.groups).to be_a Stormpath::Resource::Collection
|
40
40
|
expect(account.group_memberships).to be_a Stormpath::Resource::Collection
|
41
41
|
expect(account.applications).to be_a Stormpath::Resource::Collection
|
42
|
+
expect(account.phones).to be_a Stormpath::Resource::Collection
|
43
|
+
expect(account.factors).to be_a Stormpath::Resource::Collection
|
42
44
|
end
|
43
45
|
end
|
44
46
|
|
45
47
|
describe 'account_associations' do
|
46
|
-
let(:application) { test_api_client.applications.create(
|
47
|
-
let(:directory) { test_api_client.directories.create(
|
48
|
-
let(:account) { directory.accounts.create(
|
48
|
+
let(:application) { test_api_client.applications.create(application_attrs) }
|
49
|
+
let(:directory) { test_api_client.directories.create(directory_attrs) }
|
50
|
+
let(:account) { directory.accounts.create(account_attrs) }
|
49
51
|
before { map_account_store(application, directory, 1, true, true) }
|
50
52
|
|
51
53
|
it 'should belong_to directory' do
|
@@ -62,7 +64,7 @@ describe Stormpath::Resource::Account, :vcr do
|
|
62
64
|
end
|
63
65
|
|
64
66
|
describe 'linked accounts' do
|
65
|
-
let(:directory2) { test_api_client.directories.create(
|
67
|
+
let(:directory2) { test_api_client.directories.create(directory_attrs) }
|
66
68
|
before do
|
67
69
|
map_account_store(application, directory2, 2, false, false)
|
68
70
|
account
|
@@ -70,7 +72,7 @@ describe Stormpath::Resource::Account, :vcr do
|
|
70
72
|
|
71
73
|
after { directory2.delete }
|
72
74
|
|
73
|
-
let!(:account2) { directory2.accounts.create(
|
75
|
+
let!(:account2) { directory2.accounts.create(account_attrs) }
|
74
76
|
let!(:link_accounts) do
|
75
77
|
test_api_client.account_links.create(
|
76
78
|
left_account: {
|
@@ -97,9 +99,9 @@ describe Stormpath::Resource::Account, :vcr do
|
|
97
99
|
|
98
100
|
describe '#add_or_remove_group' do
|
99
101
|
context 'given a group' do
|
100
|
-
let(:directory) { test_api_client.directories.create(
|
101
|
-
let(:group) { directory.groups.create(
|
102
|
-
let(:account) { directory.accounts.create(
|
102
|
+
let(:directory) { test_api_client.directories.create(directory_attrs) }
|
103
|
+
let(:group) { directory.groups.create(group_attrs) }
|
104
|
+
let(:account) { directory.accounts.create(account_attrs) }
|
103
105
|
before { account.add_group(group) }
|
104
106
|
|
105
107
|
after do
|
@@ -126,10 +128,192 @@ describe Stormpath::Resource::Account, :vcr do
|
|
126
128
|
end
|
127
129
|
end
|
128
130
|
|
131
|
+
describe 'managing phones' do
|
132
|
+
let(:application) { test_api_client.applications.create(application_attrs) }
|
133
|
+
let(:directory) { test_api_client.directories.create(directory_attrs) }
|
134
|
+
|
135
|
+
before do
|
136
|
+
map_account_store(application, directory, 1, true, true)
|
137
|
+
phone
|
138
|
+
end
|
139
|
+
|
140
|
+
let(:account) { directory.accounts.create(account_attrs) }
|
141
|
+
let(:phone) do
|
142
|
+
account.phones.create(
|
143
|
+
number: '+12025550173',
|
144
|
+
name: 'test phone',
|
145
|
+
description: 'this is a testing phone number'
|
146
|
+
)
|
147
|
+
end
|
148
|
+
|
149
|
+
it 'can fetch phones' do
|
150
|
+
expect(account.phones).to include(phone)
|
151
|
+
end
|
152
|
+
|
153
|
+
it 'can fetch a specific phone' do
|
154
|
+
expect(account.phones.get(phone.href)).to be_a Stormpath::Resource::Phone
|
155
|
+
end
|
156
|
+
|
157
|
+
it 'raises error if phone with same number created' do
|
158
|
+
expect do
|
159
|
+
account.phones.create(
|
160
|
+
number: '+12025550173',
|
161
|
+
name: 'test duplicate phone'
|
162
|
+
)
|
163
|
+
end.to raise_error(Stormpath::Error, 'An existing phone with that number already exists for this Account.')
|
164
|
+
end
|
165
|
+
|
166
|
+
after do
|
167
|
+
application.delete if application
|
168
|
+
directory.delete if directory
|
169
|
+
account.delete if account
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
describe 'managing factors' do
|
174
|
+
let(:application) { test_api_client.applications.create(application_attrs) }
|
175
|
+
let(:directory) { test_api_client.directories.create(directory_attrs) }
|
176
|
+
|
177
|
+
before { map_account_store(application, directory, 1, true, true) }
|
178
|
+
|
179
|
+
let(:account) { directory.accounts.create(account_attrs) }
|
180
|
+
|
181
|
+
context 'sms type' do
|
182
|
+
let!(:factor) do
|
183
|
+
account.factors.create(
|
184
|
+
type: 'SMS',
|
185
|
+
phone: {
|
186
|
+
number: '+12025550173',
|
187
|
+
name: 'test phone',
|
188
|
+
description: 'this is a testing phone number'
|
189
|
+
}
|
190
|
+
)
|
191
|
+
end
|
192
|
+
|
193
|
+
it 'can fetch factors' do
|
194
|
+
expect(account.factors).to include(factor)
|
195
|
+
end
|
196
|
+
|
197
|
+
it 'can fetch a specific factor' do
|
198
|
+
expect(account.factors.get(factor.href)).to be_a Stormpath::Resource::Factor
|
199
|
+
end
|
200
|
+
|
201
|
+
it 'creates a phone with a factor' do
|
202
|
+
expect(account.phones.count).to eq 1
|
203
|
+
end
|
204
|
+
end
|
205
|
+
|
206
|
+
context 'google-authenticator type' do
|
207
|
+
let!(:factor) do
|
208
|
+
account.factors.create(
|
209
|
+
type: 'google-authenticator',
|
210
|
+
account_name: "marko.cilimkovic#{default_domain}",
|
211
|
+
issuer: 'ACME',
|
212
|
+
status: 'ENABLED'
|
213
|
+
)
|
214
|
+
end
|
215
|
+
|
216
|
+
it 'can fetch factors' do
|
217
|
+
expect(account.factors).to include(factor)
|
218
|
+
end
|
219
|
+
end
|
220
|
+
|
221
|
+
after do
|
222
|
+
directory.delete if directory
|
223
|
+
application.delete if application
|
224
|
+
end
|
225
|
+
end
|
226
|
+
|
227
|
+
describe '#create_factor' do
|
228
|
+
let(:application) { test_api_client.applications.create(application_attrs) }
|
229
|
+
let(:directory) { test_api_client.directories.create(directory_attrs) }
|
230
|
+
let(:account) { directory.accounts.create(account_attrs) }
|
231
|
+
before { map_account_store(application, directory, 1, true, true) }
|
232
|
+
|
233
|
+
context 'type sms' do
|
234
|
+
before do
|
235
|
+
stub_request(:post, "#{account.href}/factors?challenge=true")
|
236
|
+
.to_return(body: Stormpath::Test.mocked_factor_response)
|
237
|
+
end
|
238
|
+
|
239
|
+
let(:factor) do
|
240
|
+
account.create_factor(:sms,
|
241
|
+
phone: { number: '+12025550173',
|
242
|
+
name: 'Rspec test phone',
|
243
|
+
description: 'This is a testing phone number' },
|
244
|
+
challenge: { message: 'Enter code please: ' })
|
245
|
+
end
|
246
|
+
|
247
|
+
it 'factor should be created' do
|
248
|
+
expect(factor).to be_kind_of Stormpath::Resource::Factor
|
249
|
+
end
|
250
|
+
end
|
251
|
+
|
252
|
+
context 'type google-authenticator' do
|
253
|
+
let(:factor) do
|
254
|
+
account.create_factor(:google_authenticator, options)
|
255
|
+
end
|
256
|
+
|
257
|
+
context 'with account_name' do
|
258
|
+
let(:account_name) { "marko.cilimkovic#{default_domain}" }
|
259
|
+
let(:options) do
|
260
|
+
{
|
261
|
+
custom_options: {
|
262
|
+
account_name: account_name,
|
263
|
+
issuer: 'ACME',
|
264
|
+
status: 'ENABLED'
|
265
|
+
}
|
266
|
+
}
|
267
|
+
end
|
268
|
+
|
269
|
+
it 'should create factor with custom account_name' do
|
270
|
+
expect(factor.account_name).to eq account_name
|
271
|
+
end
|
272
|
+
end
|
273
|
+
|
274
|
+
context 'with account_name not set' do
|
275
|
+
let(:options) do
|
276
|
+
{
|
277
|
+
custom_options: {
|
278
|
+
issuer: 'ACME',
|
279
|
+
status: 'ENABLED'
|
280
|
+
}
|
281
|
+
}
|
282
|
+
end
|
283
|
+
|
284
|
+
it 'should create factor with account_name set to username' do
|
285
|
+
expect(factor.account_name).to eq account.username
|
286
|
+
end
|
287
|
+
end
|
288
|
+
|
289
|
+
context 'without custom options' do
|
290
|
+
let(:options) { {} }
|
291
|
+
it 'should create factor with account_name set to username' do
|
292
|
+
expect(factor.account_name).to eq account.username
|
293
|
+
end
|
294
|
+
end
|
295
|
+
end
|
296
|
+
|
297
|
+
context 'with bad type set' do
|
298
|
+
let(:factor) do
|
299
|
+
account.create_factor(:invalid_type)
|
300
|
+
end
|
301
|
+
|
302
|
+
it 'should raise error' do
|
303
|
+
expect { factor }.to raise_error(Stormpath::Error)
|
304
|
+
end
|
305
|
+
end
|
306
|
+
|
307
|
+
after do
|
308
|
+
directory.delete if directory
|
309
|
+
application.delete if application
|
310
|
+
end
|
311
|
+
end
|
312
|
+
|
129
313
|
describe '#save' do
|
130
314
|
context 'when property values have changed' do
|
131
|
-
let(:directory) { test_api_client.directories.create(
|
132
|
-
let(:account) { directory.accounts.create(
|
315
|
+
let(:directory) { test_api_client.directories.create(directory_attrs) }
|
316
|
+
let(:account) { directory.accounts.create(account_attrs) }
|
133
317
|
let(:account_uri) { account.href }
|
134
318
|
let(:new_surname) { 'NewSurname' }
|
135
319
|
let(:reloaded_account) { test_api_client.accounts.get(account_uri) }
|