Skip to content

Commit dc12c50

Browse files
author
Inbal Tako
committed
SN-1938 Validate user id
1 parent a2fbadc commit dc12c50

File tree

4 files changed

+12
-23
lines changed

4 files changed

+12
-23
lines changed

securenative/models/sdk_event.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ def __init__(self, event_options, securenative_options):
1414
if event_options.user_id is None or len(event_options.user_id) <= 0 or event_options.user_id == "":
1515
raise SecureNativeInvalidOptionsException("Invalid event structure; User Id is missing")
1616

17+
if event_options.event is None or len(event_options.event.value) <= 0 or event_options.event.value == "":
18+
raise SecureNativeInvalidOptionsException("Invalid event structure; Event Type is missing")
19+
1720
if event_options.context is not None:
1821
self.context = event_options.context
1922
else:

tests/api_manager_test.py

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -49,27 +49,6 @@ def test_track_event(self):
4949
finally:
5050
event_manager.stop_event_persist()
5151

52-
@responses.activate
53-
def test_securenative_invalid_options_exception(self):
54-
options = SecureNativeOptions(api_key="YOUR_API_KEY", auto_send=True, interval=10,
55-
api_url="https://api.securenative-stg.com/collector/api/v1")
56-
57-
properties = {}
58-
for i in range(1, 12):
59-
properties[i] = i
60-
61-
responses.add(responses.POST, "https://api.securenative-stg.com/collector/api/v1/track",
62-
json={}, status=200)
63-
event_manager = EventManager(options)
64-
event_manager.start_event_persist()
65-
api_manager = ApiManager(event_manager, options)
66-
67-
try:
68-
with self.assertRaises(SecureNativeInvalidOptionsException):
69-
api_manager.track(EventOptions(EventTypes.LOG_IN, "User-ID"))
70-
finally:
71-
event_manager.stop_event_persist()
72-
7352
@responses.activate
7453
def test_verify_event(self):
7554
options = SecureNativeOptions(api_key="YOUR_API_KEY",

tests/sdk_event_test.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,10 @@ def test_creating_event_without_user_id_throws(self):
1515
options = SecureNativeOptions()
1616

1717
SDKEvent(event_options, options)
18+
19+
def test_creating_event_without_event_type_throws(self):
20+
with self.assertRaises(SecureNativeInvalidOptionsException):
21+
event_options = EventOptions(None, "1234")
22+
options = SecureNativeOptions()
23+
24+
SDKEvent(event_options, options)

tests/securenative_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@ def test_init_sdk_with_api_key_and_get_instance(self):
5050

5151
self.assertEqual(securenative, SecureNative.get_instance())
5252

53-
def test_init_sdk_with_builder(self):
53+
def test_init_sdk_with_options(self):
5454
SecureNative._flush()
55-
options = SecureNativeOptions(api_key="YOUR_API_KEY", auto_send=True, interval=10,
55+
options = SecureNativeOptions(api_key="API_KEY", log_level="ERROR", max_events=10,
5656
api_url="https://api.securenative-stg.com/collector/api/v1")
5757
securenative = SecureNative.init_with_options(options)
5858

0 commit comments

Comments
 (0)