Skip to content
This repository was archived by the owner on Oct 2, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ nose==1.3.0
oauthlib==0.6.0
requests==2.0.1
requests-oauthlib==0.4.0
Werkzeug==0.9.4
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any way to make this a test-only dependency?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The dependencies in requirements.txt are for developing the library. Installation dependencies are defined in setup.py.

13 changes: 13 additions & 0 deletions tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import requests
import unittest
import time
import werkzeug.datastructures

class HttpClientMock(object):
def __init__(self, paths):
Expand Down Expand Up @@ -62,6 +63,18 @@ def test_arrays_get_flattened_for_validate(self):
except toopher.SignatureValidationError:
self.fail()

def test_immutable_dictionaries_get_copied_for_validate(self):
data = werkzeug.datastructures.ImmutableMultiDict([
('foo', 'bar'),
('timestamp', '1000'),
('session_token', ToopherIframeTests.request_token),
('toopher_sig', '6d2c7GlQssGmeYYGpcf+V/kirOI=')
])
try:
self.iframe_api.validate(data, ToopherIframeTests.request_token)
except toopher.SignatureValidationError:
self.fail()

def test_get_pair_uri(self):
expected = 'https://api.toopher.test/v1/web/pair?username=jdoe&reset_email=jdoe%40example.com&expires=1100&v=2&oauth_nonce=12345678&oauth_timestamp=1000&oauth_version=1.0&oauth_signature_method=HMAC-SHA1&oauth_consumer_key=abcdefg&oauth_signature=UGlgBEUF6UZEhYPxevJeagqy6D4%3D'
self.assertEqual(expected, self.iframe_api.pair_uri('jdoe', '[email protected]'))
Expand Down
5 changes: 4 additions & 1 deletion toopher/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ def login_uri(self, username, reset_email, request_token):
return self.auth_uri(username, reset_email, 'Log In', True, False, request_token, 'None', DEFAULT_IFRAME_TTL)

def validate(self, data, request_token=None, ttl=DEFAULT_IFRAME_TTL):
# make a mutable copy of the data
data = dict(data)

# flatten data if necessary
if hasattr(data.values()[0], '__iter__'):
data = dict((k,v[0]) for (k,v) in data.items())
Expand All @@ -75,7 +78,7 @@ def validate(self, data, request_token=None, ttl=DEFAULT_IFRAME_TTL):

if missing_keys:
raise SignatureValidationError("Missing required keys: {0}".format(missing_keys))

if request_token:
if request_token != data.get('session_token'):
raise SignatureValidationError("Session token does not match expected value!")
Expand Down