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
|
@@ -54,13 +54,13 @@ describe Stormpath::Resource::Application, :vcr do
|
|
|
54
54
|
credentialed_uri.to_s
|
|
55
55
|
end
|
|
56
56
|
|
|
57
|
-
it
|
|
58
|
-
expect
|
|
57
|
+
it 'raises a LoadError with an invalid url' do
|
|
58
|
+
expect do
|
|
59
59
|
Stormpath::Resource::Application.load 'this is an invalid url'
|
|
60
|
-
|
|
60
|
+
end.to raise_error(Stormpath::Resource::Application::LoadError)
|
|
61
61
|
end
|
|
62
62
|
|
|
63
|
-
it
|
|
63
|
+
it 'instantiates client and application objects from a composite URL' do
|
|
64
64
|
loaded_application = Stormpath::Resource::Application.load(url)
|
|
65
65
|
expect(loaded_application).to eq(application)
|
|
66
66
|
end
|
|
@@ -761,9 +761,21 @@ describe Stormpath::Resource::Application, :vcr do
|
|
|
761
761
|
account.delete if account
|
|
762
762
|
end
|
|
763
763
|
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
764
|
+
context 'with decoded password reset token' do
|
|
765
|
+
it 'retrieves the account with the reset password' do
|
|
766
|
+
expect(reset_password_account).to be
|
|
767
|
+
expect(reset_password_account.email).to eq(account.email)
|
|
768
|
+
end
|
|
769
|
+
end
|
|
770
|
+
|
|
771
|
+
context 'with encoded password reset token' do
|
|
772
|
+
let(:password_reset_token) do
|
|
773
|
+
URI.encode(application.password_reset_tokens.create(email: account.email).token, '.')
|
|
774
|
+
end
|
|
775
|
+
it 'retrieves the account with the reset password' do
|
|
776
|
+
expect(reset_password_account).to be
|
|
777
|
+
expect(reset_password_account.email).to eq(account.email)
|
|
778
|
+
end
|
|
767
779
|
end
|
|
768
780
|
|
|
769
781
|
context 'and if the password is changed' do
|
|
@@ -1041,44 +1053,130 @@ describe Stormpath::Resource::Application, :vcr do
|
|
|
1041
1053
|
|
|
1042
1054
|
before { account }
|
|
1043
1055
|
|
|
1044
|
-
context 'generate access token' do
|
|
1056
|
+
context 'generate access token from password grant request' do
|
|
1045
1057
|
let(:password_grant_request) { Stormpath::Oauth::PasswordGrantRequest.new account_data[:email], account_data[:password] }
|
|
1046
1058
|
let(:authenticate_oauth) { application.authenticate_oauth(password_grant_request) }
|
|
1047
1059
|
|
|
1048
|
-
|
|
1049
|
-
|
|
1060
|
+
context 'without organization_name_key' do
|
|
1061
|
+
it 'should return access token response' do
|
|
1062
|
+
expect(authenticate_oauth).to be_kind_of(Stormpath::Oauth::AccessTokenAuthenticationResult)
|
|
1063
|
+
end
|
|
1064
|
+
|
|
1065
|
+
it 'response should contain token data' do
|
|
1066
|
+
expect(authenticate_oauth.access_token).not_to be_empty
|
|
1067
|
+
expect(authenticate_oauth.refresh_token).not_to be_empty
|
|
1068
|
+
expect(authenticate_oauth.token_type).not_to be_empty
|
|
1069
|
+
expect(authenticate_oauth.expires_in).not_to be_nil
|
|
1070
|
+
expect(authenticate_oauth.stormpath_access_token_href).not_to be_empty
|
|
1071
|
+
end
|
|
1050
1072
|
end
|
|
1051
1073
|
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1074
|
+
context 'with the organization name key' do
|
|
1075
|
+
let!(:organization) do
|
|
1076
|
+
test_api_client.organizations.create name: 'rspec-test-org', name_key: 'rspec-test-org'
|
|
1077
|
+
end
|
|
1078
|
+
let(:account_directory) do
|
|
1079
|
+
test_api_client.directories.create(
|
|
1080
|
+
name: 'rspec-directory'
|
|
1081
|
+
)
|
|
1082
|
+
end
|
|
1083
|
+
let(:reloaded_account_directory) do
|
|
1084
|
+
test_api_client.directories.get(account_directory.href)
|
|
1085
|
+
end
|
|
1086
|
+
let(:password_grant_request) do
|
|
1087
|
+
Stormpath::Oauth::PasswordGrantRequest.new(account_data[:email],
|
|
1088
|
+
account_data[:password],
|
|
1089
|
+
organization_name_key: 'rspec-test-org')
|
|
1090
|
+
end
|
|
1091
|
+
|
|
1092
|
+
after do
|
|
1093
|
+
organization.delete
|
|
1094
|
+
reloaded_account_directory.delete
|
|
1095
|
+
end
|
|
1096
|
+
|
|
1097
|
+
before do
|
|
1098
|
+
test_api_client.account_store_mappings.create(
|
|
1099
|
+
application: application,
|
|
1100
|
+
account_store: organization
|
|
1101
|
+
)
|
|
1102
|
+
|
|
1103
|
+
test_api_client.organization_account_store_mappings.create(
|
|
1104
|
+
account_store: { href: account_directory.href },
|
|
1105
|
+
organization: { href: organization.href }
|
|
1106
|
+
)
|
|
1107
|
+
|
|
1108
|
+
account_directory.accounts.create account_data
|
|
1109
|
+
end
|
|
1110
|
+
|
|
1111
|
+
it 'should return access token response' do
|
|
1112
|
+
expect(authenticate_oauth).to be_kind_of(Stormpath::Oauth::AccessTokenAuthenticationResult)
|
|
1113
|
+
end
|
|
1114
|
+
|
|
1115
|
+
it 'response should contain token data' do
|
|
1116
|
+
expect(authenticate_oauth.access_token).not_to be_empty
|
|
1117
|
+
expect(authenticate_oauth.refresh_token).not_to be_empty
|
|
1118
|
+
expect(authenticate_oauth.token_type).not_to be_empty
|
|
1119
|
+
expect(authenticate_oauth.expires_in).not_to be_nil
|
|
1120
|
+
expect(authenticate_oauth.stormpath_access_token_href).not_to be_empty
|
|
1121
|
+
end
|
|
1122
|
+
|
|
1123
|
+
it 'access and refresh token should contain org in payload' do
|
|
1124
|
+
jw_access = JWT.decode(authenticate_oauth.access_token, test_api_client.data_store.api_key.secret)
|
|
1125
|
+
jw_refresh = JWT.decode(authenticate_oauth.refresh_token, test_api_client.data_store.api_key.secret)
|
|
1126
|
+
expect(jw_access.first).to include('org')
|
|
1127
|
+
expect(jw_refresh.first).to include('org')
|
|
1128
|
+
end
|
|
1058
1129
|
end
|
|
1059
1130
|
end
|
|
1060
1131
|
|
|
1061
|
-
context 'generate access token from
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1132
|
+
context 'generate access token from stormpath_token grant request' do
|
|
1133
|
+
context 'where status authenticated' do
|
|
1134
|
+
let(:stormpath_grant_request) do
|
|
1135
|
+
Stormpath::Oauth::StormpathGrantRequest.new(
|
|
1136
|
+
account,
|
|
1137
|
+
application,
|
|
1138
|
+
test_api_client.data_store.api_key
|
|
1139
|
+
)
|
|
1140
|
+
end
|
|
1069
1141
|
|
|
1070
|
-
|
|
1142
|
+
let(:authenticate_oauth) { application.authenticate_oauth(stormpath_grant_request) }
|
|
1071
1143
|
|
|
1072
|
-
|
|
1073
|
-
|
|
1144
|
+
it 'should return access token response' do
|
|
1145
|
+
expect(authenticate_oauth).to be_kind_of(Stormpath::Oauth::AccessTokenAuthenticationResult)
|
|
1146
|
+
end
|
|
1147
|
+
|
|
1148
|
+
it 'response should contain token data' do
|
|
1149
|
+
expect(authenticate_oauth.access_token).not_to be_empty
|
|
1150
|
+
expect(authenticate_oauth.refresh_token).not_to be_empty
|
|
1151
|
+
expect(authenticate_oauth.token_type).not_to be_empty
|
|
1152
|
+
expect(authenticate_oauth.expires_in).not_to be_nil
|
|
1153
|
+
expect(authenticate_oauth.stormpath_access_token_href).not_to be_empty
|
|
1154
|
+
end
|
|
1074
1155
|
end
|
|
1075
1156
|
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1157
|
+
context 'where status registered' do
|
|
1158
|
+
let(:stormpath_grant_request) do
|
|
1159
|
+
Stormpath::Oauth::StormpathGrantRequest.new(
|
|
1160
|
+
account,
|
|
1161
|
+
application,
|
|
1162
|
+
test_api_client.data_store.api_key,
|
|
1163
|
+
:registered
|
|
1164
|
+
)
|
|
1165
|
+
end
|
|
1166
|
+
|
|
1167
|
+
let(:authenticate_oauth) { application.authenticate_oauth(stormpath_grant_request) }
|
|
1168
|
+
|
|
1169
|
+
it 'should return access token response' do
|
|
1170
|
+
expect(authenticate_oauth).to be_kind_of(Stormpath::Oauth::AccessTokenAuthenticationResult)
|
|
1171
|
+
end
|
|
1172
|
+
|
|
1173
|
+
it 'response should contain token data' do
|
|
1174
|
+
expect(authenticate_oauth.access_token).not_to be_empty
|
|
1175
|
+
expect(authenticate_oauth.refresh_token).not_to be_empty
|
|
1176
|
+
expect(authenticate_oauth.token_type).not_to be_empty
|
|
1177
|
+
expect(authenticate_oauth.expires_in).not_to be_nil
|
|
1178
|
+
expect(authenticate_oauth.stormpath_access_token_href).not_to be_empty
|
|
1179
|
+
end
|
|
1082
1180
|
end
|
|
1083
1181
|
end
|
|
1084
1182
|
|
|
@@ -1100,13 +1198,112 @@ describe Stormpath::Resource::Application, :vcr do
|
|
|
1100
1198
|
|
|
1101
1199
|
it 'response should contain token data' do
|
|
1102
1200
|
expect(authenticate_oauth.access_token).not_to be_empty
|
|
1103
|
-
expect(authenticate_oauth.refresh_token).not_to be_empty
|
|
1104
1201
|
expect(authenticate_oauth.token_type).not_to be_empty
|
|
1105
1202
|
expect(authenticate_oauth.expires_in).not_to be_nil
|
|
1106
1203
|
expect(authenticate_oauth.stormpath_access_token_href).not_to be_empty
|
|
1107
1204
|
end
|
|
1108
1205
|
end
|
|
1109
1206
|
|
|
1207
|
+
context 'generate access token from stormpath_social grant request' do
|
|
1208
|
+
let(:authenticate_oauth) { application.authenticate_oauth(social_grant_request) }
|
|
1209
|
+
|
|
1210
|
+
context 'google' do
|
|
1211
|
+
let(:code) { '4/WByqYc1UOvcYluBOsFyFbm8_BIZHbjklC5iEz7AdXcA' }
|
|
1212
|
+
let(:social_grant_request) do
|
|
1213
|
+
Stormpath::Oauth::SocialGrantRequest.new(:google, code: code)
|
|
1214
|
+
end
|
|
1215
|
+
before do
|
|
1216
|
+
stub_request(:post,
|
|
1217
|
+
"https://#{test_api_key_id}:#{test_api_key_secret}@api.stormpath.com/v1/applications/#{application.href.split('/').last}/oauth/token")
|
|
1218
|
+
.to_return(body: Stormpath::Test.mocked_social_grant_response)
|
|
1219
|
+
end
|
|
1220
|
+
|
|
1221
|
+
it 'should return access token response' do
|
|
1222
|
+
expect(authenticate_oauth).to be_kind_of(Stormpath::Oauth::AccessTokenAuthenticationResult)
|
|
1223
|
+
end
|
|
1224
|
+
|
|
1225
|
+
it 'response should contain token data' do
|
|
1226
|
+
expect(authenticate_oauth.access_token).not_to be_empty
|
|
1227
|
+
expect(authenticate_oauth.refresh_token).not_to be_empty
|
|
1228
|
+
expect(authenticate_oauth.token_type).not_to be_empty
|
|
1229
|
+
expect(authenticate_oauth.expires_in).not_to be_nil
|
|
1230
|
+
expect(authenticate_oauth.stormpath_access_token_href).not_to be_empty
|
|
1231
|
+
end
|
|
1232
|
+
end
|
|
1233
|
+
|
|
1234
|
+
context 'linkedin' do
|
|
1235
|
+
let(:code) { '4/WByqYc1UOvcYluBOsFyFbm8_BIZHbjklC5iEz7AdXcA' }
|
|
1236
|
+
let(:social_grant_request) do
|
|
1237
|
+
Stormpath::Oauth::SocialGrantRequest.new(:linkedin, code: code)
|
|
1238
|
+
end
|
|
1239
|
+
before do
|
|
1240
|
+
stub_request(:post,
|
|
1241
|
+
"https://#{test_api_key_id}:#{test_api_key_secret}@api.stormpath.com/v1/applications/#{application.href.split('/').last}/oauth/token")
|
|
1242
|
+
.to_return(body: Stormpath::Test.mocked_social_grant_response)
|
|
1243
|
+
end
|
|
1244
|
+
|
|
1245
|
+
it 'should return access token response' do
|
|
1246
|
+
expect(authenticate_oauth).to be_kind_of(Stormpath::Oauth::AccessTokenAuthenticationResult)
|
|
1247
|
+
end
|
|
1248
|
+
|
|
1249
|
+
it 'response should contain token data' do
|
|
1250
|
+
expect(authenticate_oauth.access_token).not_to be_empty
|
|
1251
|
+
expect(authenticate_oauth.refresh_token).not_to be_empty
|
|
1252
|
+
expect(authenticate_oauth.token_type).not_to be_empty
|
|
1253
|
+
expect(authenticate_oauth.expires_in).not_to be_nil
|
|
1254
|
+
expect(authenticate_oauth.stormpath_access_token_href).not_to be_empty
|
|
1255
|
+
end
|
|
1256
|
+
end
|
|
1257
|
+
|
|
1258
|
+
context 'facebook' do
|
|
1259
|
+
let(:access_token) { '4/WByqYc1UOvcYluBOsFyFbm8_BIZHbjklC5iEz7AdXcA' }
|
|
1260
|
+
let(:social_grant_request) do
|
|
1261
|
+
Stormpath::Oauth::SocialGrantRequest.new(:google, access_token: access_token)
|
|
1262
|
+
end
|
|
1263
|
+
before do
|
|
1264
|
+
stub_request(:post,
|
|
1265
|
+
"https://#{test_api_key_id}:#{test_api_key_secret}@api.stormpath.com/v1/applications/#{application.href.split('/').last}/oauth/token")
|
|
1266
|
+
.to_return(body: Stormpath::Test.mocked_social_grant_response)
|
|
1267
|
+
end
|
|
1268
|
+
|
|
1269
|
+
it 'should return access token response' do
|
|
1270
|
+
expect(authenticate_oauth).to be_kind_of(Stormpath::Oauth::AccessTokenAuthenticationResult)
|
|
1271
|
+
end
|
|
1272
|
+
|
|
1273
|
+
it 'response should contain token data' do
|
|
1274
|
+
expect(authenticate_oauth.access_token).not_to be_empty
|
|
1275
|
+
expect(authenticate_oauth.refresh_token).not_to be_empty
|
|
1276
|
+
expect(authenticate_oauth.token_type).not_to be_empty
|
|
1277
|
+
expect(authenticate_oauth.expires_in).not_to be_nil
|
|
1278
|
+
expect(authenticate_oauth.stormpath_access_token_href).not_to be_empty
|
|
1279
|
+
end
|
|
1280
|
+
end
|
|
1281
|
+
|
|
1282
|
+
context 'github' do
|
|
1283
|
+
let(:access_token) { '4/WByqYc1UOvcYluBOsFyFbm8_BIZHbjklC5iEz7AdXcA' }
|
|
1284
|
+
let(:social_grant_request) do
|
|
1285
|
+
Stormpath::Oauth::SocialGrantRequest.new(:github, access_token: access_token)
|
|
1286
|
+
end
|
|
1287
|
+
before do
|
|
1288
|
+
stub_request(:post,
|
|
1289
|
+
"https://#{test_api_key_id}:#{test_api_key_secret}@api.stormpath.com/v1/applications/#{application.href.split('/').last}/oauth/token")
|
|
1290
|
+
.to_return(body: Stormpath::Test.mocked_social_grant_response)
|
|
1291
|
+
end
|
|
1292
|
+
|
|
1293
|
+
it 'should return access token response' do
|
|
1294
|
+
expect(authenticate_oauth).to be_kind_of(Stormpath::Oauth::AccessTokenAuthenticationResult)
|
|
1295
|
+
end
|
|
1296
|
+
|
|
1297
|
+
it 'response should contain token data' do
|
|
1298
|
+
expect(authenticate_oauth.access_token).not_to be_empty
|
|
1299
|
+
expect(authenticate_oauth.refresh_token).not_to be_empty
|
|
1300
|
+
expect(authenticate_oauth.token_type).not_to be_empty
|
|
1301
|
+
expect(authenticate_oauth.expires_in).not_to be_nil
|
|
1302
|
+
expect(authenticate_oauth.stormpath_access_token_href).not_to be_empty
|
|
1303
|
+
end
|
|
1304
|
+
end
|
|
1305
|
+
end
|
|
1306
|
+
|
|
1110
1307
|
context 'exchange id site token for access_token with invalid jwt' do
|
|
1111
1308
|
let(:invalid_jwt_token) { 'invalid_token' }
|
|
1112
1309
|
|
|
@@ -1167,23 +1364,43 @@ describe Stormpath::Resource::Application, :vcr do
|
|
|
1167
1364
|
end
|
|
1168
1365
|
|
|
1169
1366
|
context 'validate access token' do
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1367
|
+
context 'remotely' do
|
|
1368
|
+
let(:access_token) { aquire_token.access_token }
|
|
1369
|
+
let(:authenticate_oauth) do
|
|
1370
|
+
Stormpath::Oauth::VerifyAccessToken.new(application).verify(access_token)
|
|
1371
|
+
end
|
|
1372
|
+
|
|
1373
|
+
it 'should return authentication result response' do
|
|
1374
|
+
expect(authenticate_oauth).to be_kind_of(Stormpath::Oauth::VerifyTokenResult)
|
|
1375
|
+
end
|
|
1376
|
+
|
|
1377
|
+
it 'returns success on valid token' do
|
|
1378
|
+
expect(authenticate_oauth.href).not_to be_empty
|
|
1379
|
+
expect(authenticate_oauth.account).to be_a(Stormpath::Resource::Account)
|
|
1380
|
+
expect(authenticate_oauth.account).to eq(account)
|
|
1381
|
+
expect(authenticate_oauth.application).to be_a(Stormpath::Resource::Application)
|
|
1382
|
+
expect(authenticate_oauth.application).to eq(application)
|
|
1383
|
+
expect(authenticate_oauth.jwt).not_to be_empty
|
|
1384
|
+
expect(authenticate_oauth.tenant).to be_a(Stormpath::Resource::Tenant)
|
|
1385
|
+
expect(authenticate_oauth.tenant).to eq(test_api_client.tenant)
|
|
1386
|
+
expect(authenticate_oauth.expanded_jwt).not_to be_empty
|
|
1387
|
+
end
|
|
1388
|
+
end
|
|
1389
|
+
|
|
1390
|
+
context 'locally' do
|
|
1391
|
+
let(:access_token) { aquire_token.access_token }
|
|
1392
|
+
let(:authenticate_oauth) do
|
|
1393
|
+
Stormpath::Oauth::VerifyAccessToken.new(application, local: true).verify(access_token)
|
|
1394
|
+
end
|
|
1395
|
+
|
|
1396
|
+
it 'should return local access token verification result' do
|
|
1397
|
+
expect(authenticate_oauth)
|
|
1398
|
+
.to be_kind_of(Stormpath::Oauth::LocalAccessTokenVerificationResult)
|
|
1399
|
+
end
|
|
1400
|
+
|
|
1401
|
+
it 'should return result that contains account' do
|
|
1402
|
+
expect(authenticate_oauth.account).to eq(account)
|
|
1403
|
+
end
|
|
1187
1404
|
end
|
|
1188
1405
|
end
|
|
1189
1406
|
|
data/spec/resource/base_spec.rb
CHANGED
|
File without changes
|
|
@@ -277,7 +277,7 @@ describe Stormpath::Resource::Collection, :vcr do
|
|
|
277
277
|
|
|
278
278
|
# !@#$%^&*()_-+=?><:]}[{'
|
|
279
279
|
# 'jlpicard/!@$%^*()_-+&=?><:]}[{'
|
|
280
|
-
let(:username) { 'jlpicard/!@$%^ *()_
|
|
280
|
+
let(:username) { 'jlpicard/!@$%^ *()_-+=?><]}[{' }
|
|
281
281
|
|
|
282
282
|
let!(:account) do
|
|
283
283
|
directory.accounts.create username: username,
|
|
@@ -364,6 +364,64 @@ describe Stormpath::Resource::Collection, :vcr do
|
|
|
364
364
|
end
|
|
365
365
|
end
|
|
366
366
|
|
|
367
|
-
|
|
367
|
+
context 'search accounts by custom data' do
|
|
368
|
+
let(:directory) { test_api_client.directories.create name: random_directory_name }
|
|
369
|
+
|
|
370
|
+
let(:account) do
|
|
371
|
+
directory.accounts.create(
|
|
372
|
+
username: 'jlpicard',
|
|
373
|
+
email: 'capt@enterprise.com',
|
|
374
|
+
givenName: 'Jean-Luc',
|
|
375
|
+
surname: 'Picard',
|
|
376
|
+
password: 'hakunaMatata179Enterprise'
|
|
377
|
+
)
|
|
378
|
+
end
|
|
379
|
+
|
|
380
|
+
let(:account2) do
|
|
381
|
+
directory.accounts.create(
|
|
382
|
+
username: 'jlpicard2',
|
|
383
|
+
email: 'capt2@enterprise.com',
|
|
384
|
+
givenName: 'Jean-Luc2',
|
|
385
|
+
surname: 'Picard2',
|
|
386
|
+
password: 'hakunaMatata179Enterprise'
|
|
387
|
+
)
|
|
388
|
+
end
|
|
389
|
+
|
|
390
|
+
after do
|
|
391
|
+
directory.delete
|
|
392
|
+
end
|
|
368
393
|
|
|
394
|
+
context 'camelCase' do
|
|
395
|
+
before do
|
|
396
|
+
account.custom_data['targetAttribute'] = 'findMe'
|
|
397
|
+
account2.custom_data['targetAttribute'] = 'findMe'
|
|
398
|
+
account.save
|
|
399
|
+
account2.save
|
|
400
|
+
end
|
|
401
|
+
|
|
402
|
+
it 'should search accounts by custom data attribute' do
|
|
403
|
+
expect(account.custom_data['targetAttribute']).to eq 'findMe'
|
|
404
|
+
expect(directory.accounts.count).to eq 2
|
|
405
|
+
sleep 1
|
|
406
|
+
expect(directory.accounts.search('customData.targetAttribute' => 'findMe').count).to eq(2)
|
|
407
|
+
end
|
|
408
|
+
end
|
|
409
|
+
|
|
410
|
+
context 'snake_case' do
|
|
411
|
+
before do
|
|
412
|
+
account.custom_data['target_attribute'] = 'findMe'
|
|
413
|
+
account2.custom_data['target_attribute'] = 'findMe'
|
|
414
|
+
account.save
|
|
415
|
+
account2.save
|
|
416
|
+
end
|
|
417
|
+
|
|
418
|
+
it 'should be able to fetch custom data attributes with snake case' do
|
|
419
|
+
expect(account.custom_data['target_attribute']).to eq 'findMe'
|
|
420
|
+
expect(directory.accounts.count).to eq 2
|
|
421
|
+
sleep 1
|
|
422
|
+
expect(directory.accounts.search('customData.target_attribute' => 'findMe').count).to eq(2)
|
|
423
|
+
end
|
|
424
|
+
end
|
|
425
|
+
end
|
|
426
|
+
end
|
|
369
427
|
end
|
|
File without changes
|
|
@@ -83,7 +83,56 @@ describe Stormpath::Resource::Directory, :vcr do
|
|
|
83
83
|
end
|
|
84
84
|
|
|
85
85
|
it 'should be able to create and get a group' do
|
|
86
|
-
expect(directory.groups.get
|
|
86
|
+
expect(directory.groups.get(group.href)).to be
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
context 'search' do
|
|
90
|
+
before do
|
|
91
|
+
directory.groups.create(name: 'US group', description: 'Described groups from United S.')
|
|
92
|
+
directory.groups.create(name: 'EU group', description: 'Described groups from Europe')
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
it 'should return groups by name' do
|
|
96
|
+
expect(directory.groups.search(name: 'US group').count).to eq 1
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
it 'should return groups by description' do
|
|
100
|
+
expect(directory.groups.search(description: 'Described groups from Europe').count).to eq 1
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
it 'should return groups when searching name with asterisks' do
|
|
104
|
+
expect(directory.groups.search(name: '*US*').count).to eq 1
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
it 'should return groups when searching description with asterisks' do
|
|
108
|
+
expect(directory.groups.search(description: '*groups*').count).to eq 2
|
|
109
|
+
end
|
|
110
|
+
end
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
context '#organizations' do
|
|
114
|
+
let(:organization) do
|
|
115
|
+
test_api_client.organizations.create(name: 'Test organization name',
|
|
116
|
+
name_key: 'test-organization-name-key')
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
let!(:organization_account_store_mappings) do
|
|
120
|
+
test_api_client.organization_account_store_mappings.create(
|
|
121
|
+
account_store: { href: directory.href },
|
|
122
|
+
organization: { href: organization.href }
|
|
123
|
+
)
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
after do
|
|
127
|
+
organization.delete
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
it 'should be able to get organizations' do
|
|
131
|
+
expect(directory.organizations).to include(organization)
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
it 'should be able to get specific organization with organization href' do
|
|
135
|
+
expect(directory.organizations.get(organization.href)).to eq organization
|
|
87
136
|
end
|
|
88
137
|
end
|
|
89
138
|
|
|
@@ -239,6 +288,38 @@ describe Stormpath::Resource::Directory, :vcr do
|
|
|
239
288
|
end
|
|
240
289
|
end
|
|
241
290
|
|
|
291
|
+
context "BCrypt 2A hashing algorithm" do
|
|
292
|
+
before do
|
|
293
|
+
account_store_mapping
|
|
294
|
+
@account = directory.accounts.create({
|
|
295
|
+
username: "jlucpicard",
|
|
296
|
+
email: "captain@enterprise.com",
|
|
297
|
+
given_name: "Jean-Luc",
|
|
298
|
+
surname: "Picard",
|
|
299
|
+
password: "$2a$10$sWvxHJIvkARbp.u2yBpuJeGzNvpxYQo7AYxAJwFRH0HptXSWyqvwy"
|
|
300
|
+
}, password_format: 'mcf')
|
|
301
|
+
end
|
|
302
|
+
|
|
303
|
+
it 'creates an account' do
|
|
304
|
+
expect(@account).to be_a Stormpath::Resource::Account
|
|
305
|
+
expect(@account.username).to eq("jlucpicard")
|
|
306
|
+
expect(@account.email).to eq("captain@enterprise.com")
|
|
307
|
+
expect(@account.given_name).to eq("Jean-Luc")
|
|
308
|
+
expect(@account.surname).to eq("Picard")
|
|
309
|
+
end
|
|
310
|
+
|
|
311
|
+
it 'can authenticate with the account credentials' do
|
|
312
|
+
auth_request = Stormpath::Authentication::UsernamePasswordRequest.new 'jlucpicard', 'NotSecure'
|
|
313
|
+
auth_result = application.authenticate_account auth_request
|
|
314
|
+
|
|
315
|
+
expect(auth_result).to be_a Stormpath::Authentication::AuthenticationResult
|
|
316
|
+
expect(auth_result.account).to be_a Stormpath::Resource::Account
|
|
317
|
+
expect(auth_result.account.email).to eq("captain@enterprise.com")
|
|
318
|
+
expect(auth_result.account.given_name).to eq("Jean-Luc")
|
|
319
|
+
expect(auth_result.account.surname).to eq("Picard")
|
|
320
|
+
end
|
|
321
|
+
end
|
|
322
|
+
|
|
242
323
|
context 'with account data as hash' do
|
|
243
324
|
let(:account_email) { random_email }
|
|
244
325
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
data/spec/resource/group_spec.rb
CHANGED
|
File without changes
|
|
@@ -3,7 +3,7 @@ require 'spec_helper'
|
|
|
3
3
|
describe Stormpath::Resource::Organization, :vcr do
|
|
4
4
|
|
|
5
5
|
let(:organization) do
|
|
6
|
-
test_api_client.organizations.create name: '
|
|
6
|
+
test_api_client.organizations.create name: 'test_ruby_organization',
|
|
7
7
|
name_key: "testorganization", description: 'test organization'
|
|
8
8
|
end
|
|
9
9
|
|
|
@@ -11,11 +11,13 @@ describe Stormpath::Resource::Organization, :vcr do
|
|
|
11
11
|
organization.delete if organization
|
|
12
12
|
end
|
|
13
13
|
|
|
14
|
-
def create_organization_account_store_mapping(organization, account_store)
|
|
15
|
-
test_api_client.organization_account_store_mappings.create(
|
|
14
|
+
def create_organization_account_store_mapping(organization, account_store, options = {})
|
|
15
|
+
test_api_client.organization_account_store_mappings.create(
|
|
16
16
|
account_store: { href: account_store.href },
|
|
17
|
-
organization: { href: organization.href }
|
|
18
|
-
|
|
17
|
+
organization: { href: organization.href },
|
|
18
|
+
is_default_account_store: options[:default_account_store] || false,
|
|
19
|
+
is_default_group_store: options[:default_group_store] || false
|
|
20
|
+
)
|
|
19
21
|
end
|
|
20
22
|
|
|
21
23
|
describe "instances should respond to attribute property methods" do
|
|
@@ -93,10 +95,27 @@ describe Stormpath::Resource::Organization, :vcr do
|
|
|
93
95
|
context 'accounts' do
|
|
94
96
|
let(:directory) { test_api_client.directories.create name: random_directory_name }
|
|
95
97
|
|
|
96
|
-
let(:account)
|
|
98
|
+
let(:account) do
|
|
99
|
+
directory.accounts.create(
|
|
100
|
+
email: 'rubysdk@example.com',
|
|
101
|
+
given_name: 'Ruby SDK',
|
|
102
|
+
password: 'P@$$w0rd',
|
|
103
|
+
surname: 'SDK'
|
|
104
|
+
)
|
|
105
|
+
end
|
|
106
|
+
let(:org_account) do
|
|
107
|
+
organization.accounts.create(
|
|
108
|
+
email: 'rubysdk2@example.com',
|
|
109
|
+
given_name: 'Ruby SDK',
|
|
110
|
+
password: 'P@$$w0rd',
|
|
111
|
+
surname: 'SDK'
|
|
112
|
+
)
|
|
113
|
+
end
|
|
97
114
|
|
|
98
115
|
before do
|
|
99
|
-
create_organization_account_store_mapping(organization,
|
|
116
|
+
create_organization_account_store_mapping(organization,
|
|
117
|
+
directory,
|
|
118
|
+
default_account_store: true)
|
|
100
119
|
end
|
|
101
120
|
|
|
102
121
|
after do
|
|
@@ -104,10 +123,20 @@ describe Stormpath::Resource::Organization, :vcr do
|
|
|
104
123
|
directory.delete if directory
|
|
105
124
|
end
|
|
106
125
|
|
|
107
|
-
it 'returns a collection of
|
|
126
|
+
it 'returns a collection of accounts' do
|
|
108
127
|
expect(organization.accounts).to be_kind_of(Stormpath::Resource::Collection)
|
|
109
128
|
expect(organization.accounts).to include(account)
|
|
110
129
|
end
|
|
130
|
+
|
|
131
|
+
it 'can create another account' do
|
|
132
|
+
expect(org_account).to be_kind_of(Stormpath::Resource::Account)
|
|
133
|
+
expect(organization.accounts).to include(org_account)
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
it 'can get a specific account' do
|
|
137
|
+
expect(org_account).to be_kind_of(Stormpath::Resource::Account)
|
|
138
|
+
expect(organization.accounts.get(org_account.href)).to eq org_account
|
|
139
|
+
end
|
|
111
140
|
end
|
|
112
141
|
|
|
113
142
|
context 'tenant' do
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|