Skip to contentSkip to conversation

support/testing: add test for python-gnupg

PATCH Applied Julien Olivain 2 participants 2 messages Jan 16, 2022 – Jan 26, 2022

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 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.

---
 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
DEVELOPERS +2 -0
index a91e2dfcde..e038941b3b 100644
@@ -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 <[email protected]>
 F:	package/dieharder/
support/testing/tests/package/sample_python_gnupg.py new file +24 -0
new file mode 100644
index 0000000000..b5b718a8cb
@@ -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)
support/testing/tests/package/test_python_gnupg.py new file +21 -0
new file mode 100644
index 0000000000..0c71f6b6d0
@@ -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"]
Signature · 6 lines
2.34.1

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
#1 lore raw

Julien, All,

On 2022-01-16 11:41 +0100, Julien Olivain spake thusly:

Quoted 4 lines

This commit add a simple test doing symmetric encryption/decryption to check this python interface with the gpg binary is working fine.

Applied to master, thanks.

Regards,
Yann E. MORIN.

Quoted 85 lines
---
 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
DEVELOPERS +2 -0
index a91e2dfcde..e038941b3b 100644
@@ -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 <[email protected]>
 F:	package/dieharder/
support/testing/tests/package/sample_python_gnupg.py new file +24 -0
new file mode 100644
index 0000000000..b5b718a8cb
@@ -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)
support/testing/tests/package/test_python_gnupg.py new file +21 -0
new file mode 100644
index 0000000000..0c71f6b6d0
@@ -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"]
Signature · 6 lines
2.34.1

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
Signature · 10 lines
.-----------------.--------------------.------------------.--------------------.
|  Yann E. MORIN  | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
| +33 662 376 056 | Software  Designer | \ / CAMPAIGN     |  ___               |
| +33 561 099 427 `------------.-------:  X  AGAINST      |  \e/  There is no  |
| http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL    |   v   conspiracy.  |
'------------------------------^-------^------------------^--------------------'
_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot