stormpath-sdk 1.1.5 → 1.2.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 +0 -0
- data/.ruby-gemset +0 -0
- data/.travis.yml +1 -0
- data/CHANGES.md +20 -0
- data/Gemfile +0 -0
- data/README.md +78 -2
- data/Rakefile +0 -0
- data/lib/stormpath-sdk/api_key.rb +0 -0
- data/lib/stormpath-sdk/auth/authentication_result.rb +0 -0
- data/lib/stormpath-sdk/auth/basic_authenticator.rb +0 -0
- data/lib/stormpath-sdk/auth/basic_login_attempt.rb +0 -0
- data/lib/stormpath-sdk/auth/http_basic_authentication.rb +47 -0
- data/lib/stormpath-sdk/auth/http_bearer_authentication.rb +27 -0
- data/lib/stormpath-sdk/auth/username_password_request.rb +0 -0
- data/lib/stormpath-sdk/cache/cache.rb +0 -0
- data/lib/stormpath-sdk/cache/cache_entry.rb +0 -0
- data/lib/stormpath-sdk/cache/cache_manager.rb +0 -0
- data/lib/stormpath-sdk/cache/cache_stats.rb +0 -0
- data/lib/stormpath-sdk/cache/disabled_cache_store.rb +0 -0
- data/lib/stormpath-sdk/cache/memcached_store.rb +37 -0
- data/lib/stormpath-sdk/cache/memory_store.rb +0 -0
- data/lib/stormpath-sdk/cache/redis_store.rb +0 -0
- data/lib/stormpath-sdk/client.rb +0 -0
- data/lib/stormpath-sdk/data_store.rb +1 -0
- data/lib/stormpath-sdk/error.rb +5 -5
- data/lib/stormpath-sdk/http/authc/sauthc1_signer.rb +0 -0
- data/lib/stormpath-sdk/http/http_client_request_executor.rb +2 -3
- data/lib/stormpath-sdk/http/request.rb +12 -10
- data/lib/stormpath-sdk/http/response.rb +0 -0
- data/lib/stormpath-sdk/http/utils.rb +8 -5
- data/lib/stormpath-sdk/id_site/id_site_result.rb +0 -0
- data/lib/stormpath-sdk/oauth/access_token_authentication_result.rb +0 -0
- data/lib/stormpath-sdk/oauth/authenticator.rb +2 -1
- data/lib/stormpath-sdk/oauth/error.rb +12 -8
- data/lib/stormpath-sdk/oauth/id_site_grant_request.rb +0 -0
- data/lib/stormpath-sdk/oauth/local_access_token_verification.rb +45 -0
- data/lib/stormpath-sdk/oauth/password_grant.rb +9 -7
- data/lib/stormpath-sdk/oauth/password_grant_request.rb +3 -2
- data/lib/stormpath-sdk/oauth/refresh_grant_request.rb +0 -0
- data/lib/stormpath-sdk/oauth/remote_access_token_verification.rb +28 -0
- data/lib/stormpath-sdk/oauth/social_grant.rb +27 -0
- data/lib/stormpath-sdk/oauth/social_grant_request.rb +14 -0
- data/lib/stormpath-sdk/oauth/stormpath_grant_request.rb +3 -2
- data/lib/stormpath-sdk/oauth/verify_access_token.rb +11 -6
- data/lib/stormpath-sdk/oauth/{verify_token.rb → verify_token_result.rb} +1 -1
- data/lib/stormpath-sdk/provider/account_access.rb +0 -0
- data/lib/stormpath-sdk/provider/account_request.rb +0 -0
- data/lib/stormpath-sdk/provider/account_resolver.rb +0 -0
- data/lib/stormpath-sdk/provider/account_result.rb +0 -0
- data/lib/stormpath-sdk/provider/facebook/facebook_provider.rb +0 -0
- data/lib/stormpath-sdk/provider/facebook/facebook_provider_data.rb +0 -0
- data/lib/stormpath-sdk/provider/github/github_provider.rb +0 -0
- data/lib/stormpath-sdk/provider/github/github_provider_data.rb +0 -0
- data/lib/stormpath-sdk/provider/google/google_provider.rb +0 -0
- data/lib/stormpath-sdk/provider/google/google_provider_data.rb +0 -1
- data/lib/stormpath-sdk/provider/linkedin/linkedin_provider.rb +0 -0
- data/lib/stormpath-sdk/provider/linkedin/linkedin_provider_data.rb +0 -0
- data/lib/stormpath-sdk/provider/provider.rb +0 -0
- data/lib/stormpath-sdk/provider/provider_data.rb +0 -0
- data/lib/stormpath-sdk/provider/saml/saml_mapping_rules.rb +0 -0
- data/lib/stormpath-sdk/provider/saml/saml_provider.rb +0 -0
- data/lib/stormpath-sdk/provider/saml/saml_provider_data.rb +0 -0
- data/lib/stormpath-sdk/provider/saml/saml_provider_metadata.rb +0 -0
- data/lib/stormpath-sdk/provider/stormpath/stormpath_provider.rb +0 -0
- data/lib/stormpath-sdk/provider/stormpath/stormpath_provider_data.rb +0 -0
- data/lib/stormpath-sdk/resource/access_token.rb +0 -0
- data/lib/stormpath-sdk/resource/account_creation_policy.rb +3 -1
- data/lib/stormpath-sdk/resource/account_membership.rb +0 -0
- data/lib/stormpath-sdk/resource/account_overrides.rb +0 -0
- data/lib/stormpath-sdk/resource/account_store.rb +7 -8
- data/lib/stormpath-sdk/resource/account_store_mapping.rb +0 -0
- data/lib/stormpath-sdk/resource/application.rb +5 -5
- data/lib/stormpath-sdk/resource/base.rb +0 -0
- data/lib/stormpath-sdk/resource/collection.rb +0 -0
- data/lib/stormpath-sdk/resource/custom_data.rb +0 -0
- data/lib/stormpath-sdk/resource/custom_data_hash_methods.rb +0 -0
- data/lib/stormpath-sdk/resource/custom_data_storage.rb +0 -0
- data/lib/stormpath-sdk/resource/directory.rb +1 -0
- data/lib/stormpath-sdk/resource/email_template.rb +0 -0
- data/lib/stormpath-sdk/resource/email_verification_token.rb +0 -0
- data/lib/stormpath-sdk/resource/error.rb +2 -3
- data/lib/stormpath-sdk/resource/expansion.rb +0 -0
- data/lib/stormpath-sdk/resource/group.rb +0 -0
- data/lib/stormpath-sdk/resource/group_membership.rb +0 -0
- data/lib/stormpath-sdk/resource/instance.rb +0 -0
- data/lib/stormpath-sdk/resource/oauth_policy.rb +0 -0
- data/lib/stormpath-sdk/resource/organization.rb +1 -1
- data/lib/stormpath-sdk/resource/organization_account_store_mapping.rb +0 -0
- data/lib/stormpath-sdk/resource/password_policy.rb +0 -0
- data/lib/stormpath-sdk/resource/password_reset_token.rb +0 -0
- data/lib/stormpath-sdk/resource/password_strength.rb +0 -0
- data/lib/stormpath-sdk/resource/refresh_token.rb +0 -0
- data/lib/stormpath-sdk/resource/tenant.rb +0 -0
- data/lib/stormpath-sdk/resource/utils.rb +0 -0
- data/lib/stormpath-sdk/resource/verification_email.rb +0 -0
- data/lib/stormpath-sdk/util/assert.rb +0 -0
- data/lib/stormpath-sdk/util/uri_builder.rb +38 -0
- data/lib/stormpath-sdk/version.rb +2 -2
- data/lib/stormpath-sdk.rb +47 -39
- data/spec/api_key_spec.rb +0 -0
- data/spec/auth/basic_authenticator_spec.rb +0 -0
- data/spec/auth/http_basic_authentication_spec.rb +86 -0
- data/spec/auth/http_bearer_authentication_spec.rb +86 -0
- data/spec/auth/sauthc1_signer_spec.rb +0 -0
- data/spec/cache/cache_entry_spec.rb +0 -0
- data/spec/cache/cache_spec.rb +0 -0
- data/spec/cache/cache_stats_spec.rb +0 -0
- data/spec/client_spec.rb +0 -0
- data/spec/data_store_spec.rb +40 -16
- data/spec/fixtures/response/create_saml_directory.json +0 -0
- data/spec/fixtures/response/create_saml_directory_mapping_rules.json +0 -0
- data/spec/fixtures/response/get_saml_directory_provider.json +0 -0
- data/spec/fixtures/response/get_saml_directory_provider_metadata.json +0 -0
- data/spec/oauth/access_token_authentication_result_spec.rb +8 -0
- data/spec/provider/account_resolver_spec.rb +0 -0
- data/spec/provider/provider_spec.rb +0 -0
- data/spec/resource/account_creation_policy_spec.rb +125 -2
- data/spec/resource/account_store_mapping_spec.rb +0 -0
- data/spec/resource/account_store_spec.rb +40 -13
- data/spec/resource/application_spec.rb +268 -51
- data/spec/resource/base_spec.rb +0 -0
- data/spec/resource/collection_spec.rb +60 -2
- data/spec/resource/custom_data_spec.rb +0 -0
- data/spec/resource/directory_spec.rb +82 -1
- data/spec/resource/email_template_spec.rb +0 -0
- data/spec/resource/expansion_spec.rb +0 -0
- data/spec/resource/group_membership_spec.rb +0 -0
- data/spec/resource/group_spec.rb +0 -0
- data/spec/resource/organization_spec.rb +37 -8
- data/spec/resource/password_policy_spec.rb +0 -0
- data/spec/resource/password_strength_spec.rb +0 -0
- data/spec/resource/status_spec.rb +0 -0
- data/spec/resource/tenant_spec.rb +0 -0
- data/spec/spec_helper.rb +5 -6
- data/spec/support/custom_data_storage_behavior.rb +0 -0
- data/spec/support/mocked_provider_accounts.rb +129 -117
- data/spec/support/resource_factory.rb +0 -0
- data/spec/support/resource_matchers.rb +7 -0
- data/spec/support/test_cache_stores.rb +0 -0
- data/spec/support/test_request_executor.rb +0 -0
- data/spec/util/uri_builder_spec.rb +47 -0
- data/stormpath-sdk.gemspec +1 -0
- data/support/api.rb +0 -0
- metadata +29 -4
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe 'HttpBearerAuthentication', vcr: true do
|
|
4
|
+
let(:application) { test_api_client.applications.create(name: 'ruby sdk test app') }
|
|
5
|
+
let(:directory) { test_api_client.directories.create(name: random_directory_name) }
|
|
6
|
+
let(:account) do
|
|
7
|
+
application.accounts.create(
|
|
8
|
+
email: 'test@example.com',
|
|
9
|
+
given_name: 'Ruby SDK',
|
|
10
|
+
password: 'P@$$w0rd',
|
|
11
|
+
surname: 'SDK'
|
|
12
|
+
)
|
|
13
|
+
end
|
|
14
|
+
let(:password_grant_request) do
|
|
15
|
+
Stormpath::Oauth::PasswordGrantRequest.new('test@example.com', 'P@$$w0rd')
|
|
16
|
+
end
|
|
17
|
+
let(:aquire_token) { application.authenticate_oauth(password_grant_request) }
|
|
18
|
+
|
|
19
|
+
let(:access_token) { aquire_token.access_token }
|
|
20
|
+
let(:bearer_authorization_header) { "Bearer #{access_token}" }
|
|
21
|
+
let(:authenticate_locally) do
|
|
22
|
+
Stormpath::Authentication::HttpBearerAuthentication.new(application,
|
|
23
|
+
bearer_authorization_header,
|
|
24
|
+
local: true).authenticate!
|
|
25
|
+
end
|
|
26
|
+
let(:authenticate_remotely) do
|
|
27
|
+
Stormpath::Authentication::HttpBearerAuthentication.new(application,
|
|
28
|
+
bearer_authorization_header).authenticate!
|
|
29
|
+
end
|
|
30
|
+
before do
|
|
31
|
+
test_api_client.account_store_mappings.create(application: application,
|
|
32
|
+
account_store: directory,
|
|
33
|
+
list_index: 1,
|
|
34
|
+
is_default_account_store: true,
|
|
35
|
+
is_default_group_store: true)
|
|
36
|
+
account
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
after do
|
|
40
|
+
account.delete
|
|
41
|
+
directory.delete
|
|
42
|
+
application.delete
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
describe 'remote authentication' do
|
|
46
|
+
context 'with a valid bearer authorization header' do
|
|
47
|
+
it 'should return VerifyTokenResult' do
|
|
48
|
+
expect(authenticate_remotely).to be_kind_of(Stormpath::Oauth::VerifyTokenResult)
|
|
49
|
+
expect(authenticate_remotely.account).to eq(account)
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
it 'should contain the account' do
|
|
53
|
+
expect(authenticate_remotely.account).to eq(account)
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
context 'with no bearer authorization header' do
|
|
58
|
+
let(:bearer_authorization_header) { nil }
|
|
59
|
+
|
|
60
|
+
it 'should raise error' do
|
|
61
|
+
expect do
|
|
62
|
+
authenticate_remotely
|
|
63
|
+
end.to raise_error(Stormpath::Error)
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
context 'with invalid authorization header type' do
|
|
68
|
+
let(:bearer_authorization_header) { "Basic #{access_token}" }
|
|
69
|
+
|
|
70
|
+
it 'should raise error' do
|
|
71
|
+
expect do
|
|
72
|
+
authenticate_remotely
|
|
73
|
+
end.to raise_error(Stormpath::Error)
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
describe 'local authentication' do
|
|
79
|
+
context 'with a valid bearer authorization header' do
|
|
80
|
+
it 'should return account' do
|
|
81
|
+
expect(authenticate_locally).to be_kind_of(Stormpath::Oauth::LocalAccessTokenVerificationResult)
|
|
82
|
+
expect(authenticate_locally.account).to eq(account)
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
end
|
|
File without changes
|
|
File without changes
|
data/spec/cache/cache_spec.rb
CHANGED
|
File without changes
|
|
File without changes
|
data/spec/client_spec.rb
CHANGED
|
File without changes
|
data/spec/data_store_spec.rb
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
require 'spec_helper'
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
shared_examples 'a data store' do
|
|
4
4
|
let(:factory) { Stormpath::Test::ResourceFactory.new }
|
|
5
5
|
let(:request_executor) { Stormpath::Test::TestRequestExecutor.new }
|
|
6
|
-
let(:
|
|
7
|
-
|
|
6
|
+
let(:data_store) do
|
|
7
|
+
Stormpath::DataStore.new(request_executor, test_api_key, { store: store }, nil)
|
|
8
|
+
end
|
|
8
9
|
let(:application_cache) { data_store.cache_manager.get_cache 'applications' }
|
|
9
10
|
let(:tenant_cache) { data_store.cache_manager.get_cache 'tenants' }
|
|
10
11
|
let(:group_cache) { data_store.cache_manager.get_cache 'groups' }
|
|
@@ -16,12 +17,13 @@ describe Stormpath::DataStore do
|
|
|
16
17
|
|
|
17
18
|
describe '.region_for' do
|
|
18
19
|
it 'pulls resource name from href' do
|
|
19
|
-
region = data_store.send :region_for, default_base_url
|
|
20
|
+
region = data_store.send :region_for, "#{default_base_url}/directories/4NykYrYH0OBiOOVOg8LXQ5"
|
|
20
21
|
expect(region).to eq('directories')
|
|
21
22
|
end
|
|
22
23
|
|
|
23
24
|
it 'pulls resource name from href if its custom data also' do
|
|
24
|
-
region = data_store.send
|
|
25
|
+
region = data_store.send(:region_for,
|
|
26
|
+
"#{default_base_url}/v1/accounts/7jWpcEVSgawKkAZp8XDIEw/customData")
|
|
25
27
|
expect(region).to eq('customData')
|
|
26
28
|
end
|
|
27
29
|
end
|
|
@@ -30,13 +32,19 @@ describe Stormpath::DataStore do
|
|
|
30
32
|
let(:custom_data_delete_field_url_regex) { data_store.send :custom_data_delete_field_url_regex }
|
|
31
33
|
context 'CUSTOM_DATA_DELETE_FIELD_REGEX' do
|
|
32
34
|
it 'should match custom data field href' do
|
|
33
|
-
expect(default_base_url
|
|
34
|
-
|
|
35
|
+
expect("#{default_base_url}/accounts/2f8U7r5JweVf1ZTtcJ08L8/customData/rank")
|
|
36
|
+
.to match(custom_data_delete_field_url_regex)
|
|
37
|
+
|
|
38
|
+
expect("#{default_base_url}/groups/4x6vwucf1w9wjHvt7paGoY/customData/rank")
|
|
39
|
+
.to match(custom_data_delete_field_url_regex)
|
|
35
40
|
end
|
|
36
41
|
|
|
37
42
|
it 'should not match custom data resource href' do
|
|
38
|
-
expect(default_base_url
|
|
39
|
-
|
|
43
|
+
expect("#{default_base_url}/accounts/2f8U7r5JweVf1ZTtcJ08L8/customData")
|
|
44
|
+
.not_to match(custom_data_delete_field_url_regex)
|
|
45
|
+
|
|
46
|
+
expect("#{default_base_url}/groups/4x6vwucf1w9wjHvt7paGoY/customData")
|
|
47
|
+
.not_to match(custom_data_delete_field_url_regex)
|
|
40
48
|
end
|
|
41
49
|
end
|
|
42
50
|
end
|
|
@@ -79,7 +87,7 @@ describe Stormpath::DataStore do
|
|
|
79
87
|
end
|
|
80
88
|
|
|
81
89
|
it 'misses the cache on the get' do
|
|
82
|
-
expect(application_cache.stats.hits).to eq(1)
|
|
90
|
+
expect(application_cache.stats.hits).to eq(1) # this hit is when we grab @cached
|
|
83
91
|
expect(application_cache.stats.misses).to eq(1)
|
|
84
92
|
end
|
|
85
93
|
|
|
@@ -146,24 +154,40 @@ describe Stormpath::DataStore do
|
|
|
146
154
|
expect(group_cache.size).to eq(4)
|
|
147
155
|
end
|
|
148
156
|
end
|
|
149
|
-
|
|
150
157
|
end
|
|
151
158
|
|
|
152
159
|
context '#apply_default_user_agent' do
|
|
153
160
|
let(:request) do
|
|
154
|
-
Stormpath::Http::Request.new
|
|
161
|
+
Stormpath::Http::Request.new('get',
|
|
162
|
+
'http://example.com/resources/abc123',
|
|
163
|
+
nil,
|
|
164
|
+
{},
|
|
165
|
+
nil,
|
|
166
|
+
test_api_key)
|
|
155
167
|
end
|
|
156
168
|
|
|
157
169
|
before do
|
|
158
|
-
allow(Gem::Platform.local).to receive(:os) {
|
|
159
|
-
allow(Gem::Platform.local).to receive(:version) {
|
|
170
|
+
allow(Gem::Platform.local).to receive(:os) { 'darwin' }
|
|
171
|
+
allow(Gem::Platform.local).to receive(:version) { '14' }
|
|
160
172
|
|
|
161
173
|
data_store.send(:apply_default_user_agent, request)
|
|
162
174
|
end
|
|
163
175
|
|
|
164
176
|
it 'adds User-Agent to header' do
|
|
165
|
-
expect(request.http_headers[
|
|
166
|
-
expect(request.http_headers[
|
|
177
|
+
expect(request.http_headers['User-Agent']).to include('darwin')
|
|
178
|
+
expect(request.http_headers['User-Agent']).to include('14')
|
|
167
179
|
end
|
|
168
180
|
end
|
|
169
181
|
end
|
|
182
|
+
|
|
183
|
+
describe Stormpath::DataStore do
|
|
184
|
+
context 'redis store' do
|
|
185
|
+
let(:store) { Stormpath::Cache::RedisStore }
|
|
186
|
+
it_should_behave_like 'a data store'
|
|
187
|
+
end
|
|
188
|
+
|
|
189
|
+
context 'memcached store' do
|
|
190
|
+
let(:store) { Stormpath::Cache::MemcachedStore }
|
|
191
|
+
it_should_behave_like 'a data store'
|
|
192
|
+
end
|
|
193
|
+
end
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -22,6 +22,10 @@ describe Stormpath::Oauth::AccessTokenAuthenticationResult, :vcr do
|
|
|
22
22
|
expect(jwt_authentication_result.account).to eq(account)
|
|
23
23
|
end
|
|
24
24
|
|
|
25
|
+
it 'jwt access token should contain the stt header' do
|
|
26
|
+
expect(jwt_authentication_result.access_token).to have_stt_in_header('access')
|
|
27
|
+
end
|
|
28
|
+
|
|
25
29
|
it 'should be able to delete the access token' do
|
|
26
30
|
jwt_authentication_result
|
|
27
31
|
|
|
@@ -36,6 +40,10 @@ describe Stormpath::Oauth::AccessTokenAuthenticationResult, :vcr do
|
|
|
36
40
|
expect(account.access_tokens.count).to eq(0)
|
|
37
41
|
end
|
|
38
42
|
|
|
43
|
+
it 'jwt refresh token should contain the stt header' do
|
|
44
|
+
expect(jwt_authentication_result.refresh_token).to have_stt_in_header('refresh')
|
|
45
|
+
end
|
|
46
|
+
|
|
39
47
|
it 'should be able to delete the refresh token' do
|
|
40
48
|
jwt_authentication_result
|
|
41
49
|
|
|
File without changes
|
|
File without changes
|
|
@@ -1,10 +1,28 @@
|
|
|
1
1
|
require 'spec_helper'
|
|
2
2
|
|
|
3
3
|
describe Stormpath::Resource::AccountCreationPolicy, :vcr do
|
|
4
|
-
describe
|
|
4
|
+
describe 'instances should respond to attribute property methods' do
|
|
5
5
|
let(:application) { test_application }
|
|
6
6
|
let(:directory) { test_api_client.directories.create(name: random_directory_name) }
|
|
7
7
|
let(:account_creation_policy) { directory.account_creation_policy }
|
|
8
|
+
let(:create_valid_account) do
|
|
9
|
+
directory.accounts.create(
|
|
10
|
+
username: 'cilim',
|
|
11
|
+
email: 'cilim@infinum.co',
|
|
12
|
+
given_name: 'Marko',
|
|
13
|
+
surname: 'Cilimkovic',
|
|
14
|
+
password: 'wonderfulWeatherIsntIt2'
|
|
15
|
+
)
|
|
16
|
+
end
|
|
17
|
+
let(:create_invalid_account) do
|
|
18
|
+
directory.accounts.create(
|
|
19
|
+
username: 'cilim',
|
|
20
|
+
email: 'cilim@infinum.hr',
|
|
21
|
+
given_name: 'Marko',
|
|
22
|
+
surname: 'Cilimkovic',
|
|
23
|
+
password: 'wonderfulWeatherIsntIt2'
|
|
24
|
+
)
|
|
25
|
+
end
|
|
8
26
|
|
|
9
27
|
before do
|
|
10
28
|
test_api_client.account_store_mappings.create(
|
|
@@ -23,7 +41,9 @@ describe Stormpath::Resource::AccountCreationPolicy, :vcr do
|
|
|
23
41
|
|
|
24
42
|
[:welcome_email_status,
|
|
25
43
|
:verification_email_status,
|
|
26
|
-
:verification_success_email_status
|
|
44
|
+
:verification_success_email_status,
|
|
45
|
+
:email_domain_whitelist,
|
|
46
|
+
:email_domain_blacklist].each do |property_accessor|
|
|
27
47
|
expect(account_creation_policy).to respond_to(property_accessor)
|
|
28
48
|
expect(account_creation_policy).to respond_to("#{property_accessor}=")
|
|
29
49
|
end
|
|
@@ -57,5 +77,108 @@ describe Stormpath::Resource::AccountCreationPolicy, :vcr do
|
|
|
57
77
|
account_creation_policy.save
|
|
58
78
|
expect(directory.account_creation_policy.verification_success_email_status).to eq('ENABLED')
|
|
59
79
|
end
|
|
80
|
+
|
|
81
|
+
it 'can change whitelisted email domains' do
|
|
82
|
+
whitelisted = ['*infinum.co', '*infinum.hr']
|
|
83
|
+
account_creation_policy.email_domain_whitelist = whitelisted
|
|
84
|
+
account_creation_policy.save
|
|
85
|
+
expect(directory.account_creation_policy.email_domain_whitelist).to eq whitelisted
|
|
86
|
+
|
|
87
|
+
account_creation_policy.email_domain_whitelist = ['*infinum.hr']
|
|
88
|
+
account_creation_policy.save
|
|
89
|
+
expect(directory.account_creation_policy.email_domain_whitelist).to include '*infinum.hr'
|
|
90
|
+
expect(directory.account_creation_policy.email_domain_whitelist).not_to include '*infinum.co'
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
it 'can change blacklisted email domains' do
|
|
94
|
+
blacklisted = ['*spam.com', '*e1ppe.ro']
|
|
95
|
+
account_creation_policy.email_domain_blacklist = blacklisted
|
|
96
|
+
account_creation_policy.save
|
|
97
|
+
expect(directory.account_creation_policy.email_domain_blacklist).to eq blacklisted
|
|
98
|
+
|
|
99
|
+
account_creation_policy.email_domain_blacklist = ['*spam.com']
|
|
100
|
+
account_creation_policy.save
|
|
101
|
+
expect(directory.account_creation_policy.email_domain_blacklist).to include '*spam.com'
|
|
102
|
+
expect(directory.account_creation_policy.email_domain_blacklist).not_to include '*e1ppe.ro'
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
context 'when domain not string' do
|
|
106
|
+
it 'should raise error' do
|
|
107
|
+
blacklisted = ['*spam.com', 12345]
|
|
108
|
+
account_creation_policy.email_domain_blacklist = blacklisted
|
|
109
|
+
expect do
|
|
110
|
+
account_creation_policy.save
|
|
111
|
+
end.to raise_error(Stormpath::Error, /is an invalid type./)
|
|
112
|
+
end
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
context 'when domain invalid' do
|
|
116
|
+
it 'should raise error' do
|
|
117
|
+
blacklisted = ['*spam.com', '*youre@jiberish']
|
|
118
|
+
account_creation_policy.email_domain_blacklist = blacklisted
|
|
119
|
+
expect do
|
|
120
|
+
account_creation_policy.save
|
|
121
|
+
end.to raise_error(Stormpath::Error, /It is not a valid domain./)
|
|
122
|
+
end
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
describe 'create account' do
|
|
126
|
+
context 'when whitelisted domains exist' do
|
|
127
|
+
before do
|
|
128
|
+
whitelisted = ['*infinum.co']
|
|
129
|
+
account_creation_policy.email_domain_whitelist = whitelisted
|
|
130
|
+
account_creation_policy.save
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
context 'when account whitelisted' do
|
|
134
|
+
it 'should successfully create the account' do
|
|
135
|
+
account = create_valid_account
|
|
136
|
+
expect(account).to be_a Stormpath::Resource::Account
|
|
137
|
+
expect(account.username).to eq('cilim')
|
|
138
|
+
end
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
context 'when account not whitelisted' do
|
|
142
|
+
it 'should raise error' do
|
|
143
|
+
expect do
|
|
144
|
+
create_invalid_account
|
|
145
|
+
end.to raise_error(Stormpath::Error, "Cannot create the Account because your email's domain is not allowed.")
|
|
146
|
+
end
|
|
147
|
+
end
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
context 'when blacklisted domains exist' do
|
|
151
|
+
context 'when account email blacklisted' do
|
|
152
|
+
it 'should not create the account' do
|
|
153
|
+
blacklisted = ['*spam.com']
|
|
154
|
+
account_creation_policy.email_domain_blacklist = blacklisted
|
|
155
|
+
account_creation_policy.save
|
|
156
|
+
|
|
157
|
+
expect do
|
|
158
|
+
@account = directory.accounts.create(
|
|
159
|
+
username: 'cilim',
|
|
160
|
+
email: 'cilim@spam.com',
|
|
161
|
+
given_name: 'Marko',
|
|
162
|
+
surname: 'Cilimkovic',
|
|
163
|
+
password: 'wonderfulWeatherIsntIt2'
|
|
164
|
+
)
|
|
165
|
+
end.to raise_error(Stormpath::Error, "Cannot create the Account because your email's domain is not allowed.")
|
|
166
|
+
end
|
|
167
|
+
end
|
|
168
|
+
end
|
|
169
|
+
|
|
170
|
+
context 'when account email in blacklisted and whitelisted domains' do
|
|
171
|
+
it 'should not create the account' do
|
|
172
|
+
bothlisted = ['*infinum.hr']
|
|
173
|
+
account_creation_policy.email_domain_blacklist = bothlisted
|
|
174
|
+
account_creation_policy.email_domain_whitelist = bothlisted
|
|
175
|
+
account_creation_policy.save
|
|
176
|
+
|
|
177
|
+
expect do
|
|
178
|
+
create_invalid_account
|
|
179
|
+
end.to raise_error(Stormpath::Error, "Cannot create the Account because your email's domain is not allowed.")
|
|
180
|
+
end
|
|
181
|
+
end
|
|
182
|
+
end
|
|
60
183
|
end
|
|
61
184
|
end
|
|
File without changes
|
|
@@ -1,49 +1,76 @@
|
|
|
1
1
|
require 'spec_helper'
|
|
2
2
|
|
|
3
3
|
describe Stormpath::Resource::AccountStore, :vcr do
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
test_api_client.account_store_mappings.create({
|
|
4
|
+
def create_account_store_mapping(application, account_store, is_default_group_store = false)
|
|
5
|
+
test_api_client.account_store_mappings.create(
|
|
7
6
|
application: application,
|
|
8
7
|
account_store: account_store,
|
|
9
8
|
list_index: 0,
|
|
10
9
|
is_default_account_store: true,
|
|
11
10
|
is_default_group_store: is_default_group_store
|
|
12
|
-
|
|
11
|
+
)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
let(:application) do
|
|
15
|
+
test_api_client.applications.create name: random_application_name,
|
|
16
|
+
description: 'testApplication for AccountStoreMappings'
|
|
13
17
|
end
|
|
14
18
|
|
|
15
|
-
let(:
|
|
19
|
+
let(:directory) do
|
|
20
|
+
test_api_client.directories.create name: random_directory_name,
|
|
21
|
+
description: 'testDirectory for AccountStoreMappings'
|
|
22
|
+
end
|
|
16
23
|
|
|
17
|
-
let(:
|
|
24
|
+
let(:group) do
|
|
25
|
+
directory.groups.create name: 'testGroup', description: 'testGroup for AccountStoreMappings'
|
|
26
|
+
end
|
|
18
27
|
|
|
19
|
-
let(:
|
|
28
|
+
let(:organization) do
|
|
29
|
+
test_api_client.organizations.create name: 'testOrganization', name_key: 'test-organization'
|
|
30
|
+
end
|
|
20
31
|
|
|
21
32
|
after do
|
|
22
33
|
application.delete if application
|
|
23
34
|
group.delete if group
|
|
24
35
|
directory.delete if directory
|
|
36
|
+
organization.delete if organization
|
|
25
37
|
end
|
|
26
38
|
|
|
27
39
|
describe 'given an account_store_mapping and a directory' do
|
|
28
|
-
let!(:account_store_mapping) {create_account_store_mapping(application,directory,true)}
|
|
29
|
-
let(:reloaded_mapping){ application.account_store_mappings.get account_store_mapping.href }
|
|
40
|
+
let!(:account_store_mapping) { create_account_store_mapping(application, directory, true) }
|
|
41
|
+
let(:reloaded_mapping) { application.account_store_mappings.get account_store_mapping.href }
|
|
30
42
|
|
|
31
43
|
it 'should return a directory' do
|
|
32
44
|
expect(reloaded_mapping.account_store.class).to eq(Stormpath::Resource::Directory)
|
|
33
45
|
expect(reloaded_mapping.account_store).to eq(directory)
|
|
34
46
|
end
|
|
35
|
-
|
|
36
47
|
end
|
|
37
48
|
|
|
38
|
-
|
|
39
|
-
let!(:account_store_mapping) {create_account_store_mapping(application,group)}
|
|
40
|
-
let(:reloaded_mapping){ application.account_store_mappings.get account_store_mapping.href }
|
|
49
|
+
describe 'given an account_store_mapping and a group' do
|
|
50
|
+
let!(:account_store_mapping) { create_account_store_mapping(application, group) }
|
|
51
|
+
let(:reloaded_mapping) { application.account_store_mappings.get account_store_mapping.href }
|
|
41
52
|
|
|
42
53
|
it 'should return a group' do
|
|
43
54
|
expect(reloaded_mapping.account_store.class).to eq(Stormpath::Resource::Group)
|
|
44
55
|
expect(reloaded_mapping.account_store).to eq(group)
|
|
45
56
|
end
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
describe 'given an account_store_mapping and an organization' do
|
|
60
|
+
let!(:account_store_mapping) { create_account_store_mapping(application, organization) }
|
|
61
|
+
let(:reloaded_mapping) { application.account_store_mappings.get account_store_mapping.href }
|
|
46
62
|
|
|
63
|
+
it 'should return an organization' do
|
|
64
|
+
expect(reloaded_mapping.account_store.class).to eq(Stormpath::Resource::Organization)
|
|
65
|
+
expect(reloaded_mapping.account_store).to eq(organization)
|
|
66
|
+
end
|
|
47
67
|
end
|
|
48
68
|
|
|
69
|
+
describe 'given an undefined account_store_mapping' do
|
|
70
|
+
it 'should raise an error' do
|
|
71
|
+
expect do
|
|
72
|
+
create_account_store_mapping(application, 'undefined')
|
|
73
|
+
end.to raise_error
|
|
74
|
+
end
|
|
75
|
+
end
|
|
49
76
|
end
|