license: validate via key instance rather than PEM
This commit is contained in:
parent
2b00c644b5
commit
ae16d24fd1
2 changed files with 19 additions and 11 deletions
|
@ -1,11 +1,15 @@
|
|||
import unittest
|
||||
import jwt
|
||||
|
||||
from datetime import datetime, timedelta
|
||||
from util.config.provider.license import (decode_license, LICENSE_PRODUCT_NAME,
|
||||
LicenseValidationError)
|
||||
|
||||
import jwt
|
||||
|
||||
from Crypto.PublicKey import RSA
|
||||
from cryptography.hazmat.backends import default_backend
|
||||
from cryptography.hazmat.primitives.serialization import load_der_public_key
|
||||
|
||||
from util.config.provider.license import (decode_license, LICENSE_PRODUCT_NAME,
|
||||
LicenseValidationError)
|
||||
|
||||
|
||||
class TestLicense(unittest.TestCase):
|
||||
|
@ -13,16 +17,18 @@ class TestLicense(unittest.TestCase):
|
|||
with open('test/data/test.pem') as f:
|
||||
private_key = f.read()
|
||||
|
||||
return (RSA.importKey(private_key).publickey().exportKey('PEM'), private_key)
|
||||
public_key = load_der_public_key(RSA.importKey(private_key).publickey().exportKey('DER'),
|
||||
backend=default_backend())
|
||||
return (public_key, private_key)
|
||||
|
||||
def create_license(self, license_data):
|
||||
(public_key, private_key) = self.keys()
|
||||
|
||||
# Encode the license with the JWT key.
|
||||
encoded = jwt.encode(license_data, private_key, 'RS256')
|
||||
encoded = jwt.encode(license_data, private_key, algorithm='RS256')
|
||||
|
||||
# Decode it into a license object.
|
||||
return decode_license(encoded, public_key_contents=public_key)
|
||||
return decode_license(encoded, public_key_instance=public_key)
|
||||
|
||||
def get_license(self, expiration_delta=None, **kwargs):
|
||||
license_data = {
|
||||
|
|
Reference in a new issue