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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +317 -0
- data/LICENSE +21 -0
- data/README.md +290 -112
- data/lib/castle/api/filter.rb +3 -1
- 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/create_batch.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 -1
- data/lib/castle/api/privacy/delete_data.rb +23 -0
- data/lib/castle/api/privacy/request_data.rb +23 -0
- data/lib/castle/api/risk.rb +2 -1
- data/lib/castle/client.rb +15 -52
- data/lib/castle/client_actions/list_items.rb +49 -0
- data/lib/castle/client_actions/lists.rb +39 -0
- data/lib/castle/client_actions/privacy.rb +20 -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/create_batch.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/privacy/delete_data.rb +20 -0
- data/lib/castle/commands/privacy/request_data.rb +20 -0
- data/lib/castle/core/get_connection.rb +5 -1
- data/lib/castle/core/process_response.rb +1 -0
- data/lib/castle/core/process_webhook.rb +1 -1
- data/lib/castle/core/send_request.rb +2 -1
- data/lib/castle/errors.rb +1 -5
- data/lib/castle/headers/filter.rb +1 -1
- data/lib/castle/version.rb +1 -1
- data/lib/castle.rb +36 -17
- metadata +62 -162
- data/lib/castle/api/approve_device.rb +0 -20
- data/lib/castle/api/authenticate.rb +0 -28
- data/lib/castle/api/end_impersonation.rb +0 -22
- data/lib/castle/api/get_device.rb +0 -20
- data/lib/castle/api/get_devices_for_user.rb +0 -20
- data/lib/castle/api/report_device.rb +0 -20
- data/lib/castle/api/start_impersonation.rb +0 -22
- data/lib/castle/api/track.rb +0 -19
- data/lib/castle/commands/approve_device.rb +0 -17
- data/lib/castle/commands/authenticate.rb +0 -23
- data/lib/castle/commands/end_impersonation.rb +0 -25
- data/lib/castle/commands/get_device.rb +0 -17
- data/lib/castle/commands/get_devices_for_user.rb +0 -17
- data/lib/castle/commands/report_device.rb +0 -17
- data/lib/castle/commands/start_impersonation.rb +0 -25
- data/lib/castle/commands/track.rb +0 -22
- data/lib/castle/support/hanami.rb +0 -15
- data/lib/castle/support/padrino.rb +0 -19
- data/spec/integration/rails/rails_spec.rb +0 -95
- data/spec/integration/rails/support/all.rb +0 -6
- data/spec/integration/rails/support/application.rb +0 -17
- data/spec/integration/rails/support/home_controller.rb +0 -39
- data/spec/lib/castle/api/approve_device_spec.rb +0 -17
- data/spec/lib/castle/api/authenticate_spec.rb +0 -133
- data/spec/lib/castle/api/end_impersonation_spec.rb +0 -59
- data/spec/lib/castle/api/filter_spec.rb +0 -5
- data/spec/lib/castle/api/get_device_spec.rb +0 -17
- data/spec/lib/castle/api/get_devices_for_user_spec.rb +0 -17
- data/spec/lib/castle/api/log_spec.rb +0 -5
- data/spec/lib/castle/api/report_device_spec.rb +0 -17
- data/spec/lib/castle/api/risk_spec.rb +0 -5
- data/spec/lib/castle/api/start_impersonation_spec.rb +0 -59
- data/spec/lib/castle/api/track_spec.rb +0 -65
- data/spec/lib/castle/api_spec.rb +0 -36
- data/spec/lib/castle/client_id/extract_spec.rb +0 -47
- data/spec/lib/castle/client_spec.rb +0 -337
- data/spec/lib/castle/command_spec.rb +0 -9
- data/spec/lib/castle/commands/approve_device_spec.rb +0 -24
- data/spec/lib/castle/commands/authenticate_spec.rb +0 -86
- data/spec/lib/castle/commands/end_impersonation_spec.rb +0 -72
- data/spec/lib/castle/commands/filter_spec.rb +0 -72
- data/spec/lib/castle/commands/get_device_spec.rb +0 -24
- data/spec/lib/castle/commands/get_devices_for_user_spec.rb +0 -24
- data/spec/lib/castle/commands/log_spec.rb +0 -73
- data/spec/lib/castle/commands/report_device_spec.rb +0 -24
- data/spec/lib/castle/commands/risk_spec.rb +0 -73
- data/spec/lib/castle/commands/start_impersonation_spec.rb +0 -72
- data/spec/lib/castle/commands/track_spec.rb +0 -89
- data/spec/lib/castle/configuration_spec.rb +0 -14
- data/spec/lib/castle/context/get_default_spec.rb +0 -41
- data/spec/lib/castle/context/merge_spec.rb +0 -23
- data/spec/lib/castle/context/prepare_spec.rb +0 -42
- data/spec/lib/castle/context/sanitize_spec.rb +0 -27
- data/spec/lib/castle/core/get_connection_spec.rb +0 -43
- data/spec/lib/castle/core/process_response_spec.rb +0 -103
- data/spec/lib/castle/core/process_webhook_spec.rb +0 -52
- data/spec/lib/castle/core/send_request_spec.rb +0 -97
- data/spec/lib/castle/failover/strategy_spec.rb +0 -12
- data/spec/lib/castle/headers/extract_spec.rb +0 -103
- data/spec/lib/castle/headers/filter_spec.rb +0 -42
- data/spec/lib/castle/headers/format_spec.rb +0 -25
- data/spec/lib/castle/ips/extract_spec.rb +0 -91
- data/spec/lib/castle/logger_spec.rb +0 -39
- data/spec/lib/castle/payload/prepare_spec.rb +0 -52
- data/spec/lib/castle/secure_mode_spec.rb +0 -7
- data/spec/lib/castle/session_spec.rb +0 -61
- data/spec/lib/castle/singleton_configuration_spec.rb +0 -14
- data/spec/lib/castle/utils/clean_invalid_chars_spec.rb +0 -69
- data/spec/lib/castle/utils/clone_spec.rb +0 -19
- data/spec/lib/castle/utils/deep_symbolize_keys_spec.rb +0 -50
- data/spec/lib/castle/utils/get_timestamp_spec.rb +0 -16
- data/spec/lib/castle/utils/merge_spec.rb +0 -13
- data/spec/lib/castle/validators/not_supported_spec.rb +0 -19
- data/spec/lib/castle/validators/present_spec.rb +0 -25
- data/spec/lib/castle/verdict_spec.rb +0 -9
- data/spec/lib/castle/version_spec.rb +0 -5
- data/spec/lib/castle/webhooks/verify_spec.rb +0 -59
- data/spec/lib/castle_spec.rb +0 -58
- data/spec/spec_helper.rb +0 -24
- data/spec/support/shared_examples/action_request.rb +0 -167
- data/spec/support/shared_examples/configuration.rb +0 -99
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
describe Castle::Commands::Authenticate do
|
|
4
|
-
subject(:instance) { described_class }
|
|
5
|
-
|
|
6
|
-
let(:context) { { test: { test1: '1' } } }
|
|
7
|
-
let(:default_payload) { { event: '$login.authenticate', user_id: '1234', sent_at: time_auto, context: context } }
|
|
8
|
-
|
|
9
|
-
let(:time_now) { Time.now }
|
|
10
|
-
let(:time_auto) { time_now.utc.iso8601(3) }
|
|
11
|
-
|
|
12
|
-
before { Timecop.freeze(time_now) }
|
|
13
|
-
|
|
14
|
-
after { Timecop.return }
|
|
15
|
-
|
|
16
|
-
describe '.build' do
|
|
17
|
-
subject(:command) { instance.build(payload) }
|
|
18
|
-
|
|
19
|
-
context 'with properties' do
|
|
20
|
-
let(:payload) { default_payload.merge(properties: { test: '1' }) }
|
|
21
|
-
let(:command_data) { default_payload.merge(properties: { test: '1' }, context: context) }
|
|
22
|
-
|
|
23
|
-
it { expect(command.method).to be(:post) }
|
|
24
|
-
it { expect(command.path).to eql('authenticate') }
|
|
25
|
-
it { expect(command.data).to eql(command_data) }
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
context 'with user_traits' do
|
|
29
|
-
let(:payload) { default_payload.merge(user_traits: { test: '1' }) }
|
|
30
|
-
let(:command_data) { default_payload.merge(user_traits: { test: '1' }, context: context) }
|
|
31
|
-
|
|
32
|
-
it { expect(command.method).to be(:post) }
|
|
33
|
-
it { expect(command.path).to eql('authenticate') }
|
|
34
|
-
it { expect(command.data).to eql(command_data) }
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
context 'when active true' do
|
|
38
|
-
let(:payload) { default_payload.merge(context: context.merge(active: true)) }
|
|
39
|
-
let(:command_data) { default_payload.merge(context: context.merge(active: true)) }
|
|
40
|
-
|
|
41
|
-
it { expect(command.method).to be(:post) }
|
|
42
|
-
it { expect(command.path).to eql('authenticate') }
|
|
43
|
-
it { expect(command.data).to eql(command_data) }
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
context 'when active false' do
|
|
47
|
-
let(:payload) { default_payload.merge(context: context.merge(active: false)) }
|
|
48
|
-
let(:command_data) { default_payload.merge(context: context.merge(active: false)) }
|
|
49
|
-
|
|
50
|
-
it { expect(command.method).to be(:post) }
|
|
51
|
-
it { expect(command.path).to eql('authenticate') }
|
|
52
|
-
it { expect(command.data).to eql(command_data) }
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
context 'when active string' do
|
|
56
|
-
let(:payload) { default_payload.merge(context: context.merge(active: 'string')) }
|
|
57
|
-
let(:command_data) { default_payload.merge(context: context) }
|
|
58
|
-
|
|
59
|
-
it { expect(command.method).to be(:post) }
|
|
60
|
-
it { expect(command.path).to eql('authenticate') }
|
|
61
|
-
it { expect(command.data).to eql(command_data) }
|
|
62
|
-
end
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
describe '#validate!' do
|
|
66
|
-
subject(:validate!) { instance.build(payload) }
|
|
67
|
-
|
|
68
|
-
context 'with event not present' do
|
|
69
|
-
let(:payload) { {} }
|
|
70
|
-
|
|
71
|
-
it { expect { validate! }.to raise_error(Castle::InvalidParametersError, 'event is missing or empty') }
|
|
72
|
-
end
|
|
73
|
-
|
|
74
|
-
context 'with user_id not present' do
|
|
75
|
-
let(:payload) { { event: '$login.track' } }
|
|
76
|
-
|
|
77
|
-
it { expect { validate! }.not_to raise_error }
|
|
78
|
-
end
|
|
79
|
-
|
|
80
|
-
context 'with event and user_id present' do
|
|
81
|
-
let(:payload) { { event: '$login.track', user_id: '1234' } }
|
|
82
|
-
|
|
83
|
-
it { expect { validate! }.not_to raise_error }
|
|
84
|
-
end
|
|
85
|
-
end
|
|
86
|
-
end
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
describe Castle::Commands::EndImpersonation do
|
|
4
|
-
subject(:instance) { described_class }
|
|
5
|
-
|
|
6
|
-
let(:context) { { user_agent: 'test', ip: '127.0.0.1', client_id: 'test' } }
|
|
7
|
-
let(:impersonator) { 'test@castle.io' }
|
|
8
|
-
let(:default_payload) { { user_id: '1234', sent_at: time_auto, context: context } }
|
|
9
|
-
|
|
10
|
-
let(:time_now) { Time.now }
|
|
11
|
-
let(:time_auto) { time_now.utc.iso8601(3) }
|
|
12
|
-
|
|
13
|
-
before { Timecop.freeze(time_now) }
|
|
14
|
-
|
|
15
|
-
after { Timecop.return }
|
|
16
|
-
|
|
17
|
-
describe '.build' do
|
|
18
|
-
subject(:command) { instance.build(payload) }
|
|
19
|
-
|
|
20
|
-
context 'with impersonator' do
|
|
21
|
-
let(:payload) { default_payload.merge(properties: { impersonator: impersonator }) }
|
|
22
|
-
let(:command_data) { default_payload.merge(properties: { impersonator: impersonator }, context: context) }
|
|
23
|
-
|
|
24
|
-
it { expect(command.method).to be(:delete) }
|
|
25
|
-
it { expect(command.path).to eql('impersonate') }
|
|
26
|
-
it { expect(command.data).to eql(command_data) }
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
context 'when active true' do
|
|
30
|
-
let(:payload) { default_payload.merge(context: context.merge(active: true)) }
|
|
31
|
-
let(:command_data) { default_payload.merge(context: context.merge(active: true)) }
|
|
32
|
-
|
|
33
|
-
it { expect(command.method).to be(:delete) }
|
|
34
|
-
it { expect(command.path).to eql('impersonate') }
|
|
35
|
-
it { expect(command.data).to eql(command_data) }
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
context 'when active false' do
|
|
39
|
-
let(:payload) { default_payload.merge(context: context.merge(active: false)) }
|
|
40
|
-
let(:command_data) { default_payload.merge(context: context.merge(active: false)) }
|
|
41
|
-
|
|
42
|
-
it { expect(command.method).to be(:delete) }
|
|
43
|
-
it { expect(command.path).to eql('impersonate') }
|
|
44
|
-
it { expect(command.data).to eql(command_data) }
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
context 'when active string' do
|
|
48
|
-
let(:payload) { default_payload.merge(context: context.merge(active: 'string')) }
|
|
49
|
-
let(:command_data) { default_payload.merge(context: context) }
|
|
50
|
-
|
|
51
|
-
it { expect(command.method).to be(:delete) }
|
|
52
|
-
it { expect(command.path).to eql('impersonate') }
|
|
53
|
-
it { expect(command.data).to eql(command_data) }
|
|
54
|
-
end
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
describe '#validate!' do
|
|
58
|
-
subject(:validate!) { instance.build(payload) }
|
|
59
|
-
|
|
60
|
-
context 'when user_id not present' do
|
|
61
|
-
let(:payload) { {} }
|
|
62
|
-
|
|
63
|
-
it { expect { validate! }.to raise_error(Castle::InvalidParametersError, 'user_id is missing or empty') }
|
|
64
|
-
end
|
|
65
|
-
|
|
66
|
-
context 'when user_id present' do
|
|
67
|
-
let(:payload) { { user_id: '1234', context: context } }
|
|
68
|
-
|
|
69
|
-
it { expect { validate! }.not_to raise_error }
|
|
70
|
-
end
|
|
71
|
-
end
|
|
72
|
-
end
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
describe Castle::Commands::Filter do
|
|
4
|
-
subject(:instance) { described_class }
|
|
5
|
-
|
|
6
|
-
let(:context) { { test: { test1: '1' } } }
|
|
7
|
-
let(:user) { { id: '1234', email: 'foobar@mail.com' } }
|
|
8
|
-
let(:default_payload) do
|
|
9
|
-
{
|
|
10
|
-
request_token: '7e51335b-f4bc-4bc7-875d-b713fb61eb23-bf021a3022a1a302',
|
|
11
|
-
event: '$registration',
|
|
12
|
-
user: user,
|
|
13
|
-
sent_at: time_auto,
|
|
14
|
-
context: context
|
|
15
|
-
}
|
|
16
|
-
end
|
|
17
|
-
let(:time_now) { Time.now }
|
|
18
|
-
let(:time_auto) { time_now.utc.iso8601(3) }
|
|
19
|
-
|
|
20
|
-
before { Timecop.freeze(time_now) }
|
|
21
|
-
|
|
22
|
-
after { Timecop.return }
|
|
23
|
-
|
|
24
|
-
describe '.build' do
|
|
25
|
-
subject(:command) { instance.build(payload) }
|
|
26
|
-
|
|
27
|
-
context 'with properties' do
|
|
28
|
-
let(:payload) { default_payload.merge(properties: { test: '1' }) }
|
|
29
|
-
let(:command_data) { default_payload.merge(properties: { test: '1' }, context: context) }
|
|
30
|
-
|
|
31
|
-
it { expect(command.method).to be(:post) }
|
|
32
|
-
it { expect(command.path).to eql('filter') }
|
|
33
|
-
it { expect(command.data).to eql(command_data) }
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
context 'with user_traits' do
|
|
37
|
-
let(:payload) { default_payload.merge(user_traits: { test: '1' }) }
|
|
38
|
-
let(:command_data) { default_payload.merge(user_traits: { test: '1' }, context: context) }
|
|
39
|
-
|
|
40
|
-
it { expect(command.method).to be(:post) }
|
|
41
|
-
it { expect(command.path).to eql('filter') }
|
|
42
|
-
it { expect(command.data).to eql(command_data) }
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
context 'when active true' do
|
|
46
|
-
let(:payload) { default_payload.merge(context: context.merge(active: true)) }
|
|
47
|
-
let(:command_data) { default_payload.merge(context: context.merge(active: true)) }
|
|
48
|
-
|
|
49
|
-
it { expect(command.method).to be(:post) }
|
|
50
|
-
it { expect(command.path).to eql('filter') }
|
|
51
|
-
it { expect(command.data).to eql(command_data) }
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
context 'when active false' do
|
|
55
|
-
let(:payload) { default_payload.merge(context: context.merge(active: false)) }
|
|
56
|
-
let(:command_data) { default_payload.merge(context: context.merge(active: false)) }
|
|
57
|
-
|
|
58
|
-
it { expect(command.method).to be(:post) }
|
|
59
|
-
it { expect(command.path).to eql('filter') }
|
|
60
|
-
it { expect(command.data).to eql(command_data) }
|
|
61
|
-
end
|
|
62
|
-
|
|
63
|
-
context 'when active string' do
|
|
64
|
-
let(:payload) { default_payload.merge(context: context.merge(active: 'string')) }
|
|
65
|
-
let(:command_data) { default_payload.merge(context: context) }
|
|
66
|
-
|
|
67
|
-
it { expect(command.method).to be(:post) }
|
|
68
|
-
it { expect(command.path).to eql('filter') }
|
|
69
|
-
it { expect(command.data).to eql(command_data) }
|
|
70
|
-
end
|
|
71
|
-
end
|
|
72
|
-
end
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
describe Castle::Commands::GetDevice do
|
|
4
|
-
subject(:instance) { described_class }
|
|
5
|
-
|
|
6
|
-
let(:context) { {} }
|
|
7
|
-
let(:device_token) { '1234' }
|
|
8
|
-
|
|
9
|
-
describe '.build' do
|
|
10
|
-
subject(:command) { instance.build(device_token: device_token) }
|
|
11
|
-
|
|
12
|
-
context 'without device_token' do
|
|
13
|
-
let(:device_token) { '' }
|
|
14
|
-
|
|
15
|
-
it { expect { command }.to raise_error(Castle::InvalidParametersError) }
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
context 'with device_token' do
|
|
19
|
-
it { expect(command.method).to be(:get) }
|
|
20
|
-
it { expect(command.path).to eql("devices/#{device_token}") }
|
|
21
|
-
it { expect(command.data).to be_nil }
|
|
22
|
-
end
|
|
23
|
-
end
|
|
24
|
-
end
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
describe Castle::Commands::GetDevicesForUser do
|
|
4
|
-
subject(:instance) { described_class }
|
|
5
|
-
|
|
6
|
-
let(:context) { {} }
|
|
7
|
-
let(:user_id) { '1234' }
|
|
8
|
-
|
|
9
|
-
describe '.build' do
|
|
10
|
-
subject(:command) { instance.build(user_id: user_id) }
|
|
11
|
-
|
|
12
|
-
context 'without user_id' do
|
|
13
|
-
let(:user_id) { '' }
|
|
14
|
-
|
|
15
|
-
it { expect { command }.to raise_error(Castle::InvalidParametersError) }
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
context 'with user_id' do
|
|
19
|
-
it { expect(command.method).to be(:get) }
|
|
20
|
-
it { expect(command.path).to eql("users/#{user_id}/devices") }
|
|
21
|
-
it { expect(command.data).to be_nil }
|
|
22
|
-
end
|
|
23
|
-
end
|
|
24
|
-
end
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
describe Castle::Commands::Log do
|
|
4
|
-
subject(:instance) { described_class }
|
|
5
|
-
|
|
6
|
-
let(:context) { { test: { test1: '1' } } }
|
|
7
|
-
let(:user) { { id: '1234', email: 'foobar@mail.com' } }
|
|
8
|
-
let(:default_payload) do
|
|
9
|
-
{
|
|
10
|
-
request_token: '7e51335b-f4bc-4bc7-875d-b713fb61eb23-bf021a3022a1a302',
|
|
11
|
-
event: '$login',
|
|
12
|
-
status: '$failed',
|
|
13
|
-
user: user,
|
|
14
|
-
sent_at: time_auto,
|
|
15
|
-
context: context
|
|
16
|
-
}
|
|
17
|
-
end
|
|
18
|
-
let(:time_now) { Time.now }
|
|
19
|
-
let(:time_auto) { time_now.utc.iso8601(3) }
|
|
20
|
-
|
|
21
|
-
before { Timecop.freeze(time_now) }
|
|
22
|
-
|
|
23
|
-
after { Timecop.return }
|
|
24
|
-
|
|
25
|
-
describe '.build' do
|
|
26
|
-
subject(:command) { instance.build(payload) }
|
|
27
|
-
|
|
28
|
-
context 'with properties' do
|
|
29
|
-
let(:payload) { default_payload.merge(properties: { test: '1' }) }
|
|
30
|
-
let(:command_data) { default_payload.merge(properties: { test: '1' }, context: context) }
|
|
31
|
-
|
|
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
|
-
end
|
|
36
|
-
|
|
37
|
-
context 'with user_traits' do
|
|
38
|
-
let(:payload) { default_payload.merge(user_traits: { test: '1' }) }
|
|
39
|
-
let(:command_data) { default_payload.merge(user_traits: { test: '1' }, context: context) }
|
|
40
|
-
|
|
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
|
-
end
|
|
45
|
-
|
|
46
|
-
context 'when active true' do
|
|
47
|
-
let(:payload) { default_payload.merge(context: context.merge(active: true)) }
|
|
48
|
-
let(:command_data) { default_payload.merge(context: context.merge(active: true)) }
|
|
49
|
-
|
|
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
|
-
end
|
|
54
|
-
|
|
55
|
-
context 'when active false' do
|
|
56
|
-
let(:payload) { default_payload.merge(context: context.merge(active: false)) }
|
|
57
|
-
let(:command_data) { default_payload.merge(context: context.merge(active: false)) }
|
|
58
|
-
|
|
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
|
-
end
|
|
63
|
-
|
|
64
|
-
context 'when active string' do
|
|
65
|
-
let(:payload) { default_payload.merge(context: context.merge(active: 'string')) }
|
|
66
|
-
let(:command_data) { default_payload.merge(context: context) }
|
|
67
|
-
|
|
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
|
-
end
|
|
72
|
-
end
|
|
73
|
-
end
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
describe Castle::Commands::ReportDevice do
|
|
4
|
-
subject(:instance) { described_class }
|
|
5
|
-
|
|
6
|
-
let(:context) { {} }
|
|
7
|
-
let(:device_token) { '1234' }
|
|
8
|
-
|
|
9
|
-
describe '.build' do
|
|
10
|
-
subject(:command) { instance.build(device_token: device_token) }
|
|
11
|
-
|
|
12
|
-
context 'without device_token' do
|
|
13
|
-
let(:device_token) { '' }
|
|
14
|
-
|
|
15
|
-
it { expect { command }.to raise_error(Castle::InvalidParametersError) }
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
context 'with device_token' do
|
|
19
|
-
it { expect(command.method).to be(:put) }
|
|
20
|
-
it { expect(command.path).to eql("devices/#{device_token}/report") }
|
|
21
|
-
it { expect(command.data).to be_nil }
|
|
22
|
-
end
|
|
23
|
-
end
|
|
24
|
-
end
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
describe Castle::Commands::Risk do
|
|
4
|
-
subject(:instance) { described_class }
|
|
5
|
-
|
|
6
|
-
let(:context) { { test: { test1: '1' } } }
|
|
7
|
-
let(:user) { { id: '1234', email: 'foobar@mail.com' } }
|
|
8
|
-
let(:default_payload) do
|
|
9
|
-
{
|
|
10
|
-
request_token: '7e51335b-f4bc-4bc7-875d-b713fb61eb23-bf021a3022a1a302',
|
|
11
|
-
event: '$login',
|
|
12
|
-
status: '$succeeded',
|
|
13
|
-
user: user,
|
|
14
|
-
sent_at: time_auto,
|
|
15
|
-
context: context
|
|
16
|
-
}
|
|
17
|
-
end
|
|
18
|
-
let(:time_now) { Time.now }
|
|
19
|
-
let(:time_auto) { time_now.utc.iso8601(3) }
|
|
20
|
-
|
|
21
|
-
before { Timecop.freeze(time_now) }
|
|
22
|
-
|
|
23
|
-
after { Timecop.return }
|
|
24
|
-
|
|
25
|
-
describe '.build' do
|
|
26
|
-
subject(:command) { instance.build(payload) }
|
|
27
|
-
|
|
28
|
-
context 'with properties' do
|
|
29
|
-
let(:payload) { default_payload.merge(properties: { test: '1' }) }
|
|
30
|
-
let(:command_data) { default_payload.merge(properties: { test: '1' }, context: context) }
|
|
31
|
-
|
|
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
|
-
end
|
|
36
|
-
|
|
37
|
-
context 'with user_traits' do
|
|
38
|
-
let(:payload) { default_payload.merge(user_traits: { test: '1' }) }
|
|
39
|
-
let(:command_data) { default_payload.merge(user_traits: { test: '1' }, context: context) }
|
|
40
|
-
|
|
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
|
-
end
|
|
45
|
-
|
|
46
|
-
context 'when active true' do
|
|
47
|
-
let(:payload) { default_payload.merge(context: context.merge(active: true)) }
|
|
48
|
-
let(:command_data) { default_payload.merge(context: context.merge(active: true)) }
|
|
49
|
-
|
|
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
|
-
end
|
|
54
|
-
|
|
55
|
-
context 'when active false' do
|
|
56
|
-
let(:payload) { default_payload.merge(context: context.merge(active: false)) }
|
|
57
|
-
let(:command_data) { default_payload.merge(context: context.merge(active: false)) }
|
|
58
|
-
|
|
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
|
-
end
|
|
63
|
-
|
|
64
|
-
context 'when active string' do
|
|
65
|
-
let(:payload) { default_payload.merge(context: context.merge(active: 'string')) }
|
|
66
|
-
let(:command_data) { default_payload.merge(context: context) }
|
|
67
|
-
|
|
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
|
-
end
|
|
72
|
-
end
|
|
73
|
-
end
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
describe Castle::Commands::StartImpersonation do
|
|
4
|
-
subject(:instance) { described_class }
|
|
5
|
-
|
|
6
|
-
let(:context) { { user_agent: 'test', ip: '127.0.0.1', client_id: 'test' } }
|
|
7
|
-
let(:impersonator) { 'test@castle.io' }
|
|
8
|
-
let(:default_payload) { { user_id: '1234', sent_at: time_auto, context: context } }
|
|
9
|
-
|
|
10
|
-
let(:time_now) { Time.now }
|
|
11
|
-
let(:time_auto) { time_now.utc.iso8601(3) }
|
|
12
|
-
|
|
13
|
-
before { Timecop.freeze(time_now) }
|
|
14
|
-
|
|
15
|
-
after { Timecop.return }
|
|
16
|
-
|
|
17
|
-
describe '.build' do
|
|
18
|
-
subject(:command) { instance.build(payload) }
|
|
19
|
-
|
|
20
|
-
context 'with impersonator' do
|
|
21
|
-
let(:payload) { default_payload.merge(properties: { impersonator: impersonator }) }
|
|
22
|
-
let(:command_data) { default_payload.merge(properties: { impersonator: impersonator }, context: context) }
|
|
23
|
-
|
|
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) }
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
context 'when active true' do
|
|
30
|
-
let(:payload) { default_payload.merge(context: context.merge(active: true)) }
|
|
31
|
-
let(:command_data) { default_payload.merge(context: context.merge(active: true)) }
|
|
32
|
-
|
|
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) }
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
context 'when active false' do
|
|
39
|
-
let(:payload) { default_payload.merge(context: context.merge(active: false)) }
|
|
40
|
-
let(:command_data) { default_payload.merge(context: context.merge(active: false)) }
|
|
41
|
-
|
|
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) }
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
context 'when active string' do
|
|
48
|
-
let(:payload) { default_payload.merge(context: context.merge(active: 'string')) }
|
|
49
|
-
let(:command_data) { default_payload.merge(context: context) }
|
|
50
|
-
|
|
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) }
|
|
54
|
-
end
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
describe '#validate!' do
|
|
58
|
-
subject(:validate!) { instance.build(payload) }
|
|
59
|
-
|
|
60
|
-
context 'when user_id not present' do
|
|
61
|
-
let(:payload) { {} }
|
|
62
|
-
|
|
63
|
-
it { expect { validate! }.to raise_error(Castle::InvalidParametersError, 'user_id is missing or empty') }
|
|
64
|
-
end
|
|
65
|
-
|
|
66
|
-
context 'when user_id present' do
|
|
67
|
-
let(:payload) { { user_id: '1234', context: context } }
|
|
68
|
-
|
|
69
|
-
it { expect { validate! }.not_to raise_error }
|
|
70
|
-
end
|
|
71
|
-
end
|
|
72
|
-
end
|
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
describe Castle::Commands::Track do
|
|
4
|
-
subject(:instance) { described_class }
|
|
5
|
-
|
|
6
|
-
let(:context) { { test: { test1: '1' } } }
|
|
7
|
-
let(:default_payload) { { event: '$login.track', sent_at: time_auto, context: context } }
|
|
8
|
-
|
|
9
|
-
let(:time_now) { Time.now }
|
|
10
|
-
let(:time_auto) { time_now.utc.iso8601(3) }
|
|
11
|
-
|
|
12
|
-
before { Timecop.freeze(time_now) }
|
|
13
|
-
|
|
14
|
-
after { Timecop.return }
|
|
15
|
-
|
|
16
|
-
describe '#build' do
|
|
17
|
-
subject(:command) { instance.build(payload) }
|
|
18
|
-
|
|
19
|
-
context 'with user_id' do
|
|
20
|
-
let(:payload) { default_payload.merge(user_id: '1234') }
|
|
21
|
-
let(:command_data) { default_payload.merge(user_id: '1234', context: context) }
|
|
22
|
-
|
|
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
|
-
end
|
|
27
|
-
|
|
28
|
-
context 'with properties' do
|
|
29
|
-
let(:payload) { default_payload.merge(properties: { test: '1' }) }
|
|
30
|
-
let(:command_data) { default_payload.merge(properties: { test: '1' }, context: context) }
|
|
31
|
-
|
|
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
|
-
end
|
|
36
|
-
|
|
37
|
-
context 'with user_traits' do
|
|
38
|
-
let(:payload) { default_payload.merge(user_traits: { test: '1' }) }
|
|
39
|
-
let(:command_data) { default_payload.merge(user_traits: { test: '1' }, context: context) }
|
|
40
|
-
|
|
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
|
-
end
|
|
45
|
-
|
|
46
|
-
context 'when active true' do
|
|
47
|
-
let(:payload) { default_payload.merge(context: context.merge(active: true)) }
|
|
48
|
-
let(:command_data) { default_payload.merge(context: context.merge(active: true)) }
|
|
49
|
-
|
|
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
|
-
end
|
|
54
|
-
|
|
55
|
-
context 'when active false' do
|
|
56
|
-
let(:payload) { default_payload.merge(context: context.merge(active: false)) }
|
|
57
|
-
let(:command_data) { default_payload.merge(context: context.merge(active: false)) }
|
|
58
|
-
|
|
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
|
-
end
|
|
63
|
-
|
|
64
|
-
context 'when active string' do
|
|
65
|
-
let(:payload) { default_payload.merge(context: context.merge(active: 'string')) }
|
|
66
|
-
let(:command_data) { default_payload.merge(context: context) }
|
|
67
|
-
|
|
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
|
-
end
|
|
72
|
-
end
|
|
73
|
-
|
|
74
|
-
describe '#validate!' do
|
|
75
|
-
subject(:validate!) { instance.build(payload) }
|
|
76
|
-
|
|
77
|
-
context 'when event not present' do
|
|
78
|
-
let(:payload) { {} }
|
|
79
|
-
|
|
80
|
-
it { expect { validate! }.to raise_error(Castle::InvalidParametersError, 'event is missing or empty') }
|
|
81
|
-
end
|
|
82
|
-
|
|
83
|
-
context 'when event present' do
|
|
84
|
-
let(:payload) { { event: '$login.track' } }
|
|
85
|
-
|
|
86
|
-
it { expect { validate! }.not_to raise_error }
|
|
87
|
-
end
|
|
88
|
-
end
|
|
89
|
-
end
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
describe Castle::Configuration do
|
|
4
|
-
subject(:config) { described_class.new }
|
|
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('') }
|
|
14
|
-
end
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
describe Castle::Context::GetDefault do
|
|
4
|
-
subject { described_class.new(request, nil) }
|
|
5
|
-
|
|
6
|
-
let(:ip) { '1.2.3.4' }
|
|
7
|
-
let(:client_id) { 'abcd' }
|
|
8
|
-
|
|
9
|
-
let(:env) do
|
|
10
|
-
Rack::MockRequest.env_for(
|
|
11
|
-
'/',
|
|
12
|
-
'HTTP_X_FORWARDED_FOR' => ip,
|
|
13
|
-
'HTTP_ACCEPT_LANGUAGE' => 'en',
|
|
14
|
-
'HTTP_USER_AGENT' => 'test',
|
|
15
|
-
'HTTP_COOKIE' => "__cid=#{client_id};other=efgh",
|
|
16
|
-
'HTTP_CONTENT_LENGTH' => '0'
|
|
17
|
-
)
|
|
18
|
-
end
|
|
19
|
-
let(:request) { Rack::Request.new(env) }
|
|
20
|
-
let(:default_context) { subject.call }
|
|
21
|
-
let(:version) { '2.2.0' }
|
|
22
|
-
let(:result_headers) do
|
|
23
|
-
{
|
|
24
|
-
'X-Forwarded-For' => '1.2.3.4',
|
|
25
|
-
'Accept-Language' => 'en',
|
|
26
|
-
'User-Agent' => 'test',
|
|
27
|
-
'Content-Length' => '0',
|
|
28
|
-
'Cookie' => true
|
|
29
|
-
}
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
before { stub_const('Castle::VERSION', version) }
|
|
33
|
-
|
|
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') }
|
|
41
|
-
end
|