mirror of
git://git.gnupg.org/gnupg.git
synced 2024-12-22 10:19:57 +01:00
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 <justus@g10code.com>
This commit is contained in:
parent
a45dc0849d
commit
a1afc450e1
@ -90,6 +90,7 @@ XTESTS = \
|
||||
ssh-export.scm \
|
||||
quick-key-manipulation.scm \
|
||||
key-selection.scm \
|
||||
delete-keys.scm \
|
||||
issue2015.scm \
|
||||
issue2346.scm \
|
||||
issue2417.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"
|
||||
'("alfa@example.net" "alpha@example.net")
|
||||
(list
|
||||
(subkey "3B3FBC948FE59301ED629EFB6AE6D7EE46A871F8"
|
||||
"A0747D5F9425E6664F4FFBEED20FBCA79FDED2BD"))))
|
||||
(define one (new "289B0EF1D105E124B6F626020EF77096D74C5F22"
|
||||
"50B2D4FA4122C212611048BC5FC31BD44393626E"
|
||||
'("one@example.com")
|
||||
(list
|
||||
(subkey "EB467DCA4AD7676A6A62B2ABABAB28A247BE2775"
|
||||
"7E201E28B6FEB2927B321F443205F4724EBE637E"))))
|
||||
(define two (new "C1DEBB34EA8B71009EAFA474973D50E1C40FDECF"
|
||||
"343D8AF79796EE107D645A2787A9D9252F924E6F"
|
||||
'("two@example.com")
|
||||
(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))) #\;))
|
||||
|
||||
|
103
tests/openpgp/delete-keys.scm
Executable file
103
tests/openpgp/delete-keys.scm
Executable file
@ -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))))
|
@ -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)))))
|
||||
|
Loading…
x
Reference in New Issue
Block a user