Hello community, here is the log from the commit of package python-mohawk for openSUSE:Factory checked in at 2019-10-30 14:43:09 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/python-mohawk (Old) and /work/SRC/openSUSE:Factory/.python-mohawk.new.2990 (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "python-mohawk" Wed Oct 30 14:43:09 2019 rev:4 rq:743605 version:1.1.0 Changes: -------- --- /work/SRC/openSUSE:Factory/python-mohawk/python-mohawk.changes 2019-01-11 14:06:58.127710717 +0100 +++ /work/SRC/openSUSE:Factory/.python-mohawk.new.2990/python-mohawk.changes 2019-10-30 14:43:10.357885912 +0100 @@ -1,0 +2,8 @@ +Mon Oct 28 20:05:08 UTC 2019 - [email protected] + +- Update to version 1.1.0: + * Support passing file-like objects (those implementing .read(n)) + as the content parameter for Resources. See mohawk.Sender for + details. + +------------------------------------------------------------------- Old: ---- mohawk-1.0.0.tar.gz New: ---- mohawk-1.1.0.tar.gz ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ python-mohawk.spec ++++++ --- /var/tmp/diff_new_pack.Anz7rc/_old 2019-10-30 14:43:11.089886691 +0100 +++ /var/tmp/diff_new_pack.Anz7rc/_new 2019-10-30 14:43:11.089886691 +0100 @@ -20,7 +20,7 @@ %{?!python_module:%define python_module() python-%{**} python3-%{**}} %bcond_without test Name: python-mohawk -Version: 1.0.0 +Version: 1.1.0 Release: 0 Summary: Library for Hawk HTTP authorization License: MPL-2.0 ++++++ mohawk-1.0.0.tar.gz -> mohawk-1.1.0.tar.gz ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/mohawk-1.0.0/PKG-INFO new/mohawk-1.1.0/PKG-INFO --- old/mohawk-1.0.0/PKG-INFO 2019-01-09 23:01:05.000000000 +0100 +++ new/mohawk-1.1.0/PKG-INFO 2019-10-28 16:15:07.000000000 +0100 @@ -1,6 +1,6 @@ Metadata-Version: 1.1 Name: mohawk -Version: 1.0.0 +Version: 1.1.0 Summary: Library for Hawk HTTP authorization Home-page: https://github.com/kumar303/mohawk Author: Kumar McMillan, Austin King diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/mohawk-1.0.0/mohawk/sender.py new/mohawk-1.1.0/mohawk/sender.py --- old/mohawk-1.0.0/mohawk/sender.py 2018-11-02 22:44:22.000000000 +0100 +++ new/mohawk-1.1.0/mohawk/sender.py 2019-10-28 15:45:53.000000000 +0100 @@ -26,8 +26,8 @@ :param method: Method of the request. E.G. POST, GET :type method: str - :param content=EmptyValue: Byte string of request body. - :type content=EmptyValue: str + :param content=EmptyValue: Byte string of request body or a file-like object. + :type content=EmptyValue: str or file-like object :param content_type=EmptyValue: content-type header value for request. :type content_type=EmptyValue: str diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/mohawk-1.0.0/mohawk/tests.py new/mohawk-1.1.0/mohawk/tests.py --- old/mohawk-1.0.0/mohawk/tests.py 2019-01-09 21:26:13.000000000 +0100 +++ new/mohawk-1.1.0/mohawk/tests.py 2019-10-28 15:45:53.000000000 +0100 @@ -22,6 +22,7 @@ MissingContent) from .util import (parse_authorization_header, utc_now, + calculate_payload_hash, calculate_ts_mac, validate_credentials) from .bewit import (get_bewit, @@ -443,6 +444,25 @@ header = sn.request_header.replace(dlg, 'TAMPERED-WITH') self.receive(header) + def test_file_content(self): + method = "POST" + content = six.BytesIO(b"FILE CONTENT") + sn = self.Sender(method, content=content) + self.receive(sn.request_header, method=method, content=content.getvalue()) + + def test_binary_file_content(self): + method = "POST" + content = six.BytesIO(b"\x00\xffCONTENT\xff\x00") + sn = self.Sender(method, content=content) + self.receive(sn.request_header, method=method, content=content.getvalue()) + + @raises(MisComputedContentHash) + def test_bad_file_content(self): + method = "POST" + content = six.BytesIO(b"FILE CONTENT") + sn = self.Sender(method, content=content) + self.receive(sn.request_header, method=method, content="BAD FILE CONTENT") + class TestReceiver(Base): @@ -999,3 +1019,12 @@ 'other_id': self.credentials, }) check_bewit(url, credential_lookup=credential_lookup, now=1356420407 + 10) + + +class TestPayloadHash(Base): + def test_hash_file_read_blocks(self): + payload = six.BytesIO(b"\x00\xffhello world\xff\x00") + h1 = calculate_payload_hash(payload, 'sha256', 'application/json', block_size=1) + payload.seek(0) + h2 = calculate_payload_hash(payload, 'sha256', 'application/json', block_size=1024) + self.assertEqual(h1, h2) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/mohawk-1.0.0/mohawk/util.py new/mohawk-1.1.0/mohawk/util.py --- old/mohawk-1.0.0/mohawk/util.py 2017-04-17 22:58:13.000000000 +0200 +++ new/mohawk-1.1.0/mohawk/util.py 2019-10-28 15:45:53.000000000 +0100 @@ -46,7 +46,7 @@ return urlsafe_b64encode(os.urandom(length))[:length] -def calculate_payload_hash(payload, algorithm, content_type): +def calculate_payload_hash(payload, algorithm, content_type, block_size=1024): """Calculates a hash for a given payload.""" p_hash = hashlib.new(algorithm) @@ -58,9 +58,18 @@ for i, p in enumerate(parts): # Make sure we are about to hash binary strings. - if not isinstance(p, six.binary_type): + if hasattr(p, "read"): + log.debug("part %i being handled as a file object", i) + while True: + block = p.read(block_size) + if not block: + break + p_hash.update(block) + elif not isinstance(p, six.binary_type): p = p.encode('utf8') - p_hash.update(p) + p_hash.update(p) + else: + p_hash.update(p) parts[i] = p log.debug('calculating payload hash from:\n{parts}' diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/mohawk-1.0.0/mohawk.egg-info/PKG-INFO new/mohawk-1.1.0/mohawk.egg-info/PKG-INFO --- old/mohawk-1.0.0/mohawk.egg-info/PKG-INFO 2019-01-09 23:01:05.000000000 +0100 +++ new/mohawk-1.1.0/mohawk.egg-info/PKG-INFO 2019-10-28 16:15:07.000000000 +0100 @@ -1,6 +1,6 @@ Metadata-Version: 1.1 Name: mohawk -Version: 1.0.0 +Version: 1.1.0 Summary: Library for Hawk HTTP authorization Home-page: https://github.com/kumar303/mohawk Author: Kumar McMillan, Austin King diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/mohawk-1.0.0/setup.py new/mohawk-1.1.0/setup.py --- old/mohawk-1.0.0/setup.py 2019-01-09 22:59:04.000000000 +0100 +++ new/mohawk-1.1.0/setup.py 2019-10-28 15:51:01.000000000 +0100 @@ -2,7 +2,7 @@ setup(name='mohawk', - version='1.0.0', + version='1.1.0', description="Library for Hawk HTTP authorization", long_description=""" Hawk lets two parties securely communicate with each other using
