castle-rb 8.0.0 → 9.0.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.
Files changed (133) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +317 -0
  3. data/LICENSE +21 -0
  4. data/README.md +290 -112
  5. data/lib/castle/api/filter.rb +3 -1
  6. data/lib/castle/api/list_items/archive.rb +23 -0
  7. data/lib/castle/api/list_items/count.rb +22 -0
  8. data/lib/castle/api/list_items/create.rb +22 -0
  9. data/lib/castle/api/list_items/create_batch.rb +22 -0
  10. data/lib/castle/api/list_items/get.rb +22 -0
  11. data/lib/castle/api/list_items/query.rb +22 -0
  12. data/lib/castle/api/list_items/unarchive.rb +22 -0
  13. data/lib/castle/api/list_items/update.rb +22 -0
  14. data/lib/castle/api/lists/create.rb +23 -0
  15. data/lib/castle/api/lists/delete.rb +22 -0
  16. data/lib/castle/api/lists/get.rb +22 -0
  17. data/lib/castle/api/lists/get_all.rb +22 -0
  18. data/lib/castle/api/lists/query.rb +22 -0
  19. data/lib/castle/api/lists/update.rb +22 -0
  20. data/lib/castle/api/log.rb +2 -1
  21. data/lib/castle/api/privacy/delete_data.rb +23 -0
  22. data/lib/castle/api/privacy/request_data.rb +23 -0
  23. data/lib/castle/api/risk.rb +2 -1
  24. data/lib/castle/client.rb +15 -52
  25. data/lib/castle/client_actions/list_items.rb +49 -0
  26. data/lib/castle/client_actions/lists.rb +39 -0
  27. data/lib/castle/client_actions/privacy.rb +20 -0
  28. data/lib/castle/commands/list_items/archive.rb +24 -0
  29. data/lib/castle/commands/list_items/count.rb +23 -0
  30. data/lib/castle/commands/list_items/create.rb +22 -0
  31. data/lib/castle/commands/list_items/create_batch.rb +22 -0
  32. data/lib/castle/commands/list_items/get.rb +23 -0
  33. data/lib/castle/commands/list_items/query.rb +24 -0
  34. data/lib/castle/commands/list_items/unarchive.rb +23 -0
  35. data/lib/castle/commands/list_items/update.rb +22 -0
  36. data/lib/castle/commands/lists/create.rb +21 -0
  37. data/lib/castle/commands/lists/delete.rb +20 -0
  38. data/lib/castle/commands/lists/get.rb +20 -0
  39. data/lib/castle/commands/lists/get_all.rb +17 -0
  40. data/lib/castle/commands/lists/query.rb +21 -0
  41. data/lib/castle/commands/lists/update.rb +22 -0
  42. data/lib/castle/commands/privacy/delete_data.rb +20 -0
  43. data/lib/castle/commands/privacy/request_data.rb +20 -0
  44. data/lib/castle/core/get_connection.rb +5 -1
  45. data/lib/castle/core/process_response.rb +1 -0
  46. data/lib/castle/core/process_webhook.rb +1 -1
  47. data/lib/castle/core/send_request.rb +2 -1
  48. data/lib/castle/errors.rb +1 -5
  49. data/lib/castle/headers/filter.rb +1 -1
  50. data/lib/castle/version.rb +1 -1
  51. data/lib/castle.rb +36 -17
  52. metadata +62 -162
  53. data/lib/castle/api/approve_device.rb +0 -20
  54. data/lib/castle/api/authenticate.rb +0 -28
  55. data/lib/castle/api/end_impersonation.rb +0 -22
  56. data/lib/castle/api/get_device.rb +0 -20
  57. data/lib/castle/api/get_devices_for_user.rb +0 -20
  58. data/lib/castle/api/report_device.rb +0 -20
  59. data/lib/castle/api/start_impersonation.rb +0 -22
  60. data/lib/castle/api/track.rb +0 -19
  61. data/lib/castle/commands/approve_device.rb +0 -17
  62. data/lib/castle/commands/authenticate.rb +0 -23
  63. data/lib/castle/commands/end_impersonation.rb +0 -25
  64. data/lib/castle/commands/get_device.rb +0 -17
  65. data/lib/castle/commands/get_devices_for_user.rb +0 -17
  66. data/lib/castle/commands/report_device.rb +0 -17
  67. data/lib/castle/commands/start_impersonation.rb +0 -25
  68. data/lib/castle/commands/track.rb +0 -22
  69. data/lib/castle/support/hanami.rb +0 -15
  70. data/lib/castle/support/padrino.rb +0 -19
  71. data/spec/integration/rails/rails_spec.rb +0 -95
  72. data/spec/integration/rails/support/all.rb +0 -6
  73. data/spec/integration/rails/support/application.rb +0 -17
  74. data/spec/integration/rails/support/home_controller.rb +0 -39
  75. data/spec/lib/castle/api/approve_device_spec.rb +0 -17
  76. data/spec/lib/castle/api/authenticate_spec.rb +0 -133
  77. data/spec/lib/castle/api/end_impersonation_spec.rb +0 -59
  78. data/spec/lib/castle/api/filter_spec.rb +0 -5
  79. data/spec/lib/castle/api/get_device_spec.rb +0 -17
  80. data/spec/lib/castle/api/get_devices_for_user_spec.rb +0 -17
  81. data/spec/lib/castle/api/log_spec.rb +0 -5
  82. data/spec/lib/castle/api/report_device_spec.rb +0 -17
  83. data/spec/lib/castle/api/risk_spec.rb +0 -5
  84. data/spec/lib/castle/api/start_impersonation_spec.rb +0 -59
  85. data/spec/lib/castle/api/track_spec.rb +0 -65
  86. data/spec/lib/castle/api_spec.rb +0 -36
  87. data/spec/lib/castle/client_id/extract_spec.rb +0 -47
  88. data/spec/lib/castle/client_spec.rb +0 -337
  89. data/spec/lib/castle/command_spec.rb +0 -9
  90. data/spec/lib/castle/commands/approve_device_spec.rb +0 -24
  91. data/spec/lib/castle/commands/authenticate_spec.rb +0 -86
  92. data/spec/lib/castle/commands/end_impersonation_spec.rb +0 -72
  93. data/spec/lib/castle/commands/filter_spec.rb +0 -72
  94. data/spec/lib/castle/commands/get_device_spec.rb +0 -24
  95. data/spec/lib/castle/commands/get_devices_for_user_spec.rb +0 -24
  96. data/spec/lib/castle/commands/log_spec.rb +0 -73
  97. data/spec/lib/castle/commands/report_device_spec.rb +0 -24
  98. data/spec/lib/castle/commands/risk_spec.rb +0 -73
  99. data/spec/lib/castle/commands/start_impersonation_spec.rb +0 -72
  100. data/spec/lib/castle/commands/track_spec.rb +0 -89
  101. data/spec/lib/castle/configuration_spec.rb +0 -14
  102. data/spec/lib/castle/context/get_default_spec.rb +0 -41
  103. data/spec/lib/castle/context/merge_spec.rb +0 -23
  104. data/spec/lib/castle/context/prepare_spec.rb +0 -42
  105. data/spec/lib/castle/context/sanitize_spec.rb +0 -27
  106. data/spec/lib/castle/core/get_connection_spec.rb +0 -43
  107. data/spec/lib/castle/core/process_response_spec.rb +0 -103
  108. data/spec/lib/castle/core/process_webhook_spec.rb +0 -52
  109. data/spec/lib/castle/core/send_request_spec.rb +0 -97
  110. data/spec/lib/castle/failover/strategy_spec.rb +0 -12
  111. data/spec/lib/castle/headers/extract_spec.rb +0 -103
  112. data/spec/lib/castle/headers/filter_spec.rb +0 -42
  113. data/spec/lib/castle/headers/format_spec.rb +0 -25
  114. data/spec/lib/castle/ips/extract_spec.rb +0 -91
  115. data/spec/lib/castle/logger_spec.rb +0 -39
  116. data/spec/lib/castle/payload/prepare_spec.rb +0 -52
  117. data/spec/lib/castle/secure_mode_spec.rb +0 -7
  118. data/spec/lib/castle/session_spec.rb +0 -61
  119. data/spec/lib/castle/singleton_configuration_spec.rb +0 -14
  120. data/spec/lib/castle/utils/clean_invalid_chars_spec.rb +0 -69
  121. data/spec/lib/castle/utils/clone_spec.rb +0 -19
  122. data/spec/lib/castle/utils/deep_symbolize_keys_spec.rb +0 -50
  123. data/spec/lib/castle/utils/get_timestamp_spec.rb +0 -16
  124. data/spec/lib/castle/utils/merge_spec.rb +0 -13
  125. data/spec/lib/castle/validators/not_supported_spec.rb +0 -19
  126. data/spec/lib/castle/validators/present_spec.rb +0 -25
  127. data/spec/lib/castle/verdict_spec.rb +0 -9
  128. data/spec/lib/castle/version_spec.rb +0 -5
  129. data/spec/lib/castle/webhooks/verify_spec.rb +0 -59
  130. data/spec/lib/castle_spec.rb +0 -58
  131. data/spec/spec_helper.rb +0 -24
  132. data/spec/support/shared_examples/action_request.rb +0 -167
  133. data/spec/support/shared_examples/configuration.rb +0 -99
@@ -1,39 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # tmp logger for testing
4
- class TmpLogger
5
- # @param _message [String]
6
- def info(_message)
7
- end
8
- end
9
-
10
- describe Castle::Logger do
11
- subject(:log) { described_class.call(message, data) }
12
-
13
- let(:message) { 'https://localhost/test:' }
14
- let(:integration_logger) { TmpLogger.new }
15
- let(:data) { { a: 1 }.to_json }
16
- let(:logger_message) { "[CASTLE] #{message} #{data}" }
17
-
18
- before { allow(integration_logger).to receive(:info).and_call_original }
19
-
20
- describe '.call' do
21
- context 'without logger' do
22
- before do
23
- Castle.config.logger = nil
24
- log
25
- end
26
-
27
- it { expect(integration_logger).not_to have_received(:info) }
28
- end
29
-
30
- context 'with logger' do
31
- before do
32
- Castle.config.logger = integration_logger
33
- log
34
- end
35
-
36
- it { expect(integration_logger).to have_received(:info).with(logger_message) }
37
- end
38
- end
39
- end
@@ -1,52 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- describe Castle::Payload::Prepare do
4
- let(:ip) { '1.2.3.4' }
5
- let(:cookie_id) { 'abcd' }
6
- let(:ua) { 'Chrome' }
7
- let(:env) do
8
- Rack::MockRequest.env_for(
9
- '/',
10
- 'HTTP_USER_AGENT' => ua,
11
- 'HTTP_X_FORWARDED_FOR' => ip,
12
- 'HTTP_COOKIE' => "__cid=#{cookie_id};other=efgh",
13
- 'HTTP_CONTENT_LENGTH' => '0'
14
- )
15
- end
16
- let(:request) { Rack::Request.new(env) }
17
-
18
- let(:headers) { { 'Content-Length': '0', 'User-Agent': ua, 'X-Forwarded-For': ip.to_s, Cookie: true } }
19
- let(:context) do
20
- {
21
- client_id: 'abcd',
22
- active: true,
23
- user_agent: ua,
24
- headers: headers,
25
- ip: ip,
26
- library: {
27
- name: 'castle-rb',
28
- version: '2.2.0'
29
- }
30
- }
31
- end
32
-
33
- let(:time_now) { Time.now }
34
- let(:time_formatted) { time_now.utc.iso8601(3) }
35
- let(:payload_options) { { user_id: '1234', user_traits: { name: 'Jo' } } }
36
- let(:result) { { user_id: '1234', user_traits: { name: 'Jo' }, timestamp: time_formatted, context: context } }
37
-
38
- before do
39
- Timecop.freeze(time_now)
40
- stub_const('Castle::VERSION', '2.2.0')
41
- end
42
-
43
- after { Timecop.return }
44
-
45
- describe '#call' do
46
- subject(:generated) { described_class.call(payload_options, request) }
47
-
48
- context 'when active true' do
49
- it { is_expected.to eql(result) }
50
- end
51
- end
52
- end
@@ -1,7 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- describe Castle::SecureMode do
4
- it 'has signature' do
5
- expect(described_class.signature('test')).to eql('0329a06b62cd16b33eb6792be8c60b158d89a2ee3a876fce9a881ebb488c0914')
6
- end
7
- end
@@ -1,61 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- describe Castle::Session do
4
- describe '.call' do
5
- context 'when ssl false' do
6
- let(:localhost) { 'localhost' }
7
- let(:port) { 3002 }
8
-
9
- before do
10
- Castle.config.base_url = 'http://localhost:3002'
11
- stub_request(:get, 'localhost:3002/test').to_return(status: 200, body: '{}', headers: {})
12
- end
13
-
14
- context 'with block' do
15
- let(:api_url) { '/test' }
16
- let(:request) { Net::HTTP::Get.new(api_url) }
17
-
18
- before do
19
- allow(Net::HTTP).to receive(:new).with(localhost, port).and_call_original
20
-
21
- described_class.call { |http| http.request(request) }
22
- end
23
-
24
- it { expect(Net::HTTP).to have_received(:new).with(localhost, port) }
25
-
26
- it { expect(a_request(:get, 'localhost:3002/test')).to have_been_made.once }
27
- end
28
-
29
- context 'without block' do
30
- before { described_class.call }
31
-
32
- it { expect(a_request(:get, 'localhost:3002/test')).not_to have_been_made }
33
- end
34
- end
35
-
36
- context 'when ssl true' do
37
- let(:localhost) { 'localhost' }
38
- let(:port) { 443 }
39
-
40
- before do
41
- Castle.config.base_url = 'https://localhost'
42
- stub_request(:get, 'https://localhost/test').to_return(status: 200, body: '{}', headers: {})
43
- end
44
-
45
- context 'with block' do
46
- let(:api_url) { '/test' }
47
- let(:request) { Net::HTTP::Get.new(api_url) }
48
-
49
- before do
50
- allow(Net::HTTP).to receive(:new).with(localhost, port).and_call_original
51
-
52
- allow(Net::HTTP).to receive(:start)
53
-
54
- described_class.call { |http| http.request(request) }
55
- end
56
-
57
- it { expect(Net::HTTP).to have_received(:new).with(localhost, port) }
58
- end
59
- end
60
- end
61
- end
@@ -1,14 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- describe Castle::SingletonConfiguration do
4
- subject(:config) { described_class.instance }
5
-
6
- it_behaves_like 'configuration_host'
7
- it_behaves_like 'configuration_request_timeout'
8
- it_behaves_like 'configuration_allowlisted'
9
- it_behaves_like 'configuration_denylisted'
10
- it_behaves_like 'configuration_failover_strategy'
11
- it_behaves_like 'configuration_api_secret'
12
-
13
- it { expect(config.api_secret).to eql('secret') }
14
- end
@@ -1,69 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- describe Castle::Utils::CleanInvalidChars do
4
- describe '::call' do
5
- subject { described_class.call(input) }
6
-
7
- context 'when input is a string' do
8
- let(:input) { '1234' }
9
-
10
- it { is_expected.to eq input }
11
- end
12
-
13
- context 'when input is an array' do
14
- let(:input) { [1, 2, 3, '4'] }
15
-
16
- it { is_expected.to eq input }
17
- end
18
-
19
- context 'when input is a hash' do
20
- let(:input) { { user_id: 1 } }
21
-
22
- it { is_expected.to eq input }
23
- end
24
-
25
- context 'when input is nil' do
26
- let(:input) { nil }
27
-
28
- it { is_expected.to eq input }
29
- end
30
-
31
- context 'when input is a nested hash' do
32
- let(:input) { { user: { id: 1 } } }
33
-
34
- it { is_expected.to eq input }
35
- end
36
-
37
- context 'with invalid UTF-8 characters' do
38
- context 'when input is a hash' do
39
- let(:input) { { user_id: "inv\xC4lid" } }
40
-
41
- it { is_expected.to eq(user_id: 'inv�lid') }
42
- end
43
-
44
- context 'when input is a nested hash' do
45
- let(:input) { { user: { id: "inv\xC4lid" } } }
46
-
47
- it { is_expected.to eq(user: { id: 'inv�lid' }) }
48
- end
49
-
50
- context 'when input is an array of hashes' do
51
- let(:input) { [{ user: "inv\xC4lid" }] * 2 }
52
-
53
- it { is_expected.to eq([{ user: 'inv�lid' }, { user: 'inv�lid' }]) }
54
- end
55
-
56
- context 'when input is an array' do
57
- let(:input) { ["inv\xC4lid"] * 2 }
58
-
59
- it { is_expected.to eq(%w[inv�lid inv�lid]) }
60
- end
61
-
62
- context 'when input is a hash with array in key' do
63
- let(:input) { { items: ["inv\xC4lid"] * 2 } }
64
-
65
- it { is_expected.to eq(items: %w[inv�lid inv�lid]) }
66
- end
67
- end
68
- end
69
- end
@@ -1,19 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- describe Castle::Utils::Clone do
4
- subject(:clone) { described_class }
5
-
6
- describe 'call' do
7
- let(:nested) { { c: '3' } }
8
- let(:first) { { test: { test1: { c: '4' }, test2: nested, a: '1', b: '2' } } }
9
- let(:result) { { test: { test1: { c: '4' }, test2: { c: '3' }, a: '1', b: '2' } } }
10
- let(:cloned) { clone.call(first) }
11
-
12
- before { cloned }
13
-
14
- it do
15
- nested[:test] = 'sample'
16
- expect(cloned).to eql(result)
17
- end
18
- end
19
- end
@@ -1,50 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- describe Castle::Utils::DeepSymbolizeKeys do
4
- let(:nested_strings) { { 'a' => { 'b' => { 'c' => 3 } } } }
5
- let(:nested_symbols) { { a: { b: { c: 3 } } } }
6
- let(:nested_mixed) { { 'a' => { b: { 'c' => 3 } } } }
7
- let(:string_array_of_hashes) { { 'a' => [{ 'b' => 2 }, { 'c' => 3 }, 4] } }
8
- let(:symbol_array_of_hashes) { { a: [{ b: 2 }, { c: 3 }, 4] } }
9
- let(:mixed_array_of_hashes) { { a: [{ b: 2 }, { 'c' => 3 }, 4] } }
10
-
11
- describe '::call' do
12
- subject { described_class.call(hash) }
13
-
14
- context 'when nested_symbols' do
15
- let(:hash) { nested_symbols }
16
-
17
- it { is_expected.to eq(nested_symbols) }
18
- end
19
-
20
- context 'when nested_strings' do
21
- let(:hash) { nested_strings }
22
-
23
- it { is_expected.to eq(nested_symbols) }
24
- end
25
-
26
- context 'when nested_mixed' do
27
- let(:hash) { nested_mixed }
28
-
29
- it { is_expected.to eq(nested_symbols) }
30
- end
31
-
32
- context 'when string_array_of_hashes' do
33
- let(:hash) { string_array_of_hashes }
34
-
35
- it { is_expected.to eq(symbol_array_of_hashes) }
36
- end
37
-
38
- context 'when symbol_array_of_hashes' do
39
- let(:hash) { symbol_array_of_hashes }
40
-
41
- it { is_expected.to eq(symbol_array_of_hashes) }
42
- end
43
-
44
- context 'when mixed_array_of_hashes' do
45
- let(:hash) { mixed_array_of_hashes }
46
-
47
- it { is_expected.to eq(symbol_array_of_hashes) }
48
- end
49
- end
50
- end
@@ -1,16 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- describe Castle::Utils::GetTimestamp do
4
- subject(:timestamp) { described_class.call }
5
-
6
- let(:time_string) { '2018-01-10T14:14:24.407Z' }
7
- let(:time) { Time.parse(time_string) }
8
-
9
- before { Timecop.freeze(time) }
10
-
11
- after { Timecop.return }
12
-
13
- describe '#call' do
14
- it { expect(timestamp).to eql(time_string) }
15
- end
16
- end
@@ -1,13 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- describe Castle::Utils::Merge do
4
- subject(:merge) { described_class }
5
-
6
- describe 'call' do
7
- let(:first) { { test: { test1: { c: '4' }, test2: { c: '3' }, a: '1', b: '2' } } }
8
- let(:second) { { test2: '2', test: { 'test1' => { d: '5' }, :test2 => '6', :a => nil, :b => '3' } } }
9
- let(:result) { { test2: '2', test: { test1: { c: '4', d: '5' }, test2: '6', b: '3' } } }
10
-
11
- it { expect(merge.call(first, second)).to eql(result) }
12
- end
13
- end
@@ -1,19 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- describe Castle::Validators::NotSupported do
4
- describe '#call' do
5
- subject(:call) { described_class.call({ first: 1 }, keys) }
6
-
7
- context 'when keys is present' do
8
- let(:keys) { %i[first second] }
9
-
10
- it { expect { call }.to raise_error(Castle::InvalidParametersError, 'first is/are not supported') }
11
- end
12
-
13
- context 'when key is not present' do
14
- let(:keys) { %i[second third] }
15
-
16
- it { expect { call }.not_to raise_error }
17
- end
18
- end
19
- end
@@ -1,25 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- describe Castle::Validators::Present do
4
- describe '#call' do
5
- subject(:call) { described_class.call({ first: 1, second: '2', invalid: '' }, keys) }
6
-
7
- context 'when keys is not present' do
8
- let(:keys) { %i[second third] }
9
-
10
- it { expect { call }.to raise_error(Castle::InvalidParametersError, 'third is missing or empty') }
11
- end
12
-
13
- context 'when keys is empty' do
14
- let(:keys) { %i[second invalid] }
15
-
16
- it { expect { call }.to raise_error(Castle::InvalidParametersError, 'invalid is missing or empty') }
17
- end
18
-
19
- context 'when key is present' do
20
- let(:keys) { %i[first second] }
21
-
22
- it { expect { call }.not_to raise_error }
23
- end
24
- end
25
- end
@@ -1,9 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- describe Castle::Verdict do
4
- subject(:verdict) { described_class }
5
-
6
- it { expect(verdict::ALLOW).to eql('allow') }
7
- it { expect(verdict::DENY).to eql('deny') }
8
- it { expect(verdict::CHALLENGE).to eql('challenge') }
9
- end
@@ -1,5 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- describe Castle do
4
- it { expect(described_class::VERSION).to match(/\d\.\d\.\d/) }
5
- end
@@ -1,59 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- describe Castle::Webhooks::Verify do
4
- describe '#call' do
5
- subject(:call) { described_class.call(webhook) }
6
-
7
- let(:env) { Rack::MockRequest.env_for('/', 'HTTP_X_CASTLE_SIGNATURE' => signature) }
8
-
9
- let(:webhook) { Rack::Request.new(env) }
10
- let(:user_id) { '12345' }
11
- let(:webhook_body) do
12
- {
13
- api_version: 'v1',
14
- app_id: '12345',
15
- type: '$incident.confirmed',
16
- created_at: '2020-12-18T12:55:21.779Z',
17
- data: {
18
- id: 'test',
19
- device_token: 'token',
20
- user_id: user_id,
21
- trigger: '$login.succeeded',
22
- context: {
23
- },
24
- location: {
25
- },
26
- user_agent: {
27
- }
28
- },
29
- user_traits: {
30
- },
31
- properties: {
32
- },
33
- policy: {
34
- }
35
- }.to_json
36
- end
37
-
38
- context 'when success' do
39
- let(:signature) { '3ptx3rUOBnGEqPjMrbcJn2UUfzwTKP54dFyP5uyPY+Y=' }
40
-
41
- before { allow(Castle::Core::ProcessWebhook).to receive(:call).and_return(webhook_body) }
42
-
43
- it { expect { call }.not_to raise_error }
44
- end
45
-
46
- context 'when signature is malformed' do
47
- let(:signature) { '123' }
48
-
49
- before { allow(Castle::Core::ProcessWebhook).to receive(:call).and_return(webhook_body) }
50
-
51
- it do
52
- expect { call }.to raise_error(
53
- Castle::WebhookVerificationError,
54
- 'Signature not matching the expected signature'
55
- )
56
- end
57
- end
58
- end
59
- end
@@ -1,58 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- describe Castle do
4
- subject(:castle) { described_class }
5
-
6
- describe 'config' do
7
- it { expect(castle.config).to be_a(Castle::Configuration) }
8
- end
9
-
10
- describe 'api_secret setter' do
11
- let(:value) { 'new_secret' }
12
-
13
- before { castle.api_secret = value }
14
-
15
- it { expect(castle.config.api_secret).to eql(value) }
16
- end
17
-
18
- describe 'configure' do
19
- let(:value) { 'new_secret' }
20
- let(:timeout) { 60 }
21
-
22
- shared_examples 'config_setup' do
23
- it { expect(castle.config.api_secret).to eql(value) }
24
- it { expect(castle.config.request_timeout).to eql(timeout) }
25
- end
26
-
27
- context 'with block' do
28
- before do
29
- castle.configure do |config|
30
- config.api_secret = value
31
- config.request_timeout = timeout
32
- end
33
- end
34
-
35
- it_behaves_like 'config_setup'
36
- end
37
-
38
- context 'with options' do
39
- before { castle.configure(request_timeout: timeout, api_secret: value) }
40
-
41
- it_behaves_like 'config_setup'
42
- end
43
-
44
- context 'with block and options' do
45
- before { castle.configure(request_timeout: timeout) { |config| config.api_secret = value } }
46
-
47
- it_behaves_like 'config_setup'
48
- end
49
- end
50
-
51
- describe 'configure wrongly' do
52
- let(:value) { 'new_secret' }
53
-
54
- it do
55
- expect { castle.configure { |config| config.wrong_config = value } }.to raise_error(Castle::ConfigurationError)
56
- end
57
- end
58
- end
data/spec/spec_helper.rb DELETED
@@ -1,24 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'rubygems'
4
- require 'bundler/setup'
5
- require 'rack'
6
- require 'webmock/rspec'
7
- require 'byebug'
8
- require 'timecop'
9
-
10
- require 'coveralls'
11
- Coveralls.wear!
12
-
13
- require 'castle'
14
-
15
- WebMock.disable_net_connect!(allow_localhost: true)
16
-
17
- Dir['./spec/support/**/*.rb'].sort.each { |f| require f }
18
-
19
- RSpec.configure do |config|
20
- config.before do
21
- Castle.config.reset
22
- Castle.configure { |cfg| cfg.api_secret = 'secret' }
23
- end
24
- end