Skip to content

Commit a2fbadc

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

File tree

6 files changed

+27
-36
lines changed

6 files changed

+27
-36
lines changed

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,12 @@ securenative = SecureNative.init_with_api_key("YOUR_API_KEY")
6464
### Option 3: Initialize via ConfigurationBuilder
6565
```python
6666
from securenative.securenative import SecureNative
67+
from securenative.config.securenative_options import SecureNativeOptions
6768

6869

69-
securenative = SecureNative.init_with_options(SecureNative.config_builder().with_api_key("API_KEY").with_max_events(10).with_log_level("ERROR").build())
70+
options = SecureNativeOptions(api_key="YOUR_API_KEY", auto_send=True, interval=10,
71+
api_url="https://api.securenative-stg.com/collector/api/v1")
72+
securenative = SecureNative.init_with_options(options)
7073
```
7174

7275
## Getting SecureNative instance

securenative/context/securenative_context.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,4 @@ def from_http_request(request):
3030

3131
return SecureNativeContext(client_token, RequestUtils.get_client_ip_from_request(request),
3232
RequestUtils.get_remote_ip_from_request(request), headers, request.url,
33-
request.method, request.body)
33+
request.method, None)

tests/api_manager_test.py

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import responses
44

55
from securenative.api_manager import ApiManager
6-
from securenative.config.configuration_manager import ConfigurationManager
6+
from securenative.config.securenative_options import SecureNativeOptions
77
from securenative.context.securenative_context import SecureNativeContext
88
from securenative.enums.event_types import EventTypes
99
from securenative.enums.risk_level import RiskLevel
@@ -28,11 +28,8 @@ def setUp(self):
2828

2929
@responses.activate
3030
def test_track_event(self):
31-
options = ConfigurationManager.config_builder(). \
32-
with_api_key("YOUR_API_KEY"). \
33-
with_auto_send(True). \
34-
with_interval(10). \
35-
with_api_url("https://api.securenative-stg.com/collector/api/v1")
31+
options = SecureNativeOptions(api_key="YOUR_API_KEY", auto_send=True, interval=10,
32+
api_url="https://api.securenative-stg.com/collector/api/v1")
3633

3734
expected = "{\"eventType\":\"sn.user.login\",\"userId\":\"USER_ID\",\"userTraits\":{" \
3835
"\"name\":\"USER_NAME\",\"email\":\"USER_EMAIL\",\"createdAt\":null},\"request\":{" \
@@ -54,11 +51,8 @@ def test_track_event(self):
5451

5552
@responses.activate
5653
def test_securenative_invalid_options_exception(self):
57-
options = ConfigurationManager.config_builder(). \
58-
with_api_key("YOUR_API_KEY"). \
59-
with_auto_send(True). \
60-
with_interval(10). \
61-
with_api_url("https://api.securenative-stg.com/collector/api/v1")
54+
options = SecureNativeOptions(api_key="YOUR_API_KEY", auto_send=True, interval=10,
55+
api_url="https://api.securenative-stg.com/collector/api/v1")
6256

6357
properties = {}
6458
for i in range(1, 12):
@@ -78,9 +72,8 @@ def test_securenative_invalid_options_exception(self):
7872

7973
@responses.activate
8074
def test_verify_event(self):
81-
options = ConfigurationManager.config_builder(). \
82-
with_api_key("YOUR_API_KEY"). \
83-
with_api_url("https://api.securenative-stg.com/collector/api/v1")
75+
options = SecureNativeOptions(api_key="YOUR_API_KEY",
76+
api_url="https://api.securenative-stg.com/collector/api/v1")
8477

8578
responses.add(responses.POST, "https://api.securenative-stg.com/collector/api/v1/verify",
8679
json={

tests/event_manager_test.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import responses
66

7-
from securenative.config.configuration_manager import ConfigurationManager
7+
from securenative.config.securenative_options import SecureNativeOptions
88
from securenative.event_manager import EventManager
99
from securenative.models.request_context import RequestContext
1010
from securenative.models.user_traits import UserTraits
@@ -29,9 +29,8 @@ def setUp(self):
2929

3030
@responses.activate
3131
def test_should_successfully_send_sync_event_with_status_code_200(self):
32-
options = ConfigurationManager.config_builder(). \
33-
with_api_key("YOUR_API_KEY"). \
34-
with_api_url("https://api.securenative-stg.com/collector/api/v1")
32+
options = SecureNativeOptions(api_key="YOUR_API_KEY",
33+
api_url="https://api.securenative-stg.com/collector/api/v1")
3534

3635
res_body = "{\"data\": true}"
3736
responses.add(responses.POST, "https://api.securenative-stg.com/collector/api/v1/some-path/to-api",
@@ -43,9 +42,8 @@ def test_should_successfully_send_sync_event_with_status_code_200(self):
4342

4443
@responses.activate
4544
def test_should_send_sync_event_and_fail_when_status_code_401(self):
46-
options = ConfigurationManager.config_builder(). \
47-
with_api_key("YOUR_API_KEY"). \
48-
with_api_url("https://api.securenative-stg.com/collector/api/v1")
45+
options = SecureNativeOptions(api_key="YOUR_API_KEY",
46+
api_url="https://api.securenative-stg.com/collector/api/v1")
4947

5048
responses.add(responses.POST, "https://api.securenative-stg.com/collector/api/v1/some-path/to-api",
5149
json={}, status=401)
@@ -57,9 +55,8 @@ def test_should_send_sync_event_and_fail_when_status_code_401(self):
5755

5856
@responses.activate
5957
def test_should_send_sync_event_and_fail_when_status_code_500(self):
60-
options = ConfigurationManager.config_builder(). \
61-
with_api_key("YOUR_API_KEY"). \
62-
with_api_url("https://api.securenative-stg.com/collector/api/v1")
58+
options = SecureNativeOptions(api_key="YOUR_API_KEY",
59+
api_url="https://api.securenative-stg.com/collector/api/v1")
6360

6461
responses.add(responses.POST, "https://api.securenative-stg.com/collector/api/v1/some-path/to-api",
6562
json={}, status=500)

tests/securenative_http_client_test.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,16 @@
22

33
import responses
44

5-
from securenative.config.configuration_manager import ConfigurationManager
5+
from securenative.config.securenative_options import SecureNativeOptions
66
from securenative.http.securenative_http_client import SecureNativeHttpClient
77

88

99
class SecureNativeHttpClientTest(unittest.TestCase):
1010

1111
@responses.activate
1212
def test_should_make_simple_post_call(self):
13-
options = ConfigurationManager.config_builder(). \
14-
with_api_key("YOUR_API_KEY").\
15-
with_api_url("https://api.securenative-stg.com/collector/api/v1")
13+
options = SecureNativeOptions(api_key="YOUR_API_KEY", auto_send=True, interval=10,
14+
api_url="https://api.securenative-stg.com/collector/api/v1")
1615

1716
responses.add(responses.POST, "https://api.securenative-stg.com/collector/api/v1/track",
1817
json={"event": "SOME_EVENT_NAME"}, status=200)

tests/securenative_test.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import unittest
22

3-
from securenative.config.configuration_manager import ConfigurationManager
3+
from securenative.config.securenative_options import SecureNativeOptions
44
from securenative.enums.failover_strategy import FailOverStrategy
55
from securenative.exceptions.securenative_config_exception import SecureNativeConfigException
66
from securenative.exceptions.securenative_sdk_Illegal_state_exception import SecureNativeSDKIllegalStateException
@@ -16,7 +16,7 @@ def test_get_sdk_instance_without_init_throws(self):
1616

1717
def test_init_sdk_without_api_key_should_throw(self):
1818
with self.assertRaises(SecureNativeSDKException):
19-
SecureNative.init_with_options(ConfigurationManager.config_builder())
19+
SecureNative.init_with_options(SecureNativeOptions())
2020

2121
def test_init_sdk_with_empty_api_key_should_throw(self):
2222
with self.assertRaises(SecureNativeConfigException):
@@ -52,10 +52,9 @@ def test_init_sdk_with_api_key_and_get_instance(self):
5252

5353
def test_init_sdk_with_builder(self):
5454
SecureNative._flush()
55-
securenative = SecureNative.init_with_options(SecureNative.config_builder().
56-
with_api_key("API_KEY").
57-
with_max_events(10).
58-
with_log_level("ERROR"))
55+
options = SecureNativeOptions(api_key="YOUR_API_KEY", auto_send=True, interval=10,
56+
api_url="https://api.securenative-stg.com/collector/api/v1")
57+
securenative = SecureNative.init_with_options(options)
5958

6059
options = securenative.get_options()
6160
self.assertEqual(options.api_key, "API_KEY")

0 commit comments

Comments
 (0)