castle-rb 7.2.0 → 8.1.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 (140) hide show
  1. checksums.yaml +4 -4
  2. data/lib/castle/api/authenticate.rb +3 -12
  3. data/lib/castle/api/end_impersonation.rb +1 -3
  4. data/lib/castle/api/filter.rb +2 -10
  5. data/lib/castle/api/list_items/archive.rb +23 -0
  6. data/lib/castle/api/list_items/count.rb +22 -0
  7. data/lib/castle/api/list_items/create.rb +22 -0
  8. data/lib/castle/api/list_items/get.rb +22 -0
  9. data/lib/castle/api/list_items/query.rb +22 -0
  10. data/lib/castle/api/list_items/unarchive.rb +22 -0
  11. data/lib/castle/api/list_items/update.rb +22 -0
  12. data/lib/castle/api/lists/create.rb +23 -0
  13. data/lib/castle/api/lists/delete.rb +22 -0
  14. data/lib/castle/api/lists/get.rb +22 -0
  15. data/lib/castle/api/lists/get_all.rb +22 -0
  16. data/lib/castle/api/lists/query.rb +22 -0
  17. data/lib/castle/api/lists/update.rb +22 -0
  18. data/lib/castle/api/log.rb +2 -10
  19. data/lib/castle/api/risk.rb +2 -10
  20. data/lib/castle/api/start_impersonation.rb +1 -3
  21. data/lib/castle/api/track.rb +1 -3
  22. data/lib/castle/client.rb +4 -5
  23. data/lib/castle/client_actions/list_items.rb +44 -0
  24. data/lib/castle/client_actions/lists.rb +39 -0
  25. data/lib/castle/commands/list_items/archive.rb +24 -0
  26. data/lib/castle/commands/list_items/count.rb +23 -0
  27. data/lib/castle/commands/list_items/create.rb +22 -0
  28. data/lib/castle/commands/list_items/get.rb +23 -0
  29. data/lib/castle/commands/list_items/query.rb +24 -0
  30. data/lib/castle/commands/list_items/unarchive.rb +23 -0
  31. data/lib/castle/commands/list_items/update.rb +22 -0
  32. data/lib/castle/commands/lists/create.rb +21 -0
  33. data/lib/castle/commands/lists/delete.rb +20 -0
  34. data/lib/castle/commands/lists/get.rb +20 -0
  35. data/lib/castle/commands/lists/get_all.rb +17 -0
  36. data/lib/castle/commands/lists/query.rb +21 -0
  37. data/lib/castle/commands/lists/update.rb +22 -0
  38. data/lib/castle/commands/log.rb +1 -5
  39. data/lib/castle/commands/risk.rb +1 -5
  40. data/lib/castle/configuration.rb +2 -5
  41. data/lib/castle/core/process_response.rb +4 -3
  42. data/lib/castle/core/send_request.rb +1 -3
  43. data/lib/castle/errors.rb +4 -0
  44. data/lib/castle/headers/extract.rb +1 -3
  45. data/lib/castle/headers/filter.rb +2 -3
  46. data/lib/castle/payload/prepare.rb +1 -2
  47. data/lib/castle/session.rb +1 -1
  48. data/lib/castle/version.rb +1 -1
  49. data/lib/castle.rb +29 -3
  50. data/spec/integration/rails/rails_spec.rb +9 -3
  51. data/spec/integration/rails/support/application.rb +2 -2
  52. data/spec/integration/rails/support/home_controller.rb +4 -30
  53. data/spec/lib/castle/api/approve_device_spec.rb +3 -7
  54. data/spec/lib/castle/api/authenticate_spec.rb +23 -26
  55. data/spec/lib/castle/api/end_impersonation_spec.rb +9 -15
  56. data/spec/lib/castle/api/filter_spec.rb +1 -1
  57. data/spec/lib/castle/api/get_device_spec.rb +2 -4
  58. data/spec/lib/castle/api/get_devices_for_user_spec.rb +2 -4
  59. data/spec/lib/castle/api/list_items/archive_spec.rb +18 -0
  60. data/spec/lib/castle/api/list_items/count_spec.rb +21 -0
  61. data/spec/lib/castle/api/list_items/create_spec.rb +22 -0
  62. data/spec/lib/castle/api/list_items/get_spec.rb +18 -0
  63. data/spec/lib/castle/api/list_items/query_spec.rb +21 -0
  64. data/spec/lib/castle/api/list_items/unarchive_spec.rb +18 -0
  65. data/spec/lib/castle/api/list_items/update_spec.rb +22 -0
  66. data/spec/lib/castle/api/lists/create_spec.rb +21 -0
  67. data/spec/lib/castle/api/lists/delete_spec.rb +17 -0
  68. data/spec/lib/castle/api/lists/get_all_spec.rb +17 -0
  69. data/spec/lib/castle/api/lists/get_spec.rb +17 -0
  70. data/spec/lib/castle/api/lists/query_spec.rb +21 -0
  71. data/spec/lib/castle/api/lists/update_spec.rb +21 -0
  72. data/spec/lib/castle/api/log_spec.rb +1 -1
  73. data/spec/lib/castle/api/report_device_spec.rb +3 -7
  74. data/spec/lib/castle/api/risk_spec.rb +1 -1
  75. data/spec/lib/castle/api/start_impersonation_spec.rb +9 -15
  76. data/spec/lib/castle/api/track_spec.rb +10 -17
  77. data/spec/lib/castle/api_spec.rb +1 -1
  78. data/spec/lib/castle/client_id/extract_spec.rb +3 -10
  79. data/spec/lib/castle/client_spec.rb +38 -79
  80. data/spec/lib/castle/command_spec.rb +4 -4
  81. data/spec/lib/castle/commands/approve_device_spec.rb +3 -3
  82. data/spec/lib/castle/commands/authenticate_spec.rb +18 -25
  83. data/spec/lib/castle/commands/end_impersonation_spec.rb +15 -22
  84. data/spec/lib/castle/commands/filter_spec.rb +16 -16
  85. data/spec/lib/castle/commands/get_device_spec.rb +3 -3
  86. data/spec/lib/castle/commands/get_devices_for_user_spec.rb +3 -3
  87. data/spec/lib/castle/commands/list_items/archive_spec.rb +21 -0
  88. data/spec/lib/castle/commands/list_items/count_spec.rb +21 -0
  89. data/spec/lib/castle/commands/list_items/create_spec.rb +22 -0
  90. data/spec/lib/castle/commands/list_items/get_spec.rb +21 -0
  91. data/spec/lib/castle/commands/list_items/query_spec.rb +27 -0
  92. data/spec/lib/castle/commands/list_items/unarchive_spec.rb +21 -0
  93. data/spec/lib/castle/commands/list_items/update_spec.rb +21 -0
  94. data/spec/lib/castle/commands/lists/create_spec.rb +33 -0
  95. data/spec/lib/castle/commands/lists/delete_spec.rb +21 -0
  96. data/spec/lib/castle/commands/lists/get_all_spec.rb +11 -0
  97. data/spec/lib/castle/commands/lists/get_spec.rb +21 -0
  98. data/spec/lib/castle/commands/lists/query_spec.rb +27 -0
  99. data/spec/lib/castle/commands/lists/update_spec.rb +29 -0
  100. data/spec/lib/castle/commands/log_spec.rb +16 -16
  101. data/spec/lib/castle/commands/report_device_spec.rb +3 -3
  102. data/spec/lib/castle/commands/risk_spec.rb +16 -16
  103. data/spec/lib/castle/commands/start_impersonation_spec.rb +15 -22
  104. data/spec/lib/castle/commands/track_spec.rb +20 -25
  105. data/spec/lib/castle/configuration_spec.rb +2 -2
  106. data/spec/lib/castle/context/get_default_spec.rb +10 -9
  107. data/spec/lib/castle/context/merge_spec.rb +1 -1
  108. data/spec/lib/castle/context/prepare_spec.rb +4 -5
  109. data/spec/lib/castle/context/sanitize_spec.rb +1 -1
  110. data/spec/lib/castle/core/get_connection_spec.rb +1 -1
  111. data/spec/lib/castle/core/process_response_spec.rb +4 -7
  112. data/spec/lib/castle/core/process_webhook_spec.rb +13 -7
  113. data/spec/lib/castle/core/send_request_spec.rb +8 -12
  114. data/spec/lib/castle/failover/strategy_spec.rb +6 -6
  115. data/spec/lib/castle/headers/extract_spec.rb +2 -2
  116. data/spec/lib/castle/headers/filter_spec.rb +7 -4
  117. data/spec/lib/castle/headers/format_spec.rb +6 -6
  118. data/spec/lib/castle/ips/extract_spec.rb +3 -7
  119. data/spec/lib/castle/logger_spec.rb +3 -2
  120. data/spec/lib/castle/payload/prepare_spec.rb +5 -8
  121. data/spec/lib/castle/secure_mode_spec.rb +2 -4
  122. data/spec/lib/castle/session_spec.rb +2 -6
  123. data/spec/lib/castle/singleton_configuration_spec.rb +2 -2
  124. data/spec/lib/castle/utils/clean_invalid_chars_spec.rb +1 -1
  125. data/spec/lib/castle/utils/clone_spec.rb +2 -2
  126. data/spec/lib/castle/utils/deep_symbolize_keys_spec.rb +1 -1
  127. data/spec/lib/castle/utils/get_timestamp_spec.rb +1 -1
  128. data/spec/lib/castle/utils/merge_spec.rb +3 -5
  129. data/spec/lib/castle/validators/not_supported_spec.rb +2 -7
  130. data/spec/lib/castle/validators/present_spec.rb +3 -10
  131. data/spec/lib/castle/verdict_spec.rb +4 -4
  132. data/spec/lib/castle/version_spec.rb +1 -1
  133. data/spec/lib/castle/webhooks/verify_spec.rb +13 -7
  134. data/spec/lib/castle_spec.rb +6 -8
  135. data/spec/spec_helper.rb +2 -0
  136. data/spec/support/shared_examples/action_request.rb +16 -34
  137. data/spec/support/shared_examples/configuration.rb +14 -16
  138. data/spec/support/shared_examples/list_items.rb +52 -0
  139. data/spec/support/shared_examples/lists.rb +45 -0
  140. metadata +132 -48
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- describe Castle::API::EndImpersonation do
3
+ RSpec.describe Castle::API::EndImpersonation do
4
4
  subject(:call) { described_class.call(options) }
5
5
 
6
6
  let(:ip) { '1.2.3.4' }
@@ -22,9 +22,12 @@ describe Castle::API::EndImpersonation do
22
22
  before do
23
23
  Timecop.freeze(time_now)
24
24
  stub_const('Castle::VERSION', '2.2.0')
25
- stub_request(:any, /api.castle.io/)
26
- .with(basic_auth: ['', 'secret'])
27
- .to_return(status: 200, body: response_body, headers: {})
25
+ stub_request(:any, /api.castle.io/).with(basic_auth: ['', 'secret']).to_return(
26
+ status: 200,
27
+ body: response_body,
28
+ headers: {
29
+ }
30
+ )
28
31
  end
29
32
 
30
33
  after { Timecop.return }
@@ -32,19 +35,10 @@ describe Castle::API::EndImpersonation do
32
35
  describe 'call' do
33
36
  let(:impersonator) { 'test@castle.io' }
34
37
  let(:request_body) do
35
- {
36
- user_id: '1234',
37
- sent_at: time_auto,
38
- properties: {
39
- impersonator: impersonator
40
- },
41
- context: context
42
- }
38
+ { user_id: '1234', sent_at: time_auto, properties: { impersonator: impersonator }, context: context }
43
39
  end
44
40
  let(:response_body) { { success: true }.to_json }
45
- let(:options) do
46
- { user_id: '1234', properties: { impersonator: impersonator }, context: context }
47
- end
41
+ let(:options) { { user_id: '1234', properties: { impersonator: impersonator }, context: context } }
48
42
 
49
43
  context 'when used with symbol keys' do
50
44
  before { call }
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- describe Castle::API::Filter do
3
+ RSpec.describe Castle::API::Filter do
4
4
  pending
5
5
  end
@@ -1,10 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- describe Castle::API::GetDevice do
3
+ RSpec.describe Castle::API::GetDevice do
4
4
  before do
5
- stub_request(:any, /api.castle.io/)
6
- .with(basic_auth: ['', 'secret'])
7
- .to_return(status: 200, body: '{}', headers: {})
5
+ stub_request(:any, /api.castle.io/).with(basic_auth: ['', 'secret']).to_return(status: 200, body: '{}', headers: {})
8
6
  end
9
7
 
10
8
  describe '.call' do
@@ -1,10 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- describe Castle::API::GetDevicesForUser do
3
+ RSpec.describe Castle::API::GetDevicesForUser do
4
4
  before do
5
- stub_request(:any, /api.castle.io/)
6
- .with(basic_auth: ['', 'secret'])
7
- .to_return(status: 200, body: '{}', headers: {})
5
+ stub_request(:any, /api.castle.io/).with(basic_auth: ['', 'secret']).to_return(status: 200, body: '{}', headers: {})
8
6
  end
9
7
 
10
8
  describe '.call' do
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.describe Castle::API::ListItems::Archive do
4
+ before do
5
+ stub_request(:any, /api.castle.io/).with(basic_auth: ['', 'secret']).to_return(status: 200, body: '{}', headers: {})
6
+ end
7
+
8
+ describe '.call' do
9
+ subject(:all) { described_class.call(options) }
10
+
11
+ let(:url) { "https://api.castle.io/v1/lists/#{options[:list_id]}/items/#{options[:list_item_id]}/archive" }
12
+ let(:options) { { list_id: '123', list_item_id: '456' } }
13
+
14
+ before { all }
15
+
16
+ it { assert_requested :delete, url, times: 1 }
17
+ end
18
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.describe Castle::API::ListItems::Count do
4
+ before do
5
+ stub_request(:any, /api.castle.io/).with(basic_auth: ['', 'secret']).to_return(status: 200, body: '{}', headers: {})
6
+ end
7
+
8
+ describe '.call' do
9
+ subject(:all) { described_class.call(options) }
10
+
11
+ let(:options) { { list_id: '123', filters: [{ field: 'test', op: '$eq', value: 'test' }] } }
12
+
13
+ before { all }
14
+
15
+ it do
16
+ assert_requested :post, "https://api.castle.io/v1/lists/#{options[:list_id]}/items/count", times: 1 do |req|
17
+ expect(JSON.parse(req.body, symbolize_names: true)).to eq(options.except(:list_id))
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.describe Castle::API::ListItems::Create do
4
+ before do
5
+ stub_request(:any, /api.castle.io/).with(basic_auth: ['', 'secret']).to_return(status: 200, body: '{}', headers: {})
6
+ end
7
+
8
+ describe '.call' do
9
+ subject(:all) { described_class.call(options) }
10
+
11
+ let(:author) { { type: '$other', identifier: 'test identifier' } }
12
+ let(:options) { { list_id: '123', primary_value: 'test value', author: author, } }
13
+
14
+ before { all }
15
+
16
+ it do
17
+ assert_requested :post, "https://api.castle.io/v1/lists/#{options[:list_id]}/items", times: 1 do |req|
18
+ expect(JSON.parse(req.body, symbolize_names: true)).to eq(options.except(:list_id))
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.describe Castle::API::ListItems::Get do
4
+ before do
5
+ stub_request(:any, /api.castle.io/).with(basic_auth: ['', 'secret']).to_return(status: 200, body: '{}', headers: {})
6
+ end
7
+
8
+ describe '.call' do
9
+ subject(:all) { described_class.call(options) }
10
+
11
+ let(:options) { { list_id: '123', list_item_id: '456' } }
12
+ let(:url) { "https://api.castle.io/v1/lists/#{options[:list_id]}/items/#{options[:list_item_id]}" }
13
+
14
+ before { all }
15
+
16
+ it { assert_requested :get, url, times: 1 }
17
+ end
18
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.describe Castle::API::ListItems::Query do
4
+ before do
5
+ stub_request(:any, /api.castle.io/).with(basic_auth: ['', 'secret']).to_return(status: 200, body: '{}', headers: {})
6
+ end
7
+
8
+ describe '.call' do
9
+ subject(:all) { described_class.call(options) }
10
+
11
+ let(:options) { { list_id: '123', filters: [{ field: 'test', op: '$eq', value: 'test' }] } }
12
+
13
+ before { all }
14
+
15
+ it do
16
+ assert_requested :post, "https://api.castle.io/v1/lists/#{options[:list_id]}/items/query", times: 1 do |req|
17
+ expect(JSON.parse(req.body, symbolize_names: true)).to eq(options.except(:list_id))
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.describe Castle::API::ListItems::Unarchive do
4
+ before do
5
+ stub_request(:any, /api.castle.io/).with(basic_auth: ['', 'secret']).to_return(status: 200, body: '{}', headers: {})
6
+ end
7
+
8
+ describe '.call' do
9
+ subject(:all) { described_class.call(options) }
10
+
11
+ let(:url) { "https://api.castle.io/v1/lists/#{options[:list_id]}/items/#{options[:list_item_id]}/unarchive" }
12
+ let(:options) { { list_id: '123', list_item_id: '456' } }
13
+
14
+ before { all }
15
+
16
+ it { assert_requested :put, url, times: 1 }
17
+ end
18
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.describe Castle::API::ListItems::Update do
4
+ before do
5
+ stub_request(:any, /api.castle.io/).with(basic_auth: ['', 'secret']).to_return(status: 200, body: '{}', headers: {})
6
+ end
7
+
8
+ describe '.call' do
9
+ subject(:all) { described_class.call(options) }
10
+
11
+ let(:url) { "https://api.castle.io/v1/lists/#{options[:list_id]}/items/#{options[:list_item_id]}" }
12
+ let(:options) { { list_id: '123', list_item_id: '456', comment: 'updating comment!' } }
13
+
14
+ before { all }
15
+
16
+ it do
17
+ assert_requested :put, url, times: 1 do |req|
18
+ expect(JSON.parse(req.body, symbolize_names: true)).to eq(options.except(:list_id, :list_item_id))
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.describe Castle::API::Lists::Create do
4
+ before do
5
+ stub_request(:any, /api.castle.io/).with(basic_auth: ['', 'secret']).to_return(status: 200, body: '{}', headers: {})
6
+ end
7
+
8
+ describe '.call' do
9
+ subject(:all) { described_class.call(options) }
10
+
11
+ let(:options) { { name: 'name', color: '$red', primary_field: 'user.email' } }
12
+
13
+ before { all }
14
+
15
+ it do
16
+ assert_requested :post, 'https://api.castle.io/v1/lists', times: 1 do |req|
17
+ expect(JSON.parse(req.body, symbolize_names: true)).to eq(options)
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.describe Castle::API::Lists::Delete do
4
+ before do
5
+ stub_request(:any, /api.castle.io/).with(basic_auth: ['', 'secret']).to_return(status: 200, body: '{}', headers: {})
6
+ end
7
+
8
+ describe '.call' do
9
+ subject(:all) { described_class.call(options) }
10
+
11
+ let(:options) { { list_id: '123' } }
12
+
13
+ before { all }
14
+
15
+ it { assert_requested :delete, "https://api.castle.io/v1/lists/#{options[:list_id]}", times: 1 }
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.describe Castle::API::Lists::GetAll do
4
+ before do
5
+ stub_request(:any, /api.castle.io/).with(basic_auth: ['', 'secret']).to_return(status: 200, body: '{}', headers: {})
6
+ end
7
+
8
+ describe '.call' do
9
+ subject(:all) { described_class.call(options) }
10
+
11
+ let(:options) { { } }
12
+
13
+ before { all }
14
+
15
+ it { assert_requested :get, "https://api.castle.io/v1/lists", times: 1 }
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.describe Castle::API::Lists::Get do
4
+ before do
5
+ stub_request(:any, /api.castle.io/).with(basic_auth: ['', 'secret']).to_return(status: 200, body: '{}', headers: {})
6
+ end
7
+
8
+ describe '.call' do
9
+ subject(:all) { described_class.call(options) }
10
+
11
+ let(:options) { { list_id: '123' } }
12
+
13
+ before { all }
14
+
15
+ it { assert_requested :get, "https://api.castle.io/v1/lists/#{options[:list_id]}", times: 1 }
16
+ end
17
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.describe Castle::API::Lists::Query do
4
+ before do
5
+ stub_request(:any, /api.castle.io/).with(basic_auth: ['', 'secret']).to_return(status: 200, body: '{}', headers: {})
6
+ end
7
+
8
+ describe '.call' do
9
+ subject(:all) { described_class.call(options) }
10
+
11
+ let(:options) { { filters: [{ field: 'test', op: '$eq', value: 'test' }] } }
12
+
13
+ before { all }
14
+
15
+ it do
16
+ assert_requested :post, "https://api.castle.io/v1/lists/query", times: 1 do |req|
17
+ expect(JSON.parse(req.body, symbolize_names: true)).to eq(options)
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.describe Castle::API::Lists::Update do
4
+ before do
5
+ stub_request(:any, /api.castle.io/).with(basic_auth: ['', 'secret']).to_return(status: 200, body: '{}', headers: {})
6
+ end
7
+
8
+ describe '.call' do
9
+ subject(:all) { described_class.call(options) }
10
+
11
+ let(:options) { { list_id: '123', name: 'name', color: '$red' } }
12
+
13
+ before { all }
14
+
15
+ it do
16
+ assert_requested :put, "https://api.castle.io/v1/lists/#{options[:list_id]}", times: 1 do |req|
17
+ expect(JSON.parse(req.body, symbolize_names: true)).to eq(options.except(:list_id))
18
+ end
19
+ end
20
+ end
21
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- describe Castle::API::Log do
3
+ RSpec.describe Castle::API::Log do
4
4
  pending
5
5
  end
@@ -1,10 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- describe Castle::API::ReportDevice do
3
+ RSpec.describe Castle::API::ReportDevice do
4
4
  before do
5
- stub_request(:any, /api.castle.io/)
6
- .with(basic_auth: ['', 'secret'])
7
- .to_return(status: 200, body: '{}', headers: {})
5
+ stub_request(:any, /api.castle.io/).with(basic_auth: ['', 'secret']).to_return(status: 200, body: '{}', headers: {})
8
6
  end
9
7
 
10
8
  describe '.call' do
@@ -14,8 +12,6 @@ describe Castle::API::ReportDevice do
14
12
 
15
13
  before { retrieve }
16
14
 
17
- it do
18
- assert_requested :put, "https://api.castle.io/v1/devices/#{device_token}/report", times: 1
19
- end
15
+ it { assert_requested :put, "https://api.castle.io/v1/devices/#{device_token}/report", times: 1 }
20
16
  end
21
17
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- describe Castle::API::Risk do
3
+ RSpec.describe Castle::API::Risk do
4
4
  pending
5
5
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- describe Castle::API::StartImpersonation do
3
+ RSpec.describe Castle::API::StartImpersonation do
4
4
  subject(:call) { described_class.call(options) }
5
5
 
6
6
  let(:ip) { '1.2.3.4' }
@@ -22,9 +22,12 @@ describe Castle::API::StartImpersonation do
22
22
  before do
23
23
  Timecop.freeze(time_now)
24
24
  stub_const('Castle::VERSION', '2.2.0')
25
- stub_request(:any, /api.castle.io/)
26
- .with(basic_auth: ['', 'secret'])
27
- .to_return(status: 200, body: response_body, headers: {})
25
+ stub_request(:any, /api.castle.io/).with(basic_auth: ['', 'secret']).to_return(
26
+ status: 200,
27
+ body: response_body,
28
+ headers: {
29
+ }
30
+ )
28
31
  end
29
32
 
30
33
  after { Timecop.return }
@@ -32,19 +35,10 @@ describe Castle::API::StartImpersonation do
32
35
  describe 'call' do
33
36
  let(:impersonator) { 'test@castle.io' }
34
37
  let(:request_body) do
35
- {
36
- user_id: '1234',
37
- sent_at: time_auto,
38
- properties: {
39
- impersonator: impersonator
40
- },
41
- context: context
42
- }
38
+ { user_id: '1234', sent_at: time_auto, properties: { impersonator: impersonator }, context: context }
43
39
  end
44
40
  let(:response_body) { { success: true }.to_json }
45
- let(:options) do
46
- { user_id: '1234', properties: { impersonator: impersonator }, context: context }
47
- end
41
+ let(:options) { { user_id: '1234', properties: { impersonator: impersonator }, context: context } }
48
42
 
49
43
  context 'when used with symbol keys' do
50
44
  before { call }
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- describe Castle::API::Track do
3
+ RSpec.describe Castle::API::Track do
4
4
  subject(:call) { described_class.call(options) }
5
5
 
6
6
  let(:ip) { '1.2.3.4' }
@@ -24,17 +24,18 @@ describe Castle::API::Track do
24
24
  before do
25
25
  Timecop.freeze(time_now)
26
26
  stub_const('Castle::VERSION', '2.2.0')
27
- stub_request(:any, /api.castle.io/)
28
- .with(basic_auth: ['', 'secret'])
29
- .to_return(status: 200, body: response_body, headers: {})
27
+ stub_request(:any, /api.castle.io/).with(basic_auth: ['', 'secret']).to_return(
28
+ status: 200,
29
+ body: response_body,
30
+ headers: {
31
+ }
32
+ )
30
33
  end
31
34
 
32
35
  after { Timecop.return }
33
36
 
34
37
  describe 'track' do
35
- let(:request_body) do
36
- { event: '$login.succeeded', context: context, user_id: '1234', sent_at: time_auto }
37
- end
38
+ let(:request_body) { { event: '$login.succeeded', context: context, user_id: '1234', sent_at: time_auto } }
38
39
 
39
40
  before { call }
40
41
 
@@ -48,17 +49,9 @@ describe Castle::API::Track do
48
49
  end
49
50
 
50
51
  context 'when passed timestamp in options and no defined timestamp' do
51
- let(:options) do
52
- { event: '$login.succeeded', user_id: '1234', timestamp: time_user, context: context }
53
- end
52
+ let(:options) { { event: '$login.succeeded', user_id: '1234', timestamp: time_user, context: context } }
54
53
  let(:request_body) do
55
- {
56
- event: '$login.succeeded',
57
- user_id: '1234',
58
- context: context,
59
- timestamp: time_user,
60
- sent_at: time_auto
61
- }
54
+ { event: '$login.succeeded', user_id: '1234', context: context, timestamp: time_user, sent_at: time_auto }
62
55
  end
63
56
 
64
57
  it do
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- describe Castle::API do
3
+ RSpec.describe Castle::API do
4
4
  subject(:call) { described_class.call(command) }
5
5
 
6
6
  let(:command) { Castle::Commands::Track.build(event: '$login.succeeded') }
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- describe Castle::ClientId::Extract do
3
+ RSpec.describe Castle::ClientId::Extract do
4
4
  subject(:extractor) { described_class.new(formatted_headers, cookies) }
5
5
 
6
6
  let(:formatted_headers) { Castle::Headers::Filter.new(request).call }
@@ -11,20 +11,13 @@ describe Castle::ClientId::Extract do
11
11
  let(:env) { Rack::MockRequest.env_for('/', headers) }
12
12
 
13
13
  context 'with client_id' do
14
- let(:headers) do
15
- {
16
- 'HTTP_X_FORWARDED_FOR' => '1.2.3.4',
17
- 'HTTP_COOKIE' => "__cid=#{client_id_cookie};other=efgh"
18
- }
19
- end
14
+ let(:headers) { { 'HTTP_X_FORWARDED_FOR' => '1.2.3.4', 'HTTP_COOKIE' => "__cid=#{client_id_cookie};other=efgh" } }
20
15
 
21
16
  it { expect(extractor.call).to eql(client_id_cookie) }
22
17
  end
23
18
 
24
19
  context 'with X-Castle-Client-Id header' do
25
- let(:headers) do
26
- { 'HTTP_X_FORWARDED_FOR' => '1.2.3.4', 'HTTP_X_CASTLE_CLIENT_ID' => client_id_header }
27
- end
20
+ let(:headers) { { 'HTTP_X_FORWARDED_FOR' => '1.2.3.4', 'HTTP_X_CASTLE_CLIENT_ID' => client_id_header } }
28
21
 
29
22
  it 'appends the client_id' do
30
23
  expect(extractor.call).to eql(client_id_header)