Skip to content

Commit

Permalink
Don't fail when displaying IPv6 and IPv4 together in the admin (#22820)
Browse files Browse the repository at this point in the history
  • Loading branch information
diox authored Nov 6, 2024
1 parent baa72e6 commit da0d02c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/olympia/amo/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ def known_ip_adresses(self, obj):
)

contents = format_html_join(
'', '<li>{}</li>', ((ip,) for ip in sorted(ip_addresses))
'', '<li>{}</li>', sorted((str(i),) for i in ip_addresses)
)
return format_html('<ul>{}</ul>', contents)

Expand Down
12 changes: 10 additions & 2 deletions src/olympia/users/tests/test_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -994,6 +994,8 @@ def test_known_ip_adresses(self):
)
with core.override_remote_addr('130.1.2.4'):
Rating.objects.create(addon=addon_factory(), user=self.user)
with core.override_remote_addr('2001:0db8:0000:85a3:0000:0000:ac1f:8001'):
ActivityLog.objects.create(amo.LOG.LOG_IN, user=self.user)
with core.override_remote_addr('130.1.2.4'):
Rating.objects.create(addon=addon_factory(), user=self.user)
with core.override_remote_addr('15.16.23.42'):
Expand All @@ -1012,9 +1014,10 @@ def test_known_ip_adresses(self):
'127.1.2.3',
'15.16.23.42',
'172.0.0.2',
'2001:db8:0:85a3::ac1f:8001',
'4.8.15.16',
}
assert len(result) == 7
assert len(result) == 8

# Duplicates are ignored
with core.override_remote_addr('127.1.2.3'):
Expand All @@ -1029,6 +1032,10 @@ def test_known_ip_adresses(self):
ActivityLog.objects.create(amo.LOG.RESTRICTED, user=self.user)
with core.override_remote_addr('4.8.15.16'):
ActivityLog.objects.create(amo.LOG.RESTRICTED, user=self.user)
with core.override_remote_addr('2001:db8:0:85a3:0:0:ac1f:8001'):
ActivityLog.objects.create(amo.LOG.LOG_IN, user=self.user)
with core.override_remote_addr('2001:db8:0:85a3::ac1f:8001'):
ActivityLog.objects.create(amo.LOG.LOG_IN, user=self.user)
doc = pq(model_admin.known_ip_adresses(self.user))
result = doc('ul li').text().split()
assert set(result) == {
Expand All @@ -1038,9 +1045,10 @@ def test_known_ip_adresses(self):
'127.1.2.3',
'15.16.23.42',
'172.0.0.2',
'2001:db8:0:85a3::ac1f:8001',
'4.8.15.16',
}
assert len(result) == 7
assert len(result) == 8

def test_last_known_activity_time(self):
someone_else = user_factory(username='someone_else')
Expand Down

0 comments on commit da0d02c

Please sign in to comment.