From c64d1029b46523a2223b29348225d243f05807b5 Mon Sep 17 00:00:00 2001 From: decentral1se Date: Thu, 15 Apr 2021 15:06:37 +0200 Subject: [PATCH] Add failing test for missing VAPID key --- .../tests/tests_accept_subscription.py | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/djangoldp_webpushnotification/tests/tests_accept_subscription.py b/djangoldp_webpushnotification/tests/tests_accept_subscription.py index c58cd88..f0266e7 100644 --- a/djangoldp_webpushnotification/tests/tests_accept_subscription.py +++ b/djangoldp_webpushnotification/tests/tests_accept_subscription.py @@ -56,3 +56,23 @@ class TestAcceptSubscription(TestCase): push_info = PushInformation.objects.get() self.assertEqual(push_info.user, self.user) self.assertEqual(push_info.subscription, sub_info) + + def test_accept_sub_missing_vapid_key(self): + payload = { + "status_type": "subscribe", + "subscription": { + "endpoint": "https://hubl.example.com", + "keys": { + "auth": "front-end-generated-secret", + "p256dh": "INVALID-PUBLIC-KEY", + }, + }, + "browser": "firefox", + } + + url = reverse("save_webpush_info") + response = self.client.post( + url, data=json.dumps(payload), content_type="application/json" + ) + + self.assertEqual(response.status_code, 403)