stormpath-sdk 1.3.0 → 1.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rspec +1 -0
- data/.travis.yml +0 -3
- data/CHANGES.md +9 -0
- data/README.md +8 -21
- data/Rakefile +1 -15
- data/lib/stormpath-sdk/oauth/error.rb +21 -0
- data/lib/stormpath-sdk/oauth/local_access_token_verification.rb +2 -2
- data/lib/stormpath-sdk/oauth/remote_access_token_verification.rb +2 -2
- data/lib/stormpath-sdk/version.rb +2 -2
- data/spec/auth/http_basic_authentication_spec.rb +6 -21
- data/spec/auth/http_bearer_authentication_spec.rb +11 -24
- data/spec/client_spec.rb +116 -258
- data/spec/oauth/access_token_authentication_result_spec.rb +14 -14
- data/spec/provider/provider_spec.rb +32 -40
- data/spec/resource/account_creation_policy_spec.rb +8 -13
- data/spec/resource/account_link_spec.rb +4 -17
- data/spec/resource/account_spec.rb +37 -81
- data/spec/resource/account_store_mapping_spec.rb +20 -32
- data/spec/resource/account_store_spec.rb +8 -31
- data/spec/resource/api_key_spec.rb +11 -14
- data/spec/resource/application_spec.rb +39 -168
- data/spec/resource/collection_spec.rb +17 -17
- data/spec/resource/custom_data_spec.rb +2 -2
- data/spec/resource/directory_spec.rb +164 -240
- data/spec/resource/email_template_spec.rb +21 -24
- data/spec/resource/group_membership_spec.rb +9 -12
- data/spec/resource/group_spec.rb +17 -31
- data/spec/resource/linked_account_spec.rb +4 -17
- data/spec/resource/organization_spec.rb +38 -110
- data/spec/resource/password_policy_spec.rb +13 -16
- data/spec/resource/password_strength_spec.rb +15 -18
- data/spec/resource/status_spec.rb +32 -35
- data/spec/spec_helper.rb +8 -139
- data/spec/support/api_key_helpers.rb +34 -0
- data/spec/support/custom_data_storage_behavior.rb +139 -156
- data/spec/support/env_names_warning.rb +59 -0
- data/spec/support/resource_helpers.rb +84 -0
- data/spec/support/resource_matchers.rb +6 -0
- data/stormpath-sdk.gemspec +1 -0
- metadata +20 -3
- data/support/api.rb +0 -55
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7c94bbec690d16f6c04eda0f7e46dd79c9406747
|
4
|
+
data.tar.gz: 10271a383fb9537813d22cacc1646df9c67b709d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 284ad0976afabc1777161def9266669f855f2eb3bcb6eaaa026bb66e195de22537da218f7cea5b33d68554202d28d5f4714e39e9c7e0e01f91de2b94dabf68e0
|
7
|
+
data.tar.gz: dc7e80f1a5501e989c7fab8f5b1f2ee889b3c71ae9f75bb1a91bb023e593bed70c83d8ee6bf1da8288556f73a709405c9f6245a12d2019f6d469326a1ff07c59
|
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color --format Fivemat
|
data/.travis.yml
CHANGED
@@ -11,6 +11,3 @@ env:
|
|
11
11
|
global:
|
12
12
|
- secure: MeyjZGgySZvpYVRm2i7wkrhvu9KUeU7eQ5aKj7FXqIYlQe3T67k+KKA3Ejp6WC3wUEVPUFseWMZCuNkRc0UeGA5/4e4LLc++XuaZn1jLTm1yNofh/CFAAjt5VdIYz4R7sKxpyLxs0orK2+HcaiCoqSDj7ehw2SlDca9VEi0GoQk=
|
13
13
|
- secure: MrtbhfH1IfwDkkvf0pq6trgj68to/fK4c+L1daKvMaNiNvwggbA3s0ea9QjHxXfWmPqL5bf8Q5N7YqXUw8cLpRPrKUA65JkyhyzIju8FgzXz83aCvjJD+5XhJIGzpLM8qHeKh7F0K6/iURTKIUgZXbguK4HpEeCMrrdPYcof3Ew=
|
14
|
-
- secure: JChx6k5NOw/PBzH6gpHdqxHPy8hpaTALVs2riTVXorJZ5p06F3riqFBQbMh6REzXdJLjD6VKPORt19WOkmLHCPW8x0g7HxIRHT0DCDLX/4980dZZAev3blSvfJ7t1cWlBVsZb0LgVEkswvKdSYEZvDQTy5XlWsIMuNhHUclsTZk=
|
15
|
-
- secure: c5tUXb7FPMDD/KkpDwYNfnZ2k0N0RltBAQt1IYOFkdcztIAdcGmWPtT4l07He+UJiF2Vy92KrsSK709FFDwdxAleSgFKwpCrtgJRXXqRqT/gDiJUsGU1jC4QgXpu/QWCWsCSs/v1l1GzZyZF61aQzqINVrGwF5n2/MeMGOAJkaA=
|
16
|
-
- secure: SepFOaSOjRr5EJLBlXKT60FgSmKZ604zhhDaes+s9rQgJcaUsVkTxFYhkE6mkDadH7dZ6ACW1TaWWTmFm+JMFuli/bcyvX9wm5akWM6EF3BdJ8djMac34iJuTB3MWED+fOaFco9oZjMQOYZlSu9nS4VOvH0ekcTnQnThzxYxpfs=
|
data/CHANGES.md
CHANGED
data/README.md
CHANGED
@@ -79,13 +79,13 @@ If you have not already done so, register as a developer on
|
|
79
79
|
1. **Create an account for a user** on the directory.
|
80
80
|
|
81
81
|
```ruby
|
82
|
-
account = directory.accounts.create(
|
82
|
+
account = directory.accounts.create(
|
83
83
|
given_name: 'John',
|
84
84
|
surname: 'Smith',
|
85
85
|
email: 'john.smith@example.com',
|
86
86
|
username: 'johnsmith',
|
87
87
|
password: '4P@$$w0rd!'
|
88
|
-
|
88
|
+
)
|
89
89
|
```
|
90
90
|
|
91
91
|
1. **Update an account**
|
@@ -517,13 +517,13 @@ ways:
|
|
517
517
|
on the directory:
|
518
518
|
|
519
519
|
```ruby
|
520
|
-
account = directory.accounts.create(
|
520
|
+
account = directory.accounts.create(
|
521
521
|
given_name: 'John',
|
522
522
|
surname: 'Smith',
|
523
523
|
email: 'john.smith@example.com',
|
524
524
|
username: 'johnsmith',
|
525
525
|
password: '4P@$$w0rd!'
|
526
|
-
|
526
|
+
)
|
527
527
|
```
|
528
528
|
|
529
529
|
Both these methods can take either a <code>Hash</code> of the account
|
@@ -945,27 +945,14 @@ account.custom_data.delete
|
|
945
945
|
### Setup
|
946
946
|
|
947
947
|
The functional tests of the SDK run against a Stormpath tenant. In that
|
948
|
-
account
|
949
|
-
|
950
|
-
* An application reserved for testing.
|
951
|
-
* A directory reserved for test accounts. _Be sure to associate this
|
952
|
-
directory to the test application as a login source_.
|
953
|
-
* Another directory reserved for test accounts with the account
|
954
|
-
verification workflow turned on. _Be sure to associate this directory
|
955
|
-
to the test application as a login source_.
|
948
|
+
account they automatically create and destroy resources.
|
956
949
|
|
957
|
-
The following environment variables need
|
950
|
+
The following environment variables need to be set:
|
958
951
|
|
959
|
-
* <code>
|
952
|
+
* <code>STORMPATH_CLIENT_APIKEY_ID</code> - The <code>id</code> from
|
960
953
|
your Stormpath API key.
|
961
|
-
* <code>
|
954
|
+
* <code>STORMPATH_CLIENT_APIKEY_SECRET</code> - The
|
962
955
|
<code>secret</code> from your Stormpath API key.
|
963
|
-
* <code>STORMPATH_SDK_TEST_APPLICATION_URL</code> - The URL to the
|
964
|
-
application created above.
|
965
|
-
* <code>STORMPATH_SDK_TEST_DIRECTORY_URL</code> - The URL to the first
|
966
|
-
directory created above.
|
967
|
-
* <code>STORMPATH_SDK_TEST_DIRECTORY_WITH_VERIFICATION_URL</code> - The
|
968
|
-
URL to the second directory created above.
|
969
956
|
|
970
957
|
### Running
|
971
958
|
|
data/Rakefile
CHANGED
@@ -3,8 +3,6 @@ require 'rubygems'
|
|
3
3
|
require 'rubygems/package_task'
|
4
4
|
require 'rspec/core/rake_task'
|
5
5
|
require 'stormpath-sdk'
|
6
|
-
require './support/api'
|
7
|
-
|
8
6
|
|
9
7
|
spec = eval(File.read('stormpath-sdk.gemspec'))
|
10
8
|
|
@@ -17,16 +15,4 @@ RSpec::Core::RakeTask.new do |t|
|
|
17
15
|
t.rspec_opts = ['-c']
|
18
16
|
end
|
19
17
|
|
20
|
-
task :
|
21
|
-
|
22
|
-
namespace :api do
|
23
|
-
task :clean do
|
24
|
-
Stormpath::Support::Api.destroy_resources(
|
25
|
-
ENV['STORMPATH_SDK_TEST_API_KEY_ID'],
|
26
|
-
ENV['STORMPATH_SDK_TEST_API_KEY_SECRET'],
|
27
|
-
ENV['STORMPATH_SDK_TEST_APPLICATION_URL'],
|
28
|
-
ENV['STORMPATH_SDK_TEST_DIRECTORY_URL'],
|
29
|
-
ENV['STORMPATH_SDK_TEST_DIRECTORY_WITH_VERIFICATION_URL']
|
30
|
-
)
|
31
|
-
end
|
32
|
-
end
|
18
|
+
task default: :spec
|
@@ -37,6 +37,27 @@ module Stormpath
|
|
37
37
|
message: 'Token is invalid',
|
38
38
|
developer_message: 'Token is invalid because the issued at time (iat) is after the current time',
|
39
39
|
request_id: 'Oauth error UUID'
|
40
|
+
},
|
41
|
+
jwt_invalid_issuer: {
|
42
|
+
status: 400,
|
43
|
+
code: 10014,
|
44
|
+
message: 'Token is invalid',
|
45
|
+
developer_message: 'Token is invalid because the issuer of the token does not match the Application validating the token.',
|
46
|
+
request_id: 'Oauth error UUID'
|
47
|
+
},
|
48
|
+
jwt_invalid_signature: {
|
49
|
+
status: 400,
|
50
|
+
code: 10017,
|
51
|
+
message: 'Token is invalid',
|
52
|
+
developer_message: 'Token is invalid because verifying the signature of a JWT failed.',
|
53
|
+
request_id: 'Oauth error UUID'
|
54
|
+
},
|
55
|
+
jwt_invalid_stt: {
|
56
|
+
status: 400,
|
57
|
+
code: nil,
|
58
|
+
message: 'Token is invalid',
|
59
|
+
developer_message: "Token is invalid because the stt header doesn't match the right type",
|
60
|
+
request_id: 'Oauth error UUID'
|
40
61
|
}
|
41
62
|
}
|
42
63
|
end
|
@@ -26,12 +26,12 @@ module Stormpath
|
|
26
26
|
|
27
27
|
def validate_jwt_is_an_access_token
|
28
28
|
return if decoded_jwt.second['stt'] == 'access'
|
29
|
-
raise
|
29
|
+
raise Stormpath::Oauth::Error, :jwt_invalid_stt
|
30
30
|
end
|
31
31
|
|
32
32
|
def validate_jwt_has_a_valid_issuer
|
33
33
|
return if decoded_jwt.first['iss'] == application.href
|
34
|
-
raise
|
34
|
+
raise Stormpath::Oauth::Error, :jwt_invalid_issuer
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
@@ -16,8 +16,8 @@ module Stormpath
|
|
16
16
|
end
|
17
17
|
|
18
18
|
def validate_access_token
|
19
|
-
raise Stormpath::Oauth::Error, :
|
20
|
-
raise Stormpath::Oauth::Error, :
|
19
|
+
raise Stormpath::Oauth::Error, :jwt_invalid_stt unless decoded_jwt.second['stt'] == 'access'
|
20
|
+
raise Stormpath::Oauth::Error, :jwt_invalid_issuer unless decoded_jwt.first['iss'] == application.href
|
21
21
|
end
|
22
22
|
|
23
23
|
def decoded_jwt
|
@@ -1,33 +1,18 @@
|
|
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)
|
7
|
-
application.accounts.create(
|
8
|
-
email: 'test@example.com',
|
9
|
-
given_name: 'Ruby SDK',
|
10
|
-
password: 'P@$$w0rd',
|
11
|
-
surname: 'SDK'
|
12
|
-
)
|
13
|
-
end
|
4
|
+
let(:application) { test_api_client.applications.create(build_application) }
|
5
|
+
let(:directory) { test_api_client.directories.create(build_directory) }
|
6
|
+
let(:account) { application.accounts.create(build_account) }
|
14
7
|
let(:api_key) { account.api_keys.create({}) }
|
15
8
|
let(:api_key_id) { api_key.id }
|
16
9
|
let(:api_key_secret) { api_key.secret }
|
17
10
|
let(:encoded_api_key) { Base64.encode64("#{api_key_id}:#{api_key_secret}") }
|
18
11
|
let(:basic_authorization_header) { "Basic #{encoded_api_key}" }
|
19
|
-
let(:
|
20
|
-
|
21
|
-
basic_authorization_header).authenticate!
|
22
|
-
end
|
12
|
+
let(:authenticator) { Stormpath::Authentication::HttpBasicAuthentication }
|
13
|
+
let(:authenticate) { authenticator.new(application, basic_authorization_header).authenticate! }
|
23
14
|
|
24
|
-
before
|
25
|
-
test_api_client.account_store_mappings.create(application: application,
|
26
|
-
account_store: directory,
|
27
|
-
list_index: 1,
|
28
|
-
is_default_account_store: true,
|
29
|
-
is_default_group_store: true)
|
30
|
-
end
|
15
|
+
before { map_account_store(application, directory, 1, true, true) }
|
31
16
|
|
32
17
|
after do
|
33
18
|
account.delete
|
@@ -1,39 +1,25 @@
|
|
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(
|
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
|
4
|
+
let(:application) { test_api_client.applications.create(build_application) }
|
5
|
+
let(:directory) { test_api_client.directories.create(build_directory) }
|
14
6
|
let(:password_grant_request) do
|
15
|
-
Stormpath::Oauth::PasswordGrantRequest.new(
|
7
|
+
Stormpath::Oauth::PasswordGrantRequest.new("test#{default_domain}", 'P@$$w0rd')
|
16
8
|
end
|
17
9
|
let(:aquire_token) { application.authenticate_oauth(password_grant_request) }
|
18
10
|
|
19
11
|
let(:access_token) { aquire_token.access_token }
|
20
12
|
let(:bearer_authorization_header) { "Bearer #{access_token}" }
|
13
|
+
let(:authenticator) { Stormpath::Authentication::HttpBearerAuthentication }
|
21
14
|
let(:authenticate_locally) do
|
22
|
-
|
23
|
-
bearer_authorization_header,
|
24
|
-
local: true).authenticate!
|
15
|
+
authenticator.new(application, bearer_authorization_header, local: true).authenticate!
|
25
16
|
end
|
26
17
|
let(:authenticate_remotely) do
|
27
|
-
|
28
|
-
bearer_authorization_header).authenticate!
|
18
|
+
authenticator.new(application, bearer_authorization_header).authenticate!
|
29
19
|
end
|
30
|
-
before
|
31
|
-
|
32
|
-
|
33
|
-
list_index: 1,
|
34
|
-
is_default_account_store: true,
|
35
|
-
is_default_group_store: true)
|
36
|
-
account
|
20
|
+
before { map_account_store(application, directory, 1, true, true) }
|
21
|
+
let!(:account) do
|
22
|
+
application.accounts.create(build_account(email: 'test', password: 'P@$$w0rd'))
|
37
23
|
end
|
38
24
|
|
39
25
|
after do
|
@@ -78,7 +64,8 @@ describe 'HttpBearerAuthentication', vcr: true do
|
|
78
64
|
describe 'local authentication' do
|
79
65
|
context 'with a valid bearer authorization header' do
|
80
66
|
it 'should return account' do
|
81
|
-
expect(authenticate_locally)
|
67
|
+
expect(authenticate_locally)
|
68
|
+
.to be_kind_of(Stormpath::Oauth::LocalAccessTokenVerificationResult)
|
82
69
|
expect(authenticate_locally.account).to eq(account)
|
83
70
|
end
|
84
71
|
end
|
data/spec/client_spec.rb
CHANGED
@@ -33,7 +33,7 @@ describe Stormpath::Client, :vcr do
|
|
33
33
|
|
34
34
|
context 'with an api key file location', 'that points to a file' do
|
35
35
|
after do
|
36
|
-
File.delete(api_key_file_location) if File.
|
36
|
+
File.delete(api_key_file_location) if File.exist?(api_key_file_location)
|
37
37
|
end
|
38
38
|
|
39
39
|
context 'by default' do
|
@@ -59,10 +59,10 @@ properties
|
|
59
59
|
File.join(File.dirname(__FILE__), 'testApiKey.fooId.properties')
|
60
60
|
end
|
61
61
|
let(:client) do
|
62
|
-
Stormpath::Client.new(
|
62
|
+
Stormpath::Client.new(
|
63
63
|
api_key_file_location: api_key_file_location,
|
64
64
|
api_key_id_property_name: 'foo.id'
|
65
|
-
|
65
|
+
)
|
66
66
|
end
|
67
67
|
|
68
68
|
before do
|
@@ -82,10 +82,10 @@ properties
|
|
82
82
|
File.join(File.dirname(__FILE__), 'testApiKey.barBazSecret.properties')
|
83
83
|
end
|
84
84
|
let(:client) do
|
85
|
-
Stormpath::Client.new(
|
85
|
+
Stormpath::Client.new(
|
86
86
|
api_key_file_location: api_key_file_location,
|
87
87
|
api_key_secret_property_name: 'bar.baz'
|
88
|
-
|
88
|
+
)
|
89
89
|
end
|
90
90
|
|
91
91
|
before do
|
@@ -105,9 +105,9 @@ properties
|
|
105
105
|
File.join(File.dirname(__FILE__), 'testApiKey.noApiKeyId.properties')
|
106
106
|
end
|
107
107
|
let(:client) do
|
108
|
-
Stormpath::Client.new(
|
108
|
+
Stormpath::Client.new(
|
109
109
|
api_key_file_location: api_key_file_location,
|
110
|
-
|
110
|
+
)
|
111
111
|
end
|
112
112
|
|
113
113
|
before do
|
@@ -132,11 +132,7 @@ properties
|
|
132
132
|
let(:api_key_file_location) do
|
133
133
|
File.join(File.dirname(__FILE__), 'testApiKey.noApiKeySecret.properties')
|
134
134
|
end
|
135
|
-
let(:client)
|
136
|
-
Stormpath::Client.new({
|
137
|
-
api_key_file_location: api_key_file_location,
|
138
|
-
})
|
139
|
-
end
|
135
|
+
let(:client) { Stormpath::Client.new(api_key_file_location: api_key_file_location) }
|
140
136
|
|
141
137
|
before do
|
142
138
|
File.open(api_key_file_location, 'w') do |f|
|
@@ -147,11 +143,14 @@ properties
|
|
147
143
|
end
|
148
144
|
|
149
145
|
it 'raises an error' do
|
150
|
-
expect { client }
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
146
|
+
expect { client }
|
147
|
+
.to raise_error(
|
148
|
+
ArgumentError,
|
149
|
+
"No API secret in properties. Please provide a 'apiKey.secret' property in '" +
|
150
|
+
api_key_file_location +
|
151
|
+
"' or pass in an 'api_key_secret_property_name' to the Stormpath::Client " \
|
152
|
+
'constructor to specify an alternative property.'
|
153
|
+
)
|
155
154
|
end
|
156
155
|
end
|
157
156
|
|
@@ -159,17 +158,15 @@ properties
|
|
159
158
|
let(:api_key_file_location) do
|
160
159
|
'no_such_file'
|
161
160
|
end
|
162
|
-
let(:client)
|
163
|
-
Stormpath::Client.new({
|
164
|
-
api_key_file_location: api_key_file_location,
|
165
|
-
})
|
166
|
-
end
|
161
|
+
let(:client) { Stormpath::Client.new(api_key_file_location: api_key_file_location) }
|
167
162
|
|
168
163
|
it 'raises an error' do
|
169
|
-
expect { client }.to raise_error
|
164
|
+
expect { client }.to raise_error(
|
165
|
+
ArgumentError,
|
170
166
|
"No API Key file could be found or loaded from '" +
|
171
167
|
api_key_file_location +
|
172
168
|
"'."
|
169
|
+
)
|
173
170
|
end
|
174
171
|
end
|
175
172
|
end
|
@@ -177,7 +174,9 @@ properties
|
|
177
174
|
context 'with a base url' do
|
178
175
|
context 'creates a client that connects to that base' do
|
179
176
|
let(:api_key) { Stormpath::ApiKey.new(test_api_key_id, test_api_key_secret) }
|
180
|
-
let(:client)
|
177
|
+
let(:client) do
|
178
|
+
Stormpath::Client.new(api_key: api_key, base_url: 'https://api.stormpath.com/v1')
|
179
|
+
end
|
181
180
|
|
182
181
|
it_behaves_like 'a valid client'
|
183
182
|
end
|
@@ -193,11 +192,12 @@ properties
|
|
193
192
|
|
194
193
|
context 'as a hash' do
|
195
194
|
let(:client) do
|
196
|
-
Stormpath::Client.new(
|
197
|
-
api_key: {
|
198
|
-
|
195
|
+
Stormpath::Client.new(
|
196
|
+
api_key: {
|
197
|
+
id: test_api_key_id,
|
198
|
+
secret: test_api_key_secret
|
199
199
|
}
|
200
|
-
|
200
|
+
)
|
201
201
|
end
|
202
202
|
|
203
203
|
it_behaves_like 'a valid client'
|
@@ -206,24 +206,26 @@ properties
|
|
206
206
|
|
207
207
|
context 'with no api key', 'and no api key file location' do
|
208
208
|
it 'raises an error' do
|
209
|
-
expect { Stormpath::Client.new({}) }.to raise_error
|
209
|
+
expect { Stormpath::Client.new({}) }.to raise_error(
|
210
|
+
ArgumentError,
|
210
211
|
/^No API key has been provided\./
|
212
|
+
)
|
211
213
|
end
|
212
214
|
end
|
213
215
|
|
214
216
|
context 'with cache configuration' do
|
215
217
|
let(:api_key_file_location) { 'http://fake.server.com/apiKey.properties' }
|
216
218
|
let(:client) do
|
217
|
-
Stormpath::Client.new(
|
219
|
+
Stormpath::Client.new(
|
218
220
|
api_key_file_location: api_key_file_location,
|
219
221
|
cache: {
|
220
222
|
store: Stormpath::Test::FakeStore1,
|
221
223
|
regions: {
|
222
224
|
directories: { ttl_seconds: 40, tti_seconds: 20 },
|
223
|
-
groups:
|
225
|
+
groups: { ttl_seconds: 80, tti_seconds: 40, store: Stormpath::Test::FakeStore2 }
|
224
226
|
}
|
225
227
|
}
|
226
|
-
|
228
|
+
)
|
227
229
|
end
|
228
230
|
|
229
231
|
before do
|
@@ -271,16 +273,9 @@ properties
|
|
271
273
|
|
272
274
|
describe '#applications' do
|
273
275
|
context 'by default' do
|
274
|
-
let(:applications)
|
275
|
-
test_api_client.applications
|
276
|
-
end
|
276
|
+
let(:applications) { test_api_client.applications }
|
277
277
|
|
278
|
-
let(:application)
|
279
|
-
applications.create(
|
280
|
-
name: 'Client Applications Test',
|
281
|
-
description: 'A test description'
|
282
|
-
)
|
283
|
-
end
|
278
|
+
let(:application) { applications.create(build_application) }
|
284
279
|
|
285
280
|
it 'returns the collection' do
|
286
281
|
expect(applications).to be_kind_of(Stormpath::Resource::Collection)
|
@@ -295,7 +290,7 @@ properties
|
|
295
290
|
context 'pagination' do
|
296
291
|
let!(:applications) do
|
297
292
|
(0..2).to_a.map do |index|
|
298
|
-
test_api_client.applications.create
|
293
|
+
test_api_client.applications.create(build_application(name: "ruby-sdk-test-#{index}"))
|
299
294
|
end
|
300
295
|
end
|
301
296
|
|
@@ -304,58 +299,21 @@ properties
|
|
304
299
|
expect(test_api_client.applications.offset(1).limit(2).count).to be >= 2
|
305
300
|
end
|
306
301
|
|
307
|
-
after
|
308
|
-
applications.each do |application|
|
309
|
-
application.delete
|
310
|
-
end
|
311
|
-
end
|
302
|
+
after { applications.each(&:delete) }
|
312
303
|
end
|
313
304
|
|
314
305
|
context 'expansion' do
|
315
|
-
let(:client)
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
let(:
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
let(:accounts_cache_summary) do
|
327
|
-
cache_manager.get_cache('accounts').stats.summary
|
328
|
-
end
|
329
|
-
|
330
|
-
let(:directories_cache_summary) do
|
331
|
-
cache_manager.get_cache('directories').stats.summary
|
332
|
-
end
|
333
|
-
|
334
|
-
let(:groups_cache_summary) do
|
335
|
-
cache_manager.get_cache('groups').stats.summary
|
336
|
-
end
|
337
|
-
|
338
|
-
let(:directory) do
|
339
|
-
client.directories.create name: random_directory_name
|
340
|
-
end
|
341
|
-
|
342
|
-
let(:group) do
|
343
|
-
directory.groups.create name: random_group_name
|
344
|
-
end
|
345
|
-
|
346
|
-
let(:account) do
|
347
|
-
directory.accounts.create({
|
348
|
-
email: 'rubysdk@example.com',
|
349
|
-
given_name: 'Ruby SDK',
|
350
|
-
password: 'P@$$w0rd',
|
351
|
-
surname: 'SDK',
|
352
|
-
username: 'rubysdk'
|
353
|
-
})
|
354
|
-
end
|
355
|
-
|
356
|
-
before do
|
357
|
-
group.add_account account
|
358
|
-
end
|
306
|
+
let(:client) { test_api_client }
|
307
|
+
let(:data_store) { client.instance_variable_get '@data_store' }
|
308
|
+
let(:cache_manager) { data_store.cache_manager }
|
309
|
+
let(:accounts_cache_summary) { cache_manager.get_cache('accounts').stats.summary }
|
310
|
+
let(:directories_cache_summary) { cache_manager.get_cache('directories').stats.summary }
|
311
|
+
let(:groups_cache_summary) { cache_manager.get_cache('groups').stats.summary }
|
312
|
+
let(:directory) { client.directories.create(build_directory) }
|
313
|
+
let(:group) { directory.groups.create(build_group) }
|
314
|
+
let(:account) { directory.accounts.create(build_account) }
|
315
|
+
|
316
|
+
before { group.add_account(account) }
|
359
317
|
|
360
318
|
after do
|
361
319
|
group.delete if group
|
@@ -368,9 +326,7 @@ properties
|
|
368
326
|
client.accounts.get account.href, Stormpath::Resource::Expansion.new('directory')
|
369
327
|
end
|
370
328
|
|
371
|
-
before
|
372
|
-
client.data_store.initialize_cache(Hash.new)
|
373
|
-
end
|
329
|
+
before { client.data_store.initialize_cache({}) }
|
374
330
|
|
375
331
|
it 'caches the nested resource' do
|
376
332
|
expect(cached_account.directory.name).to be
|
@@ -382,14 +338,9 @@ properties
|
|
382
338
|
let(:cached_account) do
|
383
339
|
client.accounts.get account.href, Stormpath::Resource::Expansion.new('groups')
|
384
340
|
end
|
341
|
+
let(:group) { directory.groups.create(build_group) }
|
385
342
|
|
386
|
-
|
387
|
-
directory.groups.create name: random_group_name
|
388
|
-
end
|
389
|
-
|
390
|
-
before do
|
391
|
-
client.data_store.initialize_cache(Hash.new)
|
392
|
-
end
|
343
|
+
before { client.data_store.initialize_cache({}) }
|
393
344
|
|
394
345
|
it 'caches the nested resource' do
|
395
346
|
expect(cached_account.groups.first.name).to eq(group.name)
|
@@ -399,19 +350,16 @@ properties
|
|
399
350
|
end
|
400
351
|
|
401
352
|
context 'search' do
|
402
|
-
let(:first_application_name) { random_application_name(1) }
|
403
|
-
let(:second_application_name) { random_application_name(2) }
|
404
|
-
|
405
353
|
let!(:applications) do
|
406
354
|
[
|
407
|
-
test_api_client.applications.create(name:
|
408
|
-
test_api_client.applications.create(name:
|
355
|
+
test_api_client.applications.create(build_application(name: 'rubytestapp1')),
|
356
|
+
test_api_client.applications.create(build_application(name: 'rubytestapp2'))
|
409
357
|
]
|
410
358
|
end
|
411
359
|
|
412
360
|
context 'by any attribute' do
|
413
361
|
let(:search_results) do
|
414
|
-
test_api_client.applications.search(
|
362
|
+
test_api_client.applications.search('rubytestapp1')
|
415
363
|
end
|
416
364
|
|
417
365
|
it 'returns the application' do
|
@@ -421,7 +369,7 @@ properties
|
|
421
369
|
|
422
370
|
context 'by an explicit attribute' do
|
423
371
|
let(:search_results) do
|
424
|
-
test_api_client.applications.search(name:
|
372
|
+
test_api_client.applications.search(name: 'rubytestapp1')
|
425
373
|
end
|
426
374
|
|
427
375
|
it 'returns the application' do
|
@@ -429,15 +377,11 @@ properties
|
|
429
377
|
end
|
430
378
|
end
|
431
379
|
|
432
|
-
after
|
433
|
-
applications.each do |application|
|
434
|
-
application.delete
|
435
|
-
end
|
436
|
-
end
|
380
|
+
after { applications.each(&:delete) }
|
437
381
|
end
|
438
382
|
|
439
383
|
describe '.create' do
|
440
|
-
let(:application_name) {
|
384
|
+
let(:application_name) { 'rubytestapp' }
|
441
385
|
|
442
386
|
let(:application_attributes) do
|
443
387
|
{
|
@@ -447,9 +391,7 @@ properties
|
|
447
391
|
end
|
448
392
|
|
449
393
|
context do
|
450
|
-
let(:application)
|
451
|
-
test_api_client.applications.create application_attributes
|
452
|
-
end
|
394
|
+
let(:application) { test_api_client.applications.create application_attributes }
|
453
395
|
|
454
396
|
it 'creates that application' do
|
455
397
|
expect(application).to be
|
@@ -457,9 +399,7 @@ properties
|
|
457
399
|
expect(application.description).to eq(application_attributes[:description])
|
458
400
|
end
|
459
401
|
|
460
|
-
after
|
461
|
-
application.delete
|
462
|
-
end
|
402
|
+
after { application.delete }
|
463
403
|
end
|
464
404
|
|
465
405
|
describe 'auto directory creation' do
|
@@ -471,22 +411,19 @@ properties
|
|
471
411
|
|
472
412
|
context 'login source' do
|
473
413
|
let(:options) { { createDirectory: true } }
|
474
|
-
|
475
414
|
let!(:account) do
|
476
415
|
application.accounts.create(
|
477
|
-
|
478
|
-
surname: 'Smith 2',
|
479
|
-
email: 'john.smith2@example.com',
|
480
|
-
username: 'johnsmith2',
|
481
|
-
password: '4P@$$w0rd!'
|
416
|
+
build_account(username: 'johnsmith2', password: '4P@$$w0rd!')
|
482
417
|
)
|
483
418
|
end
|
419
|
+
let(:auth_request) do
|
420
|
+
Stormpath::Authentication::UsernamePasswordRequest.new 'johnsmith2', '4P@$$w0rd!'
|
421
|
+
end
|
422
|
+
let(:auth_result) { application.authenticate_account(auth_request) }
|
484
423
|
|
485
424
|
before { application }
|
486
425
|
|
487
426
|
it 'serves as the accounts store and login source' do
|
488
|
-
auth_request = Stormpath::Authentication::UsernamePasswordRequest.new 'johnsmith2', '4P@$$w0rd!'
|
489
|
-
auth_result = application.authenticate_account auth_request
|
490
427
|
expect(account).to eq(auth_result.account)
|
491
428
|
end
|
492
429
|
end
|
@@ -502,7 +439,7 @@ properties
|
|
502
439
|
context 'and existing directory' do
|
503
440
|
it 'resolves naming conflict by adding (n) to directory name' do
|
504
441
|
test_api_client.directories.each { |d| d.delete if "#{application_name} Directory" == d.name }
|
505
|
-
test_api_client.directories.create(
|
442
|
+
test_api_client.directories.create(name: "#{application_name} Directory")
|
506
443
|
application
|
507
444
|
expect(directories.map(&:name)).to include("#{application_name} Directory (2)")
|
508
445
|
end
|
@@ -558,39 +495,24 @@ properties
|
|
558
495
|
|
559
496
|
describe '#directories' do
|
560
497
|
context 'given a collection' do
|
561
|
-
let(:directories)
|
562
|
-
|
563
|
-
end
|
564
|
-
|
565
|
-
let(:directory) do
|
566
|
-
directories.create(
|
567
|
-
name: 'Client Directories Test',
|
568
|
-
description: 'A test description'
|
569
|
-
)
|
570
|
-
end
|
498
|
+
let(:directories) { test_api_client.directories }
|
499
|
+
let(:directory) { directories.create(build_directory) }
|
571
500
|
|
572
501
|
it 'returns the collection' do
|
573
502
|
expect(directories).to be_kind_of(Stormpath::Resource::Collection)
|
574
503
|
expect(directories.count).to be >= 1
|
575
504
|
end
|
576
505
|
|
577
|
-
after
|
578
|
-
directory.delete
|
579
|
-
end
|
506
|
+
after { directory.delete }
|
580
507
|
end
|
581
508
|
|
582
509
|
context 'given a collection with a limit' do
|
583
|
-
let!(:directory_1)
|
584
|
-
|
585
|
-
end
|
586
|
-
|
587
|
-
let!(:directory_2) do
|
588
|
-
test_api_client.directories.create name: random_directory_name(2)
|
589
|
-
end
|
510
|
+
let!(:directory_1) { test_api_client.directories.create(build_directory) }
|
511
|
+
let!(:directory_2) { test_api_client.directories.create(build_directory) }
|
590
512
|
|
591
513
|
after do
|
592
|
-
directory_1.delete
|
593
|
-
directory_2.delete
|
514
|
+
directory_1.delete
|
515
|
+
directory_2.delete
|
594
516
|
end
|
595
517
|
|
596
518
|
it 'should retrieve the number of directories described with the limit' do
|
@@ -599,46 +521,29 @@ properties
|
|
599
521
|
end
|
600
522
|
|
601
523
|
describe '.create' do
|
602
|
-
|
603
|
-
let(:directory_name) { random_directory_name }
|
604
|
-
|
605
|
-
let(:directory_attributes) do
|
606
|
-
{
|
607
|
-
name: directory_name,
|
608
|
-
description: 'A test description'
|
609
|
-
}
|
610
|
-
end
|
611
|
-
|
612
524
|
let(:directory) do
|
613
|
-
test_api_client.directories.create
|
525
|
+
test_api_client.directories.create(build_directory(name: 'ruby', description: 'ruby'))
|
614
526
|
end
|
615
527
|
|
616
528
|
it 'creates that application' do
|
617
529
|
expect(directory).to be
|
618
|
-
expect(directory.name).to eq(
|
619
|
-
expect(directory.description).to eq(
|
530
|
+
expect(directory.name).to eq('ruby')
|
531
|
+
expect(directory.description).to eq('ruby')
|
620
532
|
end
|
621
533
|
|
622
|
-
after
|
623
|
-
directory.delete
|
624
|
-
end
|
534
|
+
after { directory.delete }
|
625
535
|
end
|
626
536
|
end
|
627
537
|
|
628
538
|
describe '#organization' do
|
629
539
|
context 'search' do
|
630
|
-
let(:organization_name) { random_organization_name }
|
631
|
-
|
632
540
|
let!(:organization) do
|
633
|
-
test_api_client.organizations.create(
|
634
|
-
name: organization_name,
|
635
|
-
name_key: "testorganization"
|
636
|
-
)
|
541
|
+
test_api_client.organizations.create(build_organization(name: 'ruby-org'))
|
637
542
|
end
|
638
543
|
|
639
544
|
context 'by any attribute' do
|
640
545
|
let(:search_results) do
|
641
|
-
test_api_client.organizations.search(
|
546
|
+
test_api_client.organizations.search('ruby-org')
|
642
547
|
end
|
643
548
|
|
644
549
|
it 'returns the application' do
|
@@ -647,9 +552,7 @@ properties
|
|
647
552
|
end
|
648
553
|
|
649
554
|
context 'by an explicit attribute' do
|
650
|
-
let(:search_results)
|
651
|
-
test_api_client.organizations.search(name: organization_name)
|
652
|
-
end
|
555
|
+
let(:search_results) { test_api_client.organizations.search(name: 'ruby-org') }
|
653
556
|
|
654
557
|
it 'returns the application' do
|
655
558
|
expect(search_results.count).to eq 1
|
@@ -660,13 +563,7 @@ properties
|
|
660
563
|
end
|
661
564
|
|
662
565
|
context 'given a collection' do
|
663
|
-
let(:organization)
|
664
|
-
test_api_client.organizations.create(
|
665
|
-
name: random_organization_name,
|
666
|
-
name_key: random_name_key,
|
667
|
-
description: 'A test description'
|
668
|
-
)
|
669
|
-
end
|
566
|
+
let(:organization) { test_api_client.organizations.create(build_organization) }
|
670
567
|
|
671
568
|
it 'returns the collection' do
|
672
569
|
expect(test_api_client.organizations).to be_kind_of(Stormpath::Resource::Collection)
|
@@ -677,13 +574,8 @@ properties
|
|
677
574
|
end
|
678
575
|
|
679
576
|
context 'given a collection with a limit' do
|
680
|
-
let!(:organization_1)
|
681
|
-
|
682
|
-
end
|
683
|
-
|
684
|
-
let!(:organization_2) do
|
685
|
-
test_api_client.organizations.create name: random_organization_name(2), name_key: random_name_key(2)
|
686
|
-
end
|
577
|
+
let!(:organization_1) { test_api_client.organizations.create(build_organization) }
|
578
|
+
let!(:organization_2) { test_api_client.organizations.create(build_organization) }
|
687
579
|
|
688
580
|
after do
|
689
581
|
organization_1.delete
|
@@ -696,54 +588,35 @@ properties
|
|
696
588
|
end
|
697
589
|
|
698
590
|
describe '.create' do
|
699
|
-
let(:organization_name) { random_organization_name }
|
700
|
-
|
701
|
-
let(:organization_attributes) do
|
702
|
-
{
|
703
|
-
name: organization_name,
|
704
|
-
name_key: random_name_key,
|
705
|
-
description: 'A test description'
|
706
|
-
}
|
707
|
-
end
|
708
|
-
|
709
591
|
let(:organization) do
|
710
|
-
test_api_client.organizations.create
|
592
|
+
test_api_client.organizations.create(build_organization(name: 'ruby',
|
593
|
+
name_key: 'ruby-org',
|
594
|
+
description: 'ruby-org'))
|
711
595
|
end
|
712
596
|
|
713
597
|
it 'creates an organization' do
|
714
598
|
expect(organization).to be
|
715
|
-
expect(organization.name).to eq(
|
716
|
-
expect(organization.name_key).to eq(
|
717
|
-
expect(organization.description).to eq(
|
599
|
+
expect(organization.name).to eq('ruby')
|
600
|
+
expect(organization.name_key).to eq('ruby-org')
|
601
|
+
expect(organization.description).to eq('ruby-org')
|
718
602
|
end
|
719
603
|
|
720
|
-
after
|
721
|
-
organization.delete
|
722
|
-
end
|
604
|
+
after { organization.delete }
|
723
605
|
end
|
724
606
|
end
|
725
607
|
|
726
|
-
describe
|
727
|
-
let(:organization)
|
728
|
-
|
729
|
-
name_key: "testorganization"
|
730
|
-
end
|
608
|
+
describe '#organization_account_store_mappings' do
|
609
|
+
let(:organization) { test_api_client.organizations.create(build_organization) }
|
610
|
+
let(:directory) { test_api_client.directories.create(build_directory) }
|
731
611
|
|
732
|
-
let(:
|
733
|
-
|
734
|
-
let(:organization_account_store_mappings) do
|
735
|
-
test_api_client.organization_account_store_mappings.create({
|
736
|
-
account_store: { href: directory.href },
|
737
|
-
organization: { href: organization.href }
|
738
|
-
})
|
739
|
-
end
|
612
|
+
let(:organization_account_store_mappings) { map_organization_store(directory, organization) }
|
740
613
|
|
741
614
|
after do
|
742
|
-
organization.delete
|
743
|
-
directory.delete
|
615
|
+
organization.delete
|
616
|
+
directory.delete
|
744
617
|
end
|
745
618
|
|
746
|
-
it
|
619
|
+
it 'returns the mapping' do
|
747
620
|
expect(organization_account_store_mappings.is_default_account_store).to eq(false)
|
748
621
|
expect(organization_account_store_mappings.is_default_group_store).to eq(false)
|
749
622
|
expect(organization_account_store_mappings.organization).to eq(organization)
|
@@ -754,30 +627,28 @@ properties
|
|
754
627
|
|
755
628
|
describe '#accounts.verify_account_email' do
|
756
629
|
context 'given a verfication token of an account' do
|
757
|
-
let(:
|
758
|
-
|
759
|
-
|
760
|
-
account = Stormpath::Resource::Account.new({
|
761
|
-
email: random_email,
|
762
|
-
givenName: 'Ruby SDK',
|
763
|
-
password: 'P@$$w0rd',
|
764
|
-
surname: 'SDK',
|
765
|
-
username: random_user_name
|
766
|
-
})
|
767
|
-
directory.create_account account
|
630
|
+
let(:application) { test_api_client.applications.create(build_application) }
|
631
|
+
let(:directory_with_verification) do
|
632
|
+
test_api_client.directories.create(build_directory(description: 'verification enabled'))
|
768
633
|
end
|
769
634
|
|
770
|
-
|
771
|
-
|
635
|
+
before do
|
636
|
+
map_account_store(application, directory_with_verification, 1, false, false)
|
637
|
+
enable_email_verification(directory_with_verification)
|
772
638
|
end
|
773
639
|
|
774
|
-
|
775
|
-
|
640
|
+
after do
|
641
|
+
application.delete
|
642
|
+
account.delete
|
643
|
+
directory_with_verification.delete
|
776
644
|
end
|
777
645
|
|
778
|
-
|
779
|
-
|
646
|
+
let(:account) do
|
647
|
+
directory_with_verification.create_account(Stormpath::Resource::Account.new(build_account))
|
780
648
|
end
|
649
|
+
let(:verification_token) { account.email_verification_token.token }
|
650
|
+
|
651
|
+
let(:verified_account) { test_api_client.accounts.verify_email_token verification_token }
|
781
652
|
|
782
653
|
it 'returns the account' do
|
783
654
|
expect(verified_account).to be
|
@@ -799,28 +670,15 @@ properties
|
|
799
670
|
end
|
800
671
|
|
801
672
|
before do
|
802
|
-
|
803
|
-
|
804
|
-
account_store: directory1,
|
805
|
-
list_index: 1,
|
806
|
-
is_default_account_store: true,
|
807
|
-
is_default_group_store: false
|
808
|
-
)
|
809
|
-
|
810
|
-
test_api_client.account_store_mappings.create(
|
811
|
-
application: application,
|
812
|
-
account_store: directory2,
|
813
|
-
list_index: 2,
|
814
|
-
is_default_account_store: false,
|
815
|
-
is_default_group_store: false
|
816
|
-
)
|
673
|
+
map_account_store(application, directory1, 1, true, false)
|
674
|
+
map_account_store(application, directory2, 2, false, false)
|
817
675
|
end
|
818
676
|
|
819
677
|
let!(:account1) do
|
820
|
-
directory1.accounts.create(build_account(email: 'jekyll
|
678
|
+
directory1.accounts.create(build_account(email: 'jekyll', username: 'jekyll'))
|
821
679
|
end
|
822
680
|
let!(:account2) do
|
823
|
-
directory2.accounts.create(build_account(email: 'hyde
|
681
|
+
directory2.accounts.create(build_account(email: 'hyde', username: 'hyde'))
|
824
682
|
end
|
825
683
|
|
826
684
|
let(:link_accounts) do
|