Test VAPIDKeyset can generate a public key
This commit is contained in:
parent
d03672e01e
commit
74b2712699
@ -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(
|
||||
|
@ -4,6 +4,7 @@ yaml_config = """
|
||||
dependencies:
|
||||
|
||||
ldppackages:
|
||||
- djangoldp_webpushnotification
|
||||
- djangoldp_webpushnotification.tests
|
||||
|
||||
server:
|
||||
|
@ -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)
|
||||
|
Reference in New Issue
Block a user