|
|
@ -13,31 +13,24 @@ class UnsubscribeEmailTestCase(BaseTestCase): |
|
|
|
self.channel.value = "[email protected]" |
|
|
|
self.channel.save() |
|
|
|
|
|
|
|
def test_it_serves_confirmation_form(self): |
|
|
|
token = self.channel.make_token() |
|
|
|
url = "/integrations/%s/unsub/%s/" % (self.channel.code, token) |
|
|
|
signer = TimestampSigner(salt="alerts") |
|
|
|
signed_token = signer.sign(self.channel.make_token()) |
|
|
|
self.url = f"/integrations/{self.channel.code}/unsub/{signed_token}/" |
|
|
|
|
|
|
|
r = self.client.get(url) |
|
|
|
def test_it_serves_confirmation_form(self): |
|
|
|
r = self.client.get(self.url) |
|
|
|
self.assertContains(r, "Please press the button below") |
|
|
|
self.assertNotContains(r, "submit()") |
|
|
|
|
|
|
|
def test_post_unsubscribes(self): |
|
|
|
token = self.channel.make_token() |
|
|
|
url = "/integrations/%s/unsub/%s/" % (self.channel.code, token) |
|
|
|
|
|
|
|
r = self.client.post(url) |
|
|
|
r = self.client.post(self.url) |
|
|
|
self.assertContains(r, "has been unsubscribed", status_code=200) |
|
|
|
|
|
|
|
q = Channel.objects.filter(code=self.channel.code) |
|
|
|
self.assertEqual(q.count(), 0) |
|
|
|
|
|
|
|
def test_fresh_signature_does_not_autosubmit(self): |
|
|
|
signer = TimestampSigner(salt="alerts") |
|
|
|
signed_token = signer.sign(self.channel.make_token()) |
|
|
|
|
|
|
|
url = "/integrations/%s/unsub/%s/" % (self.channel.code, signed_token) |
|
|
|
|
|
|
|
r = self.client.get(url) |
|
|
|
r = self.client.get(self.url) |
|
|
|
self.assertContains( |
|
|
|
r, "Please press the button below to unsubscribe", status_code=200 |
|
|
|
) |
|
|
@ -49,7 +42,7 @@ class UnsubscribeEmailTestCase(BaseTestCase): |
|
|
|
signer = TimestampSigner(salt="alerts") |
|
|
|
signed_token = signer.sign(self.channel.make_token()) |
|
|
|
|
|
|
|
url = "/integrations/%s/unsub/%s/" % (self.channel.code, signed_token) |
|
|
|
url = f"/integrations/{self.channel.code}/unsub/{signed_token}/" |
|
|
|
|
|
|
|
r = self.client.get(url) |
|
|
|
self.assertContains( |
|
|
@ -59,13 +52,13 @@ class UnsubscribeEmailTestCase(BaseTestCase): |
|
|
|
|
|
|
|
def test_it_checks_signature(self): |
|
|
|
signed_token = self.channel.make_token() + ":bad:signature" |
|
|
|
url = "/integrations/%s/unsub/%s/" % (self.channel.code, signed_token) |
|
|
|
url = f"/integrations/{self.channel.code}/unsub/{signed_token}/" |
|
|
|
|
|
|
|
r = self.client.get(url) |
|
|
|
self.assertContains(r, "link you just used is incorrect", status_code=200) |
|
|
|
|
|
|
|
def test_it_checks_token(self): |
|
|
|
url = "/integrations/%s/unsub/faketoken/" % self.channel.code |
|
|
|
url = f"/integrations/{self.channel.code}/unsub/faketoken/" |
|
|
|
|
|
|
|
r = self.client.get(url) |
|
|
|
self.assertContains(r, "link you just used is incorrect", status_code=200) |
|
|
@ -74,8 +67,5 @@ class UnsubscribeEmailTestCase(BaseTestCase): |
|
|
|
self.channel.kind = "webhook" |
|
|
|
self.channel.save() |
|
|
|
|
|
|
|
token = self.channel.make_token() |
|
|
|
url = "/integrations/%s/unsub/%s/" % (self.channel.code, token) |
|
|
|
|
|
|
|
r = self.client.get(url) |
|
|
|
r = self.client.get(self.url) |
|
|
|
self.assertEqual(r.status_code, 404) |