diff options
authorChristopher Viel <>2018-01-03 19:03:04 (GMT)
committerChristopher Viel <>2018-01-03 19:58:23 (GMT)
commitc289cdbfe677b524ab97e5a54b8b421a1cd54f15 (patch)
parent1db719e153ae980a60dbef9ca68171027bf9f170 (diff)
Copy subscription before altering the keys.
Altering subscriptions reference by changing the keys from string to byte causes hard to debug issues in libraries. For exemple, trying to call `json.dumps()` after initializing `WebPusher` throws an error because json cannot handle bytes.
2 files changed, 7 insertions, 3 deletions
diff --git a/pywebpush/ b/pywebpush/
index 3312745..d093bf8 100644
--- a/pywebpush/
+++ b/pywebpush/
@@ -3,6 +3,7 @@
# file, You can obtain one at
import base64
+from copy import deepcopy
import json
import os
@@ -116,7 +117,7 @@ class WebPusher:
if 'endpoint' not in subscription_info:
raise WebPushException("subscription_info missing endpoint URL")
- self.subscription_info = subscription_info
+ self.subscription_info = deepcopy(subscription_info)
self.auth_key = self.receiver_key = None
if 'keys' in subscription_info:
keys = self.subscription_info['keys']
diff --git a/pywebpush/tests/ b/pywebpush/tests/
index 136f749..ded6a69 100644
--- a/pywebpush/tests/
+++ b/pywebpush/tests/
@@ -4,7 +4,7 @@ import os
import unittest
from mock import patch
-from import eq_, ok_, assert_raises
+from import eq_, ok_, assert_is_not, assert_raises
import http_ece
from cryptography.hazmat.primitives.asymmetric import ec
from cryptography.hazmat.backends import default_backend
@@ -75,7 +75,10 @@ class WebpushTestCase(unittest.TestCase):
"keys": {'p256dh': 'AAA=', 'auth': 'AAA='}})
push = WebPusher(subscription_info)
- eq_(push.subscription_info, subscription_info)
+ assert_is_not(push.subscription_info, subscription_info)
+ assert_is_not(push.subscription_info['keys'],
+ subscription_info['keys'])
+ eq_(push.subscription_info['endpoint'], subscription_info['endpoint'])
eq_(push.receiver_key, rk_decode)
eq_(push.auth_key, b'\x93\xc2U\xea\xc8\xddn\x10"\xd6}\xff,0K\xbc')