kumquat-buildroot/support/testing/tests/package/sample_python_gnupg.py
Julien Olivain 9a79397fc5 support/testing: add test for python-gnupg
This commit add a simple test doing symmetric encryption/decryption
to check this python interface with the gpg binary is working fine.

Signed-off-by: Julien Olivain <ju.o@free.fr>
Signed-off-by: Yann E. MORIN <yann.morin.1998@free.fr>
2022-01-26 18:01:08 +01:00

25 lines
635 B
Python

import gnupg
gpg = gnupg.GPG(verbose=True)
plain_data = "Some plain text data"
good_passphrase = "Good Passphrase"
# Test Encrypt
result = gpg.encrypt(plain_data, None, passphrase=good_passphrase, symmetric=True)
assert(result.returncode == 0)
enc_data = str(result)
assert(enc_data != plain_data)
# Test Good Decrypt
result = gpg.decrypt(enc_data, passphrase=good_passphrase)
assert(result.returncode == 0)
dec_data = str(result)
assert(dec_data == plain_data)
# Test Bad Decrypt
result = gpg.decrypt(enc_data, passphrase='A Wrong Passphrase')
assert(result.returncode != 0)
dec_data = str(result)
assert(dec_data != plain_data)