Esempio n. 1
0
 def test_integration(self):
     # These values were taken from a test page. DO NOT ALTER!
     key = ("BDd3_hVL9fZi9Ybo2UUzA284WG5FZR30_95YeZJsiApwXKpNcF1rRPF3foI"
            "iBHXRdJI2Qhumhf6_LFTeZaNndIo")
     auth = ("eyJ0eXAiOiJKV1QiLCJhbGciOiJFUzI1NiJ9.eyJhdWQiOiJod"
             "HRwczovL3VwZGF0ZXMucHVzaC5zZXJ2aWNlcy5tb3ppbGxhLmNvbSIsImV"
             "4cCI6MTQ5NDY3MTQ3MCwic3ViIjoibWFpbHRvOnNpbXBsZS1wdXNoLWRlb"
             "W9AZ2F1bnRmYWNlLmNvLnVrIn0.LqPi86T-HJ71TXHAYFptZEHD7Wlfjcc"
             "4u5jYZ17WpqOlqDcW-5Wtx3x1OgYX19alhJ9oLumlS2VzEvNioZolQA")
     ok_(Vapid01.verify(key=key, auth="webpush {}".format(auth)))
     ok_(Vapid02.verify(auth="vapid t={},k={}".format(auth, key)))
Esempio n. 2
0
 def test_sign_02_localhost(self):
     v = Vapid02.from_file("/tmp/private")
     claims = {
         "aud": "http://*****:*****@example.com",
         "foo": "extra value"
     }
     result = v.sign(claims, "id=previous")
     auth = result['Authorization']
     assert auth[:6] == 'vapid '
     assert ' t=' in auth
     assert ',k=' in auth
Esempio n. 3
0
 def test_sign_02(self):
     v = Vapid02.from_file("/tmp/private")
     claims = {"aud": "example.com",
               "sub": "*****@*****.**",
               "foo": "extra value"}
     result = v.sign(claims, "id=previous")
     auth = result['Authorization']
     eq_(auth[:6], 'vapid ')
     ok_(' t=' in auth)
     ok_(',k=' in auth)
     parts = auth[6:].split(',')
     eq_(len(parts), 2)
     t_val = json.loads(base64.urlsafe_b64decode(
         self.repad(parts[0][2:].split('.')[1])
     ).decode('utf8'))
     k_val = binascii.a2b_base64(self.repad(parts[1][2:]))
     eq_(binascii.hexlify(k_val)[:2], b'04')
     eq_(len(k_val), 65)
     for k in claims:
         eq_(t_val[k], claims[k])
Esempio n. 4
0
 def test_sign_02(self):
     v = Vapid02.from_file("/tmp/private")
     claims = {"aud": "https://example.com",
               "sub": "mailto:[email protected]",
               "foo": "extra value"}
     result = v.sign(claims, "id=previous")
     auth = result['Authorization']
     eq_(auth[:6], 'vapid ')
     ok_(' t=' in auth)
     ok_(',k=' in auth)
     parts = auth[6:].split(',')
     eq_(len(parts), 2)
     t_val = json.loads(base64.urlsafe_b64decode(
         self.repad(parts[0][2:].split('.')[1])
     ).decode('utf8'))
     k_val = binascii.a2b_base64(self.repad(parts[1][2:]))
     eq_(binascii.hexlify(k_val)[:2], b'04')
     eq_(len(k_val), 65)
     for k in claims:
         eq_(t_val[k], claims[k])
Esempio n. 5
0
 def test_sign_02(self):
     v = Vapid02.from_file("/tmp/private")
     claims = {
         "aud": "https://example.com",
         "sub": "mailto:[email protected]",
         "foo": "extra value"
     }
     claim_check = copy.deepcopy(claims)
     result = v.sign(claims, "id=previous")
     auth = result['Authorization']
     assert auth[:6] == 'vapid '
     assert ' t=' in auth
     assert ',k=' in auth
     parts = auth[6:].split(',')
     assert len(parts) == 2
     t_val = json.loads(
         base64.urlsafe_b64decode(self.repad(
             parts[0][2:].split('.')[1])).decode('utf8'))
     k_val = binascii.a2b_base64(self.repad(parts[1][2:]))
     assert binascii.hexlify(k_val)[:2] == b'04'
     assert len(k_val) == 65
     assert claims == claim_check
     for k in claims:
         assert t_val[k] == claims[k]
Esempio n. 6
0
 def test_ignore_sub(self):
     v = Vapid02.from_file("/tmp/private")
     v.conf['no-strict'] = True
     assert v.sign({"sub": "foo", "aud": "http://localhost:8000"})