From 1071fde2f715c9564d19f4e5eee6a5910c2839b1 Mon Sep 17 00:00:00 2001 From: Ib Lundgren Date: Wed, 24 Sep 2014 17:24:14 +0100 Subject: Allow alternative crypto library cryptography. An alternative to PyCrypto is taking form and it would be nice to allow users to choose which library they prefer to use for their RSA signing. CC #226. --- tests/oauth1/rfc5849/test_signatures.py | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) (limited to 'tests/oauth1') diff --git a/tests/oauth1/rfc5849/test_signatures.py b/tests/oauth1/rfc5849/test_signatures.py index aca6142..b57dc8a 100644 --- a/tests/oauth1/rfc5849/test_signatures.py +++ b/tests/oauth1/rfc5849/test_signatures.py @@ -1,6 +1,8 @@ # -*- coding: utf-8 -*- from __future__ import absolute_import, unicode_literals +import os + try: from urllib import quote except ImportError: @@ -13,7 +15,7 @@ from oauthlib.oauth1.rfc5849.signature import normalize_parameters from oauthlib.oauth1.rfc5849.signature import sign_hmac_sha1, sign_hmac_sha1_with_client from oauthlib.oauth1.rfc5849.signature import sign_rsa_sha1, sign_rsa_sha1_with_client from oauthlib.oauth1.rfc5849.signature import sign_plaintext, sign_plaintext_with_client -from oauthlib.common import unicode_type +from oauthlib.common import unicode_type, to_unicode from ...unittest import TestCase @@ -27,7 +29,7 @@ class SignatureTests(TestCase): def decode(self): for k, v in self.items(): - self[k] = v.decode('utf-8') + self[k] = to_unicode(v) uri_query = "b5=%3D%253D&a3=a&c%40=&a2=r%20b&c2=&a3=2+q" authorization_header = """OAuth realm="Example", @@ -314,6 +316,13 @@ class SignatureTests(TestCase): control_signature = self.control_signature_rsa_sha1 + os.environ['OAUTHLIB_FORCE_PYCRYPTO'] = '' + sign = sign_rsa_sha1(base_string, private_key) + self.assertEquals(sign, control_signature) + sign = sign_rsa_sha1(base_string.decode('utf-8'), private_key) + self.assertEquals(sign, control_signature) + + os.environ['OAUTHLIB_FORCE_PYCRYPTO'] = '1' sign = sign_rsa_sha1(base_string, private_key) self.assertEquals(sign, control_signature) sign = sign_rsa_sha1(base_string.decode('utf-8'), private_key) @@ -327,16 +336,19 @@ class SignatureTests(TestCase): control_signature = self.control_signature_rsa_sha1 + os.environ['OAUTHLIB_FORCE_PYCRYPTO'] = '' sign = sign_rsa_sha1_with_client(base_string, self.client) - self.assertEquals(sign, control_signature) - self.client.decode() ## Decode `rsa_private_key` from UTF-8 - sign = sign_rsa_sha1_with_client(base_string, self.client) - self.assertEquals(sign, control_signature) + os.environ['OAUTHLIB_FORCE_PYCRYPTO'] = '1' + sign = sign_rsa_sha1_with_client(base_string, self.client) + self.assertEquals(sign, control_signature) + self.client.decode() ## Decode `rsa_private_key` from UTF-8 + sign = sign_rsa_sha1_with_client(base_string, self.client) + self.assertEquals(sign, control_signature) control_signature_plaintext = ( "ECrDNoq1VYzzzzzzzzzyAK7TwZNtPnkqatqZZZZ&" -- cgit v1.2.1