Skip to content

Commit df806b0

Browse files
authored
Merge pull request #32 from securenative/SN-1556-align-sdk
Fix event manager delay
2 parents 02f8cd2 + 71ebc31 commit df806b0

File tree

6 files changed

+25
-22
lines changed

6 files changed

+25
-22
lines changed

README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
</p>
88
<p align="center">
99
<a href="https://github.com/securenative/securenative-python">
10-
<img alt="Github Actions" src="https://github.com/securenative/securenative-java/workflows/CI/badge.svg">
10+
<img alt="Github Actions" src="https://github.com/securenative/securenative-python/workflows/CI/badge.svg">
1111
</a>
1212
<a href="https://codecov.io/gh/securenative/securenative-python">
1313
<img src="https://codecov.io/gh/securenative/securenative-python/branch/master/graph/badge.svg" />
@@ -46,7 +46,7 @@ SecureNative can automatically load your config from *securenative.ini* file or
4646
from securenative.securenative import SecureNative
4747

4848

49-
secureative = SecureNative.init()
49+
securenative = SecureNative.init()
5050
```
5151
### Option 2: Initialize via API Key
5252

@@ -99,8 +99,8 @@ context = SecureNative.context_builder().\
9999
build()
100100

101101
event_options = EventOptionsBuilder(EventTypes.LOG_IN).\
102-
with_user_id("USER_ID").\
103-
with_user_traits(UserTraits("USER_NAME", "USER_EMAIL")).\
102+
with_user_id("1234").\
103+
with_user_traits(UserTraits("Your Name", "[email protected]")).\
104104
with_context(context).\
105105
with_properties({"prop1": "CUSTOM_PARAM_VALUE", "prop2": True, "prop3": 3}).\
106106
build()
@@ -122,8 +122,8 @@ def track(request):
122122
context = SecureNative.context_builder().from_http_request(request).build()
123123

124124
event_options = EventOptionsBuilder(EventTypes.LOG_IN).\
125-
with_user_id("USER_ID").\
126-
with_user_traits(UserTraits("USER_NAME", "USER_EMAIL")).\
125+
with_user_id("1234").\
126+
with_user_traits(UserTraits("Your Name", "[email protected]")).\
127127
with_context(context).\
128128
with_properties({"prop1": "CUSTOM_PARAM_VALUE", "prop2": True, "prop3": 3}).\
129129
build()
@@ -147,8 +147,8 @@ def track(request):
147147
context = SecureNative.context_builder().from_http_request(request).build()
148148

149149
event_options = EventOptionsBuilder(EventTypes.LOG_IN).\
150-
with_user_id("USER_ID").\
151-
with_user_traits(UserTraits("USER_NAME", "USER_EMAIL")).\
150+
with_user_id("1234").\
151+
with_user_traits(UserTraits("Your Name", "[email protected]")).\
152152
with_context(context).\
153153
with_properties({"prop1": "CUSTOM_PARAM_VALUE", "prop2": True, "prop3": 3}).\
154154
build()

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.2.0
1+
0.2.1

securenative/event_manager.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,9 @@ def run(self):
9090
if res.status_code == 401:
9191
item.retry = False
9292
elif res.status_code != 200:
93-
raise SecureNativeHttpException(res.status_code)
93+
item.retry = True
9494

9595
Logger.debug("Event successfully sent; {}".format(item.body))
96-
return res
9796
except Exception as e:
9897
Logger.error("Failed to send event; {}".format(e))
9998
if item.retry:

securenative/securenative.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from securenative.exceptions.securenative_sdk_Illegal_state_exception import SecureNativeSDKIllegalStateException
88
from securenative.exceptions.securenative_sdk_exception import SecureNativeSDKException
99
from securenative.logger import Logger
10+
from securenative.utils.signature_utils import SignatureUtils
1011
from securenative.utils.utils import Utils
1112

1213

@@ -75,15 +76,17 @@ def context_builder():
7576
return ContextBuilder.default_context_builder()
7677

7778
def track(self, event_options):
78-
self._api_manager.track(event_options)
79+
return self._api_manager.track(event_options)
7980

8081
def verify(self, event_options):
81-
self._api_manager.verify(event_options)
82+
return self._api_manager.verify(event_options)
8283

8384
@classmethod
8485
def _flush(cls):
8586
cls._securenative = None
8687

87-
# TODO!
8888
def verify_request_payload(self, request):
89-
pass
89+
request_signature = request.header[SignatureUtils.SignatureHeader]
90+
body = request.body
91+
92+
SignatureUtils.is_valid_signature(self._options.api_key, body, request_signature)

securenative/utils/signature_utils.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44

55
class SignatureUtils(object):
6+
SignatureHeader = "x-securenative"
67

78
@staticmethod
89
def is_valid_signature(api_key, payload, header_signature):

tests/encryption_utils_test.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,16 @@ def setUp(self):
1313
self.CID = "198a41ff-a10f-4cda-a2f3-a9ca80c0703b"
1414
self.FP = "6d8cabd95987f8318b1fe01593d5c2a5.24700f9f1986800ab4fcc880530dd0ed"
1515

16-
@pytest.mark.skip("Differences in crypto version fails this test when in reality it's passing")
1716
def test_decrypt(self):
18-
result = EncryptionUtils.encrypt(self.PAYLOAD, self.SECRET_KEY)
19-
20-
self.assertIsNotNone(result)
21-
self.assertGreater(len(self.PAYLOAD), len(result))
22-
23-
def test_encrypt(self):
2417
encrypted_payload = "5208ae703cc2fa0851347f55d3b76d3fd6035ee081d71a401e8bc92ebdc25d42440f62310bda60628537744ac03f200d78da9e61f1019ce02087b7ce6c976e7b2d8ad6aa978c532cea8f3e744cc6a5cafedc4ae6cd1b08a4ef75d6e37aa3c0c76954d16d57750be2980c2c91ac7ef0bbd0722abd59bf6be22493ea9b9759c3ff4d17f17ab670b0b6fc320e6de982313f1c4e74c0897f9f5a32d58e3e53050ae8fdbebba9009d0d1250fe34dcde1ebb42acbc22834a02f53889076140f0eb8db1"
2518
result = EncryptionUtils.decrypt(encrypted_payload, self.SECRET_KEY)
2619

2720
self.assertEqual(result.cid, self.CID)
2821
self.assertEqual(result.fp, self.FP)
22+
23+
@pytest.mark.skip("Differences in crypto version fails this test when in reality it's passing")
24+
def test_encrypt(self):
25+
result = EncryptionUtils.encrypt(self.PAYLOAD, self.SECRET_KEY)
26+
27+
self.assertIsNotNone(result)
28+
self.assertGreater(len(self.PAYLOAD), len(result))

0 commit comments

Comments
 (0)