Skip to content

Commit

Permalink
Update version to 1.11.1 and fix 11paths
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanprjcts committed Jan 21, 2021
1 parent 12503e3 commit 0370b8a
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 4 deletions.
5 changes: 5 additions & 0 deletions docs/about/release-notes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ To upgrade Sdklib to the latest version, use pip:
Sdklib 1.11.x series
===================

Sdklib 1.11.1
-------------

- Fix 11paths authorization using body in python3.

Sdklib 1.11.0
-------------

Expand Down
2 changes: 1 addition & 1 deletion sdklib/__version__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
release = '1.11.0'
release = '1.11.1'
6 changes: 3 additions & 3 deletions sdklib/http/authorization.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

from sdklib.compat import convert_str_to_bytes, convert_bytes_to_str
from sdklib.http import url_encode
from sdklib.http.renderers import FormRenderer, MultiPartRenderer, JSONRenderer, guess_file_name_stream_type_header
from sdklib.http.renderers import FormRenderer, guess_file_name_stream_type_header
from sdklib.http.headers import (
AUTHORIZATION_HEADER_NAME, X_11PATHS_DATE_HEADER_NAME, X_11PATHS_BODY_HASH_HEADER_NAME,
X_11PATHS_FILE_HASH_HEADER_NAME
Expand Down Expand Up @@ -76,7 +76,7 @@ def _sign_data(secret, data):

def _hash_body(context):
body, _ = context.renderer.encode_params(context.body_params, files=context.files)
return sha1(body).hexdigest()
return sha1(convert_str_to_bytes(body)).hexdigest()


def _hash_file(context):
Expand All @@ -85,7 +85,7 @@ def _hash_file(context):

for param in files:
_, fdata, _, _ = guess_file_name_stream_type_header(files[param])
return sha1(fdata).hexdigest()
return sha1(convert_str_to_bytes(fdata)).hexdigest()


def _get_utc():
Expand Down
20 changes: 20 additions & 0 deletions tests/test_authorization.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,14 @@ def test_11paths_authentication_with_body(self):
utc="2016-01-01 00:00:00")
self.assertEqual("11PATHS 123456 8Ok3S1xUFLtjRxRkWVoZAKXZc1A=", header_value)

def test_11paths_authentication_with_json_body(self):
context = HttpRequestContext(method="POST", url_path="/path/",
headers={"Content-Type": "application/json"},
body_params={"param": "value"}, renderer=JSONRenderer())
header_value = x_11paths_authorization(app_id="123456", secret="654321", context=context,
utc="2016-01-01 00:00:00")
self.assertEqual("11PATHS 123456 VXVXfFsBVfCIwheS/27C8DqqpfQ=", header_value)

def test_11paths_authentication_class_with_static_time(self):
auth = X11PathsAuthentication(app_id="123456", secret="654321", utc="2016-01-01 00:00:00")
context = HttpRequestContext(method="POST", url_path="/path/",
Expand Down Expand Up @@ -142,3 +150,15 @@ def test_11paths_authentication_post_json_empty_body_params(self):
res_context.headers["Authorization"])
self.assertEqual("application/json", res_context.headers["Content-Type"])
self.assertEqual("da39a3ee5e6b4b0d3255bfef95601890afd80709", res_context.headers["X-11paths-body-hash"])

def test_11paths_authentication_post_json_body_params(self):
auth = X11PathsAuthentication(app_id="2kNhWLEETQ46KWLnAg48", secret="lBc4BSeqCGkidJZXictc3yiHbKBS87hjE05YrswJ",
utc="2017-01-27 08:27:44")
context = HttpRequestContext(method="POST", url_path="/ExternalApi/CleanFile",
body_params={"param": "value"},
headers={"Content-Type": "application/json"})
res_context = auth.apply_authentication(context=context)
self.assertEqual("11PATHS 2kNhWLEETQ46KWLnAg48 zvsWw6S2XZpke6rSvdpe0swlOIc=",
res_context.headers["Authorization"])
self.assertEqual("application/json", res_context.headers["Content-Type"])
self.assertEqual("f247c7579b452d08f38eec23c2d1a4a23daee0d2", res_context.headers["X-11paths-body-hash"])

0 comments on commit 0370b8a

Please sign in to comment.