diff mbox series

[1/1] support/testing: add test for python-gnupg

Message ID 20220116104114.103601-1-ju.o@free.fr
State Accepted
Headers show
Series [1/1] support/testing: add test for python-gnupg | expand

Commit Message

Julien Olivain Jan. 16, 2022, 10:41 a.m. UTC
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>
---
 DEVELOPERS                                    |  2 ++
 .../tests/package/sample_python_gnupg.py      | 24 +++++++++++++++++++
 .../tests/package/test_python_gnupg.py        | 21 ++++++++++++++++
 3 files changed, 47 insertions(+)
 create mode 100644 support/testing/tests/package/sample_python_gnupg.py
 create mode 100644 support/testing/tests/package/test_python_gnupg.py

Comments

Yann E. MORIN Jan. 26, 2022, 5:42 p.m. UTC | #1
Julien, All,

On 2022-01-16 11:41 +0100, Julien Olivain spake thusly:
> 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>

Applied to master, thanks.

Regards,
Yann E. MORIN.

> ---
>  DEVELOPERS                                    |  2 ++
>  .../tests/package/sample_python_gnupg.py      | 24 +++++++++++++++++++
>  .../tests/package/test_python_gnupg.py        | 21 ++++++++++++++++
>  3 files changed, 47 insertions(+)
>  create mode 100644 support/testing/tests/package/sample_python_gnupg.py
>  create mode 100644 support/testing/tests/package/test_python_gnupg.py
> 
> diff --git a/DEVELOPERS b/DEVELOPERS
> index a91e2dfcde..e038941b3b 100644
> --- a/DEVELOPERS
> +++ b/DEVELOPERS
> @@ -1611,6 +1611,8 @@ F:	package/python-distro/
>  F:	package/python-gnupg/
>  F:	package/python-pyalsa/
>  F:	package/riscv-isa-sim/
> +F:	support/testing/tests/package/sample_python_gnupg.py
> +F:	support/testing/tests/package/test_python_gnupg.py
>  
>  N:	Julien Viard de Galbert <julien@vdg.name>
>  F:	package/dieharder/
> diff --git a/support/testing/tests/package/sample_python_gnupg.py b/support/testing/tests/package/sample_python_gnupg.py
> new file mode 100644
> index 0000000000..b5b718a8cb
> --- /dev/null
> +++ b/support/testing/tests/package/sample_python_gnupg.py
> @@ -0,0 +1,24 @@
> +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)
> diff --git a/support/testing/tests/package/test_python_gnupg.py b/support/testing/tests/package/test_python_gnupg.py
> new file mode 100644
> index 0000000000..0c71f6b6d0
> --- /dev/null
> +++ b/support/testing/tests/package/test_python_gnupg.py
> @@ -0,0 +1,21 @@
> +from tests.package.test_python import TestPythonPackageBase
> +
> +
> +class TestPythonPy2GnuPG(TestPythonPackageBase):
> +    __test__ = True
> +    config = TestPythonPackageBase.config + \
> +        """
> +        BR2_PACKAGE_PYTHON=y
> +        BR2_PACKAGE_PYTHON_GNUPG=y
> +        """
> +    sample_scripts = ["tests/package/sample_python_gnupg.py"]
> +
> +
> +class TestPythonPy3GnuPG(TestPythonPackageBase):
> +    __test__ = True
> +    config = TestPythonPackageBase.config + \
> +        """
> +        BR2_PACKAGE_PYTHON3=y
> +        BR2_PACKAGE_PYTHON_GNUPG=y
> +        """
> +    sample_scripts = ["tests/package/sample_python_gnupg.py"]
> -- 
> 2.34.1
> 
> _______________________________________________
> buildroot mailing list
> buildroot@buildroot.org
> https://lists.buildroot.org/mailman/listinfo/buildroot
diff mbox series

Patch

diff --git a/DEVELOPERS b/DEVELOPERS
index a91e2dfcde..e038941b3b 100644
--- a/DEVELOPERS
+++ b/DEVELOPERS
@@ -1611,6 +1611,8 @@  F:	package/python-distro/
 F:	package/python-gnupg/
 F:	package/python-pyalsa/
 F:	package/riscv-isa-sim/
+F:	support/testing/tests/package/sample_python_gnupg.py
+F:	support/testing/tests/package/test_python_gnupg.py
 
 N:	Julien Viard de Galbert <julien@vdg.name>
 F:	package/dieharder/
diff --git a/support/testing/tests/package/sample_python_gnupg.py b/support/testing/tests/package/sample_python_gnupg.py
new file mode 100644
index 0000000000..b5b718a8cb
--- /dev/null
+++ b/support/testing/tests/package/sample_python_gnupg.py
@@ -0,0 +1,24 @@ 
+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)
diff --git a/support/testing/tests/package/test_python_gnupg.py b/support/testing/tests/package/test_python_gnupg.py
new file mode 100644
index 0000000000..0c71f6b6d0
--- /dev/null
+++ b/support/testing/tests/package/test_python_gnupg.py
@@ -0,0 +1,21 @@ 
+from tests.package.test_python import TestPythonPackageBase
+
+
+class TestPythonPy2GnuPG(TestPythonPackageBase):
+    __test__ = True
+    config = TestPythonPackageBase.config + \
+        """
+        BR2_PACKAGE_PYTHON=y
+        BR2_PACKAGE_PYTHON_GNUPG=y
+        """
+    sample_scripts = ["tests/package/sample_python_gnupg.py"]
+
+
+class TestPythonPy3GnuPG(TestPythonPackageBase):
+    __test__ = True
+    config = TestPythonPackageBase.config + \
+        """
+        BR2_PACKAGE_PYTHON3=y
+        BR2_PACKAGE_PYTHON_GNUPG=y
+        """
+    sample_scripts = ["tests/package/sample_python_gnupg.py"]