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
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
RSpec.describe Castle::Commands::ListItems::Unarchive do
|
4
|
+
describe '.build' do
|
5
|
+
subject(:command) { described_class.build(options) }
|
6
|
+
|
7
|
+
context 'with valid options' do
|
8
|
+
let(:options) { { list_id: 'list_id', list_item_id: 'list_item_id'} }
|
9
|
+
|
10
|
+
it { expect(command.method).to be(:put) }
|
11
|
+
it { expect(command.path).to eql('lists/list_id/items/list_item_id/unarchive') }
|
12
|
+
it { expect(command.data).to be_nil }
|
13
|
+
end
|
14
|
+
|
15
|
+
context 'with invalid options' do
|
16
|
+
let(:options) { { list_id: 'list_id' } }
|
17
|
+
|
18
|
+
it { expect { command }.to raise_error(Castle::InvalidParametersError) }
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
RSpec.describe Castle::Commands::ListItems::Update do
|
4
|
+
describe '.build' do
|
5
|
+
subject(:command) { described_class.build(options) }
|
6
|
+
|
7
|
+
context 'with valid options' do
|
8
|
+
let(:options) { { list_id: 'list_id', list_item_id: 'list_item_id', comment: 'updating item' } }
|
9
|
+
|
10
|
+
it { expect(command.method).to be(:put) }
|
11
|
+
it { expect(command.path).to eql('lists/list_id/items/list_item_id') }
|
12
|
+
it { expect(command.data).to eql(options.except(:list_id, :list_item_id)) }
|
13
|
+
end
|
14
|
+
|
15
|
+
context 'with invalid options' do
|
16
|
+
let(:options) { { list_id: 'list_id', list_item_id: 'list_item_id' } }
|
17
|
+
|
18
|
+
it { expect { command }.to raise_error(Castle::InvalidParametersError) }
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
RSpec.describe Castle::Commands::Lists::Create do
|
4
|
+
describe '.build' do
|
5
|
+
subject(:command) { described_class.build(options) }
|
6
|
+
|
7
|
+
let(:options) { { name: 'list_name', color: '$green', primary_field: 'user.email' } }
|
8
|
+
|
9
|
+
context 'with valid options' do
|
10
|
+
it { expect(command.method).to be(:post) }
|
11
|
+
it { expect(command.path).to eql('lists') }
|
12
|
+
it { expect(command.data).to eql(options) }
|
13
|
+
end
|
14
|
+
|
15
|
+
context 'without name' do
|
16
|
+
let(:options) { { color: '$green', primary_field: 'user.email' } }
|
17
|
+
|
18
|
+
it { expect { command }.to raise_error(Castle::InvalidParametersError) }
|
19
|
+
end
|
20
|
+
|
21
|
+
context 'without color' do
|
22
|
+
let(:options) { { name: 'list_name', primary_field: 'user.email' } }
|
23
|
+
|
24
|
+
it { expect { command }.to raise_error(Castle::InvalidParametersError) }
|
25
|
+
end
|
26
|
+
|
27
|
+
context 'without primary_field' do
|
28
|
+
let(:options) { { name: 'list_name', color: '$green' } }
|
29
|
+
|
30
|
+
it { expect { command }.to raise_error(Castle::InvalidParametersError) }
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
RSpec.describe Castle::Commands::Lists::Delete do
|
4
|
+
describe '.build' do
|
5
|
+
subject(:command) { described_class.build(options) }
|
6
|
+
|
7
|
+
let(:options) { { list_id: 'list_id' } }
|
8
|
+
|
9
|
+
context 'with valid options' do
|
10
|
+
it { expect(command.method).to be(:delete) }
|
11
|
+
it { expect(command.path).to eql('lists/list_id') }
|
12
|
+
it { expect(command.data).to be_nil }
|
13
|
+
end
|
14
|
+
|
15
|
+
context 'without list_id' do
|
16
|
+
let(:options) { {} }
|
17
|
+
|
18
|
+
it { expect { command }.to raise_error(Castle::InvalidParametersError) }
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
RSpec.describe Castle::Commands::Lists::GetAll do
|
4
|
+
describe '.build' do
|
5
|
+
subject(:command) { described_class.build }
|
6
|
+
|
7
|
+
it { expect(command.method).to be(:get) }
|
8
|
+
it { expect(command.path).to eql('lists') }
|
9
|
+
it { expect(command.data).to be_nil }
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
RSpec.describe Castle::Commands::Lists::Get do
|
4
|
+
describe '.build' do
|
5
|
+
subject(:command) { described_class.build(options) }
|
6
|
+
|
7
|
+
let(:options) { { list_id: 'list_id' } }
|
8
|
+
|
9
|
+
context 'with valid options' do
|
10
|
+
it { expect(command.method).to be(:get) }
|
11
|
+
it { expect(command.path).to eql('lists/list_id') }
|
12
|
+
it { expect(command.data).to be_nil }
|
13
|
+
end
|
14
|
+
|
15
|
+
context 'without list_id' do
|
16
|
+
let(:options) { {} }
|
17
|
+
|
18
|
+
it { expect { command }.to raise_error(Castle::InvalidParametersError) }
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
RSpec.describe Castle::Commands::Lists::Query do
|
4
|
+
describe '.build' do
|
5
|
+
subject(:command) { described_class.build(options) }
|
6
|
+
|
7
|
+
context 'with valid options' do
|
8
|
+
let(:options) { { filters: [{ field: 'primary_field', op: '$eq', value: 'test' }]} }
|
9
|
+
|
10
|
+
it { expect(command.method).to be(:post) }
|
11
|
+
it { expect(command.path).to eql('lists/query') }
|
12
|
+
it { expect(command.data).to eq(options.except(:list_id)) }
|
13
|
+
end
|
14
|
+
|
15
|
+
context 'with invalid filters' do
|
16
|
+
let(:options) { { filters: [{ field: 'primary_field', op: '$eq' }]} }
|
17
|
+
|
18
|
+
it { expect { command }.to raise_error(Castle::InvalidParametersError) }
|
19
|
+
end
|
20
|
+
|
21
|
+
context 'with invalid sort' do
|
22
|
+
let(:options) { { sort: { field: 'primary_field' } } }
|
23
|
+
|
24
|
+
it { expect { command }.to raise_error(Castle::InvalidParametersError) }
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
RSpec.describe Castle::Commands::Lists::Update do
|
4
|
+
describe '.build' do
|
5
|
+
subject(:command) { described_class.build(options) }
|
6
|
+
|
7
|
+
context 'with valid options' do
|
8
|
+
let(:options) do
|
9
|
+
{
|
10
|
+
list_id: 'list_id',
|
11
|
+
name: 'name',
|
12
|
+
description: 'description',
|
13
|
+
color: '$yellow',
|
14
|
+
default_item_archivation_time: 6000
|
15
|
+
}
|
16
|
+
end
|
17
|
+
|
18
|
+
it { expect(command.method).to be(:put) }
|
19
|
+
it { expect(command.path).to eql('lists/list_id') }
|
20
|
+
it { expect(command.data).to eql(options.except(:list_id)) }
|
21
|
+
end
|
22
|
+
|
23
|
+
context 'without list_id' do
|
24
|
+
let(:options) { { name: 'name' } }
|
25
|
+
|
26
|
+
it { expect { command }.to raise_error(Castle::InvalidParametersError) }
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
describe Castle::Commands::Log do
|
3
|
+
RSpec.describe Castle::Commands::Log do
|
4
4
|
subject(:instance) { described_class }
|
5
5
|
|
6
6
|
let(:context) { { test: { test1: '1' } } }
|
@@ -29,45 +29,45 @@ describe Castle::Commands::Log do
|
|
29
29
|
let(:payload) { default_payload.merge(properties: { test: '1' }) }
|
30
30
|
let(:command_data) { default_payload.merge(properties: { test: '1' }, context: context) }
|
31
31
|
|
32
|
-
it { expect(command.method).to
|
33
|
-
it { expect(command.path).to
|
34
|
-
it { expect(command.data).to
|
32
|
+
it { expect(command.method).to be(:post) }
|
33
|
+
it { expect(command.path).to eql('log') }
|
34
|
+
it { expect(command.data).to eql(command_data) }
|
35
35
|
end
|
36
36
|
|
37
37
|
context 'with user_traits' do
|
38
38
|
let(:payload) { default_payload.merge(user_traits: { test: '1' }) }
|
39
39
|
let(:command_data) { default_payload.merge(user_traits: { test: '1' }, context: context) }
|
40
40
|
|
41
|
-
it { expect(command.method).to
|
42
|
-
it { expect(command.path).to
|
43
|
-
it { expect(command.data).to
|
41
|
+
it { expect(command.method).to be(:post) }
|
42
|
+
it { expect(command.path).to eql('log') }
|
43
|
+
it { expect(command.data).to eql(command_data) }
|
44
44
|
end
|
45
45
|
|
46
46
|
context 'when active true' do
|
47
47
|
let(:payload) { default_payload.merge(context: context.merge(active: true)) }
|
48
48
|
let(:command_data) { default_payload.merge(context: context.merge(active: true)) }
|
49
49
|
|
50
|
-
it { expect(command.method).to
|
51
|
-
it { expect(command.path).to
|
52
|
-
it { expect(command.data).to
|
50
|
+
it { expect(command.method).to be(:post) }
|
51
|
+
it { expect(command.path).to eql('log') }
|
52
|
+
it { expect(command.data).to eql(command_data) }
|
53
53
|
end
|
54
54
|
|
55
55
|
context 'when active false' do
|
56
56
|
let(:payload) { default_payload.merge(context: context.merge(active: false)) }
|
57
57
|
let(:command_data) { default_payload.merge(context: context.merge(active: false)) }
|
58
58
|
|
59
|
-
it { expect(command.method).to
|
60
|
-
it { expect(command.path).to
|
61
|
-
it { expect(command.data).to
|
59
|
+
it { expect(command.method).to be(:post) }
|
60
|
+
it { expect(command.path).to eql('log') }
|
61
|
+
it { expect(command.data).to eql(command_data) }
|
62
62
|
end
|
63
63
|
|
64
64
|
context 'when active string' do
|
65
65
|
let(:payload) { default_payload.merge(context: context.merge(active: 'string')) }
|
66
66
|
let(:command_data) { default_payload.merge(context: context) }
|
67
67
|
|
68
|
-
it { expect(command.method).to
|
69
|
-
it { expect(command.path).to
|
70
|
-
it { expect(command.data).to
|
68
|
+
it { expect(command.method).to be(:post) }
|
69
|
+
it { expect(command.path).to eql('log') }
|
70
|
+
it { expect(command.data).to eql(command_data) }
|
71
71
|
end
|
72
72
|
end
|
73
73
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
describe Castle::Commands::ReportDevice do
|
3
|
+
RSpec.describe Castle::Commands::ReportDevice do
|
4
4
|
subject(:instance) { described_class }
|
5
5
|
|
6
6
|
let(:context) { {} }
|
@@ -16,8 +16,8 @@ describe Castle::Commands::ReportDevice do
|
|
16
16
|
end
|
17
17
|
|
18
18
|
context 'with device_token' do
|
19
|
-
it { expect(command.method).to
|
20
|
-
it { expect(command.path).to
|
19
|
+
it { expect(command.method).to be(:put) }
|
20
|
+
it { expect(command.path).to eql("devices/#{device_token}/report") }
|
21
21
|
it { expect(command.data).to be_nil }
|
22
22
|
end
|
23
23
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
describe Castle::Commands::Risk do
|
3
|
+
RSpec.describe Castle::Commands::Risk do
|
4
4
|
subject(:instance) { described_class }
|
5
5
|
|
6
6
|
let(:context) { { test: { test1: '1' } } }
|
@@ -29,45 +29,45 @@ describe Castle::Commands::Risk do
|
|
29
29
|
let(:payload) { default_payload.merge(properties: { test: '1' }) }
|
30
30
|
let(:command_data) { default_payload.merge(properties: { test: '1' }, context: context) }
|
31
31
|
|
32
|
-
it { expect(command.method).to
|
33
|
-
it { expect(command.path).to
|
34
|
-
it { expect(command.data).to
|
32
|
+
it { expect(command.method).to be(:post) }
|
33
|
+
it { expect(command.path).to eql('risk') }
|
34
|
+
it { expect(command.data).to eql(command_data) }
|
35
35
|
end
|
36
36
|
|
37
37
|
context 'with user_traits' do
|
38
38
|
let(:payload) { default_payload.merge(user_traits: { test: '1' }) }
|
39
39
|
let(:command_data) { default_payload.merge(user_traits: { test: '1' }, context: context) }
|
40
40
|
|
41
|
-
it { expect(command.method).to
|
42
|
-
it { expect(command.path).to
|
43
|
-
it { expect(command.data).to
|
41
|
+
it { expect(command.method).to be(:post) }
|
42
|
+
it { expect(command.path).to eql('risk') }
|
43
|
+
it { expect(command.data).to eql(command_data) }
|
44
44
|
end
|
45
45
|
|
46
46
|
context 'when active true' do
|
47
47
|
let(:payload) { default_payload.merge(context: context.merge(active: true)) }
|
48
48
|
let(:command_data) { default_payload.merge(context: context.merge(active: true)) }
|
49
49
|
|
50
|
-
it { expect(command.method).to
|
51
|
-
it { expect(command.path).to
|
52
|
-
it { expect(command.data).to
|
50
|
+
it { expect(command.method).to be(:post) }
|
51
|
+
it { expect(command.path).to eql('risk') }
|
52
|
+
it { expect(command.data).to eql(command_data) }
|
53
53
|
end
|
54
54
|
|
55
55
|
context 'when active false' do
|
56
56
|
let(:payload) { default_payload.merge(context: context.merge(active: false)) }
|
57
57
|
let(:command_data) { default_payload.merge(context: context.merge(active: false)) }
|
58
58
|
|
59
|
-
it { expect(command.method).to
|
60
|
-
it { expect(command.path).to
|
61
|
-
it { expect(command.data).to
|
59
|
+
it { expect(command.method).to be(:post) }
|
60
|
+
it { expect(command.path).to eql('risk') }
|
61
|
+
it { expect(command.data).to eql(command_data) }
|
62
62
|
end
|
63
63
|
|
64
64
|
context 'when active string' do
|
65
65
|
let(:payload) { default_payload.merge(context: context.merge(active: 'string')) }
|
66
66
|
let(:command_data) { default_payload.merge(context: context) }
|
67
67
|
|
68
|
-
it { expect(command.method).to
|
69
|
-
it { expect(command.path).to
|
70
|
-
it { expect(command.data).to
|
68
|
+
it { expect(command.method).to be(:post) }
|
69
|
+
it { expect(command.path).to eql('risk') }
|
70
|
+
it { expect(command.data).to eql(command_data) }
|
71
71
|
end
|
72
72
|
end
|
73
73
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
describe Castle::Commands::StartImpersonation do
|
3
|
+
RSpec.describe Castle::Commands::StartImpersonation do
|
4
4
|
subject(:instance) { described_class }
|
5
5
|
|
6
6
|
let(:context) { { user_agent: 'test', ip: '127.0.0.1', client_id: 'test' } }
|
@@ -19,40 +19,38 @@ describe Castle::Commands::StartImpersonation do
|
|
19
19
|
|
20
20
|
context 'with impersonator' do
|
21
21
|
let(:payload) { default_payload.merge(properties: { impersonator: impersonator }) }
|
22
|
-
let(:command_data)
|
23
|
-
default_payload.merge(properties: { impersonator: impersonator }, context: context)
|
24
|
-
end
|
22
|
+
let(:command_data) { default_payload.merge(properties: { impersonator: impersonator }, context: context) }
|
25
23
|
|
26
|
-
it { expect(command.method).to
|
27
|
-
it { expect(command.path).to
|
28
|
-
it { expect(command.data).to
|
24
|
+
it { expect(command.method).to be(:post) }
|
25
|
+
it { expect(command.path).to eql('impersonate') }
|
26
|
+
it { expect(command.data).to eql(command_data) }
|
29
27
|
end
|
30
28
|
|
31
29
|
context 'when active true' do
|
32
30
|
let(:payload) { default_payload.merge(context: context.merge(active: true)) }
|
33
31
|
let(:command_data) { default_payload.merge(context: context.merge(active: true)) }
|
34
32
|
|
35
|
-
it { expect(command.method).to
|
36
|
-
it { expect(command.path).to
|
37
|
-
it { expect(command.data).to
|
33
|
+
it { expect(command.method).to be(:post) }
|
34
|
+
it { expect(command.path).to eql('impersonate') }
|
35
|
+
it { expect(command.data).to eql(command_data) }
|
38
36
|
end
|
39
37
|
|
40
38
|
context 'when active false' do
|
41
39
|
let(:payload) { default_payload.merge(context: context.merge(active: false)) }
|
42
40
|
let(:command_data) { default_payload.merge(context: context.merge(active: false)) }
|
43
41
|
|
44
|
-
it { expect(command.method).to
|
45
|
-
it { expect(command.path).to
|
46
|
-
it { expect(command.data).to
|
42
|
+
it { expect(command.method).to be(:post) }
|
43
|
+
it { expect(command.path).to eql('impersonate') }
|
44
|
+
it { expect(command.data).to eql(command_data) }
|
47
45
|
end
|
48
46
|
|
49
47
|
context 'when active string' do
|
50
48
|
let(:payload) { default_payload.merge(context: context.merge(active: 'string')) }
|
51
49
|
let(:command_data) { default_payload.merge(context: context) }
|
52
50
|
|
53
|
-
it { expect(command.method).to
|
54
|
-
it { expect(command.path).to
|
55
|
-
it { expect(command.data).to
|
51
|
+
it { expect(command.method).to be(:post) }
|
52
|
+
it { expect(command.path).to eql('impersonate') }
|
53
|
+
it { expect(command.data).to eql(command_data) }
|
56
54
|
end
|
57
55
|
end
|
58
56
|
|
@@ -62,12 +60,7 @@ describe Castle::Commands::StartImpersonation do
|
|
62
60
|
context 'when user_id not present' do
|
63
61
|
let(:payload) { {} }
|
64
62
|
|
65
|
-
it
|
66
|
-
expect { validate! }.to raise_error(
|
67
|
-
Castle::InvalidParametersError,
|
68
|
-
'user_id is missing or empty'
|
69
|
-
)
|
70
|
-
end
|
63
|
+
it { expect { validate! }.to raise_error(Castle::InvalidParametersError, 'user_id is missing or empty') }
|
71
64
|
end
|
72
65
|
|
73
66
|
context 'when user_id present' do
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
describe Castle::Commands::Track do
|
3
|
+
RSpec.describe Castle::Commands::Track do
|
4
4
|
subject(:instance) { described_class }
|
5
5
|
|
6
6
|
let(:context) { { test: { test1: '1' } } }
|
@@ -20,54 +20,54 @@ describe Castle::Commands::Track do
|
|
20
20
|
let(:payload) { default_payload.merge(user_id: '1234') }
|
21
21
|
let(:command_data) { default_payload.merge(user_id: '1234', context: context) }
|
22
22
|
|
23
|
-
it { expect(command.method).to
|
24
|
-
it { expect(command.path).to
|
25
|
-
it { expect(command.data).to
|
23
|
+
it { expect(command.method).to be(:post) }
|
24
|
+
it { expect(command.path).to eql('track') }
|
25
|
+
it { expect(command.data).to eql(command_data) }
|
26
26
|
end
|
27
27
|
|
28
28
|
context 'with properties' do
|
29
29
|
let(:payload) { default_payload.merge(properties: { test: '1' }) }
|
30
30
|
let(:command_data) { default_payload.merge(properties: { test: '1' }, context: context) }
|
31
31
|
|
32
|
-
it { expect(command.method).to
|
33
|
-
it { expect(command.path).to
|
34
|
-
it { expect(command.data).to
|
32
|
+
it { expect(command.method).to be(:post) }
|
33
|
+
it { expect(command.path).to eql('track') }
|
34
|
+
it { expect(command.data).to eql(command_data) }
|
35
35
|
end
|
36
36
|
|
37
37
|
context 'with user_traits' do
|
38
38
|
let(:payload) { default_payload.merge(user_traits: { test: '1' }) }
|
39
39
|
let(:command_data) { default_payload.merge(user_traits: { test: '1' }, context: context) }
|
40
40
|
|
41
|
-
it { expect(command.method).to
|
42
|
-
it { expect(command.path).to
|
43
|
-
it { expect(command.data).to
|
41
|
+
it { expect(command.method).to be(:post) }
|
42
|
+
it { expect(command.path).to eql('track') }
|
43
|
+
it { expect(command.data).to eql(command_data) }
|
44
44
|
end
|
45
45
|
|
46
46
|
context 'when active true' do
|
47
47
|
let(:payload) { default_payload.merge(context: context.merge(active: true)) }
|
48
48
|
let(:command_data) { default_payload.merge(context: context.merge(active: true)) }
|
49
49
|
|
50
|
-
it { expect(command.method).to
|
51
|
-
it { expect(command.path).to
|
52
|
-
it { expect(command.data).to
|
50
|
+
it { expect(command.method).to be(:post) }
|
51
|
+
it { expect(command.path).to eql('track') }
|
52
|
+
it { expect(command.data).to eql(command_data) }
|
53
53
|
end
|
54
54
|
|
55
55
|
context 'when active false' do
|
56
56
|
let(:payload) { default_payload.merge(context: context.merge(active: false)) }
|
57
57
|
let(:command_data) { default_payload.merge(context: context.merge(active: false)) }
|
58
58
|
|
59
|
-
it { expect(command.method).to
|
60
|
-
it { expect(command.path).to
|
61
|
-
it { expect(command.data).to
|
59
|
+
it { expect(command.method).to be(:post) }
|
60
|
+
it { expect(command.path).to eql('track') }
|
61
|
+
it { expect(command.data).to eql(command_data) }
|
62
62
|
end
|
63
63
|
|
64
64
|
context 'when active string' do
|
65
65
|
let(:payload) { default_payload.merge(context: context.merge(active: 'string')) }
|
66
66
|
let(:command_data) { default_payload.merge(context: context) }
|
67
67
|
|
68
|
-
it { expect(command.method).to
|
69
|
-
it { expect(command.path).to
|
70
|
-
it { expect(command.data).to
|
68
|
+
it { expect(command.method).to be(:post) }
|
69
|
+
it { expect(command.path).to eql('track') }
|
70
|
+
it { expect(command.data).to eql(command_data) }
|
71
71
|
end
|
72
72
|
end
|
73
73
|
|
@@ -77,12 +77,7 @@ describe Castle::Commands::Track do
|
|
77
77
|
context 'when event not present' do
|
78
78
|
let(:payload) { {} }
|
79
79
|
|
80
|
-
it
|
81
|
-
expect { validate! }.to raise_error(
|
82
|
-
Castle::InvalidParametersError,
|
83
|
-
'event is missing or empty'
|
84
|
-
)
|
85
|
-
end
|
80
|
+
it { expect { validate! }.to raise_error(Castle::InvalidParametersError, 'event is missing or empty') }
|
86
81
|
end
|
87
82
|
|
88
83
|
context 'when event present' do
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
describe Castle::Configuration do
|
3
|
+
RSpec.describe Castle::Configuration do
|
4
4
|
subject(:config) { described_class.new }
|
5
5
|
|
6
6
|
it_behaves_like 'configuration_host'
|
@@ -10,5 +10,5 @@ describe Castle::Configuration do
|
|
10
10
|
it_behaves_like 'configuration_failover_strategy'
|
11
11
|
it_behaves_like 'configuration_api_secret'
|
12
12
|
|
13
|
-
it { expect(config.api_secret).to
|
13
|
+
it { expect(config.api_secret).to eql('') }
|
14
14
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
describe Castle::Context::GetDefault do
|
3
|
+
RSpec.describe Castle::Context::GetDefault do
|
4
4
|
subject { described_class.new(request, nil) }
|
5
5
|
|
6
6
|
let(:ip) { '1.2.3.4' }
|
@@ -12,7 +12,8 @@ describe Castle::Context::GetDefault do
|
|
12
12
|
'HTTP_X_FORWARDED_FOR' => ip,
|
13
13
|
'HTTP_ACCEPT_LANGUAGE' => 'en',
|
14
14
|
'HTTP_USER_AGENT' => 'test',
|
15
|
-
'HTTP_COOKIE' => "__cid=#{client_id};other=efgh"
|
15
|
+
'HTTP_COOKIE' => "__cid=#{client_id};other=efgh",
|
16
|
+
'HTTP_CONTENT_LENGTH' => '0'
|
16
17
|
)
|
17
18
|
end
|
18
19
|
let(:request) { Rack::Request.new(env) }
|
@@ -30,11 +31,11 @@ describe Castle::Context::GetDefault do
|
|
30
31
|
|
31
32
|
before { stub_const('Castle::VERSION', version) }
|
32
33
|
|
33
|
-
it { expect(default_context[:active]).to
|
34
|
-
it { expect(default_context[:headers]).to
|
35
|
-
it { expect(default_context[:ip]).to
|
36
|
-
it { expect(default_context[:client_id]).to
|
37
|
-
it { expect(default_context[:library][:name]).to
|
38
|
-
it { expect(default_context[:library][:version]).to
|
39
|
-
it { expect(default_context[:user_agent]).to
|
34
|
+
it { expect(default_context[:active]).to be(true) }
|
35
|
+
it { expect(default_context[:headers]).to eql(result_headers) }
|
36
|
+
it { expect(default_context[:ip]).to eql(ip) }
|
37
|
+
it { expect(default_context[:client_id]).to eql(client_id) }
|
38
|
+
it { expect(default_context[:library][:name]).to eql('castle-rb') }
|
39
|
+
it { expect(default_context[:library][:version]).to eql(version) }
|
40
|
+
it { expect(default_context[:user_agent]).to eql('test') }
|
40
41
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
describe Castle::Context::Prepare do
|
3
|
+
RSpec.describe Castle::Context::Prepare do
|
4
4
|
let(:ip) { '1.2.3.4' }
|
5
5
|
let(:cookie_id) { 'abcd' }
|
6
6
|
let(:ua) { 'Chrome' }
|
@@ -9,7 +9,8 @@ describe Castle::Context::Prepare do
|
|
9
9
|
'/',
|
10
10
|
'HTTP_USER_AGENT' => ua,
|
11
11
|
'HTTP_X_FORWARDED_FOR' => ip,
|
12
|
-
'HTTP_COOKIE' => "__cid=#{cookie_id};other=efgh"
|
12
|
+
'HTTP_COOKIE' => "__cid=#{cookie_id};other=efgh",
|
13
|
+
'HTTP_CONTENT_LENGTH' => '0'
|
13
14
|
)
|
14
15
|
end
|
15
16
|
let(:request) { Rack::Request.new(env) }
|
@@ -27,9 +28,7 @@ describe Castle::Context::Prepare do
|
|
27
28
|
}
|
28
29
|
end
|
29
30
|
|
30
|
-
let(:headers)
|
31
|
-
{ 'Content-Length': '0', 'User-Agent': ua, 'X-Forwarded-For': ip.to_s, 'Cookie': true }
|
32
|
-
end
|
31
|
+
let(:headers) { { 'Content-Length': '0', 'User-Agent': ua, 'X-Forwarded-For': ip.to_s, Cookie: true } }
|
33
32
|
|
34
33
|
before { stub_const('Castle::VERSION', '6.0.0') }
|
35
34
|
|