From commits-return-17194-apmail-allura-commits-archive=allura.apache.org@allura.apache.org Tue Mar 10 16:11:54 2020 Return-Path: X-Original-To: apmail-allura-commits-archive@www.apache.org Delivered-To: apmail-allura-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [207.244.88.153]) by minotaur.apache.org (Postfix) with SMTP id 6E60C19FB4 for ; Tue, 10 Mar 2020 16:11:54 +0000 (UTC) Received: (qmail 76203 invoked by uid 500); 10 Mar 2020 16:11:53 -0000 Delivered-To: apmail-allura-commits-archive@allura.apache.org Received: (qmail 76153 invoked by uid 500); 10 Mar 2020 16:11:53 -0000 Mailing-List: contact commits-help@allura.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@allura.apache.org Delivered-To: mailing list commits@allura.apache.org Received: (qmail 75925 invoked by uid 99); 10 Mar 2020 16:11:53 -0000 Received: from ec2-52-202-80-70.compute-1.amazonaws.com (HELO gitbox.apache.org) (52.202.80.70) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 10 Mar 2020 16:11:53 +0000 Received: by gitbox.apache.org (ASF Mail Server at gitbox.apache.org, from userid 33) id D02568DAD4; Tue, 10 Mar 2020 16:11:52 +0000 (UTC) Date: Tue, 10 Mar 2020 16:12:02 +0000 To: "commits@allura.apache.org" Subject: [allura] 10/14: [#8354] unicode/byte fixes encountered during nearly all tests setup MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit From: brondsem@apache.org In-Reply-To: <158385671248.22632.15512783501573495449@gitbox.apache.org> References: <158385671248.22632.15512783501573495449@gitbox.apache.org> X-Git-Host: gitbox.apache.org X-Git-Repo: allura X-Git-Refname: refs/heads/db/8354 X-Git-Reftype: branch X-Git-Rev: 99a5ef8c2b74bd72f0c9d8dbbba14de8000c709b X-Git-NotificationType: diff X-Git-Multimail-Version: 1.5.dev Auto-Submitted: auto-generated Message-Id: <20200310161152.D02568DAD4@gitbox.apache.org> This is an automated email from the ASF dual-hosted git repository. brondsem pushed a commit to branch db/8354 in repository https://gitbox.apache.org/repos/asf/allura.git commit 99a5ef8c2b74bd72f0c9d8dbbba14de8000c709b Author: Dave Brondsema AuthorDate: Fri Mar 6 17:51:53 2020 -0500 [#8354] unicode/byte fixes encountered during nearly all tests setup --- Allura/allura/app.py | 2 -- Allura/allura/lib/custom_middleware.py | 2 +- Allura/allura/lib/helpers.py | 7 ++++++- Allura/allura/lib/plugin.py | 4 ++-- Allura/allura/lib/widgets/forms.py | 2 +- Allura/allura/templates/jinja_master/lib.html | 4 ++-- Allura/allura/tests/test_plugin.py | 1 + 7 files changed, 13 insertions(+), 9 deletions(-) diff --git a/Allura/allura/app.py b/Allura/allura/app.py index 24ea6ff..effa59c 100644 --- a/Allura/allura/app.py +++ b/Allura/allura/app.py @@ -118,8 +118,6 @@ class SitemapEntry(object): """ self.label = label self.className = className - if url is not None: - url = url.encode('utf-8') self.url = url self.small = small self.ui_icon = ui_icon diff --git a/Allura/allura/lib/custom_middleware.py b/Allura/allura/lib/custom_middleware.py index 061d792..4ae9df1 100644 --- a/Allura/allura/lib/custom_middleware.py +++ b/Allura/allura/lib/custom_middleware.py @@ -241,7 +241,7 @@ class SSLMiddleware(object): try: request_uri = req.url - request_uri.decode('ascii') + six.ensure_binary(request_uri).decode('ascii') except UnicodeError: resp = exc.HTTPBadRequest() else: diff --git a/Allura/allura/lib/helpers.py b/Allura/allura/lib/helpers.py index 79e57b3..3f537ad 100644 --- a/Allura/allura/lib/helpers.py +++ b/Allura/allura/lib/helpers.py @@ -433,8 +433,13 @@ def nonce(length=4): def cryptographic_nonce(length=40): + rand_bytes = os.urandom(length) + if six.PY2: + rand_ints = tuple(map(ord, rand_bytes)) + else: + rand_ints = tuple(rand_bytes) hex_format = '%.2x' * length - return hex_format % tuple(map(ord, os.urandom(length))) + return hex_format % rand_ints def random_password(length=20, chars=string.ascii_uppercase + string.digits): diff --git a/Allura/allura/lib/plugin.py b/Allura/allura/lib/plugin.py index a1b2629..a79750c 100644 --- a/Allura/allura/lib/plugin.py +++ b/Allura/allura/lib/plugin.py @@ -577,8 +577,8 @@ class LocalAuthenticationProvider(AuthenticationProvider): if salt is None: salt = ''.join(chr(randint(1, 0x7f)) for i in range(M.User.SALT_LEN)) - hashpass = sha256(salt + password.encode('utf-8')).digest() - return 'sha256' + salt + b64encode(hashpass) + hashpass = sha256((salt + password).encode('utf-8')).digest() + return 'sha256' + salt + six.ensure_text(b64encode(hashpass)) def user_project_shortname(self, user): # "_" isn't valid for subdomains (which project names are used with) diff --git a/Allura/allura/lib/widgets/forms.py b/Allura/allura/lib/widgets/forms.py index 888baa5..ab0ef32 100644 --- a/Allura/allura/lib/widgets/forms.py +++ b/Allura/allura/lib/widgets/forms.py @@ -82,7 +82,7 @@ class NeighborhoodProjectShortNameValidator(fev.FancyValidator): """ if neighborhood is None: neighborhood = M.Neighborhood.query.get(name=state.full_dict['neighborhood']) - value = h.really_unicode(value or '').encode('utf-8') + value = h.really_unicode(value or '') self._validate_shortname(value, neighborhood, state) if check_allowed: self._validate_allowed(value, neighborhood, state) diff --git a/Allura/allura/templates/jinja_master/lib.html b/Allura/allura/templates/jinja_master/lib.html index 0a85183..9114986 100644 --- a/Allura/allura/templates/jinja_master/lib.html +++ b/Allura/allura/templates/jinja_master/lib.html @@ -18,13 +18,13 @@ -#} {% macro csrf() -%} - {% if request -%} + {% if request is defined -%} {{ request.cookies['_session_id'] or request.environ['_session_id'] }} {%- endif %} {%- endmacro %} {% macro csrf_token() -%} - {% if request %} + {% if request is defined %} {% endif %} {%- endmacro %} diff --git a/Allura/allura/tests/test_plugin.py b/Allura/allura/tests/test_plugin.py index 8e02010..ce23474 100644 --- a/Allura/allura/tests/test_plugin.py +++ b/Allura/allura/tests/test_plugin.py @@ -598,6 +598,7 @@ class TestLocalAuthenticationProvider(object): ep = self.provider._encode_password assert ep('test_pass') != ep('test_pass') assert ep('test_pass', '0000') == ep('test_pass', '0000') + assert_equal(ep('test_pass', '0000'), 'sha2560000j7pRjKKZ5L8G0jScZKja9ECmYF2zBV82Mi+E3wkop30=') def test_set_password_with_old_password(self): user = Mock()