From 02497626adad0da120315e00ef8a323546ce53b8 Mon Sep 17 00:00:00 2001 From: Julien Olivain Date: Fri, 8 Sep 2023 23:02:53 +0200 Subject: [PATCH] support/testing/tests/package/test_libgpgme.py: new runtime test Signed-off-by: Julien Olivain Signed-off-by: Thomas Petazzoni --- DEVELOPERS | 1 + .../testing/tests/package/test_libgpgme.py | 88 +++++++++++++++++++ 2 files changed, 89 insertions(+) create mode 100644 support/testing/tests/package/test_libgpgme.py diff --git a/DEVELOPERS b/DEVELOPERS index a0e2dcca27..d72dce866f 100644 --- a/DEVELOPERS +++ b/DEVELOPERS @@ -1742,6 +1742,7 @@ F: support/testing/tests/package/test_kexec/ F: support/testing/tests/package/test_kmscube.py F: support/testing/tests/package/test_kmscube/ F: support/testing/tests/package/test_less.py +F: support/testing/tests/package/test_libgpgme.py F: support/testing/tests/package/test_libjxl.py F: support/testing/tests/package/test_lrzip.py F: support/testing/tests/package/test_lzip.py diff --git a/support/testing/tests/package/test_libgpgme.py b/support/testing/tests/package/test_libgpgme.py new file mode 100644 index 0000000000..28a33bab03 --- /dev/null +++ b/support/testing/tests/package/test_libgpgme.py @@ -0,0 +1,88 @@ +import os + +import infra.basetest + + +class TestLibGpgme(infra.basetest.BRTest): + config = infra.basetest.BASIC_TOOLCHAIN_CONFIG + \ + """ + BR2_PACKAGE_LIBGPGME=y + BR2_TARGET_ROOTFS_CPIO=y + # BR2_TARGET_ROOTFS_TAR is not set + """ + + def test_run(self): + cpio_file = os.path.join(self.builddir, "images", "rootfs.cpio") + self.emulator.boot(arch="armv5", + kernel="builtin", + options=["-initrd", cpio_file]) + self.emulator.login() + + # We check the binary program can execute. + self.assertRunOk("gpgme-tool --version") + + # Some common data for all the tests. + plain_data = "Hello Buildroot!" + gpg_userid = "br-test@buildroot" + plain_file = "reference-plain.txt" + enc_file = "encrypted.dat" + dec_file = "decrypted.txt" + + # We did not create a gpg key yet. We should not be able to + # list our key. + gpgme_listkey = f"echo LISTKEYS | gpgme-tool | grep '{gpg_userid}'" + _, exit_code = self.emulator.run(gpgme_listkey) + self.assertNotEqual(exit_code, 0) + + # We now create our gpg key. + cmd = "gpg --batch --passphrase ''" + cmd += f" --quick-generate-key {gpg_userid} default default" + self.assertRunOk(cmd) + + # We should now see our key in the list. + self.assertRunOk(gpgme_listkey) + + # We generate a plain text data file. + cmd = f"echo '{plain_data}' > {plain_file}" + self.assertRunOk(cmd) + + # We encrypt the plain text file using gpgme-tool commands. + gpgme_enc_cmds = [ + "RESET", + f"INPUT FILE={plain_file}", + f"OUTPUT FILE={enc_file}", + f"RECIPIENT {gpg_userid}", + "ENCRYPT", + "BYE" + ] + cmd = "gpgme-tool <