Skip to content

Commit

Permalink
Merge pull request #314 from singingwolfboy/require-rsa-key-when-bein…
Browse files Browse the repository at this point in the history
…g-used

Check for rsa_key when it's actually needed
  • Loading branch information
thedrow committed Jul 1, 2015
2 parents 70879b5 + 96caa49 commit c806879
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
4 changes: 0 additions & 4 deletions oauthlib/oauth1/rfc5849/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,6 @@ def __init__(self, client_key,
self.nonce = encode(nonce)
self.timestamp = encode(timestamp)

if self.signature_method == SIGNATURE_RSA and self.rsa_key is None:
raise ValueError(
'rsa_key is required when using RSA signature method.')

def __repr__(self):
attrs = vars(self).copy()
attrs['client_secret'] = '****' if attrs['client_secret'] else None
Expand Down
2 changes: 2 additions & 0 deletions oauthlib/oauth1/rfc5849/signature.py
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,8 @@ def sign_rsa_sha1(base_string, rsa_private_key):


def sign_rsa_sha1_with_client(base_string, client):
if not client.rsa_key:
raise ValueError('rsa_key is required when using RSA signature method.')
return sign_rsa_sha1(base_string, client.rsa_key)


Expand Down
8 changes: 7 additions & 1 deletion tests/oauth1/rfc5849/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ def test_decoding(self):
self.assertIsInstance(k, bytes_type)
self.assertIsInstance(v, bytes_type)

def test_rsa(self):
client = Client('client_key', signature_method=SIGNATURE_RSA)
self.assertIsNone(client.rsa_key) # don't need an RSA key to instantiate


class SignatureMethodTest(TestCase):

Expand Down Expand Up @@ -96,7 +100,6 @@ def test_rsa_method(self):
'HJILzZ8iFOvS6w5E%3D"')
self.assertEqual(h['Authorization'], correct)


def test_plaintext_method(self):
client = Client('client_key',
signature_method=SIGNATURE_PLAINTEXT,
Expand All @@ -115,6 +118,9 @@ def test_invalid_method(self):
client = Client('client_key', signature_method='invalid')
self.assertRaises(ValueError, client.sign, 'http://example.com')

def test_rsa_no_key(self):
client = Client('client_key', signature_method=SIGNATURE_RSA)
self.assertRaises(ValueError, client.sign, 'http://example.com')

def test_register_method(self):
Client.register_signature_method('PIZZA',
Expand Down

0 comments on commit c806879

Please sign in to comment.