You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by br...@apache.org on 2020/03/10 16:12:02 UTC
[allura] 10/14: [#8354] unicode/byte fixes encountered during
nearly all tests setup
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 <da...@brondsema.net>
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 %}
<input name="_session_id" type="hidden" value="{{csrf()}}">
{% 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()