mirror of
https://github.com/simple-login/app.git
synced 2025-02-23 23:34:05 +08:00
add tests for sign_data
This commit is contained in:
parent
c1b8f717b5
commit
4b8a2a1851
3 changed files with 17 additions and 2 deletions
|
@ -1,5 +1,6 @@
|
|||
import os
|
||||
from io import BytesIO
|
||||
from typing import Union
|
||||
|
||||
import gnupg
|
||||
import pgpy
|
||||
|
@ -101,12 +102,12 @@ if PGP_SENDER_PRIVATE_KEY:
|
|||
_SIGN_KEY_ID = gpg.import_keys(PGP_SENDER_PRIVATE_KEY).fingerprints[0]
|
||||
|
||||
|
||||
def sign_data(data: str) -> str:
|
||||
def sign_data(data: Union[str, bytes]) -> str:
|
||||
signature = str(gpg.sign(data, keyid=_SIGN_KEY_ID, detach=True))
|
||||
return signature
|
||||
|
||||
|
||||
def sign_data_with_pgpy(data: str) -> str:
|
||||
def sign_data_with_pgpy(data: Union[str, bytes]) -> str:
|
||||
key = pgpy.PGPKey()
|
||||
key.parse(PGP_SENDER_PRIVATE_KEY)
|
||||
signature = str(key.sign(data))
|
||||
|
|
|
@ -57,3 +57,5 @@ GOOGLE_CLIENT_SECRET=to_fill
|
|||
# Facebook
|
||||
FACEBOOK_CLIENT_ID=to_fill
|
||||
FACEBOOK_CLIENT_SECRET=to_fill
|
||||
|
||||
PGP_SENDER_PRIVATE_KEY_PATH=local_data/private-pgp.asc
|
|
@ -10,6 +10,8 @@ from app.pgp_utils import (
|
|||
gpg,
|
||||
encrypt_file,
|
||||
encrypt_file_with_pgpy,
|
||||
sign_data,
|
||||
sign_data_with_pgpy,
|
||||
)
|
||||
|
||||
|
||||
|
@ -51,3 +53,13 @@ def encrypt_decrypt_text(text: str):
|
|||
assert decrypted == text
|
||||
elif type(decrypted) == bytearray:
|
||||
assert decrypted.decode() == text
|
||||
|
||||
|
||||
def test_sign_data():
|
||||
assert sign_data("heyhey")
|
||||
assert sign_data(b"bytes")
|
||||
|
||||
|
||||
def test_sign_data_with_pgpy():
|
||||
assert sign_data_with_pgpy("unicode")
|
||||
assert sign_data_with_pgpy(b"bytes")
|
||||
|
|
Loading…
Reference in a new issue