mirror of
https://github.com/django/django.git
synced 2025-11-01 20:31:40 +00:00
Fixed #16302 -- Ensure contrib.comments is IPv6 capable
Changed the ip_address field for Comment to GenericIPAddressField. Added instructions to the release notes on how to update the schema of existing databases.
This commit is contained in:
parent
e4ee3d8fca
commit
ade992c61e
3 changed files with 57 additions and 3 deletions
|
|
@ -101,13 +101,43 @@ class CommentViewTests(CommentTestCase):
|
|||
settings.DEBUG = olddebug
|
||||
|
||||
def testCreateValidComment(self):
|
||||
address = "1.2.3.4"
|
||||
a = Article.objects.get(pk=1)
|
||||
data = self.getValidData(a)
|
||||
self.response = self.client.post("/post/", data, REMOTE_ADDR="1.2.3.4")
|
||||
self.response = self.client.post("/post/", data, REMOTE_ADDR=address)
|
||||
self.assertEqual(self.response.status_code, 302)
|
||||
self.assertEqual(Comment.objects.count(), 1)
|
||||
c = Comment.objects.all()[0]
|
||||
self.assertEqual(c.ip_address, "1.2.3.4")
|
||||
self.assertEqual(c.ip_address, address)
|
||||
self.assertEqual(c.comment, "This is my comment")
|
||||
|
||||
def testCreateValidCommentIPv6(self):
|
||||
"""
|
||||
Test creating a valid comment with a long IPv6 address.
|
||||
Note that this test should fail when Comment.ip_address is an IPAddress instead of a GenericIPAddress,
|
||||
but does not do so on SQLite or PostgreSQL, because they use the TEXT and INET types, which already
|
||||
allow storing an IPv6 address internally.
|
||||
"""
|
||||
address = "2a02::223:6cff:fe8a:2e8a"
|
||||
a = Article.objects.get(pk=1)
|
||||
data = self.getValidData(a)
|
||||
self.response = self.client.post("/post/", data, REMOTE_ADDR=address)
|
||||
self.assertEqual(self.response.status_code, 302)
|
||||
self.assertEqual(Comment.objects.count(), 1)
|
||||
c = Comment.objects.all()[0]
|
||||
self.assertEqual(c.ip_address, address)
|
||||
self.assertEqual(c.comment, "This is my comment")
|
||||
|
||||
def testCreateValidCommentIPv6Unpack(self):
|
||||
address = "::ffff:18.52.18.52"
|
||||
a = Article.objects.get(pk=1)
|
||||
data = self.getValidData(a)
|
||||
self.response = self.client.post("/post/", data, REMOTE_ADDR=address)
|
||||
self.assertEqual(self.response.status_code, 302)
|
||||
self.assertEqual(Comment.objects.count(), 1)
|
||||
c = Comment.objects.all()[0]
|
||||
# We trim the '::ffff:' bit off because it is an IPv4 addr
|
||||
self.assertEqual(c.ip_address, address[7:])
|
||||
self.assertEqual(c.comment, "This is my comment")
|
||||
|
||||
def testPostAsAuthenticatedUser(self):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue