Commit cb50604156af15486931732a6593b47abca75efe
1 parent
3e0832cc
Fixed #93 -- All empty REMOTE_ADDR values should set ip_address to null
Showing
2 changed files
with
10 additions
and
1 deletions
| ... | ... | @@ -106,7 +106,7 @@ def post_comment(request, next=None, using=None): |
| 106 | 106 | |
| 107 | 107 | # Otherwise create the comment |
| 108 | 108 | comment = form.get_comment_object(site_id=get_current_site(request).id) |
| 109 | - comment.ip_address = request.META.get("REMOTE_ADDR", None) | |
| 109 | + comment.ip_address = request.META.get("REMOTE_ADDR", None) or None | |
| 110 | 110 | if user_is_authenticated: |
| 111 | 111 | comment.user = request.user |
| 112 | 112 | ... | ... |
| ... | ... | @@ -140,6 +140,15 @@ class CommentViewTests(CommentTestCase): |
| 140 | 140 | self.assertEqual(c.ip_address, address) |
| 141 | 141 | self.assertEqual(c.comment, "This is my comment") |
| 142 | 142 | |
| 143 | + def testCreateValidCommentNoIP(self): | |
| 144 | + """Empty REMOTE_ADDR value should always set a null ip_address value.""" | |
| 145 | + a = Article.objects.get(pk=1) | |
| 146 | + data = self.getValidData(a) | |
| 147 | + for address in ('', None, b''): | |
| 148 | + self.client.post("/post/", data, REMOTE_ADDR=address) | |
| 149 | + c = Comment.objects.last() | |
| 150 | + self.assertEqual(c.ip_address, None) | |
| 151 | + | |
| 143 | 152 | def testCreateValidCommentIPv6Unpack(self): |
| 144 | 153 | address = "::ffff:18.52.18.52" |
| 145 | 154 | a = Article.objects.get(pk=1) | ... | ... |
Please
register
or
login
to post a comment