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
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])
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])
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]
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"})