allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brond...@apache.org
Subject allura git commit: [#7881] ticket:787 Clean up phone numbers before using them
Date Wed, 03 Jun 2015 17:57:02 GMT
Repository: allura
Updated Branches:
  refs/heads/master 90da7b3c5 -> c742acaf5


[#7881] ticket:787 Clean up phone numbers before using them


Project: http://git-wip-us.apache.org/repos/asf/allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/allura/commit/c742acaf
Tree: http://git-wip-us.apache.org/repos/asf/allura/tree/c742acaf
Diff: http://git-wip-us.apache.org/repos/asf/allura/diff/c742acaf

Branch: refs/heads/master
Commit: c742acaf5c7d1686ed0acf0cb3061ca79cd5d5a9
Parents: 90da7b3
Author: Igor Bondarenko <jetmind2@gmail.com>
Authored: Tue Jun 2 13:39:59 2015 +0000
Committer: Igor Bondarenko <jetmind2@gmail.com>
Committed: Wed Jun 3 11:41:47 2015 +0000

----------------------------------------------------------------------
 Allura/allura/lib/plugin.py                         |  2 ++
 Allura/allura/lib/utils.py                          | 10 +++++++++-
 Allura/allura/tests/functional/test_neighborhood.py | 10 +++++-----
 Allura/allura/tests/test_plugin.py                  |  4 ++--
 Allura/allura/tests/test_utils.py                   |  8 ++++++++
 5 files changed, 26 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/c742acaf/Allura/allura/lib/plugin.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/plugin.py b/Allura/allura/lib/plugin.py
index 29a3ee6..abb5c8c 100644
--- a/Allura/allura/lib/plugin.py
+++ b/Allura/allura/lib/plugin.py
@@ -54,6 +54,7 @@ from ming.orm import ThreadLocalORMSession, session
 from allura.lib import helpers as h
 from allura.lib import security
 from allura.lib import exceptions as forge_exc
+from allura.lib import utils
 
 log = logging.getLogger(__name__)
 
@@ -735,6 +736,7 @@ class ProjectRegistrationProvider(object):
         ok = {'status': 'ok'}
         if not asbool(config.get('project.verify_phone')):
             return ok
+        number = utils.clean_phone_number(number)
         return g.phone_service.verify(number)
 
     def check_phone_verification(self, user, request_id, pin, number_hash):

http://git-wip-us.apache.org/repos/asf/allura/blob/c742acaf/Allura/allura/lib/utils.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/utils.py b/Allura/allura/lib/utils.py
index 73475db..143868e 100644
--- a/Allura/allura/lib/utils.py
+++ b/Allura/allura/lib/utils.py
@@ -602,7 +602,15 @@ class DateJSONEncoder(json.JSONEncoder):
         return json.JSONEncoder.default(self, obj)
 
 
-def phone_number_hash(number):
+def clean_phone_number(number):
     pattern = re.compile('\W+')
     number = pattern.sub('', number)
+    if len(number) == 10:
+        # assume US phone
+        number = u'1' + number
+    return number
+
+
+def phone_number_hash(number):
+    number = clean_phone_number(number)
     return hashlib.sha1(number).hexdigest()

http://git-wip-us.apache.org/repos/asf/allura/blob/c742acaf/Allura/allura/tests/functional/test_neighborhood.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/functional/test_neighborhood.py b/Allura/allura/tests/functional/test_neighborhood.py
index dde6647..b3ab279 100644
--- a/Allura/allura/tests/functional/test_neighborhood.py
+++ b/Allura/allura/tests/functional/test_neighborhood.py
@@ -984,13 +984,13 @@ class TestPhoneVerificationOnProjectRegistration(TestController):
         with h.push_config(config, **{'project.verify_phone': 'true'}):
             phone_service.verify.return_value = {
                 'request_id': 'request-id', 'status': 'ok'}
-            r = self.app.get('/p/verify_phone', {'number': '1234567890'})
-            phone_service.verify.assert_called_once_with('1234567890')
+            r = self.app.get('/p/verify_phone', {'number': '555-444-3333'})
+            phone_service.verify.assert_called_once_with('15554443333')
             assert_equal(r.json, {'status': 'ok'})
             rid = r.session.get('phone_verification.request_id')
             hash = r.session.get('phone_verification.number_hash')
             assert_equal(rid, 'request-id')
-            assert_equal(hash, '01b307acba4f54f55aafc33bb06bbbf6ca803e9a')
+            assert_equal(hash, 'f9ac49faef45d18746ced08d001e23b179107940')
 
     def test_check_phone_verification_no_params(self):
         with h.push_config(config, **{'project.verify_phone': 'true'}):
@@ -1024,7 +1024,7 @@ class TestPhoneVerificationOnProjectRegistration(TestController):
             # make request to verify first to initialize session
             phone_service.verify.return_value = {
                 'request_id': req_id, 'status': 'ok'}
-            r = self.app.get('/p/verify_phone', {'number': '1234567890'})
+            r = self.app.get('/p/verify_phone', {'number': '11234567890'})
 
             r = self.app.get('/p/check_phone_verification', {'pin': '1234'})
             assert_equal(r.json, {'status': 'ok'})
@@ -1032,7 +1032,7 @@ class TestPhoneVerificationOnProjectRegistration(TestController):
 
             user = M.User.by_username('test-admin')
             hash = user.get_tool_data('phone_verification', 'number_hash')
-            assert_equal(hash, '01b307acba4f54f55aafc33bb06bbbf6ca803e9a')
+            assert_equal(hash, '54c61c96d5d5aea5254c2d4f41508a938e5501b4')
 
     def test_register_phone_not_verified(self):
         with h.push_config(config, **{'project.verify_phone': 'true'}):

http://git-wip-us.apache.org/repos/asf/allura/blob/c742acaf/Allura/allura/tests/test_plugin.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/test_plugin.py b/Allura/allura/tests/test_plugin.py
index 236e7be..64b9695 100644
--- a/Allura/allura/tests/test_plugin.py
+++ b/Allura/allura/tests/test_plugin.py
@@ -152,8 +152,8 @@ class TestProjectRegistrationProviderPhoneVerification(object):
     def test_verify_phone(self, g):
         g.phone_service = Mock(spec=phone.PhoneService)
         with h.push_config(tg.config, **{'project.verify_phone': 'true'}):
-            result = self.p.verify_phone(self.user, '12345')
-            g.phone_service.verify.assert_called_once_with('12345')
+            result = self.p.verify_phone(self.user, '123 45 45')
+            g.phone_service.verify.assert_called_once_with('1234545')
             assert_equal(result, g.phone_service.verify.return_value)
 
     @patch.object(plugin, 'g')

http://git-wip-us.apache.org/repos/asf/allura/blob/c742acaf/Allura/allura/tests/test_utils.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/test_utils.py b/Allura/allura/tests/test_utils.py
index ae4eef8..5043e3d 100644
--- a/Allura/allura/tests/test_utils.py
+++ b/Allura/allura/tests/test_utils.py
@@ -311,6 +311,14 @@ def test_DateJSONEncoder():
     assert_equal(result, '{"date": "2015-01-30T13:13:13Z", "message": "Hi!"}')
 
 
+def test_clean_phone_number():
+    clean = utils.clean_phone_number
+    assert_equal(clean('123456789'), '123456789')
+    assert_equal(clean('+123 456:789'), '123456789')
+    assert_equal(clean('555-555-5555'), '15555555555')
+    assert_equal(clean('1-555-555-5555'), '15555555555')
+
+
 def test_phone_number_hash():
     hash = utils.phone_number_hash
     assert_equal(hash('1234567890'), hash('+123 456:7890'))


Mime
View raw message