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/01/27 21:03:07 UTC

[allura] branch master updated (854f5ed -> b6f250a)

This is an automated email from the ASF dual-hosted git repository.

brondsem pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/allura.git.


    from 854f5ed  [#7878] GitLikeTree fixes for forgehg; other fixes for unicode in repo filenames and repo file contents
     new b1a077a  [#7878] unicode fixes for rss feeds
     new b6f250a  [#7878] ldap unicode fixes

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 Allura/allura/lib/helpers.py                        | 17 +++++++++++++++++
 Allura/allura/lib/plugin.py                         | 20 ++++++++++----------
 Allura/allura/model/artifact.py                     |  4 ++--
 Allura/allura/tests/unit/test_ldap_auth_provider.py |  4 ++--
 ForgeBlog/forgeblog/tests/functional/test_feeds.py  | 16 ++++++++++------
 5 files changed, 41 insertions(+), 20 deletions(-)


[allura] 02/02: [#7878] ldap unicode fixes

Posted by br...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

brondsem pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/allura.git

commit b6f250ad58bbf27ef4f552830fa2d13b633dcf5f
Author: Dave Brondsema <da...@brondsema.net>
AuthorDate: Mon Jan 27 15:44:02 2020 -0500

    [#7878] ldap unicode fixes
---
 Allura/allura/lib/plugin.py                         | 20 ++++++++++----------
 Allura/allura/tests/unit/test_ldap_auth_provider.py |  4 ++--
 2 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/Allura/allura/lib/plugin.py b/Allura/allura/lib/plugin.py
index 904ddca..5c09d53 100644
--- a/Allura/allura/lib/plugin.py
+++ b/Allura/allura/lib/plugin.py
@@ -657,7 +657,7 @@ class LdapAuthenticationProvider(AuthenticationProvider):
                 return result
 
         # full registration into LDAP
-        uid = str(M.AuthGlobals.get_next_uid())
+        uid = str(M.AuthGlobals.get_next_uid()).encode('utf-8')
         try:
             con = ldap_conn()
             uname = user_doc['username'].encode('utf-8')
@@ -665,14 +665,14 @@ class LdapAuthenticationProvider(AuthenticationProvider):
             ldif_u = modlist.addModlist(dict(
                 uid=uname,
                 userPassword=self._encode_password(user_doc['password']),
-                objectClass=['account', 'posixAccount'],
+                objectClass=[b'account', b'posixAccount'],
                 cn=display_name,
                 uidNumber=uid,
-                gidNumber='10001',
-                homeDirectory='/home/' + uname,
-                loginShell='/bin/bash',
+                gidNumber=b'10001',
+                homeDirectory=b'/home/' + uname,
+                loginShell=b'/bin/bash',
                 gecos=uname,
-                description='SCM user account'))
+                description=b'SCM user account'))
             try:
                 con.add_s(ldap_user_dn(user_doc['username']), ldif_u)
             except ldap.ALREADY_EXISTS:
@@ -720,9 +720,9 @@ class LdapAuthenticationProvider(AuthenticationProvider):
         rounds = asint(config.get(cfg_prefix + 'rounds', 6000))
         salt = self._get_salt(salt_len) if salt is None else salt
         encrypted = crypt.crypt(
-            password.encode('utf-8'),
+            six.ensure_str(password),
             '$%s$rounds=%s$%s' % (algorithm, rounds, salt))
-        return '{CRYPT}%s' % encrypted
+        return b'{CRYPT}%s' % encrypted.encode('utf-8')
 
     def by_username(self, username):
         from allura import model as M
@@ -739,7 +739,7 @@ class LdapAuthenticationProvider(AuthenticationProvider):
             con = ldap_conn(ldap_ident, ldap_pass)
             new_password = self._encode_password(new_password)
             con.modify_s(
-                dn, [(ldap.MOD_REPLACE, 'userPassword', new_password)])
+                dn, [(ldap.MOD_REPLACE, b'userPassword', new_password)])
             con.unbind_s()
             user.last_password_updated = datetime.utcnow()
             session(user).flush(user)
@@ -1734,7 +1734,7 @@ class LdapUserPreferencesProvider(UserPreferencesProvider):
             con = ldap_conn()
             ldap_attr = self.fields[pref_name]
             con.modify_s(ldap_user_dn(user.username),
-                         [(ldap.MOD_REPLACE, ldap_attr, pref_value.encode('utf-8'))])
+                         [(ldap.MOD_REPLACE, ldap_attr.encode('utf-8'), pref_value.encode('utf-8'))])
             con.unbind_s()
         else:
             return LocalUserPreferencesProvider().set_pref(user, pref_name, pref_value)
diff --git a/Allura/allura/tests/unit/test_ldap_auth_provider.py b/Allura/allura/tests/unit/test_ldap_auth_provider.py
index f635dd5..69865dc 100644
--- a/Allura/allura/tests/unit/test_ldap_auth_provider.py
+++ b/Allura/allura/tests/unit/test_ldap_auth_provider.py
@@ -64,9 +64,9 @@ class TestLdapAuthenticationProvider(object):
         self.provider.set_password(user, 'old-pass', 'new-pass')
         ldap.initialize.assert_called_once_with('ldaps://localhost/')
         connection = ldap.initialize.return_value
-        connection.bind_s.called_once_with(dn, 'old-pass')
+        connection.bind_s.called_once_with(dn, b'old-pass')
         connection.modify_s.assert_called_once_with(
-            dn, [(ldap.MOD_REPLACE, 'userPassword', 'new-pass-hash')])
+            dn, [(ldap.MOD_REPLACE, b'userPassword', b'new-pass-hash')])
         assert_equal(connection.unbind_s.call_count, 1)
 
     @patch('allura.lib.plugin.ldap')


[allura] 01/02: [#7878] unicode fixes for rss feeds

Posted by br...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

brondsem pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/allura.git

commit b1a077ab154bbdb8a50d94b6d152786ab34e54e4
Author: Dave Brondsema <da...@brondsema.net>
AuthorDate: Mon Jan 27 15:43:45 2020 -0500

    [#7878] unicode fixes for rss feeds
---
 Allura/allura/lib/helpers.py                       | 17 +++++++++++++++++
 Allura/allura/model/artifact.py                    |  4 ++--
 ForgeBlog/forgeblog/tests/functional/test_feeds.py | 16 ++++++++++------
 3 files changed, 29 insertions(+), 8 deletions(-)

diff --git a/Allura/allura/lib/helpers.py b/Allura/allura/lib/helpers.py
index 6c35dcb..419a9b8 100644
--- a/Allura/allura/lib/helpers.py
+++ b/Allura/allura/lib/helpers.py
@@ -178,6 +178,23 @@ def urlquoteplus(url, safe=b""):
         return urllib.quote_plus(url.encode('utf-8'), safe=safe)
 
 
+def urlquote_path_only(url):
+    """
+    Given a relative url like /fö/bar/?sdf&sdf
+    urlquote only the path portion of it, leaving any querystring or target hash unquoted
+    :param url:
+    :return:
+    """
+    if '?' in url:
+        url_path, url_joiner, url_remainder = url.partition('?')
+    elif '#' in url:
+        url_path, url_joiner, url_remainder = url.partition('#')
+    else:
+        url_path = url
+        url_joiner = url_remainder = ''
+    return urlquote(url_path) + url_joiner + url_remainder
+
+
 def _attempt_encodings(s, encodings):
     if s is None:
         return ''
diff --git a/Allura/allura/model/artifact.py b/Allura/allura/model/artifact.py
index 71a22ee..2094270 100644
--- a/Allura/allura/model/artifact.py
+++ b/Allura/allura/model/artifact.py
@@ -960,7 +960,7 @@ class Feed(MappedClass):
     def feed(cls, q, feed_type, title, link, description,
              since=None, until=None, page=None, limit=None):
         "Produces webhelper.feedgenerator Feed"
-        d = dict(title=title, link=h.absurl(link),
+        d = dict(title=title, link=h.absurl(h.urlquote(link)),
                  description=description, language='en',
                  feed_url=request.url)
         if feed_type == 'atom':
@@ -982,7 +982,7 @@ class Feed(MappedClass):
         cur = cur.skip(limit * page)
         for r in cur:
             feed.add_item(title=r.title,
-                          link=h.absurl(r.link.encode('utf-8')),
+                          link=h.absurl(h.urlquote_path_only(r.link)),
                           pubdate=r.pubdate,
                           description=r.description,
                           unique_id=h.absurl(r.unique_id),
diff --git a/ForgeBlog/forgeblog/tests/functional/test_feeds.py b/ForgeBlog/forgeblog/tests/functional/test_feeds.py
index a90fa68..5ea699f 100644
--- a/ForgeBlog/forgeblog/tests/functional/test_feeds.py
+++ b/ForgeBlog/forgeblog/tests/functional/test_feeds.py
@@ -1,3 +1,4 @@
+# coding=utf-8
 #       Licensed to the Apache Software Foundation (ASF) under one
 #       or more contributor license agreements.  See the NOTICE file
 #       distributed with this work for additional information
@@ -33,7 +34,7 @@ class TestFeeds(TestController):
 
     def _post(self, slug='', **kw):
         d = {
-            'title': 'My Post',
+            'title': 'My Pôst'.encode('utf-8'),
             'text': 'Nothing to see here',
             'labels': '',
             'state': 'published'}
@@ -60,8 +61,11 @@ class TestFeeds(TestController):
         return datetime.datetime.utcnow().strftime('%Y/%m')
 
     def test_feeds(self):
-        self.app.get('/blog/feed.rss')
-        self.app.get('/blog/feed.atom')
+        self._post()
+        r = self.app.get('/blog/feed.rss')
+        r.mustcontain('/my-p%C3%B4st/</link>')
+        r = self.app.get('/blog/feed.atom')
+        r.mustcontain('/my-p%C3%B4st/"')
 
     def test_rss_feed_contains_self_link(self):
         r = self.app.get('/blog/feed.rss')
@@ -74,9 +78,9 @@ class TestFeeds(TestController):
     def test_post_feeds(self):
         self._post()
         d = self._blog_date()
-        response = self.app.get('/blog/%s/my-post/feed.rss' % d)
+        response = self.app.get(h.urlquote('/blog/%s/my-pôst/feed.rss' % d))
         assert 'Nothing to see' in response
-        response = self.app.get('/blog/%s/my-post/feed.atom' % d)
+        response = self.app.get(h.urlquote('/blog/%s/my-pôst/feed.atom' % d))
         assert 'Nothing to see' in response
         self._post(title='test', text='*sometext*')
         response = self.app.get('/blog/feed')
@@ -139,7 +143,7 @@ class TestFeeds(TestController):
             blog_post.discussion_thread.add_post(text='You are a good blogger, I am a boring commentor.')
         ThreadLocalORMSession.flush_all()
 
-        resp = self.app.get("/blog/" + self._blog_date() + "/my-post/feed.rss")
+        resp = self.app.get(h.urlquote("/blog/" + self._blog_date() + "/my-pôst/feed.rss"))
         assert_in('boring comment', resp)
 
         resp = self.app.get("/blog/feed.rss")