Fix import certificate private key encoding (#434)
When importing a certificate, the private key is passed to the import/upload process from the UI as a str object. In Python3 this raises two issues when processing the private key - the private key validation fails and database insert of the certificate fails. The fix in both cases is to correctly encode the private key as a bytes object.
This commit is contained in:
committed by
kevgliss
parent
6cac2838e3
commit
3ad7a37f95
29
lemur/tests/test_validators.py
Normal file
29
lemur/tests/test_validators.py
Normal file
@ -0,0 +1,29 @@
|
||||
from marshmallow.exceptions import ValidationError
|
||||
from .vectors import PRIVATE_KEY_STR
|
||||
|
||||
|
||||
def test_private_key():
|
||||
from lemur.common.validators import private_key
|
||||
try:
|
||||
private_key(PRIVATE_KEY_STR)
|
||||
assert True
|
||||
except ValidationError:
|
||||
assert False, "failed to validate private key as a bytes object"
|
||||
|
||||
|
||||
def test_private_key_str_object():
|
||||
from lemur.common.validators import private_key
|
||||
try:
|
||||
private_key(PRIVATE_KEY_STR.decode('utf-8'))
|
||||
assert True
|
||||
except ValidationError:
|
||||
assert False, "failed to validate private key as a str object"
|
||||
|
||||
|
||||
def test_private_key_invalid():
|
||||
from lemur.common.validators import private_key
|
||||
try:
|
||||
private_key('invalid_private_key')
|
||||
assert False, "invalid private key should have raised an exception"
|
||||
except ValidationError:
|
||||
assert True
|
Reference in New Issue
Block a user