stormpath-sdk 1.3.1 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -1,12 +1,12 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Stormpath::Resource::EmailTemplate, :vcr do
4
- let(:application) { test_api_client.applications.create(build_application) }
4
+ let(:application) { test_api_client.applications.create(application_attrs) }
5
5
 
6
6
  after { application.delete }
7
7
 
8
8
  describe 'instances should respond to attribute property methods' do
9
- let(:directory) { test_api_client.directories.create(build_directory) }
9
+ let(:directory) { test_api_client.directories.create(directory_attrs) }
10
10
  let(:password_policy) { directory.password_policy }
11
11
  let(:reset_email_template) { password_policy.reset_email_templates.first }
12
12
 
@@ -0,0 +1,124 @@
1
+ require 'spec_helper'
2
+
3
+ describe Stormpath::Resource::Factor, :vcr do
4
+ describe 'instances should respond to attribute property methods' do
5
+ let(:directory) { test_api_client.directories.create(directory_attrs) }
6
+ let(:account) { directory.accounts.create(account_attrs) }
7
+
8
+ after do
9
+ factor.delete if factor
10
+ account.delete if account
11
+ directory.delete if directory
12
+ end
13
+
14
+ context 'type sms' do
15
+ let(:factor) do
16
+ account.factors.create(
17
+ type: 'SMS',
18
+ phone: {
19
+ number: '+12025550173',
20
+ name: 'test phone',
21
+ description: 'this is a testing phone number'
22
+ }
23
+ )
24
+ end
25
+
26
+ it do
27
+ [:type, :status].each do |property_accessor|
28
+ expect(factor).to respond_to(property_accessor)
29
+ expect(factor).to respond_to("#{property_accessor}=")
30
+ expect(factor.send(property_accessor)).to be_a String
31
+ end
32
+
33
+ [:verification_status].each do |property_getter|
34
+ expect(factor).to respond_to(property_getter)
35
+ expect(factor.send(property_getter)).to be_a String
36
+ end
37
+
38
+ expect(factor.account).to be_a Stormpath::Resource::Account
39
+ expect(factor.phone).to be_a Stormpath::Resource::Phone
40
+ expect(factor.challenges).to be_a Stormpath::Resource::Collection
41
+ end
42
+ end
43
+
44
+ context 'type google_authenticator' do
45
+ let(:factor) do
46
+ account.factors.create(
47
+ type: 'google-authenticator',
48
+ issuer: 'ACME'
49
+ )
50
+ end
51
+
52
+ it do
53
+ [:type, :status].each do |property_accessor|
54
+ expect(factor).to respond_to(property_accessor)
55
+ expect(factor).to respond_to("#{property_accessor}=")
56
+ expect(factor.send(property_accessor)).to be_a String
57
+ end
58
+
59
+ [:verification_status, :secret, :key_uri, :base64_q_r_image, :qr_code].each do |property_getter|
60
+ expect(factor).to respond_to(property_getter)
61
+ expect(factor.send(property_getter)).to be_a String
62
+ end
63
+
64
+ expect(factor.account).to be_a Stormpath::Resource::Account
65
+ end
66
+ end
67
+ end
68
+
69
+ describe 'factor associations' do
70
+ let(:app) { test_api_client.applications.create(application_attrs) }
71
+ let(:application) { test_api_client.applications.get app.href }
72
+ let(:directory) { test_api_client.directories.create(directory_attrs) }
73
+
74
+ before { map_account_store(app, directory, 1, true, true) }
75
+ let(:account) { directory.accounts.create(account_attrs) }
76
+ let(:phone_number) { '+12025550173' }
77
+
78
+ let(:factor) do
79
+ account.factors.create(
80
+ type: 'SMS',
81
+ phone: {
82
+ number: phone_number,
83
+ name: 'test phone',
84
+ description: 'this is a testing phone number'
85
+ }
86
+ )
87
+ end
88
+
89
+ it 'should belong_to account' do
90
+ expect(factor.account).to eq(account)
91
+ end
92
+
93
+ it 'should have one phone' do
94
+ expect(factor.phone.number).to eq(phone_number)
95
+ end
96
+
97
+ context 'challenges' do
98
+ before do
99
+ stub_request(:post, "#{factor.href}/challenges")
100
+ .to_return(body: Stormpath::Test.mocked_challenge)
101
+ stub_request(:get, factor.href)
102
+ .to_return(body: Stormpath::Test.mocked_factor_response)
103
+ end
104
+ let!(:challenge) { factor.challenges.create(message: 'Enter code: ${code}') }
105
+
106
+ it 'should have a collection of challenges' do
107
+ expect(factor.challenges).to be_a Stormpath::Resource::Collection
108
+ end
109
+
110
+ it 'should have the most recent challenge' do
111
+ most_recent_challenge = factor.challenges.create(message: 'Enter new code: ${code}')
112
+ reloaded_factor = account.factors.get(factor.href)
113
+ expect(reloaded_factor.most_recent_challenge.href).to eq(most_recent_challenge.href)
114
+ end
115
+ end
116
+
117
+ after do
118
+ application.delete if application
119
+ account.delete if account
120
+ directory.delete if directory
121
+ factor.delete if factor
122
+ end
123
+ end
124
+ end
@@ -0,0 +1,35 @@
1
+ require 'spec_helper'
2
+
3
+ describe Stormpath::Resource::Field, :vcr do
4
+ let(:application) { test_api_client.applications.create(application_attrs) }
5
+ let(:directory) { test_api_client.directories.create(directory_attrs) }
6
+ let(:schema) { directory.account_schema }
7
+ let(:field) { schema.fields.first }
8
+
9
+ after do
10
+ directory.delete
11
+ application.delete
12
+ end
13
+
14
+ describe 'instances should respond to attribute property methods' do
15
+ it do
16
+ expect(field).to be_a Stormpath::Resource::Field
17
+
18
+ [:name, :created_at, :modified_at].each do |property_getter|
19
+ expect(field).to respond_to(property_getter)
20
+ expect(field.send(property_getter)).to be_a String
21
+ end
22
+
23
+ expect(field).to respond_to(:required)
24
+ expect(field.required).to eq !!field.required
25
+ end
26
+ end
27
+
28
+ describe 'field associations' do
29
+ context '#schema' do
30
+ it 'should be able to get the account schema' do
31
+ expect(field.schema).to be_a Stormpath::Resource::Schema
32
+ end
33
+ end
34
+ end
35
+ end
@@ -7,9 +7,9 @@ describe Stormpath::Resource::GroupMembership, :vcr do
7
7
 
8
8
  describe '#add_account' do
9
9
  context 'given an account and a group' do
10
- let(:directory) { test_api_client.directories.create(build_directory) }
11
- let(:group) { directory.groups.create(build_group) }
12
- let(:account) { directory.accounts.create(build_account) }
10
+ let(:directory) { test_api_client.directories.create(directory_attrs) }
11
+ let(:group) { directory.groups.create(group_attrs) }
12
+ let(:account) { directory.accounts.create(account_attrs) }
13
13
 
14
14
  before { group.add_account account }
15
15
 
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Stormpath::Resource::Group, :vcr do
4
- let(:directory) { test_api_client.directories.create(build_directory) }
4
+ let(:directory) { test_api_client.directories.create(directory_attrs) }
5
5
  after { directory.delete }
6
6
 
7
7
  describe 'instances should respond to attribute property methods' do
@@ -40,8 +40,8 @@ describe Stormpath::Resource::Group, :vcr do
40
40
 
41
41
  describe '#add_or_remove_account' do
42
42
  context 'given an account' do
43
- let(:group) { directory.groups.create(build_group) }
44
- let(:account) { directory.accounts.create(build_account) }
43
+ let(:group) { directory.groups.create(group_attrs) }
44
+ let(:account) { directory.accounts.create(account_attrs) }
45
45
 
46
46
  before { group.add_account(account) }
47
47
 
@@ -7,10 +7,10 @@ describe Stormpath::Resource::LinkedAccount, :vcr do
7
7
  let(:directory1) { test_api_client.directories.create(name: 'ruby sdk dir 1') }
8
8
  let(:directory2) { test_api_client.directories.create(name: 'ruby sdk dir 2') }
9
9
  let(:account1) do
10
- directory1.accounts.create(build_account(email: 'jekyll', username: 'jekyll'))
10
+ directory1.accounts.create(account_attrs(email: 'jekyll', username: 'jekyll'))
11
11
  end
12
12
  let(:account2) do
13
- directory2.accounts.create(build_account(email: 'hyde', username: 'hyde'))
13
+ directory2.accounts.create(account_attrs(email: 'hyde', username: 'hyde'))
14
14
  end
15
15
 
16
16
  before do
@@ -2,7 +2,7 @@ require 'spec_helper'
2
2
 
3
3
  describe Stormpath::Resource::Organization, :vcr do
4
4
  let(:organization) do
5
- test_api_client.organizations.create(build_organization(name: 'test_ruby_organization',
5
+ test_api_client.organizations.create(organization_attrs(name: 'test_ruby_organization',
6
6
  name_key: 'testorganization',
7
7
  description: 'test organization'))
8
8
  end
@@ -56,14 +56,14 @@ describe Stormpath::Resource::Organization, :vcr do
56
56
 
57
57
  it 'should raise Stormpath::Error' do
58
58
  expect do
59
- test_api_client.organizations.create(build_organization(name_key: 'testorganization'))
59
+ test_api_client.organizations.create(organization_attrs(name_key: 'testorganization'))
60
60
  end.to raise_error(Stormpath::Error)
61
61
  end
62
62
  end
63
63
  end
64
64
 
65
65
  describe 'associations' do
66
- let(:directory) { test_api_client.directories.create(build_directory) }
66
+ let(:directory) { test_api_client.directories.create(directory_attrs) }
67
67
  after { directory.delete }
68
68
 
69
69
  context 'groups' do
@@ -77,8 +77,8 @@ describe Stormpath::Resource::Organization, :vcr do
77
77
  end
78
78
 
79
79
  context 'accounts' do
80
- let(:account) { directory.accounts.create(build_account(email: 'rubysdk')) }
81
- let(:org_account) { directory.accounts.create(build_account(email: 'rubysdk2')) }
80
+ let(:account) { directory.accounts.create(account_attrs(email: 'rubysdk')) }
81
+ let(:org_account) { directory.accounts.create(account_attrs(email: 'rubysdk2')) }
82
82
 
83
83
  before { map_organization_store(directory, organization, true) }
84
84
 
@@ -129,7 +129,7 @@ describe Stormpath::Resource::Organization, :vcr do
129
129
  end
130
130
 
131
131
  describe 'organization account store mapping' do
132
- let(:directory) { test_api_client.directories.create(build_directory) }
132
+ let(:directory) { test_api_client.directories.create(directory_attrs) }
133
133
  after { directory.delete }
134
134
 
135
135
  context 'given an account_store is a directory' do
@@ -1,12 +1,12 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Stormpath::Resource::PasswordPolicy, :vcr do
4
- let(:application) { test_api_client.applications.create(build_application) }
4
+ let(:application) { test_api_client.applications.create(application_attrs) }
5
5
 
6
6
  after { application.delete }
7
7
 
8
8
  describe 'instances should respond to attribute property methods' do
9
- let(:directory) { test_api_client.directories.create(build_directory) }
9
+ let(:directory) { test_api_client.directories.create(directory_attrs) }
10
10
  let(:password_policy) { directory.password_policy }
11
11
 
12
12
  before do
@@ -1,12 +1,12 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Stormpath::Resource::PasswordStrength, :vcr do
4
- let(:application) { test_api_client.applications.create(build_application) }
4
+ let(:application) { test_api_client.applications.create(application_attrs) }
5
5
 
6
6
  after { application.delete }
7
7
 
8
8
  describe 'instances should respond to attribute property methods' do
9
- let(:directory) { test_api_client.directories.create(build_directory) }
9
+ let(:directory) { test_api_client.directories.create(directory_attrs) }
10
10
  let(:password_policy) { directory.password_policy }
11
11
  let(:password_strength) { password_policy.strength }
12
12
 
@@ -0,0 +1,63 @@
1
+ require 'spec_helper'
2
+
3
+ describe Stormpath::Resource::Phone, :vcr do
4
+ describe 'instances should respond to attribute property methods' do
5
+ let(:directory) { test_api_client.directories.create(directory_attrs) }
6
+ let(:account) { directory.accounts.create(account_attrs) }
7
+ let(:phone) do
8
+ account.phones.create(
9
+ number: '+12025550173',
10
+ name: 'test phone',
11
+ description: 'this is a testing phone number'
12
+ )
13
+ end
14
+
15
+ after do
16
+ phone.delete
17
+ account.delete
18
+ directory.delete
19
+ end
20
+
21
+ it do
22
+ [:number, :name, :description].each do |property_accessor|
23
+ expect(phone).to respond_to(property_accessor)
24
+ expect(phone).to respond_to("#{property_accessor}=")
25
+ expect(phone.send(property_accessor)).to be_a String
26
+ end
27
+
28
+ [:verification_status, :status, :created_at, :modified_at].each do |property_getter|
29
+ expect(phone).to respond_to(property_getter)
30
+ expect(phone.send(property_getter)).to be_a String
31
+ end
32
+
33
+ expect(phone.account).to be_a Stormpath::Resource::Account
34
+ end
35
+ end
36
+
37
+ describe 'phone associations' do
38
+ let(:app) { test_api_client.applications.create(application_attrs) }
39
+ let(:application) { test_api_client.applications.get app.href }
40
+ let(:directory) { test_api_client.directories.create(directory_attrs) }
41
+
42
+ before { map_account_store(app, directory, 1, true, true) }
43
+ let(:account) { directory.accounts.create(account_attrs) }
44
+ let(:phone) do
45
+ account.phones.create(
46
+ number: '+12025550173',
47
+ name: 'test phone',
48
+ description: 'this is a testing phone number'
49
+ )
50
+ end
51
+
52
+ it 'should belong_to account' do
53
+ expect(phone.account).to eq(account)
54
+ end
55
+
56
+ after do
57
+ application.delete if application
58
+ account.delete if account
59
+ directory.delete if directory
60
+ phone.delete if phone
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,39 @@
1
+ require 'spec_helper'
2
+
3
+ describe Stormpath::Resource::Schema, :vcr do
4
+ let(:application) { test_api_client.applications.create(application_attrs) }
5
+ let(:directory) { test_api_client.directories.create(directory_attrs) }
6
+ let(:schema) { directory.account_schema }
7
+
8
+ after do
9
+ directory.delete
10
+ application.delete
11
+ end
12
+
13
+ describe 'instances should respond to attribute property methods' do
14
+ it do
15
+ expect(schema).to be_a Stormpath::Resource::Schema
16
+
17
+ [:created_at, :modified_at].each do |property_getter|
18
+ expect(schema).to respond_to(property_getter)
19
+ expect(schema.send(property_getter)).to be_a String
20
+ end
21
+ end
22
+ end
23
+
24
+ describe 'schema associations' do
25
+ context '#fields' do
26
+ let(:field) { directory.fields.first }
27
+
28
+ it 'should be able to get a list of fields' do
29
+ expect(schema.fields).to be_a Stormpath::Resource::Collection
30
+ end
31
+ end
32
+
33
+ context '#directory' do
34
+ it 'should be able to fetch the directory' do
35
+ expect(schema.directory).to eq directory
36
+ end
37
+ end
38
+ end
39
+ end
@@ -7,11 +7,11 @@ describe 'StatusOnDirectoryAndAccount', :vcr do
7
7
  let(:authenticate_user) do
8
8
  application.authenticate_account(auth_request)
9
9
  end
10
- let(:directory) { test_api_client.directories.create(build_directory) }
11
- let(:application) { test_api_client.applications.create(build_application) }
12
- let(:group) { directory.groups.create(build_group) }
10
+ let(:directory) { test_api_client.directories.create(directory_attrs) }
11
+ let(:application) { test_api_client.applications.create(application_attrs) }
12
+ let(:group) { directory.groups.create(group_attrs) }
13
13
  let!(:account) do
14
- directory.accounts.create(build_account(email: 'rubytest', password: 'P@$$w0rd'))
14
+ directory.accounts.create(account_attrs(email: 'rubytest', password: 'P@$$w0rd'))
15
15
  end
16
16
  let(:reloaded_account) { test_api_client.accounts.get account.href }
17
17
  before { map_account_store(application, directory, 0, true, true) }
@@ -15,15 +15,18 @@ require 'uuidtools'
15
15
 
16
16
  Dir['./spec/support/*.rb'].each { |file| require file }
17
17
 
18
- HIJACK_HTTP_REQUESTS_WITH_VCR = ENV['STORMPATH_SDK_TEST_ENVIRONMENT'] != 'CI'
19
-
20
18
  WebMock.allow_net_connect!
21
19
 
22
20
  VCR.configure do |c|
23
21
  c.cassette_library_dir = 'spec/fixtures/vcr_cassettes'
24
22
  c.hook_into :webmock
25
23
  c.configure_rspec_metadata!
26
- c.ignore_request { |r| HIJACK_HTTP_REQUESTS_WITH_VCR == false }
24
+
25
+ c.before_record do |i|
26
+ i.request.headers.delete('Authorization')
27
+ u = URI.parse(i.request.uri)
28
+ i.request.uri.sub!(/:\/\/.*#{Regexp.escape(u.host)}/, "://#{u.host}" )
29
+ end
27
30
  end
28
31
 
29
32
  RSpec.configure do |c|
@@ -1,6 +1,6 @@
1
1
  shared_examples_for 'account_custom_data' do
2
2
  context 'account' do
3
- let(:custom_data_storage) { directory.accounts.create(build_account) }
3
+ let(:custom_data_storage) { directory.accounts.create(account_attrs) }
4
4
  let(:custom_data_storage_w_nested_custom_data) do
5
5
  directory.accounts.create(
6
6
  username: 'ruby username',
@@ -24,7 +24,7 @@ end
24
24
 
25
25
  shared_examples_for 'group_custom_data' do
26
26
  context 'group' do
27
- let(:custom_data_storage) { directory.groups.create(build_group) }
27
+ let(:custom_data_storage) { directory.groups.create(group_attrs) }
28
28
  let(:custom_data_storage_w_nested_custom_data) do
29
29
  directory.groups.create(
30
30
  name: 'ruby group',