Skip to content

Commit c832fa8

Browse files
committed
fixed the hmac signature verification
1 parent 64d93fe commit c832fa8

File tree

3 files changed

+67
-7
lines changed

3 files changed

+67
-7
lines changed

setup.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@
1212

1313
setup(
1414
name="pythepeer",
15-
version="1.0.2",
16-
description="python sdk for interacting with thepeer payment processing infrastructure",
15+
version="1.0.3",
16+
description="official python sdk for interacting with thepeer payment processing \
17+
infrastructure",
1718
author="Osagie Iyayi",
1819
packages=["thepeer"],
1920
author_email="[email protected]",

thepeer/main.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import hashlib
21
import hmac
2+
import hashlib
33
import json # type: ignore
44
import os
55
import sys
@@ -31,9 +31,8 @@ def validate_signature(self, data, signature):
3131
Returns:
3232
_type_: boolean if the signature is valid or not
3333
"""
34-
return (
35-
signature == hmac.new(self.secret.encode(), data.encode(), hashlib.sha1()).hexdigest()
36-
)
34+
SHA1 = hashlib.sha1
35+
return signature == hmac.new(self.secret.encode(), data.encode(), SHA1).hexdigest()
3736

3837
def index_user(self, name, identifier, email):
3938

thepeer/tests/thepeer_test.py

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,15 @@
55

66

77
class ThePeerInitMethods(unittest.TestCase):
8+
def test_validate_signature(self):
9+
self.assertEqual.__self__.maxDiff = None
10+
self.assertEqual(
11+
thepeer_test_suites.validate_signature(
12+
"I love the peer", "27154e4751dc49d1b40281b18deecd4fd2392e43"
13+
),
14+
True,
15+
)
16+
817
def test_index_user(self):
918
self.assertEqual.__self__.maxDiff = None
1019
self.assertEqual(
@@ -32,7 +41,7 @@ def test_view_user(self):
3241
)
3342

3443
def test_all_users(self):
35-
44+
self.assertEqual.__self__.maxDiff = None
3645
self.assertEqual(
3746
thepeer_test_suites.all_users(),
3847
{
@@ -63,13 +72,64 @@ def test_all_users(self):
6372
)
6473

6574
def test_user_links(self):
75+
self.assertEqual.__self__.maxDiff = None
6676
self.assertEqual(
6777
thepeer_test_suites.get_user_links("3bbb0fbf-82fa-48a0-80eb-d2c0338fe7dd"),
6878
{"links": []},
6979
)
7080

7181
def test_single_link(self):
82+
self.assertEqual.__self__.maxDiff = None
7283
self.assertEqual(
7384
thepeer_test_suites.get_single_link("3bbb0fbf-82fa-48a0-80eb-d2c0338fe7dd"),
7485
{"message": "link not found"},
7586
)
87+
88+
def test_charge_link(self):
89+
self.assertEqual.__self__.maxDiff = None
90+
self.assertEqual(
91+
thepeer_test_suites.charge_link(
92+
"3bbb0fbf-82fa-48a0-80eb-d2c0338fe7dd", 2000, "try thepeer"
93+
),
94+
{
95+
"message": "The given data was invalid.",
96+
"errors": {"amount": ["The amount must be at least 10000."]},
97+
},
98+
)
99+
100+
def test_charge_link_2(self):
101+
self.assertEqual.__self__.maxDiff = None
102+
self.assertEqual(
103+
thepeer_test_suites.charge_link(
104+
"3bbb0fbf-82fa-48a0-80eb-d2c0338fe7dd", 10000, "try thepeer"
105+
),
106+
{"message": "link not found"},
107+
)
108+
109+
def test_authorize_direct_charge(self):
110+
self.assertEqual.__self__.maxDiff = None
111+
self.assertEqual(
112+
thepeer_test_suites.authorize_direct_charge(
113+
"3bbb0fbf-82fa-48a0-80eb-d2c0338fe7dd", "charge"
114+
),
115+
{
116+
"message": "The given data was invalid.",
117+
"errors": {"event": ["The selected event is invalid."]},
118+
},
119+
)
120+
121+
def test_transaction_detail(self):
122+
self.assertEqual.__self__.maxDiff = None
123+
self.assertEqual(
124+
thepeer_test_suites.get_transaction_detail("3bbb0fbf-82fa-48a0-80eb-d2c0338fe7dd"),
125+
{"message": "transaction not found"},
126+
)
127+
128+
def test_refund_transaction(self):
129+
self.assertEqual.__self__.maxDiff = None
130+
self.assertEqual(
131+
thepeer_test_suites.refund_transaction(
132+
"3bbb0fbf-82fa-48a0-80eb-d2c0338fe7dd", "possibly fraudulent"
133+
),
134+
{"message": "this feature is only available on live mode"},
135+
)

0 commit comments

Comments
 (0)