Skip to content

Commit

Permalink
2866 Missing key results in strip() being called on None
Browse files Browse the repository at this point in the history
When no reset key is present then None is used to verify the key
and it is strip()ed first, resulting in an error.
  • Loading branch information
rossjones committed Aug 16, 2012
1 parent 18f95bf commit 5e338d9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
2 changes: 2 additions & 0 deletions ckan/lib/mailer.py
Expand Up @@ -95,6 +95,8 @@ def send_reset_link(user):
mail_user(user, _('Reset your password'), body)

def verify_reset_link(user, key):
if not key:
return False
if not user.reset_key or len(user.reset_key) < 5:
return False
return key.strip() == user.reset_key
Expand Down
9 changes: 9 additions & 0 deletions ckan/tests/functional/test_user.py
Expand Up @@ -965,6 +965,15 @@ def test_perform_reset_user_password_link_key_incorrect(self):
key='randomness') # i.e. incorrect
res = self.app.get(offset, status=403) # error

def test_perform_reset_user_password_link_key_missing(self):
CreateTestData.create_user(name='jack', password='test1')
user = model.User.by_name(u'jack')
offset = url_for(controller='user',
action='perform_reset',
id=user.id) # not, no key specified
res = self.app.get(offset, status=403) # error


def test_perform_reset_user_password_link_user_incorrect(self):
# Make up a key - i.e. trying to hack this
user = model.User.by_name(u'jack')
Expand Down

0 comments on commit 5e338d9

Please sign in to comment.