aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorIngo Klöcker <[email protected]>2023-02-08 12:25:27 +0000
committerIngo Klöcker <[email protected]>2023-02-08 12:25:27 +0000
commit844e6cd3b923834727f042b92d6a9a2db86b3fed (patch)
tree9bf30adbc70a57a723c6adfd8cd26ae6b6ef8b47 /tests
parentdoc: Add new flags (diff)
downloadgpgme-844e6cd3b923834727f042b92d6a9a2db86b3fed.tar.gz
gpgme-844e6cd3b923834727f042b92d6a9a2db86b3fed.zip
tests: Make t-edit-sign idempotent
* tests/gpg/t-edit-sign.c (test_key, test_key_fpr, import_key, delete_key): New. (main): Remove key_fpr. Import test key to sign. Delete test key after test. -- Using a dedicated test key for testing key signing, which is imported before the test and deleted after the test, makes sure that the keys in the test key ring don't change. This is important for stable results of the key listing tests. GnuPG-bug-id: 6342
Diffstat (limited to 'tests')
-rw-r--r--tests/gpg/t-edit-sign.c59
1 files changed, 56 insertions, 3 deletions
diff --git a/tests/gpg/t-edit-sign.c b/tests/gpg/t-edit-sign.c
index a3938b92..059a912b 100644
--- a/tests/gpg/t-edit-sign.c
+++ b/tests/gpg/t-edit-sign.c
@@ -39,6 +39,58 @@
#include "t-support.h"
+static const char *test_key = "-----BEGIN PGP PUBLIC KEY BLOCK-----\n"
+"\n"
+"mDMEY+NyJBYJKwYBBAHaRw8BAQdA4VfyC5sa6T3xVSus55LjyqQetFuE1shtu/71\n"
+"pHLxg8W0KFNpZ24gbWUgKGRlbW8ga2V5KSA8c2lnbi1tZUBleGFtcGxlLm5ldD6I\n"
+"kwQTFgoAOxYhBPPHuA+qbf/jPmLyYnJg+w/EtKy+BQJj43IkAhsDBQsJCAcCAiIC\n"
+"BhUKCQgLAgQWAgMBAh4HAheAAAoJEHJg+w/EtKy+26gBAMhaI/lYA9BK35525kQT\n"
+"OhvpQwgThJxQp8AOQk3UMgkGAP0ahV9lFXwv9ZnoeHEhjECsNpAFbj9fxBlzNmMZ\n"
+"Z92+AA==\n"
+"=Koy1\n"
+"-----END PGP PUBLIC KEY BLOCK-----\n";
+static const char *test_key_fpr = "F3C7B80FAA6DFFE33E62F2627260FB0FC4B4ACBE";
+
+static void
+import_key (const char *keydata)
+{
+ gpgme_ctx_t ctx;
+ gpgme_error_t err;
+ gpgme_data_t in;
+
+ err = gpgme_new (&ctx);
+ fail_if_err (err);
+
+ err = gpgme_data_new_from_mem (&in, keydata, strlen(keydata), 0);
+ fail_if_err (err);
+
+ err = gpgme_op_import (ctx, in);
+ fail_if_err (err);
+
+ gpgme_data_release (in);
+ gpgme_release (ctx);
+}
+
+static void
+delete_key (const char *fpr)
+{
+ gpgme_ctx_t ctx;
+ gpgme_error_t err;
+ gpgme_key_t key = NULL;
+
+ err = gpgme_new (&ctx);
+ fail_if_err (err);
+
+ err = gpgme_get_key (ctx, fpr, &key, 0);
+ fail_if_err (err);
+
+ err = gpgme_op_delete_ext (ctx, key, GPGME_DELETE_FORCE);
+ fail_if_err (err);
+
+ gpgme_key_unref (key);
+ gpgme_release (ctx);
+}
+
static void
flush_data (gpgme_data_t dh)
{
@@ -205,15 +257,16 @@ main (int argc, char **argv)
{
const char *signer_fpr = "A0FF4590BB6122EDEF6E3C542D727CC768697734"; /* Alpha Test */
const char *signer_keyid = signer_fpr + strlen(signer_fpr) - 16;
- const char *key_fpr = "D695676BDCEDCC2CDD6152BCFE180B1DA9E3B0B2"; /* Bravo Test */
(void)argc;
(void)argv;
init_gpgme (GPGME_PROTOCOL_OpenPGP);
- sign_key (key_fpr, signer_fpr);
- verify_key_signature (key_fpr, signer_keyid);
+ import_key (test_key);
+ sign_key (test_key_fpr, signer_fpr);
+ verify_key_signature (test_key_fpr, signer_keyid);
+ delete_key (test_key_fpr);
return 0;
}