All of lore.kernel.org
 help / color / mirror / Atom feed
* [Buildroot] [PATCH 1/1] support/testing/tests/package/test_libgpgme.py: new runtime test
@ 2023-09-08 21:02 Julien Olivain
  2023-09-10 16:36 ` Thomas Petazzoni via buildroot
  0 siblings, 1 reply; 2+ messages in thread
From: Julien Olivain @ 2023-09-08 21:02 UTC (permalink / raw)
  To: buildroot; +Cc: Julien Olivain

Signed-off-by: Julien Olivain <ju.o@free.fr>
---
 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 26d0a0c223..b3dcfce6c2 100644
--- a/DEVELOPERS
+++ b/DEVELOPERS
@@ -1769,6 +1769,7 @@ F:	support/testing/tests/package/test_hwloc.py
 F:	support/testing/tests/package/test_iperf3.py
 F:	support/testing/tests/package/test_kexec.py
 F:	support/testing/tests/package/test_kexec/
+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..5f39f4a610
--- /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 created 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 <<EOF\n"
+        cmd += "\n".join(gpgme_enc_cmds)
+        cmd += "\nEOF"
+        self.assertRunOk(cmd)
+
+        # The output encrypted file is supposed to exist and to have a
+        # size greater than zero.
+        self.assertRunOk(f"test -s {enc_file}")
+
+        # The output encrypted file is also expected to be different
+        # from the input plain text file.
+        _, exit_code = self.emulator.run(f"cmp {plain_file} {enc_file}")
+        self.assertNotEqual(exit_code, 0)
+
+        # We now decrypt the encrypted file using gpgme-tool commands.
+        gpgme_dec_cmds = [
+            "RESET",
+            f"INPUT FILE={enc_file}",
+            f"OUTPUT FILE={dec_file}",
+            "DECRYPT",
+            "BYE"
+        ]
+        cmd = "gpgme-tool <<EOF\n"
+        cmd += "\n".join(gpgme_dec_cmds)
+        cmd += "\nEOF"
+        self.assertRunOk(cmd)
+
+        # The decrypted file is supposed to be the same as the initial
+        # plain text file.
+        cmd = f"cmp {plain_file} {dec_file}"
+        self.assertRunOk(cmd)
-- 
2.41.0

_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [Buildroot] [PATCH 1/1] support/testing/tests/package/test_libgpgme.py: new runtime test
  2023-09-08 21:02 [Buildroot] [PATCH 1/1] support/testing/tests/package/test_libgpgme.py: new runtime test Julien Olivain
@ 2023-09-10 16:36 ` Thomas Petazzoni via buildroot
  0 siblings, 0 replies; 2+ messages in thread
From: Thomas Petazzoni via buildroot @ 2023-09-10 16:36 UTC (permalink / raw)
  To: Julien Olivain; +Cc: buildroot

On Fri,  8 Sep 2023 23:02:53 +0200
Julien Olivain <ju.o@free.fr> wrote:

> Signed-off-by: Julien Olivain <ju.o@free.fr>
> ---
>  DEVELOPERS                                    |  1 +
>  .../testing/tests/package/test_libgpgme.py    | 88 +++++++++++++++++++
>  2 files changed, 89 insertions(+)
>  create mode 100644 support/testing/tests/package/test_libgpgme.py

Applied to master, thanks.

Thomas
-- 
Thomas Petazzoni, CTO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-09-10 16:37 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-09-08 21:02 [Buildroot] [PATCH 1/1] support/testing/tests/package/test_libgpgme.py: new runtime test Julien Olivain
2023-09-10 16:36 ` Thomas Petazzoni via buildroot

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.