securenative 0.1.23 → 0.1.29
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/README.md +43 -29
- data/lib/securenative.rb +47 -81
- data/{out/test/securenative-ruby → spec}/spec_helper.rb +0 -0
- metadata +8 -109
- data/.github/workflows/ci.yml +0 -49
- data/.github/workflows/publish.yml +0 -60
- data/.github/workflows/test.yml +0 -48
- data/.gitignore +0 -40
- data/.rakeTasks +0 -7
- data/.rspec +0 -3
- data/Gemfile +0 -11
- data/Gemfile.lock +0 -272
- data/LICENSE +0 -21
- data/Rakefile +0 -6
- data/bin/console +0 -14
- data/bin/setup +0 -8
- data/lib/api_manager.rb +0 -39
- data/lib/config/configuration_builder.rb +0 -27
- data/lib/config/configuration_manager.rb +0 -56
- data/lib/config/securenative_options.rb +0 -23
- data/lib/context/hanami_context.rb +0 -42
- data/lib/context/rails_context.rb +0 -44
- data/lib/context/securenative_context.rb +0 -67
- data/lib/context/sinatra_context.rb +0 -42
- data/lib/enums/api_route.rb +0 -6
- data/lib/enums/event_types.rb +0 -23
- data/lib/enums/failover_strategy.rb +0 -6
- data/lib/enums/risk_level.rb +0 -7
- data/lib/errors/securenative_config_error.rb +0 -4
- data/lib/errors/securenative_http_error.rb +0 -4
- data/lib/errors/securenative_invalid_options_error.rb +0 -4
- data/lib/errors/securenative_invalid_uri_error.rb +0 -4
- data/lib/errors/securenative_parse_error.rb +0 -4
- data/lib/errors/securenative_sdk_Illegal_state_error.rb +0 -4
- data/lib/errors/securenative_sdk_error.rb +0 -4
- data/lib/event_manager.rb +0 -157
- data/lib/http/secure_native_http_response.rb +0 -12
- data/lib/http/securenative_http_client.rb +0 -50
- data/lib/models/client_token.rb +0 -12
- data/lib/models/device.rb +0 -10
- data/lib/models/event_options.rb +0 -37
- data/lib/models/request_context.rb +0 -18
- data/lib/models/request_options.rb +0 -12
- data/lib/models/sdk_event.rb +0 -49
- data/lib/models/user_traits.rb +0 -13
- data/lib/models/verify_result.rb +0 -16
- data/lib/utils/date_utils.rb +0 -9
- data/lib/utils/encryption_utils.rb +0 -49
- data/lib/utils/ip_utils.rb +0 -23
- data/lib/utils/request_utils.rb +0 -69
- data/lib/utils/secure_native_logger.rb +0 -44
- data/lib/utils/signature_utils.rb +0 -16
- data/lib/utils/utils.rb +0 -9
- data/lib/utils/version_utils.rb +0 -11
- 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_config_error.rb +0 -4
- data/out/production/securenative-ruby/errors/securenative_http_error.rb +0 -4
- data/out/production/securenative-ruby/errors/securenative_invalid_options_error.rb +0 -4
- 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/errors/securenative_sdk_Illegal_state_error.rb +0 -4
- data/out/production/securenative-ruby/errors/securenative_sdk_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
- data/securenative.gemspec +0 -28
@@ -1,87 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'api_manager'
|
4
|
-
require 'webmock/rspec'
|
5
|
-
require 'config/configuration_builder'
|
6
|
-
require 'errors/securenative_invalid_options_error'
|
7
|
-
require 'models/event_options'
|
8
|
-
require 'models/verify_result'
|
9
|
-
require 'models/user_traits'
|
10
|
-
require 'enums/event_types'
|
11
|
-
require 'enums/risk_level'
|
12
|
-
require 'event_manager'
|
13
|
-
require 'rspec'
|
14
|
-
|
15
|
-
RSpec.describe ApiManager do
|
16
|
-
it 'tracks an event' do
|
17
|
-
options = ConfigurationBuilder.new(api_key: 'YOUR_API_KEY', auto_send: true, interval: 10, api_url: 'https://api.securenative-stg.com/collector/api/v1')
|
18
|
-
|
19
|
-
stub_request(:post, 'https://api.securenative-stg.com/collector/api/v1/track').to_return(status: 200)
|
20
|
-
event_manager = EventManager.new(options)
|
21
|
-
event_manager.start_event_persist
|
22
|
-
api_manager = ApiManager.new(event_manager, options)
|
23
|
-
event_options = EventOptions.new(event: EventTypes::LOG_IN, user_id: 'USER_ID',
|
24
|
-
user_traits: UserTraits.new(name: 'USER_NAME', email: 'USER_EMAIL', phone: '+1234567890'),
|
25
|
-
properties: { prop1: 'CUSTOM_PARAM_VALUE', prop2: true, prop3: 3 })
|
26
|
-
|
27
|
-
begin
|
28
|
-
res = api_manager.track(event_options)
|
29
|
-
ensure
|
30
|
-
event_manager.stop_event_persist
|
31
|
-
end
|
32
|
-
|
33
|
-
expect(res).to_not be_nil
|
34
|
-
end
|
35
|
-
|
36
|
-
it 'uses invalid options' do
|
37
|
-
options = ConfigurationBuilder.new(api_key: 'YOUR_API_KEY', auto_send: true, interval: 10, api_url: 'https://api.securenative-stg.com/collector/api/v1')
|
38
|
-
|
39
|
-
properties = {}
|
40
|
-
(0..12).each do |i|
|
41
|
-
properties[i] = i
|
42
|
-
end
|
43
|
-
|
44
|
-
stub_request(:post, 'https://api.securenative-stg.com/collector/api/v1/track').to_return(status: 200)
|
45
|
-
event_manager = EventManager.new(options)
|
46
|
-
event_manager.start_event_persist
|
47
|
-
api_manager = ApiManager.new(event_manager, options)
|
48
|
-
|
49
|
-
begin
|
50
|
-
expect { api_manager.track(EventOptions.new(event: EventTypes::LOG_IN, properties: properties)) }
|
51
|
-
.to raise_error(SecureNativeInvalidOptionsError)
|
52
|
-
ensure
|
53
|
-
event_manager.stop_event_persist
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
it 'verifies an event' do
|
58
|
-
options = ConfigurationBuilder.new(api_key: 'YOUR_API_KEY', api_url: 'https://api.securenative-stg.com/collector/api/v1')
|
59
|
-
|
60
|
-
stub_request(:post, "https://api.securenative-stg.com/collector/api/v1/verify").
|
61
|
-
with(
|
62
|
-
headers: {
|
63
|
-
'Accept'=>'*/*',
|
64
|
-
'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
|
65
|
-
'Authorization'=>'YOUR_API_KEY',
|
66
|
-
'Content-Type'=>'application/json',
|
67
|
-
'Sn-Version'=>'0.1.22',
|
68
|
-
'User-Agent'=>'SecureNative-ruby'
|
69
|
-
}).
|
70
|
-
to_return(status: 200, body: "", headers: {})
|
71
|
-
|
72
|
-
|
73
|
-
event_manager = EventManager.new(options)
|
74
|
-
event_manager.start_event_persist
|
75
|
-
api_manager = ApiManager.new(event_manager, options)
|
76
|
-
event_options = EventOptions.new(event: EventTypes::LOG_IN, user_id: 'USER_ID',
|
77
|
-
user_traits: UserTraits.new(name: 'USER_NAME', email: 'USER_EMAIL', phone: '+1234567890'),
|
78
|
-
properties: { prop1: 'CUSTOM_PARAM_VALUE', prop2: true, prop3: 3 })
|
79
|
-
|
80
|
-
result = api_manager.verify(event_options)
|
81
|
-
|
82
|
-
expect(result).not_to be_nil
|
83
|
-
expect(result.risk_level).to eq('low')
|
84
|
-
expect(result.score).to eq(0)
|
85
|
-
expect(result.triggers).to eq(nil)
|
86
|
-
end
|
87
|
-
end
|
@@ -1,87 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'context/securenative_context'
|
4
|
-
require 'webmock/rspec'
|
5
|
-
require 'rails'
|
6
|
-
require 'hanami'
|
7
|
-
require 'sinatra'
|
8
|
-
require 'rspec'
|
9
|
-
|
10
|
-
RSpec.describe SecureNativeContext do
|
11
|
-
it 'creates context from ruby default request' do
|
12
|
-
stub_request(:any, 'www.example.com')
|
13
|
-
.to_return(status: 200,
|
14
|
-
headers: { '_sn': '71532c1fad2c7f56118f7969e401f3cf080239140d208e7934e6a530818c37e544a0c2330a487bcc6fe4f662a57f265a3ed9f37871e80529128a5e4f2ca02db0fb975ded401398f698f19bb0cafd68a239c6caff99f6f105286ab695eaf3477365bdef524f5d70d9be1d1d474506b433aed05d7ed9a435eeca357de57817b37c638b6bb417ffb101eaf856987615a77a' })
|
15
|
-
|
16
|
-
request = Net::HTTP.get_response('www.example.com', '/')
|
17
|
-
context = SecureNativeContext.from_http_request(request)
|
18
|
-
|
19
|
-
expect(context.ip).to eq('')
|
20
|
-
expect(context.http_method).to eq('')
|
21
|
-
expect(context.url).to eq('')
|
22
|
-
expect(context.remote_ip).to eq('')
|
23
|
-
expect(context.headers['-sn']).to eq(['71532c1fad2c7f56118f7969e401f3cf080239140d208e7934e6a530818c37e544a0c2330a487bcc6fe4f662a57f265a3ed9f37871e80529128a5e4f2ca02db0fb975ded401398f698f19bb0cafd68a239c6caff99f6f105286ab695eaf3477365bdef524f5d70d9be1d1d474506b433aed05d7ed9a435eeca357de57817b37c638b6bb417ffb101eaf856987615a77a'])
|
24
|
-
expect(context.body).to eq('')
|
25
|
-
end
|
26
|
-
|
27
|
-
it 'creates context from rails request' do
|
28
|
-
request = ActionDispatch::Request.new(nil)
|
29
|
-
context = SecureNativeContext.from_http_request(request)
|
30
|
-
|
31
|
-
expect(context.ip).to eq('')
|
32
|
-
expect(context.http_method).to eq('')
|
33
|
-
expect(context.url).to eq('')
|
34
|
-
expect(context.remote_ip).to eq('')
|
35
|
-
expect(context.headers).to eq([])
|
36
|
-
expect(context.body).to eq('')
|
37
|
-
end
|
38
|
-
|
39
|
-
it 'creates context from sinatra request' do
|
40
|
-
request = Sinatra::Request.new(nil)
|
41
|
-
context = SecureNativeContext.from_http_request(request)
|
42
|
-
|
43
|
-
expect(context.ip).to eq('')
|
44
|
-
expect(context.http_method).to eq('')
|
45
|
-
expect(context.url).to eq('')
|
46
|
-
expect(context.remote_ip).to eq('')
|
47
|
-
expect(context.headers).to eq([])
|
48
|
-
expect(context.body).to eq('')
|
49
|
-
end
|
50
|
-
|
51
|
-
it 'creates context from hanami request' do
|
52
|
-
request = Hanami::Action::Request
|
53
|
-
context = SecureNativeContext.from_http_request(request)
|
54
|
-
|
55
|
-
expect(context.ip).to eq('')
|
56
|
-
expect(context.http_method).to eq('')
|
57
|
-
expect(context.url).to eq('')
|
58
|
-
expect(context.remote_ip).to eq('')
|
59
|
-
expect(context.headers).to eq([])
|
60
|
-
expect(context.body).to eq('')
|
61
|
-
end
|
62
|
-
|
63
|
-
it 'creates default context builder' do
|
64
|
-
context = SecureNativeContext.default_context_builder
|
65
|
-
|
66
|
-
expect(context.client_token).to eq('')
|
67
|
-
expect(context.ip).to eq('')
|
68
|
-
expect(context.http_method).to eq('')
|
69
|
-
expect(context.url).to eq('')
|
70
|
-
expect(context.remote_ip).to eq('')
|
71
|
-
expect(context.headers).to be_nil
|
72
|
-
expect(context.body).to eq('')
|
73
|
-
end
|
74
|
-
|
75
|
-
it 'creates custom context with context builder' do
|
76
|
-
context = SecureNativeContext.new(client_token: 'SECRET_TOKEN', ip: '10.0.0.0', remote_ip: '10.0.0.0',
|
77
|
-
headers: { 'header' => 'value1' }, url: '/some-url', http_method: 'Get', body: nil)
|
78
|
-
|
79
|
-
expect(context.url).to eq('/some-url')
|
80
|
-
expect(context.client_token).to eq('SECRET_TOKEN')
|
81
|
-
expect(context.ip).to eq('10.0.0.0')
|
82
|
-
expect(context.body).to be_nil
|
83
|
-
expect(context.http_method).to eq('Get')
|
84
|
-
expect(context.remote_ip).to eq('10.0.0.0')
|
85
|
-
expect(context.headers).to eq({ 'header' => 'value1' })
|
86
|
-
end
|
87
|
-
end
|
@@ -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
|