securenative 0.1.17 → 0.1.23
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/.github/workflows/ci.yml +5 -2
- data/.github/workflows/test.yml +5 -2
- data/.gitignore +3 -1
- data/Gemfile +6 -4
- data/Gemfile.lock +234 -25
- data/README.md +37 -32
- data/lib/api_manager.rb +39 -0
- data/lib/config/configuration_builder.rb +27 -0
- data/lib/config/configuration_manager.rb +56 -0
- data/lib/config/securenative_options.rb +23 -0
- data/lib/context/hanami_context.rb +42 -0
- data/lib/context/rails_context.rb +44 -0
- data/lib/context/securenative_context.rb +67 -0
- data/lib/context/sinatra_context.rb +42 -0
- data/lib/enums/api_route.rb +6 -0
- data/lib/enums/event_types.rb +23 -0
- data/lib/enums/failover_strategy.rb +6 -0
- data/lib/enums/risk_level.rb +7 -0
- data/lib/errors/securenative_config_error.rb +4 -0
- data/lib/errors/securenative_http_error.rb +4 -0
- data/lib/errors/securenative_invalid_options_error.rb +4 -0
- data/lib/errors/securenative_invalid_uri_error.rb +4 -0
- data/lib/errors/securenative_parse_error.rb +4 -0
- data/lib/errors/securenative_sdk_Illegal_state_error.rb +4 -0
- data/lib/errors/securenative_sdk_error.rb +4 -0
- data/lib/event_manager.rb +157 -0
- data/lib/{securenative/http/http_response.rb → http/secure_native_http_response.rb} +4 -2
- data/lib/http/securenative_http_client.rb +50 -0
- data/lib/{securenative/models → models}/client_token.rb +2 -0
- data/lib/{securenative/models → models}/device.rb +3 -1
- data/lib/models/event_options.rb +37 -0
- data/lib/{securenative/models → models}/request_context.rb +7 -4
- data/lib/models/request_options.rb +12 -0
- data/lib/models/sdk_event.rb +49 -0
- data/lib/{securenative/models → models}/user_traits.rb +4 -2
- data/lib/{securenative/models → models}/verify_result.rb +8 -2
- data/lib/securenative.rb +83 -0
- data/lib/utils/date_utils.rb +9 -0
- data/lib/utils/encryption_utils.rb +49 -0
- data/lib/{securenative/utils → utils}/ip_utils.rb +7 -6
- data/lib/utils/request_utils.rb +69 -0
- data/lib/{securenative/logger.rb → utils/secure_native_logger.rb} +5 -3
- data/lib/{securenative/utils → utils}/signature_utils.rb +4 -2
- data/lib/utils/utils.rb +9 -0
- data/lib/utils/version_utils.rb +11 -0
- data/out/production/securenative-ruby/api_manager.rb +39 -0
- data/out/production/securenative-ruby/config/configuration_builder.rb +27 -0
- data/out/production/securenative-ruby/config/configuration_manager.rb +56 -0
- data/out/production/securenative-ruby/config/securenative_options.rb +23 -0
- data/out/production/securenative-ruby/context/hanami_context.rb +42 -0
- data/out/production/securenative-ruby/context/rails_context.rb +44 -0
- data/out/production/securenative-ruby/context/securenative_context.rb +67 -0
- data/out/production/securenative-ruby/context/sinatra_context.rb +42 -0
- data/out/production/securenative-ruby/enums/api_route.rb +6 -0
- data/out/production/securenative-ruby/enums/event_types.rb +23 -0
- data/out/production/securenative-ruby/enums/failover_strategy.rb +6 -0
- data/out/production/securenative-ruby/enums/risk_level.rb +7 -0
- data/out/production/securenative-ruby/errors/securenative_config_error.rb +4 -0
- data/out/production/securenative-ruby/errors/securenative_http_error.rb +4 -0
- data/out/production/securenative-ruby/errors/securenative_invalid_options_error.rb +4 -0
- data/out/production/securenative-ruby/errors/securenative_invalid_uri_error.rb +4 -0
- data/out/production/securenative-ruby/errors/securenative_parse_error.rb +4 -0
- data/out/production/securenative-ruby/errors/securenative_sdk_Illegal_state_error.rb +4 -0
- data/out/production/securenative-ruby/errors/securenative_sdk_error.rb +4 -0
- data/out/production/securenative-ruby/event_manager.rb +157 -0
- data/out/production/securenative-ruby/http/secure_native_http_response.rb +12 -0
- data/out/production/securenative-ruby/http/securenative_http_client.rb +50 -0
- data/out/production/securenative-ruby/models/client_token.rb +12 -0
- data/out/production/securenative-ruby/models/device.rb +10 -0
- data/out/production/securenative-ruby/models/event_options.rb +37 -0
- data/out/production/securenative-ruby/models/request_context.rb +18 -0
- data/out/production/securenative-ruby/models/request_options.rb +12 -0
- data/out/production/securenative-ruby/models/sdk_event.rb +49 -0
- data/out/production/securenative-ruby/models/user_traits.rb +13 -0
- data/out/production/securenative-ruby/models/verify_result.rb +16 -0
- data/out/production/securenative-ruby/securenative.rb +83 -0
- data/out/production/securenative-ruby/utils/date_utils.rb +9 -0
- data/out/production/securenative-ruby/utils/encryption_utils.rb +49 -0
- data/out/production/securenative-ruby/utils/ip_utils.rb +23 -0
- data/out/production/securenative-ruby/utils/request_utils.rb +69 -0
- data/out/production/securenative-ruby/utils/secure_native_logger.rb +44 -0
- data/out/production/securenative-ruby/utils/signature_utils.rb +16 -0
- data/out/production/securenative-ruby/utils/utils.rb +9 -0
- data/out/production/securenative-ruby/utils/version_utils.rb +11 -0
- data/out/test/securenative-ruby/spec_api_manager.rb +87 -0
- data/out/test/securenative-ruby/spec_context_builder.rb +87 -0
- data/out/test/securenative-ruby/spec_date_utils.rb +13 -0
- data/out/test/securenative-ruby/spec_encryption_utils.rb +26 -0
- data/out/test/securenative-ruby/spec_event_manager.rb +93 -0
- data/out/test/securenative-ruby/spec_helper.rb +28 -0
- data/out/test/securenative-ruby/spec_ip_utils.rb +41 -0
- data/out/test/securenative-ruby/spec_request_utils.rb +25 -0
- data/out/test/securenative-ruby/spec_sdk_event.rb +24 -0
- data/out/test/securenative-ruby/spec_securenative.rb +61 -0
- data/out/test/securenative-ruby/spec_securenative_http_client.rb +31 -0
- data/out/test/securenative-ruby/spec_signature_utils.rb +18 -0
- data/out/test/securenative-ruby/spec_version_util.rb +10 -0
- data/securenative.gemspec +2 -2
- metadata +93 -43
- data/.travis.yml +0 -6
- data/VERSION +0 -1
- data/lib/securenative/api_manager.rb +0 -30
- data/lib/securenative/config/configuration_builder.rb +0 -26
- data/lib/securenative/config/configuration_manager.rb +0 -53
- data/lib/securenative/config/securenative_options.rb +0 -18
- data/lib/securenative/context/context_builder.rb +0 -59
- data/lib/securenative/context/securenative_context.rb +0 -14
- data/lib/securenative/enums/api_route.rb +0 -4
- data/lib/securenative/enums/event_types.rb +0 -21
- data/lib/securenative/enums/failover_strategy.rb +0 -4
- data/lib/securenative/enums/risk_level.rb +0 -5
- data/lib/securenative/event_manager.rb +0 -150
- data/lib/securenative/event_options_builder.rb +0 -30
- data/lib/securenative/exceptions/securenative_config_exception.rb +0 -2
- data/lib/securenative/exceptions/securenative_http_exception.rb +0 -2
- data/lib/securenative/exceptions/securenative_invalid_options_exception.rb +0 -2
- data/lib/securenative/exceptions/securenative_invalid_uri_exception.rb +0 -2
- data/lib/securenative/exceptions/securenative_parse_exception.rb +0 -2
- data/lib/securenative/exceptions/securenative_sdk_Illegal_state_exception.rb +0 -2
- data/lib/securenative/exceptions/securenative_sdk_exception.rb +0 -2
- data/lib/securenative/http/securenative_http_client.rb +0 -30
- data/lib/securenative/models/event_options.rb +0 -13
- data/lib/securenative/models/request_options.rb +0 -10
- data/lib/securenative/models/sdk_event.rb +0 -25
- data/lib/securenative/securenative.iml +0 -9
- data/lib/securenative/securenative.rb +0 -82
- data/lib/securenative/utils/date_utils.rb +0 -7
- data/lib/securenative/utils/encryption_utils.rb +0 -38
- data/lib/securenative/utils/request_utils.rb +0 -21
- data/lib/securenative/utils/utils.rb +0 -9
- data/lib/securenative/utils/version_utils.rb +0 -10
@@ -0,0 +1,13 @@
|
|
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
|
@@ -0,0 +1,26 @@
|
|
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
|
@@ -0,0 +1,93 @@
|
|
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
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'webmock/rspec'
|
5
|
+
require 'simplecov'
|
6
|
+
require 'codecov'
|
7
|
+
|
8
|
+
SimpleCov.start
|
9
|
+
SimpleCov.formatter = SimpleCov::Formatter::Codecov
|
10
|
+
|
11
|
+
RSpec.configure do |config|
|
12
|
+
# Enable flags like --only-failures and --next-failure
|
13
|
+
config.example_status_persistence_file_path = '.rspec_status'
|
14
|
+
|
15
|
+
# Disable RSpec exposing methods globally on `Module` and `main`
|
16
|
+
config.disable_monkey_patching!
|
17
|
+
|
18
|
+
config.expect_with :rspec do |c|
|
19
|
+
c.syntax = :expect
|
20
|
+
end
|
21
|
+
|
22
|
+
config.mock_with :rspec do |mocks|
|
23
|
+
# Prevents you from mocking or stubbing a method that does not exist on
|
24
|
+
# a real object. This is generally recommended, and will default to
|
25
|
+
# `true` in RSpec 4.
|
26
|
+
mocks.verify_partial_doubles = true
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,41 @@
|
|
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
|
@@ -0,0 +1,25 @@
|
|
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
|
@@ -0,0 +1,24 @@
|
|
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
|
@@ -0,0 +1,61 @@
|
|
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
|
@@ -0,0 +1,31 @@
|
|
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.22',
|
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
|
@@ -0,0 +1,18 @@
|
|
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
|
data/securenative.gemspec
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
lib = File.expand_path("lib", __dir__)
|
2
2
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
-
require_relative "lib/
|
3
|
+
require_relative "lib/utils/version_utils"
|
4
4
|
|
5
5
|
Gem::Specification.new do |spec|
|
6
6
|
spec.name = "securenative"
|
7
|
-
spec.version =
|
7
|
+
spec.version = "0.1.23"
|
8
8
|
spec.authors = ["SecureNative"]
|
9
9
|
spec.email = ["support@securenative.com"]
|
10
10
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: securenative
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.23
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- SecureNative
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-09-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -51,54 +51,104 @@ files:
|
|
51
51
|
- ".gitignore"
|
52
52
|
- ".rakeTasks"
|
53
53
|
- ".rspec"
|
54
|
-
- ".travis.yml"
|
55
54
|
- Gemfile
|
56
55
|
- Gemfile.lock
|
57
56
|
- LICENSE
|
58
57
|
- README.md
|
59
58
|
- Rakefile
|
60
|
-
- VERSION
|
61
59
|
- bin/console
|
62
60
|
- bin/setup
|
63
|
-
- lib/
|
64
|
-
- lib/
|
65
|
-
- lib/
|
66
|
-
- lib/
|
67
|
-
- lib/
|
68
|
-
- lib/
|
69
|
-
- lib/
|
70
|
-
- lib/
|
71
|
-
- lib/
|
72
|
-
- lib/
|
73
|
-
- lib/
|
74
|
-
- lib/
|
75
|
-
- lib/
|
76
|
-
- lib/
|
77
|
-
- lib/
|
78
|
-
- lib/
|
79
|
-
- lib/
|
80
|
-
- lib/
|
81
|
-
- lib/
|
82
|
-
- lib/
|
83
|
-
- lib/
|
84
|
-
- lib/
|
85
|
-
- lib/
|
86
|
-
- lib/
|
87
|
-
- lib/
|
88
|
-
- lib/
|
89
|
-
- lib/
|
90
|
-
- lib/
|
91
|
-
- lib/
|
92
|
-
- lib/
|
93
|
-
- lib/securenative
|
94
|
-
- lib/
|
95
|
-
- lib/
|
96
|
-
- lib/
|
97
|
-
- lib/
|
98
|
-
- lib/
|
99
|
-
- lib/
|
100
|
-
- lib/
|
101
|
-
- lib/
|
61
|
+
- lib/api_manager.rb
|
62
|
+
- lib/config/configuration_builder.rb
|
63
|
+
- lib/config/configuration_manager.rb
|
64
|
+
- lib/config/securenative_options.rb
|
65
|
+
- lib/context/hanami_context.rb
|
66
|
+
- lib/context/rails_context.rb
|
67
|
+
- lib/context/securenative_context.rb
|
68
|
+
- lib/context/sinatra_context.rb
|
69
|
+
- lib/enums/api_route.rb
|
70
|
+
- lib/enums/event_types.rb
|
71
|
+
- lib/enums/failover_strategy.rb
|
72
|
+
- lib/enums/risk_level.rb
|
73
|
+
- lib/errors/securenative_config_error.rb
|
74
|
+
- lib/errors/securenative_http_error.rb
|
75
|
+
- lib/errors/securenative_invalid_options_error.rb
|
76
|
+
- lib/errors/securenative_invalid_uri_error.rb
|
77
|
+
- lib/errors/securenative_parse_error.rb
|
78
|
+
- lib/errors/securenative_sdk_Illegal_state_error.rb
|
79
|
+
- lib/errors/securenative_sdk_error.rb
|
80
|
+
- lib/event_manager.rb
|
81
|
+
- lib/http/secure_native_http_response.rb
|
82
|
+
- lib/http/securenative_http_client.rb
|
83
|
+
- lib/models/client_token.rb
|
84
|
+
- lib/models/device.rb
|
85
|
+
- lib/models/event_options.rb
|
86
|
+
- lib/models/request_context.rb
|
87
|
+
- lib/models/request_options.rb
|
88
|
+
- lib/models/sdk_event.rb
|
89
|
+
- lib/models/user_traits.rb
|
90
|
+
- lib/models/verify_result.rb
|
91
|
+
- lib/securenative.rb
|
92
|
+
- lib/utils/date_utils.rb
|
93
|
+
- lib/utils/encryption_utils.rb
|
94
|
+
- lib/utils/ip_utils.rb
|
95
|
+
- lib/utils/request_utils.rb
|
96
|
+
- lib/utils/secure_native_logger.rb
|
97
|
+
- lib/utils/signature_utils.rb
|
98
|
+
- lib/utils/utils.rb
|
99
|
+
- lib/utils/version_utils.rb
|
100
|
+
- out/production/securenative-ruby/api_manager.rb
|
101
|
+
- out/production/securenative-ruby/config/configuration_builder.rb
|
102
|
+
- out/production/securenative-ruby/config/configuration_manager.rb
|
103
|
+
- out/production/securenative-ruby/config/securenative_options.rb
|
104
|
+
- out/production/securenative-ruby/context/hanami_context.rb
|
105
|
+
- out/production/securenative-ruby/context/rails_context.rb
|
106
|
+
- out/production/securenative-ruby/context/securenative_context.rb
|
107
|
+
- out/production/securenative-ruby/context/sinatra_context.rb
|
108
|
+
- out/production/securenative-ruby/enums/api_route.rb
|
109
|
+
- out/production/securenative-ruby/enums/event_types.rb
|
110
|
+
- out/production/securenative-ruby/enums/failover_strategy.rb
|
111
|
+
- out/production/securenative-ruby/enums/risk_level.rb
|
112
|
+
- out/production/securenative-ruby/errors/securenative_config_error.rb
|
113
|
+
- out/production/securenative-ruby/errors/securenative_http_error.rb
|
114
|
+
- out/production/securenative-ruby/errors/securenative_invalid_options_error.rb
|
115
|
+
- out/production/securenative-ruby/errors/securenative_invalid_uri_error.rb
|
116
|
+
- out/production/securenative-ruby/errors/securenative_parse_error.rb
|
117
|
+
- out/production/securenative-ruby/errors/securenative_sdk_Illegal_state_error.rb
|
118
|
+
- out/production/securenative-ruby/errors/securenative_sdk_error.rb
|
119
|
+
- out/production/securenative-ruby/event_manager.rb
|
120
|
+
- out/production/securenative-ruby/http/secure_native_http_response.rb
|
121
|
+
- out/production/securenative-ruby/http/securenative_http_client.rb
|
122
|
+
- out/production/securenative-ruby/models/client_token.rb
|
123
|
+
- out/production/securenative-ruby/models/device.rb
|
124
|
+
- out/production/securenative-ruby/models/event_options.rb
|
125
|
+
- out/production/securenative-ruby/models/request_context.rb
|
126
|
+
- out/production/securenative-ruby/models/request_options.rb
|
127
|
+
- out/production/securenative-ruby/models/sdk_event.rb
|
128
|
+
- out/production/securenative-ruby/models/user_traits.rb
|
129
|
+
- out/production/securenative-ruby/models/verify_result.rb
|
130
|
+
- out/production/securenative-ruby/securenative.rb
|
131
|
+
- out/production/securenative-ruby/utils/date_utils.rb
|
132
|
+
- out/production/securenative-ruby/utils/encryption_utils.rb
|
133
|
+
- out/production/securenative-ruby/utils/ip_utils.rb
|
134
|
+
- out/production/securenative-ruby/utils/request_utils.rb
|
135
|
+
- out/production/securenative-ruby/utils/secure_native_logger.rb
|
136
|
+
- out/production/securenative-ruby/utils/signature_utils.rb
|
137
|
+
- out/production/securenative-ruby/utils/utils.rb
|
138
|
+
- out/production/securenative-ruby/utils/version_utils.rb
|
139
|
+
- out/test/securenative-ruby/spec_api_manager.rb
|
140
|
+
- out/test/securenative-ruby/spec_context_builder.rb
|
141
|
+
- out/test/securenative-ruby/spec_date_utils.rb
|
142
|
+
- out/test/securenative-ruby/spec_encryption_utils.rb
|
143
|
+
- out/test/securenative-ruby/spec_event_manager.rb
|
144
|
+
- out/test/securenative-ruby/spec_helper.rb
|
145
|
+
- out/test/securenative-ruby/spec_ip_utils.rb
|
146
|
+
- out/test/securenative-ruby/spec_request_utils.rb
|
147
|
+
- out/test/securenative-ruby/spec_sdk_event.rb
|
148
|
+
- out/test/securenative-ruby/spec_securenative.rb
|
149
|
+
- out/test/securenative-ruby/spec_securenative_http_client.rb
|
150
|
+
- out/test/securenative-ruby/spec_signature_utils.rb
|
151
|
+
- out/test/securenative-ruby/spec_version_util.rb
|
102
152
|
- securenative.gemspec
|
103
153
|
homepage: https://www.securenative.com
|
104
154
|
licenses:
|