aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJustus Winter <[email protected]>2016-12-19 14:33:55 +0000
committerJustus Winter <[email protected]>2016-12-19 14:42:35 +0000
commita1afc450e182af02ad5e6f6ba79e9dc4332ca2bc (patch)
tree71176d6fa26987e7f1df7f900f3e3c6427517856
parentgpgscm: Change associativity of ::. (diff)
downloadgnupg-a1afc450e182af02ad5e6f6ba79e9dc4332ca2bc.tar.gz
gnupg-a1afc450e182af02ad5e6f6ba79e9dc4332ca2bc.zip
tests: New test for --delete-[secret-]keys.
* tests/openpgp/Makefile.am (XTESTS): Add new test. * tests/openpgp/defs.scm (keys): New variable. (have-public-key?): New function. (have-secret-key?): Likewise. (have-secret-key-file?): Likewise. * tests/openpgp/delete-keys.scm: New file. * tests/openpgp/quick-key-manipulation.scm: Move the accessors to 'defs.scm'. Signed-off-by: Justus Winter <[email protected]>
-rw-r--r--tests/openpgp/Makefile.am1
-rw-r--r--tests/openpgp/defs.scm49
-rwxr-xr-xtests/openpgp/delete-keys.scm103
-rwxr-xr-xtests/openpgp/quick-key-manipulation.scm7
4 files changed, 153 insertions, 7 deletions
diff --git a/tests/openpgp/Makefile.am b/tests/openpgp/Makefile.am
index deed63d82..06705311d 100644
--- a/tests/openpgp/Makefile.am
+++ b/tests/openpgp/Makefile.am
@@ -90,6 +90,7 @@ XTESTS = \
ssh-export.scm \
quick-key-manipulation.scm \
key-selection.scm \
+ delete-keys.scm \
issue2015.scm \
issue2346.scm \
issue2417.scm \
diff --git a/tests/openpgp/defs.scm b/tests/openpgp/defs.scm
index ef81f9964..78670801a 100644
--- a/tests/openpgp/defs.scm
+++ b/tests/openpgp/defs.scm
@@ -35,6 +35,31 @@
;; first and then search for the encryption subkey.)
(define dsa-usrname2 "0xCB879DE9")
+(define keys
+ (package
+ (define (new fpr grip uids subkeys)
+ (package))
+ (define (subkey fpr grip)
+ (package))
+ (define alfa (new "A0FF4590BB6122EDEF6E3C542D727CC768697734"
+ "76F7E2B35832976B50A27A282D9B87E44577EB66"
+ (list
+ (subkey "3B3FBC948FE59301ED629EFB6AE6D7EE46A871F8"
+ "A0747D5F9425E6664F4FFBEED20FBCA79FDED2BD"))))
+ (define one (new "289B0EF1D105E124B6F626020EF77096D74C5F22"
+ "50B2D4FA4122C212611048BC5FC31BD44393626E"
+ (list
+ (subkey "EB467DCA4AD7676A6A62B2ABABAB28A247BE2775"
+ "7E201E28B6FEB2927B321F443205F4724EBE637E"))))
+ (define two (new "C1DEBB34EA8B71009EAFA474973D50E1C40FDECF"
+ "343D8AF79796EE107D645A2787A9D9252F924E6F"
+ (list
+ (subkey "CD3D0F5701CBFCACB2A4907305A37887B27907AA"
+ "8B5ABF3EF9EB8D96B91A0B8C2C4401C91C834C34"))))))
+
(define key-file1 "samplekeys/rsa-rsa-sample-1.asc")
(define key-file2 "samplekeys/ed25519-cv25519-sample-1.asc")
@@ -117,6 +142,30 @@
(map (lambda (line) (string-split line #\:))
(string-split-newlines s))))
+;; Convenient accessors for the colon output.
+(define (:type x) (string->symbol (list-ref x 0)))
+(define (:length x) (string->number (list-ref x 2)))
+(define (:alg x) (string->number (list-ref x 3)))
+(define (:expire x) (list-ref x 6))
+(define (:fpr x) (list-ref x 9))
+(define (:cap x) (list-ref x 11))
+
+(define (have-public-key? key)
+ (catch #f
+ (pair? (filter (lambda (l) (and (equal? 'fpr (:type l))
+ (equal? key::fpr (:fpr l))))
+ (gpg-with-colons `(--list-keys ,key::fpr))))))
+
+(define (have-secret-key? key)
+ (catch #f
+ (pair? (filter (lambda (l) (and (equal? 'fpr (:type l))
+ (equal? key::fpr (:fpr l))))
+ (gpg-with-colons `(--list-secret-keys ,key::fpr))))))
+
+(define (have-secret-key-file? key)
+ (file-exists? (path-join (getenv "GNUPGHOME") "private-keys-v1.d"
+ (string-append key::grip ".key"))))
+
(define (get-config what)
(string-split (caddar (gpg-with-colons `(--list-config ,what))) #\;))
diff --git a/tests/openpgp/delete-keys.scm b/tests/openpgp/delete-keys.scm
new file mode 100755
index 000000000..9a187a2f9
--- /dev/null
+++ b/tests/openpgp/delete-keys.scm
@@ -0,0 +1,103 @@
+#!/usr/bin/env gpgscm
+
+;; Copyright (C) 2016 g10 Code GmbH
+;;
+;; This file is part of GnuPG.
+;;
+;; GnuPG is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation; either version 3 of the License, or
+;; (at your option) any later version.
+;;
+;; GnuPG is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;; GNU General Public License for more details.
+;;
+;; You should have received a copy of the GNU General Public License
+;; along with this program; if not, see <http://www.gnu.org/licenses/>.
+
+(load (with-path "defs.scm"))
+(setup-legacy-environment)
+
+(let* ((key keys::alfa)
+ (subkey (car key::subkeys)))
+ (assert (have-public-key? key))
+ (assert (have-public-key? subkey))
+ (assert (have-secret-key? key))
+ (assert (have-secret-key-file? key))
+ (assert (have-secret-key? subkey))
+ (assert (have-secret-key-file? subkey))
+
+ ;; Firstly, delete the secret key.
+ (call-check `(,@gpg --delete-secret-keys ,key::fpr))
+ (assert (have-public-key? key))
+ (assert (have-public-key? subkey))
+ (assert (not (have-secret-key? key)))
+ (assert (not (have-secret-key-file? key)))
+ (assert (not (have-secret-key? subkey)))
+ (assert (not (have-secret-key-file? subkey)))
+
+ ;; Now, delete the public key.
+ (call-check `(,@gpg --delete-keys ,key::fpr))
+ (assert (not (have-public-key? key)))
+ (assert (not (have-public-key? subkey))))
+
+;; Do the same for key one, but do the subkeys separately.
+(let* ((key keys::one)
+ (subkey (car key::subkeys)))
+ (assert (have-public-key? key))
+ (assert (have-public-key? subkey))
+ (assert (have-secret-key? key))
+ (assert (have-secret-key-file? key))
+ (assert (have-secret-key-file? key))
+ (assert (have-secret-key? subkey))
+ (assert (have-secret-key-file? subkey))
+
+ ;; Firstly, delete the secret subkey.
+ (call-check `(,@gpg --delete-secret-keys ,subkey::fpr))
+ (assert (have-public-key? key))
+ (assert (have-public-key? subkey))
+ ;; JW: Deleting the secret subkey also deletes the secret key.
+ ;; XXX (assert (have-secret-key? key))
+ ;; XXX (assert (have-secret-key-file? key))
+ (assert (not (have-secret-key? subkey)))
+ (assert (not (have-secret-key-file? subkey)))
+
+ ;; Then, delete the secret key.
+ ;; XXX (call-check `(,@gpg --delete-secret-keys ,key::fpr))
+ (assert (have-public-key? key))
+ (assert (have-public-key? subkey))
+ (assert (not (have-secret-key? key)))
+ (assert (not (have-secret-key-file? key)))
+ (assert (not (have-secret-key? subkey)))
+ (assert (not (have-secret-key-file? subkey)))
+
+ ;; Now, delete the public subkey.
+ (call-check `(,@gpg --delete-keys ,subkey::fpr))
+ ;; JW: Deleting the subkey also deletes the key.
+ ;; XXX (assert (have-public-key? key))
+ (assert (not (have-public-key? subkey)))
+
+ ;; Now, delete the public key.
+ ;; XXX (call-check `(,@gpg --delete-keys ,key::fpr))
+ (assert (not (have-public-key? key)))
+ (assert (not (have-public-key? subkey))))
+
+(let* ((key keys::two)
+ (subkey (car key::subkeys)))
+ (assert (have-public-key? key))
+ (assert (have-public-key? subkey))
+ (assert (have-secret-key? key))
+ (assert (have-secret-key-file? key))
+ (assert (have-secret-key? subkey))
+ (assert (have-secret-key-file? subkey))
+
+ ;; Delete everything at once.
+ (call-check `(,@gpg --delete-secret-and-public-key ,key::fpr))
+ (assert (not (have-public-key? key)))
+ (assert (not (have-public-key? subkey)))
+ (assert (not (have-secret-key? key)))
+ (assert (not (have-secret-key-file? key)))
+ (assert (not (have-secret-key? subkey)))
+ (assert (not (have-secret-key-file? subkey))))
diff --git a/tests/openpgp/quick-key-manipulation.scm b/tests/openpgp/quick-key-manipulation.scm
index 9b9c91914..d43f7b53a 100755
--- a/tests/openpgp/quick-key-manipulation.scm
+++ b/tests/openpgp/quick-key-manipulation.scm
@@ -27,13 +27,6 @@
(define (exact id)
(string-append "=" id))
-;; Convenient accessors for the colon output.
-(define (:length x) (string->number (list-ref x 2)))
-(define (:alg x) (string->number (list-ref x 3)))
-(define (:expire x) (list-ref x 6))
-(define (:fpr x) (list-ref x 9))
-(define (:cap x) (list-ref x 11))
-
(define (count-uids-of-secret-key id)
(length (filter (lambda (x) (and (string=? "uid" (car x))
(not (string=? "r" (cadr x)))))