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.
- checksums.yaml +4 -4
- data/lib/castle/api/authenticate.rb +3 -12
- data/lib/castle/api/end_impersonation.rb +1 -3
- data/lib/castle/api/filter.rb +2 -10
- data/lib/castle/api/list_items/archive.rb +23 -0
- data/lib/castle/api/list_items/count.rb +22 -0
- data/lib/castle/api/list_items/create.rb +22 -0
- data/lib/castle/api/list_items/get.rb +22 -0
- data/lib/castle/api/list_items/query.rb +22 -0
- data/lib/castle/api/list_items/unarchive.rb +22 -0
- data/lib/castle/api/list_items/update.rb +22 -0
- data/lib/castle/api/lists/create.rb +23 -0
- data/lib/castle/api/lists/delete.rb +22 -0
- data/lib/castle/api/lists/get.rb +22 -0
- data/lib/castle/api/lists/get_all.rb +22 -0
- data/lib/castle/api/lists/query.rb +22 -0
- data/lib/castle/api/lists/update.rb +22 -0
- data/lib/castle/api/log.rb +2 -10
- data/lib/castle/api/risk.rb +2 -10
- data/lib/castle/api/start_impersonation.rb +1 -3
- data/lib/castle/api/track.rb +1 -3
- data/lib/castle/client.rb +4 -5
- data/lib/castle/client_actions/list_items.rb +44 -0
- data/lib/castle/client_actions/lists.rb +39 -0
- data/lib/castle/commands/list_items/archive.rb +24 -0
- data/lib/castle/commands/list_items/count.rb +23 -0
- data/lib/castle/commands/list_items/create.rb +22 -0
- data/lib/castle/commands/list_items/get.rb +23 -0
- data/lib/castle/commands/list_items/query.rb +24 -0
- data/lib/castle/commands/list_items/unarchive.rb +23 -0
- data/lib/castle/commands/list_items/update.rb +22 -0
- data/lib/castle/commands/lists/create.rb +21 -0
- data/lib/castle/commands/lists/delete.rb +20 -0
- data/lib/castle/commands/lists/get.rb +20 -0
- data/lib/castle/commands/lists/get_all.rb +17 -0
- data/lib/castle/commands/lists/query.rb +21 -0
- data/lib/castle/commands/lists/update.rb +22 -0
- data/lib/castle/commands/log.rb +1 -5
- data/lib/castle/commands/risk.rb +1 -5
- data/lib/castle/configuration.rb +2 -5
- data/lib/castle/core/process_response.rb +4 -3
- data/lib/castle/core/send_request.rb +1 -3
- data/lib/castle/errors.rb +4 -0
- data/lib/castle/headers/extract.rb +1 -3
- data/lib/castle/headers/filter.rb +2 -3
- data/lib/castle/payload/prepare.rb +1 -2
- data/lib/castle/session.rb +1 -1
- data/lib/castle/version.rb +1 -1
- data/lib/castle.rb +29 -3
- data/spec/integration/rails/rails_spec.rb +9 -3
- data/spec/integration/rails/support/application.rb +2 -2
- data/spec/integration/rails/support/home_controller.rb +4 -30
- data/spec/lib/castle/api/approve_device_spec.rb +3 -7
- data/spec/lib/castle/api/authenticate_spec.rb +23 -26
- data/spec/lib/castle/api/end_impersonation_spec.rb +9 -15
- data/spec/lib/castle/api/filter_spec.rb +1 -1
- data/spec/lib/castle/api/get_device_spec.rb +2 -4
- data/spec/lib/castle/api/get_devices_for_user_spec.rb +2 -4
- data/spec/lib/castle/api/list_items/archive_spec.rb +18 -0
- data/spec/lib/castle/api/list_items/count_spec.rb +21 -0
- data/spec/lib/castle/api/list_items/create_spec.rb +22 -0
- data/spec/lib/castle/api/list_items/get_spec.rb +18 -0
- data/spec/lib/castle/api/list_items/query_spec.rb +21 -0
- data/spec/lib/castle/api/list_items/unarchive_spec.rb +18 -0
- data/spec/lib/castle/api/list_items/update_spec.rb +22 -0
- data/spec/lib/castle/api/lists/create_spec.rb +21 -0
- data/spec/lib/castle/api/lists/delete_spec.rb +17 -0
- data/spec/lib/castle/api/lists/get_all_spec.rb +17 -0
- data/spec/lib/castle/api/lists/get_spec.rb +17 -0
- data/spec/lib/castle/api/lists/query_spec.rb +21 -0
- data/spec/lib/castle/api/lists/update_spec.rb +21 -0
- data/spec/lib/castle/api/log_spec.rb +1 -1
- data/spec/lib/castle/api/report_device_spec.rb +3 -7
- data/spec/lib/castle/api/risk_spec.rb +1 -1
- data/spec/lib/castle/api/start_impersonation_spec.rb +9 -15
- data/spec/lib/castle/api/track_spec.rb +10 -17
- data/spec/lib/castle/api_spec.rb +1 -1
- data/spec/lib/castle/client_id/extract_spec.rb +3 -10
- data/spec/lib/castle/client_spec.rb +38 -79
- data/spec/lib/castle/command_spec.rb +4 -4
- data/spec/lib/castle/commands/approve_device_spec.rb +3 -3
- data/spec/lib/castle/commands/authenticate_spec.rb +18 -25
- data/spec/lib/castle/commands/end_impersonation_spec.rb +15 -22
- data/spec/lib/castle/commands/filter_spec.rb +16 -16
- data/spec/lib/castle/commands/get_device_spec.rb +3 -3
- data/spec/lib/castle/commands/get_devices_for_user_spec.rb +3 -3
- data/spec/lib/castle/commands/list_items/archive_spec.rb +21 -0
- data/spec/lib/castle/commands/list_items/count_spec.rb +21 -0
- data/spec/lib/castle/commands/list_items/create_spec.rb +22 -0
- data/spec/lib/castle/commands/list_items/get_spec.rb +21 -0
- data/spec/lib/castle/commands/list_items/query_spec.rb +27 -0
- data/spec/lib/castle/commands/list_items/unarchive_spec.rb +21 -0
- data/spec/lib/castle/commands/list_items/update_spec.rb +21 -0
- data/spec/lib/castle/commands/lists/create_spec.rb +33 -0
- data/spec/lib/castle/commands/lists/delete_spec.rb +21 -0
- data/spec/lib/castle/commands/lists/get_all_spec.rb +11 -0
- data/spec/lib/castle/commands/lists/get_spec.rb +21 -0
- data/spec/lib/castle/commands/lists/query_spec.rb +27 -0
- data/spec/lib/castle/commands/lists/update_spec.rb +29 -0
- data/spec/lib/castle/commands/log_spec.rb +16 -16
- data/spec/lib/castle/commands/report_device_spec.rb +3 -3
- data/spec/lib/castle/commands/risk_spec.rb +16 -16
- data/spec/lib/castle/commands/start_impersonation_spec.rb +15 -22
- data/spec/lib/castle/commands/track_spec.rb +20 -25
- data/spec/lib/castle/configuration_spec.rb +2 -2
- data/spec/lib/castle/context/get_default_spec.rb +10 -9
- data/spec/lib/castle/context/merge_spec.rb +1 -1
- data/spec/lib/castle/context/prepare_spec.rb +4 -5
- data/spec/lib/castle/context/sanitize_spec.rb +1 -1
- data/spec/lib/castle/core/get_connection_spec.rb +1 -1
- data/spec/lib/castle/core/process_response_spec.rb +4 -7
- data/spec/lib/castle/core/process_webhook_spec.rb +13 -7
- data/spec/lib/castle/core/send_request_spec.rb +8 -12
- data/spec/lib/castle/failover/strategy_spec.rb +6 -6
- data/spec/lib/castle/headers/extract_spec.rb +2 -2
- data/spec/lib/castle/headers/filter_spec.rb +7 -4
- data/spec/lib/castle/headers/format_spec.rb +6 -6
- data/spec/lib/castle/ips/extract_spec.rb +3 -7
- data/spec/lib/castle/logger_spec.rb +3 -2
- data/spec/lib/castle/payload/prepare_spec.rb +5 -8
- data/spec/lib/castle/secure_mode_spec.rb +2 -4
- data/spec/lib/castle/session_spec.rb +2 -6
- data/spec/lib/castle/singleton_configuration_spec.rb +2 -2
- data/spec/lib/castle/utils/clean_invalid_chars_spec.rb +1 -1
- data/spec/lib/castle/utils/clone_spec.rb +2 -2
- data/spec/lib/castle/utils/deep_symbolize_keys_spec.rb +1 -1
- data/spec/lib/castle/utils/get_timestamp_spec.rb +1 -1
- data/spec/lib/castle/utils/merge_spec.rb +3 -5
- data/spec/lib/castle/validators/not_supported_spec.rb +2 -7
- data/spec/lib/castle/validators/present_spec.rb +3 -10
- data/spec/lib/castle/verdict_spec.rb +4 -4
- data/spec/lib/castle/version_spec.rb +1 -1
- data/spec/lib/castle/webhooks/verify_spec.rb +13 -7
- data/spec/lib/castle_spec.rb +6 -8
- data/spec/spec_helper.rb +2 -0
- data/spec/support/shared_examples/action_request.rb +16 -34
- data/spec/support/shared_examples/configuration.rb +14 -16
- data/spec/support/shared_examples/list_items.rb +52 -0
- data/spec/support/shared_examples/lists.rb +45 -0
- 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
|
-
|
27
|
-
|
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)
|
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,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,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
|
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,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
|
-
|
27
|
-
|
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)
|
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
|
-
|
29
|
-
|
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)
|
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)
|
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
|
data/spec/lib/castle/api_spec.rb
CHANGED
@@ -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)
|
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)
|
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)
|