You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by he...@apache.org on 2015/06/02 22:07:21 UTC
[30/39] allura git commit: [#7868] ticket:776 Strip all
non-alphanumeric chars from number before hashing
[#7868] ticket:776 Strip all non-alphanumeric chars from number before hashing
Project: http://git-wip-us.apache.org/repos/asf/allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/allura/commit/1d32c5db
Tree: http://git-wip-us.apache.org/repos/asf/allura/tree/1d32c5db
Diff: http://git-wip-us.apache.org/repos/asf/allura/diff/1d32c5db
Branch: refs/heads/hs/7825
Commit: 1d32c5dbfa449a9effd505ec5dc57bab8b534ad4
Parents: 77f5ba2
Author: Igor Bondarenko <je...@gmail.com>
Authored: Mon May 25 17:19:48 2015 +0000
Committer: Dave Brondsema <db...@slashdotmedia.com>
Committed: Thu May 28 20:11:46 2015 +0000
----------------------------------------------------------------------
Allura/allura/controllers/project.py | 2 +-
Allura/allura/lib/utils.py | 6 ++++++
Allura/allura/tests/test_utils.py | 13 ++++++++++++-
3 files changed, 19 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/allura/blob/1d32c5db/Allura/allura/controllers/project.py
----------------------------------------------------------------------
diff --git a/Allura/allura/controllers/project.py b/Allura/allura/controllers/project.py
index ebf1e65..f0e068b 100644
--- a/Allura/allura/controllers/project.py
+++ b/Allura/allura/controllers/project.py
@@ -205,7 +205,7 @@ class NeighborhoodController(object):
request_id = result.pop('request_id', None)
if request_id:
session['phone_verification.request_id'] = request_id
- number_hash = sha1(h.really_unicode(number)).hexdigest()
+ number_hash = utils.phone_number_hash(number)
session['phone_verification.number_hash'] = number_hash
session.save()
return result
http://git-wip-us.apache.org/repos/asf/allura/blob/1d32c5db/Allura/allura/lib/utils.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/utils.py b/Allura/allura/lib/utils.py
index 83950c6..73475db 100644
--- a/Allura/allura/lib/utils.py
+++ b/Allura/allura/lib/utils.py
@@ -600,3 +600,9 @@ class DateJSONEncoder(json.JSONEncoder):
if isinstance(obj, datetime.datetime):
return obj.strftime('%Y-%m-%dT%H:%M:%SZ')
return json.JSONEncoder.default(self, obj)
+
+
+def phone_number_hash(number):
+ pattern = re.compile('\W+')
+ number = pattern.sub('', number)
+ return hashlib.sha1(number).hexdigest()
http://git-wip-us.apache.org/repos/asf/allura/blob/1d32c5db/Allura/allura/tests/test_utils.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/test_utils.py b/Allura/allura/tests/test_utils.py
index 7903ba3..ae4eef8 100644
--- a/Allura/allura/tests/test_utils.py
+++ b/Allura/allura/tests/test_utils.py
@@ -25,7 +25,12 @@ from os import path
from webob import Request
from mock import Mock, patch
-from nose.tools import assert_equal, assert_raises, assert_in
+from nose.tools import (
+ assert_equal,
+ assert_not_equal,
+ assert_raises,
+ assert_in,
+)
from pygments import highlight
from pygments.lexers import get_lexer_for_filename
from tg import config
@@ -304,3 +309,9 @@ def test_DateJSONEncoder():
'date': dt.datetime(2015, 01, 30, 13, 13, 13)}
result = json.dumps(data, cls=utils.DateJSONEncoder)
assert_equal(result, '{"date": "2015-01-30T13:13:13Z", "message": "Hi!"}')
+
+
+def test_phone_number_hash():
+ hash = utils.phone_number_hash
+ assert_equal(hash('1234567890'), hash('+123 456:7890'))
+ assert_not_equal(hash('1234567890'), hash('1234567891'))