You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by tv...@apache.org on 2013/01/08 00:45:41 UTC
git commit: [#5534] Ensure akismet data can be urlencoded
Updated Branches:
refs/heads/tv/5534 [created] 10536d743
[#5534] Ensure akismet data can be urlencoded
Project: http://git-wip-us.apache.org/repos/asf/incubator-allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-allura/commit/10536d74
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/10536d74
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/10536d74
Branch: refs/heads/tv/5534
Commit: 10536d7439c413b598072239747f1bf1f18c22d3
Parents: 0ee6907
Author: Tim Van Steenburgh <tv...@gmail.com>
Authored: Mon Jan 7 23:45:12 2013 +0000
Committer: Tim Van Steenburgh <tv...@gmail.com>
Committed: Mon Jan 7 23:45:12 2013 +0000
----------------------------------------------------------------------
Allura/allura/lib/spam/akismetservice.py | 5 +++++
Allura/allura/tests/unit/test_spam.py | 19 +++++++++++++------
2 files changed, 18 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/10536d74/Allura/allura/lib/spam/akismetservice.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/spam/akismetservice.py b/Allura/allura/lib/spam/akismetservice.py
index 9378914..af5ece7 100644
--- a/Allura/allura/lib/spam/akismetservice.py
+++ b/Allura/allura/lib/spam/akismetservice.py
@@ -3,6 +3,8 @@ import logging
from pylons import request
from pylons import tmpl_context as c
+from allura.lib import helpers as h
+
import akismet
log = logging.getLogger(__name__)
@@ -23,6 +25,9 @@ class Akismet(akismet.Akismet):
kw['user_ip'] = user_ip.split(',')[0].strip()
kw['user_agent'] = request.headers.get('USER_AGENT')
kw['referrer'] = request.headers.get('REFERER')
+ # kw will be urlencoded, need to utf8-encode
+ for k, v in kw.items():
+ kw[k] = h.really_unicode(v).encode('utf8')
res = self.comment_check(text, data=kw, build_data=False)
log.info("spam=%s (akismet): %s" % (str(res), log_msg))
return res
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/10536d74/Allura/allura/tests/unit/test_spam.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/unit/test_spam.py b/Allura/allura/tests/unit/test_spam.py
index d09c907..e364783 100644
--- a/Allura/allura/tests/unit/test_spam.py
+++ b/Allura/allura/tests/unit/test_spam.py
@@ -1,5 +1,8 @@
+# -*- coding: utf-8 -*-
+
import mock
import unittest
+import urllib
try:
from allura.lib.spam.akismetservice import Akismet
@@ -11,18 +14,22 @@ except ImportError:
class TestAkismet(unittest.TestCase):
def setUp(self):
self.akismet = Akismet()
- self.akismet.comment_check = mock.Mock()
+ def side_effect(*args, **kw):
+ # side effect to test that data being sent to
+ # akismet can be successfully urlencoded
+ urllib.urlencode(kw.get('data', {}))
+ self.akismet.comment_check = mock.Mock(side_effect=side_effect)
self.fake_artifact = mock.Mock(**{'url.return_value': 'artifact url'})
- self.fake_user = mock.Mock(display_name='Some User',
+ self.fake_user = mock.Mock(display_name=u'Søme User',
email_addresses=['user@domain'])
self.fake_headers = dict(
REMOTE_ADDR='fallback ip',
X_FORWARDED_FOR='some ip',
USER_AGENT='some browser',
REFERER='some url')
- self.content = 'spam text'
+ self.content = u'spåm text'
self.expected_data = dict(
- comment_content=self.content,
+ comment_content=self.content.encode('utf8'),
comment_type='comment',
user_ip='some ip',
user_agent='some browser',
@@ -65,7 +72,7 @@ class TestAkismet(unittest.TestCase):
c.user = None
self.akismet.check(self.content, user=self.fake_user)
expected_data = self.expected_data
- expected_data.update(comment_author='Some User',
+ expected_data.update(comment_author=u'Søme User'.encode('utf8'),
comment_author_email='user@domain')
self.akismet.comment_check.assert_called_once_with(self.content,
data=expected_data, build_data=False)
@@ -77,7 +84,7 @@ class TestAkismet(unittest.TestCase):
c.user = self.fake_user
self.akismet.check(self.content)
expected_data = self.expected_data
- expected_data.update(comment_author='Some User',
+ expected_data.update(comment_author=u'Søme User'.encode('utf8'),
comment_author_email='user@domain')
self.akismet.comment_check.assert_called_once_with(self.content,
data=expected_data, build_data=False)