Project

General

Profile

0001-remove-scheme-identifier-from-unsubscription-page-12.patch

Serghei Mihai, 12 July 2016 03:47 PM

Download (2.69 KB)

View differences:

Subject: [PATCH] remove scheme identifier from unsubscription page (#12544)

 corbo/views.py         |  8 +++++++-
 tests/test_emailing.py | 10 +++++++---
 2 files changed, 14 insertions(+), 4 deletions(-)
corbo/views.py
def get_object(self, queryset=None):
data = signing.loads(self.kwargs['unsubscription_token'])
try:
return models.Subscription.objects.get(category__pk=data['category'],
s = models.Subscription.objects.get(category__pk=data['category'],
identifier=data['identifier'])
try:
# remove schema from identifier
scheme, s.identifier = s.identifier.split(':')
except ValueError:
pass
return s
except models.Subscription.DoesNotExist:
raise Http404
tests/test_emailing.py
def test_unsubscription_link(app, categories, announces):
for category in categories:
uuid = uuid4()
email = '%s@example.net' % uuid
scheme = 'mailto:'
uri = scheme + '%s@example.net' % uuid
s = Subscription.objects.create(category=category,
identifier=email,
identifier=uri,
uuid=str(uuid))
for announce in announces:
if announce.category != category:
......
assert broadcast.result
assert mail.outbox
signature = signing.dumps({'category': announce.category.pk,
'identifier': email})
'identifier': uri})
unsubscription_link = reverse('unsubscribe', kwargs={'unsubscription_token': signature})
assert mail.outbox[0].subject == announce.title
assert unsubscription_link in mail.outbox[0].html
assert unsubscription_link in mail.outbox[0].text
mail.outbox = []
# make sure the uri schema is not in the page
resp = app.get(unsubscription_link)
assert scheme not in resp.content