stormpath-sdk 1.3.0 → 1.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. checksums.yaml +4 -4
  2. data/.rspec +1 -0
  3. data/.travis.yml +0 -3
  4. data/CHANGES.md +9 -0
  5. data/README.md +8 -21
  6. data/Rakefile +1 -15
  7. data/lib/stormpath-sdk/oauth/error.rb +21 -0
  8. data/lib/stormpath-sdk/oauth/local_access_token_verification.rb +2 -2
  9. data/lib/stormpath-sdk/oauth/remote_access_token_verification.rb +2 -2
  10. data/lib/stormpath-sdk/version.rb +2 -2
  11. data/spec/auth/http_basic_authentication_spec.rb +6 -21
  12. data/spec/auth/http_bearer_authentication_spec.rb +11 -24
  13. data/spec/client_spec.rb +116 -258
  14. data/spec/oauth/access_token_authentication_result_spec.rb +14 -14
  15. data/spec/provider/provider_spec.rb +32 -40
  16. data/spec/resource/account_creation_policy_spec.rb +8 -13
  17. data/spec/resource/account_link_spec.rb +4 -17
  18. data/spec/resource/account_spec.rb +37 -81
  19. data/spec/resource/account_store_mapping_spec.rb +20 -32
  20. data/spec/resource/account_store_spec.rb +8 -31
  21. data/spec/resource/api_key_spec.rb +11 -14
  22. data/spec/resource/application_spec.rb +39 -168
  23. data/spec/resource/collection_spec.rb +17 -17
  24. data/spec/resource/custom_data_spec.rb +2 -2
  25. data/spec/resource/directory_spec.rb +164 -240
  26. data/spec/resource/email_template_spec.rb +21 -24
  27. data/spec/resource/group_membership_spec.rb +9 -12
  28. data/spec/resource/group_spec.rb +17 -31
  29. data/spec/resource/linked_account_spec.rb +4 -17
  30. data/spec/resource/organization_spec.rb +38 -110
  31. data/spec/resource/password_policy_spec.rb +13 -16
  32. data/spec/resource/password_strength_spec.rb +15 -18
  33. data/spec/resource/status_spec.rb +32 -35
  34. data/spec/spec_helper.rb +8 -139
  35. data/spec/support/api_key_helpers.rb +34 -0
  36. data/spec/support/custom_data_storage_behavior.rb +139 -156
  37. data/spec/support/env_names_warning.rb +59 -0
  38. data/spec/support/resource_helpers.rb +84 -0
  39. data/spec/support/resource_matchers.rb +6 -0
  40. data/stormpath-sdk.gemspec +1 -0
  41. metadata +20 -3
  42. data/support/api.rb +0 -55
@@ -0,0 +1,59 @@
1
+ module Stormpath
2
+ module Test
3
+ module EnvNamesWarning
4
+ TEST_ENV_VARS = {
5
+ required: {
6
+ STORMPATH_CLIENT_APIKEY_ID: 'The id from your Stormpath API Key',
7
+ STORMPATH_CLIENT_APIKEY_SECRET: 'The secret from your Stormpath API Key'
8
+ },
9
+ deprecated: {
10
+ STORMPATH_SDK_TEST_API_KEY_ID: 'The id from your Stormpath API Key',
11
+ STORMPATH_SDK_TEST_API_KEY_SECRET: 'The secret from your Stormpath API Key'
12
+ }
13
+ }.freeze
14
+
15
+ def self.test_missing_deprecated_env_vars
16
+ TEST_ENV_VARS[:deprecated].reject do |var, _|
17
+ ENV[var.to_s]
18
+ end
19
+ end
20
+
21
+ def self.test_missing_required_env_vars
22
+ TEST_ENV_VARS[:required].reject do |var, _|
23
+ ENV[var.to_s]
24
+ end
25
+ end
26
+
27
+ def self.env_vars_not_set?
28
+ !test_missing_deprecated_env_vars.empty? && !test_missing_required_env_vars.empty?
29
+ end
30
+
31
+ def self.check_env_variable_names
32
+ unless Stormpath::Test::EnvNamesWarning.test_missing_required_env_vars.empty?
33
+ warn_message = "\n\n"
34
+ 40.times { warn_message << '*' }
35
+ warn_message << 'STORMPATH RUBY SDK'
36
+ 52.times { warn_message << '*' }
37
+ warn_message << "\n\n"
38
+ warn_message << TEST_ENV_VARS[:deprecated].map do |var, _|
39
+ "\t#{var} will be deprecated in the next release of the Ruby SDK."
40
+ end.join("\n")
41
+ warn_message << "\n\tPlease update your environment variables to use the new names:\n"
42
+ warn_message << "\n\t\texport STORMPATH_CLIENT_APIKEY_ID=your_api_key_id"
43
+ warn_message << "\n\t\texport STORMPATH_CLIENT_APIKEY_SECRET=your_api_key_secret\n\n"
44
+ 110.times { warn_message << '*' }
45
+ warn "#{warn_message}\n\n"
46
+ end
47
+
48
+ if Stormpath::Test::EnvNamesWarning.env_vars_not_set?
49
+ set_up_message = "In order to run the specs of the Stormpath SDK you need to setup the following environment variables:\n\t"
50
+ set_up_message << Stormpath::Test::EnvNamesWarning.test_missing_required_env_vars.map do |var, message|
51
+ "#{var} : #{message}"
52
+ end.join("\n\t")
53
+ set_up_message << "\nBe sure to configure these before running the specs again."
54
+ raise set_up_message
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,84 @@
1
+ module Stormpath
2
+ module Test
3
+ module ResourceHelpers
4
+ def build_account(opts = {})
5
+ opts.tap do |o|
6
+ if !opts[:email].blank? && opts[:email]
7
+ if opts[:email].include?('@')
8
+ raise ArgumentError, "Invalid email format. Please send the email without the domain. For example, 'anakin.skywalker', instead of 'anakin.skywalker@darkside.com'"
9
+ end
10
+ o[:email] = "#{opts[:email]}#{default_domain}"
11
+ else
12
+ o[:email] = "ruby#{random_number}#{default_domain}"
13
+ end
14
+ o[:username] = (!opts[:username].blank? && opts[:username]) || "ruby#{random_number}"
15
+ o[:password] = (!opts[:password].blank? && opts[:password]) || 'P@$$w0rd'
16
+ o[:surname] = (!opts[:surname].blank? && opts[:surname]) || 'surname'
17
+ o[:given_name] = (!opts[:given_name].blank? && opts[:given_name]) || 'givenname'
18
+ o[:middle_name] = (!opts[:middle_name].blank? && opts[:middle_name]) || 'middle_name'
19
+ o[:status] = (!opts[:status].blank? && opts[:status]) || 'ENABLED'
20
+ end
21
+ end
22
+
23
+ def default_domain
24
+ '@testmail.stormpath.com'
25
+ end
26
+
27
+ def build_application(opts = {})
28
+ opts.tap do |o|
29
+ o[:name] = (!opts[:name].blank? && opts[:name]) || "ruby#{random_number}-app"
30
+ o[:description] = (!opts[:description].blank? && opts[:description]) || "ruby#{random_number}-desc"
31
+ end
32
+ end
33
+
34
+ def build_directory(opts = {})
35
+ opts.tap do |o|
36
+ o[:name] = (!opts[:name].blank? && opts[:name]) || "ruby#{random_number}-dir"
37
+ o[:description] = (!opts[:description].blank? && opts[:description]) || "ruby#{random_number}-desc"
38
+ end
39
+ end
40
+
41
+ def build_organization(opts = {})
42
+ opts.tap do |o|
43
+ o[:name] = (!opts[:name].blank? && opts[:name]) || "ruby#{random_number}-org"
44
+ o[:name_key] = (!opts[:name_key].blank? && opts[:name_key]) || "ruby#{random_number}-org"
45
+ end
46
+ end
47
+
48
+ def build_group(opts = {})
49
+ opts.tap do |o|
50
+ o[:name] = (!opts[:name].blank? && opts[:name]) || "ruby#{random_number}-group"
51
+ end
52
+ end
53
+
54
+ def enable_email_verification(directory)
55
+ directory.account_creation_policy.verification_email_status = 'ENABLED'
56
+ directory.account_creation_policy.verification_success_email_status = 'ENABLED'
57
+ directory.account_creation_policy.welcome_email_status = 'ENABLED'
58
+ directory.account_creation_policy.save
59
+ end
60
+
61
+ def map_account_store(app, store, index, default_account_store, default_group_store)
62
+ test_api_client.account_store_mappings.create(
63
+ application: app,
64
+ account_store: store,
65
+ list_index: index,
66
+ is_default_account_store: default_account_store,
67
+ is_default_group_store: default_group_store
68
+ )
69
+ end
70
+
71
+ def map_organization_store(account_store, organization, default_account_store = false)
72
+ test_api_client.organization_account_store_mappings.create(
73
+ account_store: { href: account_store.href },
74
+ organization: { href: organization.href },
75
+ is_default_account_store: default_account_store
76
+ )
77
+ end
78
+
79
+ def random_number
80
+ Random.rand(1..10_000)
81
+ end
82
+ end
83
+ end
84
+ end
@@ -32,3 +32,9 @@ RSpec::Matchers.define :have_stt_in_header do |expected|
32
32
  header.include?('stt') && header['stt'] == expected
33
33
  end
34
34
  end
35
+
36
+ RSpec::Matchers.define :be_boolean do
37
+ match do |actual|
38
+ actual == true || actual == false
39
+ end
40
+ end
@@ -40,6 +40,7 @@ Gem::Specification.new do |s|
40
40
  s.add_development_dependency 'redis', '~> 3.0.4'
41
41
  s.add_development_dependency 'memcached', '~> 1.8.0'
42
42
  s.add_development_dependency 'listen', '~> 3.0.6'
43
+ s.add_development_dependency 'fivemat', '~> 1.3.2'
43
44
 
44
45
  s.rdoc_options = ['--line-numbers', '--inline-source', '--title', 'stormpath-sdk', '--main']
45
46
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stormpath-sdk
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stormpath, Inc
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-11-04 00:00:00.000000000 Z
12
+ date: 2016-11-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: multi_json
@@ -291,6 +291,20 @@ dependencies:
291
291
  - - "~>"
292
292
  - !ruby/object:Gem::Version
293
293
  version: 3.0.6
294
+ - !ruby/object:Gem::Dependency
295
+ name: fivemat
296
+ requirement: !ruby/object:Gem::Requirement
297
+ requirements:
298
+ - - "~>"
299
+ - !ruby/object:Gem::Version
300
+ version: 1.3.2
301
+ type: :development
302
+ prerelease: false
303
+ version_requirements: !ruby/object:Gem::Requirement
304
+ requirements:
305
+ - - "~>"
306
+ - !ruby/object:Gem::Version
307
+ version: 1.3.2
294
308
  description: Stormpath SDK used to interact with the Stormpath REST API
295
309
  email: support@stormpath.com
296
310
  executables: []
@@ -298,6 +312,7 @@ extensions: []
298
312
  extra_rdoc_files: []
299
313
  files:
300
314
  - ".gitignore"
315
+ - ".rspec"
301
316
  - ".ruby-gemset"
302
317
  - ".travis.yml"
303
318
  - CHANGES.md
@@ -445,15 +460,17 @@ files:
445
460
  - spec/resource/status_spec.rb
446
461
  - spec/resource/tenant_spec.rb
447
462
  - spec/spec_helper.rb
463
+ - spec/support/api_key_helpers.rb
448
464
  - spec/support/custom_data_storage_behavior.rb
465
+ - spec/support/env_names_warning.rb
449
466
  - spec/support/mocked_provider_accounts.rb
450
467
  - spec/support/resource_factory.rb
468
+ - spec/support/resource_helpers.rb
451
469
  - spec/support/resource_matchers.rb
452
470
  - spec/support/test_cache_stores.rb
453
471
  - spec/support/test_request_executor.rb
454
472
  - spec/util/uri_builder_spec.rb
455
473
  - stormpath-sdk.gemspec
456
- - support/api.rb
457
474
  homepage: https://github.com/stormpath/stormpath-sdk-ruby
458
475
  licenses:
459
476
  - Apache-2.0
@@ -1,55 +0,0 @@
1
- module Stormpath
2
- module Support
3
- class Api
4
- def self.destroy_resources(
5
- api_key_id, api_key_secret, application_url,
6
- directory_url, directory_with_verification_url
7
- )
8
-
9
- api_key = Stormpath::ApiKey.new(
10
- api_key_id, api_key_secret
11
- )
12
-
13
- Stormpath::Client.new(api_key: api_key).tap do |client|
14
- delete_applications client.applications, application_url
15
-
16
- client.directories.each do |dir|
17
- delete_accounts dir.accounts
18
-
19
- unless [directory_url, directory_with_verification_url].include? dir.href
20
- delete_directory dir
21
- end
22
- end
23
- end
24
- end
25
-
26
- def self.delete_applications applications, application_url
27
- applications.each do |app|
28
- begin
29
- app.delete if app.href != application_url
30
- rescue Stormpath::Error => e
31
- raise e if e.message != "System Application cannot be deleted!!!"
32
- end
33
- end
34
- end
35
-
36
- def self.delete_accounts accounts
37
- accounts.each do |account|
38
- begin
39
- account.delete
40
- rescue Stormpath::Error => e
41
- raise e unless e.code == 4001
42
- end
43
- end
44
- end
45
-
46
- def self.delete_directory directory
47
- begin
48
- directory.delete
49
- rescue Stormpath::Error => e
50
- raise e if e.message != "System Directory cannot be deleted!"
51
- end
52
- end
53
- end
54
- end
55
- end