Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</p>
<p align="center">
<a href="https://github.com/securenative/securenative-python">
<img alt="Github Actions" src="https://github.com/securenative/securenative-java/workflows/CI/badge.svg">
<img alt="Github Actions" src="https://github.com/securenative/securenative-python/workflows/CI/badge.svg">
</a>
<a href="https://codecov.io/gh/securenative/securenative-python">
<img src="https://codecov.io/gh/securenative/securenative-python/branch/master/graph/badge.svg" />
Expand Down Expand Up @@ -46,7 +46,7 @@ SecureNative can automatically load your config from *securenative.ini* file or
from securenative.securenative import SecureNative


secureative = SecureNative.init()
securenative = SecureNative.init()
```
### Option 2: Initialize via API Key

Expand Down Expand Up @@ -99,8 +99,8 @@ context = SecureNative.context_builder().\
build()

event_options = EventOptionsBuilder(EventTypes.LOG_IN).\
with_user_id("USER_ID").\
with_user_traits(UserTraits("USER_NAME", "USER_EMAIL")).\
with_user_id("1234").\
with_user_traits(UserTraits("Your Name", "name@gmail.com")).\
with_context(context).\
with_properties({"prop1": "CUSTOM_PARAM_VALUE", "prop2": True, "prop3": 3}).\
build()
Expand All @@ -122,8 +122,8 @@ def track(request):
context = SecureNative.context_builder().from_http_request(request).build()

event_options = EventOptionsBuilder(EventTypes.LOG_IN).\
with_user_id("USER_ID").\
with_user_traits(UserTraits("USER_NAME", "USER_EMAIL")).\
with_user_id("1234").\
with_user_traits(UserTraits("Your Name", "name@gmail.com")).\
with_context(context).\
with_properties({"prop1": "CUSTOM_PARAM_VALUE", "prop2": True, "prop3": 3}).\
build()
Expand All @@ -147,8 +147,8 @@ def track(request):
context = SecureNative.context_builder().from_http_request(request).build()

event_options = EventOptionsBuilder(EventTypes.LOG_IN).\
with_user_id("USER_ID").\
with_user_traits(UserTraits("USER_NAME", "USER_EMAIL")).\
with_user_id("1234").\
with_user_traits(UserTraits("Your Name", "name@gmail.com")).\
with_context(context).\
with_properties({"prop1": "CUSTOM_PARAM_VALUE", "prop2": True, "prop3": 3}).\
build()
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.2.0
0.2.1
3 changes: 1 addition & 2 deletions securenative/event_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,9 @@ def run(self):
if res.status_code == 401:
item.retry = False
elif res.status_code != 200:
raise SecureNativeHttpException(res.status_code)
item.retry = True

Logger.debug("Event successfully sent; {}".format(item.body))
return res
except Exception as e:
Logger.error("Failed to send event; {}".format(e))
if item.retry:
Expand Down
11 changes: 7 additions & 4 deletions securenative/securenative.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from securenative.exceptions.securenative_sdk_Illegal_state_exception import SecureNativeSDKIllegalStateException
from securenative.exceptions.securenative_sdk_exception import SecureNativeSDKException
from securenative.logger import Logger
from securenative.utils.signature_utils import SignatureUtils
from securenative.utils.utils import Utils


Expand Down Expand Up @@ -75,15 +76,17 @@ def context_builder():
return ContextBuilder.default_context_builder()

def track(self, event_options):
self._api_manager.track(event_options)
return self._api_manager.track(event_options)

def verify(self, event_options):
self._api_manager.verify(event_options)
return self._api_manager.verify(event_options)

@classmethod
def _flush(cls):
cls._securenative = None

# TODO!
def verify_request_payload(self, request):
pass
request_signature = request.header[SignatureUtils.SignatureHeader]
body = request.body

SignatureUtils.is_valid_signature(self._options.api_key, body, request_signature)
1 change: 1 addition & 0 deletions securenative/utils/signature_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@


class SignatureUtils(object):
SignatureHeader = "x-securenative"

@staticmethod
def is_valid_signature(api_key, payload, header_signature):
Expand Down
14 changes: 7 additions & 7 deletions tests/encryption_utils_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@ def setUp(self):
self.CID = "198a41ff-a10f-4cda-a2f3-a9ca80c0703b"
self.FP = "6d8cabd95987f8318b1fe01593d5c2a5.24700f9f1986800ab4fcc880530dd0ed"

@pytest.mark.skip("Differences in crypto version fails this test when in reality it's passing")
def test_decrypt(self):
result = EncryptionUtils.encrypt(self.PAYLOAD, self.SECRET_KEY)

self.assertIsNotNone(result)
self.assertGreater(len(self.PAYLOAD), len(result))

def test_encrypt(self):
encrypted_payload = "5208ae703cc2fa0851347f55d3b76d3fd6035ee081d71a401e8bc92ebdc25d42440f62310bda60628537744ac03f200d78da9e61f1019ce02087b7ce6c976e7b2d8ad6aa978c532cea8f3e744cc6a5cafedc4ae6cd1b08a4ef75d6e37aa3c0c76954d16d57750be2980c2c91ac7ef0bbd0722abd59bf6be22493ea9b9759c3ff4d17f17ab670b0b6fc320e6de982313f1c4e74c0897f9f5a32d58e3e53050ae8fdbebba9009d0d1250fe34dcde1ebb42acbc22834a02f53889076140f0eb8db1"
result = EncryptionUtils.decrypt(encrypted_payload, self.SECRET_KEY)

self.assertEqual(result.cid, self.CID)
self.assertEqual(result.fp, self.FP)

@pytest.mark.skip("Differences in crypto version fails this test when in reality it's passing")
def test_encrypt(self):
result = EncryptionUtils.encrypt(self.PAYLOAD, self.SECRET_KEY)

self.assertIsNotNone(result)
self.assertGreater(len(self.PAYLOAD), len(result))