summaryrefslogtreecommitdiff
path: root/tests/contrib/test_algorithms.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/contrib/test_algorithms.py')
-rw-r--r--tests/contrib/test_algorithms.py36
1 files changed, 19 insertions, 17 deletions
diff --git a/tests/contrib/test_algorithms.py b/tests/contrib/test_algorithms.py
index 1fbe10d..6d5ca75 100644
--- a/tests/contrib/test_algorithms.py
+++ b/tests/contrib/test_algorithms.py
@@ -1,8 +1,10 @@
import base64
+from jwt.utils import force_bytes, force_unicode
+
import pytest
-from ..utils import ensure_bytes, ensure_unicode, key_path
+from ..utils import key_path
try:
from jwt.contrib.algorithms.pycrypto import RSAAlgorithm
@@ -29,7 +31,7 @@ class TestPycryptoAlgorithms:
algo = RSAAlgorithm(RSAAlgorithm.SHA256)
with open(key_path('testkey_rsa'), 'r') as rsa_key:
- algo.prepare_key(ensure_unicode(rsa_key.read()))
+ algo.prepare_key(force_unicode(rsa_key.read()))
def test_rsa_should_reject_non_string_key(self):
algo = RSAAlgorithm(RSAAlgorithm.SHA256)
@@ -40,9 +42,9 @@ class TestPycryptoAlgorithms:
def test_rsa_sign_should_generate_correct_signature_value(self):
algo = RSAAlgorithm(RSAAlgorithm.SHA256)
- jwt_message = ensure_bytes('Hello World!')
+ jwt_message = force_bytes('Hello World!')
- expected_sig = base64.b64decode(ensure_bytes(
+ expected_sig = base64.b64decode(force_bytes(
'yS6zk9DBkuGTtcBzLUzSpo9gGJxJFOGvUqN01iLhWHrzBQ9ZEz3+Ae38AXp'
'10RWwscp42ySC85Z6zoN67yGkLNWnfmCZSEv+xqELGEvBJvciOKsrhiObUl'
'2mveSc1oeO/2ujkGDkkkJ2epn0YliacVjZF5+/uDmImUfAAj8lzjnHlzYix'
@@ -63,9 +65,9 @@ class TestPycryptoAlgorithms:
def test_rsa_verify_should_return_false_if_signature_invalid(self):
algo = RSAAlgorithm(RSAAlgorithm.SHA256)
- jwt_message = ensure_bytes('Hello World!')
+ jwt_message = force_bytes('Hello World!')
- jwt_sig = base64.b64decode(ensure_bytes(
+ jwt_sig = base64.b64decode(force_bytes(
'yS6zk9DBkuGTtcBzLUzSpo9gGJxJFOGvUqN01iLhWHrzBQ9ZEz3+Ae38AXp'
'10RWwscp42ySC85Z6zoN67yGkLNWnfmCZSEv+xqELGEvBJvciOKsrhiObUl'
'2mveSc1oeO/2ujkGDkkkJ2epn0YliacVjZF5+/uDmImUfAAj8lzjnHlzYix'
@@ -73,7 +75,7 @@ class TestPycryptoAlgorithms:
'fHJnNUzAEUOXS0WahHVb57D30pcgIji9z923q90p5c7E2cU8V+E1qe8NdCA'
'APCDzZZ9zQ/dgcMVaBrGrgimrcLbPjueOKFgSO+SSjIElKA=='))
- jwt_sig += ensure_bytes('123') # Signature is now invalid
+ jwt_sig += force_bytes('123') # Signature is now invalid
with open(key_path('testkey_rsa.pub'), 'r') as keyfile:
jwt_pub_key = algo.prepare_key(keyfile.read())
@@ -84,9 +86,9 @@ class TestPycryptoAlgorithms:
def test_rsa_verify_should_return_true_if_signature_valid(self):
algo = RSAAlgorithm(RSAAlgorithm.SHA256)
- jwt_message = ensure_bytes('Hello World!')
+ jwt_message = force_bytes('Hello World!')
- jwt_sig = base64.b64decode(ensure_bytes(
+ jwt_sig = base64.b64decode(force_bytes(
'yS6zk9DBkuGTtcBzLUzSpo9gGJxJFOGvUqN01iLhWHrzBQ9ZEz3+Ae38AXp'
'10RWwscp42ySC85Z6zoN67yGkLNWnfmCZSEv+xqELGEvBJvciOKsrhiObUl'
'2mveSc1oeO/2ujkGDkkkJ2epn0YliacVjZF5+/uDmImUfAAj8lzjnHlzYix'
@@ -122,14 +124,14 @@ class TestEcdsaAlgorithms:
algo = ECAlgorithm(ECAlgorithm.SHA256)
with open(key_path('testkey_ec'), 'r') as ec_key:
- algo.prepare_key(ensure_unicode(ec_key.read()))
+ algo.prepare_key(force_unicode(ec_key.read()))
def test_ec_sign_should_generate_correct_signature_value(self):
algo = ECAlgorithm(ECAlgorithm.SHA256)
- jwt_message = ensure_bytes('Hello World!')
+ jwt_message = force_bytes('Hello World!')
- expected_sig = base64.b64decode(ensure_bytes(
+ expected_sig = base64.b64decode(force_bytes(
'AC+m4Jf/xI3guAC6w0w37t5zRpSCF6F4udEz5LiMiTIjCS4vcVe6dDOxK+M'
'mvkF8PxJuvqxP2CO3TR3okDPCl/NjATTO1jE+qBZ966CRQSSzcCM+tzcHzw'
'LZS5kbvKu0Acd/K6Ol2/W3B1NeV5F/gjvZn/jOwaLgWEUYsg0o4XVrAg65'))
@@ -147,14 +149,14 @@ class TestEcdsaAlgorithms:
def test_ec_verify_should_return_false_if_signature_invalid(self):
algo = ECAlgorithm(ECAlgorithm.SHA256)
- jwt_message = ensure_bytes('Hello World!')
+ jwt_message = force_bytes('Hello World!')
- jwt_sig = base64.b64decode(ensure_bytes(
+ jwt_sig = base64.b64decode(force_bytes(
'AC+m4Jf/xI3guAC6w0w37t5zRpSCF6F4udEz5LiMiTIjCS4vcVe6dDOxK+M'
'mvkF8PxJuvqxP2CO3TR3okDPCl/NjATTO1jE+qBZ966CRQSSzcCM+tzcHzw'
'LZS5kbvKu0Acd/K6Ol2/W3B1NeV5F/gjvZn/jOwaLgWEUYsg0o4XVrAg65'))
- jwt_sig += ensure_bytes('123') # Signature is now invalid
+ jwt_sig += force_bytes('123') # Signature is now invalid
with open(key_path('testkey_ec.pub'), 'r') as keyfile:
jwt_pub_key = algo.prepare_key(keyfile.read())
@@ -165,9 +167,9 @@ class TestEcdsaAlgorithms:
def test_ec_verify_should_return_true_if_signature_valid(self):
algo = ECAlgorithm(ECAlgorithm.SHA256)
- jwt_message = ensure_bytes('Hello World!')
+ jwt_message = force_bytes('Hello World!')
- jwt_sig = base64.b64decode(ensure_bytes(
+ jwt_sig = base64.b64decode(force_bytes(
'AC+m4Jf/xI3guAC6w0w37t5zRpSCF6F4udEz5LiMiTIjCS4vcVe6dDOxK+M'
'mvkF8PxJuvqxP2CO3TR3okDPCl/NjATTO1jE+qBZ966CRQSSzcCM+tzcHzw'
'LZS5kbvKu0Acd/K6Ol2/W3B1NeV5F/gjvZn/jOwaLgWEUYsg0o4XVrAg65'))