Test VAPIDKeyset can generate a public key

This commit is contained in:
decentral1se 2021-04-08 16:28:49 +02:00
parent d03672e01e
commit 74b2712699
Signed by: decentral1se
GPG Key ID: 92DAD76BD9567B8A
3 changed files with 13 additions and 3 deletions

View File

@ -15,7 +15,7 @@ class VAPIDKeyset(models.Model):
@property
def public_key(self):
key_str = self.private_key.tobytes()
key_str = self.private_key
padding = len(key_str) % 4
key_str += b"=" * padding
key = SigningKey.from_string(

View File

@ -4,6 +4,7 @@ yaml_config = """
dependencies:
ldppackages:
- djangoldp_webpushnotification
- djangoldp_webpushnotification.tests
server:

View File

@ -1,6 +1,15 @@
from base64 import urlsafe_b64encode
import ecdsa
from django.test import TestCase
from djangoldp_webpushnotification.models import VAPIDKeyset
from ecdsa import SigningKey
class TestRSAKey(TestCase):
def test_foobar(self):
assert 2 == 2
def test_vapidkeyset_public_key(self):
priv_key = SigningKey.generate(curve=ecdsa.NIST256p)
vapid_key_set = VAPIDKeyset.objects.create(
private_key=urlsafe_b64encode(priv_key.to_string()).strip(b"=")
)
assert isinstance(vapid_key_set.public_key, bytes)