Skip to content

Commit 937c241

Browse files
author
Inbal Tako
committed
SN-1938 Validate user id
1 parent d0af0c4 commit 937c241

5 files changed

Lines changed: 37 additions & 4 deletions

File tree

Gemfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: .
33
specs:
4-
securenative (0.1.21)
4+
securenative (0.1.22)
55

66
GEM
77
remote: https://rubygems.org/

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ require 'models/user_traits'
9696

9797
def track
9898
securenative = SecureNative.instance
99-
context = SecureNativeContext.new(client_token: '2a980d872b939c7e4f4378aa111a5eeffb22808b58b5372f658d34904ebd5b05fff0daab91921243ac08b72442a5b3992e402dc21df16aa7cc0e19f8bffa9d6cc59996d480d70aa22b857189403675d37fd144ebaf9dc697fed149b907678f2b1f964d73b332dc8ea7df63fcfc3c11f7bbb51ba2672652ca7d5d43f36a62e15db8b13dfd794a5eccfc5968ca514dd7cce59f2df2b9d8184d076eba808c81b311', ip: '127.0.0.1',
99+
context = SecureNativeContext.new(client_token: 'SECURED_CLIENT_TOKEN', ip: '127.0.0.1',
100100
headers: { 'user-agent' => 'Mozilla: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:47.0) Gecko/20100101 Firefox/47.3 Mozilla/5.0 (Macintosh; Intel Mac OS X x.y; rv:42.0) Gecko/20100101 Firefox/43.4' })
101101

102102
event_options = EventOptions.new(event: EventTypes::LOG_IN, user_id: '1234', context: context,
@@ -118,7 +118,7 @@ require 'enums/event_types'
118118
require 'models/user_traits'
119119

120120

121-
def track
121+
def track(request)
122122
securenative = SecureNative.instance
123123
context = SecureNativeContext.from_http_request(request)
124124

lib/models/sdk_event.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# frozen_string_literal: true
22

33
require 'context/securenative_context'
4+
require 'errors/securenative_invalid_options_error'
45
require 'utils/encryption_utils'
56
require 'utils/date_utils'
67
require 'models/request_context'
@@ -11,6 +12,14 @@ class SDKEvent
1112
attr_writer :context, :rid, :event_type, :user_id, :user_traits, :request, :timestamp, :properties
1213

1314
def initialize(event_options, securenative_options)
15+
if event_options.user_id.nil? || event_options.user_id.length <= 0 || event_options.user_id == ''
16+
raise SecureNativeInvalidOptionsError.new, 'Invalid event structure; User Id is missing'
17+
end
18+
19+
if event_options.event.nil? || event_options.event.length <= 0 || event_options.event == ''
20+
raise SecureNativeInvalidOptionsError.new, 'Invalid event structure; Event Type is missing'
21+
end
22+
1423
@context = if !event_options.context.nil?
1524
event_options.context
1625
else

securenative.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ require_relative "lib/utils/version_utils"
44

55
Gem::Specification.new do |spec|
66
spec.name = "securenative"
7-
spec.version = "0.1.21"
7+
spec.version = "0.1.22"
88
spec.authors = ["SecureNative"]
99
spec.email = ["support@securenative.com"]
1010

spec/spec_sdk_event.rb

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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 commit comments

Comments
 (0)