aboutsummaryrefslogtreecommitdiff
path: root/python/tests/utils_test.py
diff options
context:
space:
mode:
authorDamir Jelić <poljar@termina.org.uk>2019-04-10 15:18:07 +0200
committerDamir Jelić <poljar@termina.org.uk>2019-04-10 15:18:07 +0200
commit086133f39a175a72ea7c898c708fed38b8dbd36b (patch)
treef335cf726acafae819d1b824c6b23186eddaa9df /python/tests/utils_test.py
parentc79d9282dcb9946144905a93ec9b5f14b17cc30c (diff)
parent54cb52e05e0d715c9e3c71ffeff05050732dea41 (diff)
Merge branch 'python-sas'
Diffstat (limited to 'python/tests/utils_test.py')
-rw-r--r--python/tests/utils_test.py29
1 files changed, 29 insertions, 0 deletions
diff --git a/python/tests/utils_test.py b/python/tests/utils_test.py
new file mode 100644
index 0000000..a552d12
--- /dev/null
+++ b/python/tests/utils_test.py
@@ -0,0 +1,29 @@
+import base64
+import hashlib
+
+from future.utils import bytes_to_native_str
+from hypothesis import given
+from hypothesis.strategies import text
+
+from olm import sha256
+from olm._compat import to_bytes
+
+
+class TestClass(object):
+ @given(text(), text())
+ def test_sha256(self, input1, input2):
+ first_hash = sha256(input1)
+ second_hash = sha256(input2)
+
+ hashlib_hash = base64.b64encode(
+ hashlib.sha256(to_bytes(input1)).digest()
+ )
+
+ hashlib_hash = bytes_to_native_str(hashlib_hash[:-1])
+
+ if input1 == input2:
+ assert first_hash == second_hash
+ else:
+ assert first_hash != second_hash
+
+ assert hashlib_hash == first_hash