securenative 0.1.28 → 0.1.33
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +2 -2
- data/README.md +23 -32
- data/lib/securenative.rb +49 -0
- data/lib/securenative/api_manager.rb +10 -17
- data/lib/securenative/client.rb +79 -0
- data/lib/securenative/{models/client_token.rb → client_token.rb} +0 -0
- data/lib/securenative/config/configuration_builder.rb +22 -22
- data/lib/securenative/config/configuration_manager.rb +42 -43
- data/lib/securenative/context.rb +65 -0
- data/lib/securenative/{models/device.rb → device.rb} +0 -0
- data/lib/securenative/enums/api_route.rb +5 -3
- data/lib/securenative/enums/risk_level.rb +7 -5
- data/{out/production/securenative-ruby/errors/securenative_config_error.rb → lib/securenative/errors/config_error.rb} +0 -0
- data/{out/production/securenative-ruby/errors/securenative_http_error.rb → lib/securenative/errors/http_error.rb} +0 -0
- data/{out/production/securenative-ruby/errors/securenative_invalid_options_error.rb → lib/securenative/errors/invalid_options_error.rb} +0 -0
- data/lib/securenative/errors/{securenative_invalid_uri_error.rb → invalid_uri_error.rb} +0 -0
- data/lib/securenative/errors/{securenative_parse_error.rb → parse_error.rb} +0 -2
- data/{out/production/securenative-ruby/errors/securenative_sdk_Illegal_state_error.rb → lib/securenative/errors/sdk_Illegal_state_error.rb} +0 -0
- data/{out/production/securenative-ruby/errors/securenative_sdk_error.rb → lib/securenative/errors/sdk_error.rb} +0 -0
- data/lib/securenative/event_manager.rb +125 -127
- data/lib/securenative/{models/event_options.rb → event_options.rb} +3 -7
- data/lib/securenative/{enums/event_types.rb → event_types.rb} +0 -0
- data/lib/securenative/{enums/failover_strategy.rb → failover_strategy.rb} +0 -0
- data/lib/securenative/frameworks/hanami.rb +46 -0
- data/lib/securenative/frameworks/rails.rb +48 -0
- data/lib/securenative/frameworks/sinatra.rb +46 -0
- data/lib/securenative/{http/securenative_http_client.rb → http_client.rb} +7 -12
- data/lib/securenative/{http/secure_native_http_response.rb → http_response.rb} +1 -1
- data/lib/securenative/{config/securenative_options.rb → options.rb} +1 -3
- data/lib/securenative/{models/request_context.rb → request_context.rb} +0 -0
- data/lib/securenative/{models/request_options.rb → request_options.rb} +0 -0
- data/lib/securenative/{models/sdk_event.rb → sdk_event.rb} +4 -11
- data/lib/securenative/{models/user_traits.rb → user_traits.rb} +0 -0
- data/lib/securenative/utils/date_utils.rb +6 -4
- data/lib/securenative/utils/encryption_utils.rb +34 -37
- data/lib/securenative/utils/ip_utils.rb +15 -15
- data/lib/securenative/utils/{secure_native_logger.rb → log.rb} +1 -1
- data/lib/securenative/utils/request_utils.rb +66 -47
- data/lib/securenative/utils/signature_utils.rb +12 -12
- data/lib/securenative/utils/utils.rb +6 -4
- data/lib/securenative/utils/version_utils.rb +9 -7
- data/lib/securenative/{models/verify_result.rb → verify_result.rb} +0 -0
- data/lib/securenative/{errors/securenative_sdk_error.rb → version.rb} +1 -2
- data/securenative.gemspec +5 -2
- data/{out/test/securenative-ruby → spec}/spec_helper.rb +0 -0
- metadata +35 -83
- data/lib/securenative/context/hanami_context.rb +0 -44
- data/lib/securenative/context/rails_context.rb +0 -46
- data/lib/securenative/context/securenative_context.rb +0 -69
- data/lib/securenative/context/sinatra_context.rb +0 -44
- data/lib/securenative/errors/securenative_config_error.rb +0 -6
- data/lib/securenative/errors/securenative_http_error.rb +0 -6
- data/lib/securenative/errors/securenative_invalid_options_error.rb +0 -6
- data/lib/securenative/errors/securenative_sdk_Illegal_state_error.rb +0 -6
- data/lib/securenative/sdk.rb +0 -85
- data/out/production/securenative-ruby/api_manager.rb +0 -39
- data/out/production/securenative-ruby/config/configuration_builder.rb +0 -27
- data/out/production/securenative-ruby/config/configuration_manager.rb +0 -56
- data/out/production/securenative-ruby/config/securenative_options.rb +0 -23
- data/out/production/securenative-ruby/context/hanami_context.rb +0 -42
- data/out/production/securenative-ruby/context/rails_context.rb +0 -44
- data/out/production/securenative-ruby/context/securenative_context.rb +0 -67
- data/out/production/securenative-ruby/context/sinatra_context.rb +0 -42
- data/out/production/securenative-ruby/enums/api_route.rb +0 -6
- data/out/production/securenative-ruby/enums/event_types.rb +0 -23
- data/out/production/securenative-ruby/enums/failover_strategy.rb +0 -6
- data/out/production/securenative-ruby/enums/risk_level.rb +0 -7
- data/out/production/securenative-ruby/errors/securenative_invalid_uri_error.rb +0 -4
- data/out/production/securenative-ruby/errors/securenative_parse_error.rb +0 -4
- data/out/production/securenative-ruby/event_manager.rb +0 -157
- data/out/production/securenative-ruby/http/secure_native_http_response.rb +0 -12
- data/out/production/securenative-ruby/http/securenative_http_client.rb +0 -50
- data/out/production/securenative-ruby/models/client_token.rb +0 -12
- data/out/production/securenative-ruby/models/device.rb +0 -10
- data/out/production/securenative-ruby/models/event_options.rb +0 -37
- data/out/production/securenative-ruby/models/request_context.rb +0 -18
- data/out/production/securenative-ruby/models/request_options.rb +0 -12
- data/out/production/securenative-ruby/models/sdk_event.rb +0 -49
- data/out/production/securenative-ruby/models/user_traits.rb +0 -13
- data/out/production/securenative-ruby/models/verify_result.rb +0 -16
- data/out/production/securenative-ruby/securenative.rb +0 -83
- data/out/production/securenative-ruby/utils/date_utils.rb +0 -9
- data/out/production/securenative-ruby/utils/encryption_utils.rb +0 -49
- data/out/production/securenative-ruby/utils/ip_utils.rb +0 -23
- data/out/production/securenative-ruby/utils/request_utils.rb +0 -69
- data/out/production/securenative-ruby/utils/secure_native_logger.rb +0 -44
- data/out/production/securenative-ruby/utils/signature_utils.rb +0 -16
- data/out/production/securenative-ruby/utils/utils.rb +0 -9
- data/out/production/securenative-ruby/utils/version_utils.rb +0 -11
- data/out/test/securenative-ruby/spec_api_manager.rb +0 -87
- data/out/test/securenative-ruby/spec_context_builder.rb +0 -87
- data/out/test/securenative-ruby/spec_date_utils.rb +0 -13
- data/out/test/securenative-ruby/spec_encryption_utils.rb +0 -26
- data/out/test/securenative-ruby/spec_event_manager.rb +0 -93
- data/out/test/securenative-ruby/spec_ip_utils.rb +0 -41
- data/out/test/securenative-ruby/spec_request_utils.rb +0 -25
- data/out/test/securenative-ruby/spec_sdk_event.rb +0 -24
- data/out/test/securenative-ruby/spec_securenative.rb +0 -61
- data/out/test/securenative-ruby/spec_securenative_http_client.rb +0 -31
- data/out/test/securenative-ruby/spec_signature_utils.rb +0 -18
- data/out/test/securenative-ruby/spec_version_util.rb +0 -10
@@ -1,13 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'utils/date_utils'
|
4
|
-
require 'rspec'
|
5
|
-
|
6
|
-
RSpec.describe DateUtils do
|
7
|
-
it 'converts to timestamp' do
|
8
|
-
iso_8601_date = '2020-05-20T15:07:13Z'
|
9
|
-
result = DateUtils.to_timestamp(iso_8601_date)
|
10
|
-
|
11
|
-
expect(result).to eq(iso_8601_date)
|
12
|
-
end
|
13
|
-
end
|
@@ -1,26 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'utils/encryption_utils'
|
4
|
-
require 'rspec'
|
5
|
-
|
6
|
-
RSpec.describe EncryptionUtils do
|
7
|
-
it 'encrypts' do
|
8
|
-
secret_key = 'AFD16D89150FD7FB19EE9E936DC1AE3547CE119B'
|
9
|
-
payload = '{"cid":"198a41ff-a10f-4cda-a2f3-a9ca80c0703b","vi":"148a42ff-b40f-4cda-a2f3-a8ca80c0703b","fp":"6d8cabd95987f8318b1fe01593d5c2a5.24700f9f1986800ab4fcc880530dd0ed"}'
|
10
|
-
result = EncryptionUtils.encrypt(payload, secret_key)
|
11
|
-
|
12
|
-
expect(result).not_to be_nil
|
13
|
-
end
|
14
|
-
|
15
|
-
it 'decrypts' do
|
16
|
-
secret_key = 'AFD16D89150FD7FB19EE9E936DC1AE3547CE119B'
|
17
|
-
encrypted_payload = 'dfcc35bc71653771d4541f08937c35cbc98faea2c061ff7904f80abf7c072f0029157ed97a55b00efe09fb0d2f86f5693ecbba3f6339862ed3908f0d746533133c8c838be641dad76cf3f9cce67dc1b48cbc8574f24637be4aa90f802ec4b7e5d50b5f9cb3d64e6887ef99b8b941e69370ac7994ccafaf17ceff1d7a68ac30e4b0fe4eb1b844460d5f7687f16902cea61d0ccc085f7ea6087fae38482cd1ee1c7574dc4b0e996bc4e5946eeb8e8509fbdd9f1884eb3f02cbbaefe4566c999d50'
|
18
|
-
cid = '12946065-65af-4825-9893-fce901c8da49'
|
19
|
-
fp = '9a6e6a7d636ca772924bd2219853d73c.24700f9f1986800ab4fcc880530dd0ed'
|
20
|
-
|
21
|
-
result = EncryptionUtils.decrypt(encrypted_payload, secret_key)
|
22
|
-
|
23
|
-
expect(result.cid).to eq(cid)
|
24
|
-
expect(result.fp).to eq(fp)
|
25
|
-
end
|
26
|
-
end
|
@@ -1,93 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'event_manager'
|
4
|
-
require 'config/configuration_builder'
|
5
|
-
require 'models/user_traits'
|
6
|
-
require 'models/request_context'
|
7
|
-
require 'rspec'
|
8
|
-
require 'webmock/rspec'
|
9
|
-
|
10
|
-
class SampleEvent
|
11
|
-
attr_reader :event_type, :timestamp, :rid, :user_id, :user_traits, :request, :properties
|
12
|
-
|
13
|
-
def initialize
|
14
|
-
@event_type = 'custom-event'
|
15
|
-
@timestamp = Time.now.strftime('%Y-%m-%dT%H:%M:%S.%L%Z')
|
16
|
-
@rid = '432532'
|
17
|
-
@user_id = '1'
|
18
|
-
@user_traits = UserTraits.new(name: 'some user', email: 'email@securenative.com', phone: '+1234567890')
|
19
|
-
@request = RequestContext.new
|
20
|
-
@properties = []
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
RSpec.describe EventManager do
|
25
|
-
it 'successfully sends sync event with status code 200' do
|
26
|
-
options = ConfigurationBuilder.new(api_key: 'YOUR_API_KEY', api_url: 'https://api.securenative-stg.com/collector/api/v1')
|
27
|
-
event = SampleEvent.new
|
28
|
-
|
29
|
-
stub_request(:post, "https://api.securenative-stg.com/collector/api/v1/some-path/to-api").
|
30
|
-
with(
|
31
|
-
headers: {
|
32
|
-
'Accept'=>'*/*',
|
33
|
-
'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
|
34
|
-
'Authorization'=>'YOUR_API_KEY',
|
35
|
-
'Content-Type'=>'application/json',
|
36
|
-
'Sn-Version'=>'0.1.22',
|
37
|
-
'User-Agent'=>'SecureNative-ruby'
|
38
|
-
}).
|
39
|
-
to_return(status: 200, body: "", headers: {})
|
40
|
-
|
41
|
-
event_manager = EventManager.new(options)
|
42
|
-
|
43
|
-
event_manager.start_event_persist
|
44
|
-
res = event_manager.send_sync(event, 'some-path/to-api', false)
|
45
|
-
event_manager.stop_event_persist
|
46
|
-
|
47
|
-
expect(res.code).to eq('200')
|
48
|
-
end
|
49
|
-
|
50
|
-
it 'fails when send sync event status code is 401' do
|
51
|
-
options = ConfigurationBuilder.new(api_key: 'YOUR_API_KEY', api_url: 'https://api.securenative-stg.com/collector/api/v1')
|
52
|
-
event = SampleEvent.new
|
53
|
-
|
54
|
-
stub_request(:post, "https://api.securenative-stg.com/collector/api/v1/some-path/to-api").
|
55
|
-
with(
|
56
|
-
headers: {
|
57
|
-
'Accept'=>'*/*',
|
58
|
-
'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
|
59
|
-
'Authorization'=>'YOUR_API_KEY',
|
60
|
-
'Content-Type'=>'application/json',
|
61
|
-
'Sn-Version'=>'0.1.22',
|
62
|
-
'User-Agent'=>'SecureNative-ruby'
|
63
|
-
}).
|
64
|
-
to_return(status: 401, body: "", headers: {})
|
65
|
-
|
66
|
-
event_manager = EventManager.new(options)
|
67
|
-
res = event_manager.send_sync(event, 'some-path/to-api', false)
|
68
|
-
|
69
|
-
expect(res.code).to eq('401')
|
70
|
-
end
|
71
|
-
|
72
|
-
it 'fails when send sync event status code is 500' do
|
73
|
-
options = ConfigurationBuilder.new(api_key: 'YOUR_API_KEY', api_url: 'https://api.securenative-stg.com/collector/api/v1')
|
74
|
-
event = SampleEvent.new
|
75
|
-
|
76
|
-
stub_request(:post, "https://api.securenative-stg.com/collector/api/v1/some-path/to-api").
|
77
|
-
with(
|
78
|
-
headers: {
|
79
|
-
'Accept'=>'*/*',
|
80
|
-
'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
|
81
|
-
'Authorization'=>'YOUR_API_KEY',
|
82
|
-
'Content-Type'=>'application/json',
|
83
|
-
'Sn-Version'=>'0.1.22',
|
84
|
-
'User-Agent'=>'SecureNative-ruby'
|
85
|
-
}).
|
86
|
-
to_return(status: 500, body: "", headers: {})
|
87
|
-
|
88
|
-
event_manager = EventManager.new(options)
|
89
|
-
res = event_manager.send_sync(event, 'some-path/to-api', false)
|
90
|
-
|
91
|
-
expect(res.code).to eq('500')
|
92
|
-
end
|
93
|
-
end
|
@@ -1,41 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'utils/ip_utils'
|
4
|
-
require 'rspec'
|
5
|
-
|
6
|
-
RSpec.describe IpUtils do
|
7
|
-
it 'checks if ip address valid ipv4' do
|
8
|
-
valid_ipv4 = '172.16.254.1'
|
9
|
-
expect(IpUtils.ip_address?(valid_ipv4)).to be_truthy
|
10
|
-
end
|
11
|
-
|
12
|
-
it 'checks if ip address valid ipv6' do
|
13
|
-
valid_ipv6 = '2001:db8:1234:0000:0000:0000:0000:0000'
|
14
|
-
expect(IpUtils.ip_address?(valid_ipv6)).to be_truthy
|
15
|
-
end
|
16
|
-
|
17
|
-
it 'checks if ip address invalid ipv4' do
|
18
|
-
invalid_ipv4 = '172.16.2541'
|
19
|
-
expect(IpUtils.ip_address?(invalid_ipv4)).to be_falsey
|
20
|
-
end
|
21
|
-
|
22
|
-
it 'checks if ip address invalid ipv6' do
|
23
|
-
invalid_ipv6 = '2001:db8:1234:0000'
|
24
|
-
expect(IpUtils.ip_address?(invalid_ipv6)).to be_falsey
|
25
|
-
end
|
26
|
-
|
27
|
-
it 'checks if valid public ip' do
|
28
|
-
ip = '64.71.222.37'
|
29
|
-
expect(IpUtils.valid_public_ip?(ip)).to be_truthy
|
30
|
-
end
|
31
|
-
|
32
|
-
it 'checks if not valid public ip' do
|
33
|
-
ip = '10.0.0.0'
|
34
|
-
expect(IpUtils.valid_public_ip?(ip)).to be_falsey
|
35
|
-
end
|
36
|
-
|
37
|
-
it 'checks if valid loopback ip' do
|
38
|
-
ip = '127.0.0.1'
|
39
|
-
expect(IpUtils.loop_back?(ip)).to be_truthy
|
40
|
-
end
|
41
|
-
end
|
@@ -1,25 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'config/securenative_options'
|
4
|
-
require 'utils/request_utils'
|
5
|
-
require 'webmock/rspec'
|
6
|
-
require 'rspec'
|
7
|
-
|
8
|
-
RSpec.describe RequestUtils do
|
9
|
-
it 'extract a request with proxy headers' do
|
10
|
-
options = SecureNativeOptions.new
|
11
|
-
options.proxy_headers = [
|
12
|
-
'CF-Connecting-IP'
|
13
|
-
]
|
14
|
-
|
15
|
-
stub_request(:get, 'http://www.example.com/').with(
|
16
|
-
headers: {
|
17
|
-
'Accept' => '*/*',
|
18
|
-
'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
|
19
|
-
'User-Agent' => 'Ruby'
|
20
|
-
}).to_return(status: 200, body: '', headers: { 'CF-Connecting-IP' => 'CF-Connecting-IP: 203.0.113.1' })
|
21
|
-
|
22
|
-
request = Net::HTTP.get_response('www.example.com', '/')
|
23
|
-
RequestUtils.get_client_ip_from_request(request, options)
|
24
|
-
end
|
25
|
-
end
|
@@ -1,24 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'models/sdk_event'
|
4
|
-
require 'models/event_options'
|
5
|
-
require 'config/securenative_options'
|
6
|
-
require 'enums/event_types'
|
7
|
-
require 'errors/securenative_invalid_options_error'
|
8
|
-
require 'rspec'
|
9
|
-
|
10
|
-
RSpec.describe SDKEvent do
|
11
|
-
it 'throws when event created without user id' do
|
12
|
-
event_options = EventOptions.new(event: EventTypes::LOG_IN, user_id: nil)
|
13
|
-
options = SecureNativeOptions.new
|
14
|
-
|
15
|
-
expect { SDKEvent.new(event_options, options) }.to raise_error(SecureNativeInvalidOptionsError)
|
16
|
-
end
|
17
|
-
|
18
|
-
it 'throws when event created without event type' do
|
19
|
-
event_options = EventOptions.new(event: nil, user_id: '1234')
|
20
|
-
options = SecureNativeOptions.new
|
21
|
-
|
22
|
-
expect { SDKEvent.new(event_options, options) }.to raise_error(SecureNativeInvalidOptionsError)
|
23
|
-
end
|
24
|
-
end
|
@@ -1,61 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'securenative'
|
4
|
-
require 'config/configuration_manager'
|
5
|
-
require 'errors/securenative_sdk_error'
|
6
|
-
require 'errors/securenative_sdk_Illegal_state_error'
|
7
|
-
require 'errors/securenative_config_error'
|
8
|
-
require 'rspec'
|
9
|
-
|
10
|
-
RSpec.describe SecureNative do
|
11
|
-
it 'gets sdk instance without init throws' do
|
12
|
-
expect { SecureNative.instance }.to raise_error(SecureNativeSDKIllegalStateError)
|
13
|
-
end
|
14
|
-
|
15
|
-
it 'inits sdk without api key and throws' do
|
16
|
-
expect { SecureNative.init_with_options(ConfigurationManager.config_builder) }.to raise_error(SecureNativeSDKError)
|
17
|
-
end
|
18
|
-
|
19
|
-
it 'inits sdk with empty api key and throws' do
|
20
|
-
expect { SecureNative.init_with_api_key('') }.to raise_error(SecureNativeConfigError)
|
21
|
-
end
|
22
|
-
|
23
|
-
it 'inits sdk with api key and defaults' do
|
24
|
-
SecureNative._flush
|
25
|
-
api_key = 'API_KEY'
|
26
|
-
securenative = SecureNative.init_with_api_key(api_key)
|
27
|
-
options = securenative.options
|
28
|
-
|
29
|
-
expect(options.api_key).to eq(api_key)
|
30
|
-
expect(options.api_url).to eq('https://api.securenative.com/collector/api/v1')
|
31
|
-
expect(options.interval).to eq(1000)
|
32
|
-
expect(options.timeout).to eq(1500)
|
33
|
-
expect(options.max_events).to eq(1000)
|
34
|
-
expect(options.auto_send).to eq(true)
|
35
|
-
expect(options.disable).to eq(false)
|
36
|
-
expect(options.log_level).to eq('FATAL')
|
37
|
-
expect(options.fail_over_strategy).to eq(FailOverStrategy::FAIL_OPEN)
|
38
|
-
end
|
39
|
-
|
40
|
-
it 'inits sdk twice and throws' do
|
41
|
-
expect { SecureNative.init_with_api_key('API_KEY') }.to raise_error(SecureNativeSDKError)
|
42
|
-
end
|
43
|
-
|
44
|
-
it 'inits sdk with api key and gets instance' do
|
45
|
-
SecureNative._flush
|
46
|
-
api_key = 'API_KEY'
|
47
|
-
securenative = SecureNative.init_with_api_key(api_key)
|
48
|
-
|
49
|
-
expect(securenative).to eq(SecureNative.instance)
|
50
|
-
end
|
51
|
-
|
52
|
-
it 'inits sdk with builder' do
|
53
|
-
SecureNative._flush
|
54
|
-
securenative = SecureNative.init_with_options(ConfigurationBuilder.new(api_key: 'API_KEY', max_events: 10, log_level: 'ERROR'))
|
55
|
-
options = securenative.options
|
56
|
-
|
57
|
-
expect(options.api_key).to eq('API_KEY')
|
58
|
-
expect(options.max_events).to eq(10)
|
59
|
-
expect(options.log_level).to eq('ERROR')
|
60
|
-
end
|
61
|
-
end
|
@@ -1,31 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'http/securenative_http_client'
|
4
|
-
require 'config/configuration_builder'
|
5
|
-
require 'webmock/rspec'
|
6
|
-
require 'rspec'
|
7
|
-
|
8
|
-
RSpec.describe SecureNativeHttpClient do
|
9
|
-
it 'makes a simple post call' do
|
10
|
-
options = ConfigurationBuilder.new(api_key: 'YOUR_API_KEY', api_url: 'https://api.securenative-stg.com/collector/api/v1')
|
11
|
-
|
12
|
-
stub_request(:post, 'https://api.securenative-stg.com/collector/api/v1/track')
|
13
|
-
.with(
|
14
|
-
body: '{"event": "SOME_EVENT_NAME"}',
|
15
|
-
headers: {
|
16
|
-
'Accept' => '*/*',
|
17
|
-
'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
|
18
|
-
'Authorization' => 'YOUR_API_KEY',
|
19
|
-
'Content-Type' => 'application/json',
|
20
|
-
'Sn-Version' => '0.1.28',
|
21
|
-
'User-Agent' => 'SecureNative-ruby'
|
22
|
-
}
|
23
|
-
).to_return(status: 200, body: '', headers: {})
|
24
|
-
client = SecureNativeHttpClient.new(options)
|
25
|
-
payload = '{"event": "SOME_EVENT_NAME"}'
|
26
|
-
|
27
|
-
res = client.post('track', payload)
|
28
|
-
|
29
|
-
expect(res.code).to eq('200')
|
30
|
-
end
|
31
|
-
end
|
@@ -1,18 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'utils/signature_utils'
|
4
|
-
require 'rspec'
|
5
|
-
|
6
|
-
RSpec.describe SignatureUtils do
|
7
|
-
it 'verifies request payload' do
|
8
|
-
signature = 'c4574c1748064735513697750c6223ff36b03ae3b85b160ce8788557d01e1d9d1c9cd942074323ee0061d3dcc8c94359c5acfa6eee8e2da095b3967b1a88ab73'
|
9
|
-
payload = '{"id":"4a9157ffbd18cfbd73a57298","type":"security-action","flow":{"id":"62298c73a9bb433fbd1f75984a9157fd","name":"Block user that violates geo velocity"},"userId":"73a9bb433fbd1f75984a9157","userTraits":{"name":"John Doe","email":"john.doe@gmail.com"},"request":{"ip":"10.0.0.0","fp":"9bb433fb984a9157d1f7598"},"action":"block","properties":{"type":"customer"},"timestamp":"2020-02-23T22:28:55.387Z"}'
|
10
|
-
secret_key = 'B00C42DAD33EAC6F6572DA756EA4915349C0A4F6'
|
11
|
-
|
12
|
-
expect(SignatureUtils.valid_signature?(secret_key, payload, signature)).to be_truthy
|
13
|
-
end
|
14
|
-
|
15
|
-
it 'verifies request empty signature' do
|
16
|
-
expect(SignatureUtils.valid_signature?('', '', 'B00C42DAD33EAC6F6572DA756EA4915349C0A4F6')).to be_falsey
|
17
|
-
end
|
18
|
-
end
|