diff options
author | Justus Winter <justus@g10code.com> | 2016-06-21 18:10:18 +0200 |
---|---|---|
committer | Justus Winter <justus@g10code.com> | 2016-06-21 18:15:30 +0200 |
commit | f548383d9af912bf93217068cc8aa99a9a6eda93 (patch) | |
tree | 61786a73598fb2ad30eba9bd9e98d7be4543e117 | |
parent | gpgscm: Add more file handling functions. (diff) | |
download | gnupg2-f548383d9af912bf93217068cc8aa99a9a6eda93.tar.xz gnupg2-f548383d9af912bf93217068cc8aa99a9a6eda93.zip |
tests/migrations: Convert to Scheme and re-enable.
* configure.ac: Re-enable.
* tests/Makefile.am: Likewise.
* tests/migrations/Makefile.am (TESTS): Use Scheme tests.
* tests/migrations/common.scm: New file.
* tests/migrations/extended-private-key-format.scm: Likewise.
* tests/migrations/from-classic.scm: Likewise.
* tests/migrations/extended-private-key-format.test: Drop file.
* tests/migrations/from-classic.test: Drop file.
Signed-off-by: Justus Winter <justus@g10code.com>
-rw-r--r-- | configure.ac | 1 | ||||
-rw-r--r-- | tests/Makefile.am | 2 | ||||
-rw-r--r-- | tests/migrations/Makefile.am | 8 | ||||
-rw-r--r-- | tests/migrations/common.scm | 40 | ||||
-rwxr-xr-x | tests/migrations/extended-private-key-format.scm | 56 | ||||
-rwxr-xr-x | tests/migrations/extended-private-key-format.test | 57 | ||||
-rwxr-xr-x | tests/migrations/from-classic.scm | 65 | ||||
-rwxr-xr-x | tests/migrations/from-classic.test | 77 |
8 files changed, 168 insertions, 138 deletions
diff --git a/configure.ac b/configure.ac index bb925c513..215831b73 100644 --- a/configure.ac +++ b/configure.ac @@ -1905,6 +1905,7 @@ doc/Makefile tests/Makefile tests/gpgscm/Makefile tests/openpgp/Makefile +tests/migrations/Makefile tests/pkits/Makefile g10/gpg.w32-manifest ]) diff --git a/tests/Makefile.am b/tests/Makefile.am index ee8f3a425..f349763a6 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -25,7 +25,7 @@ else openpgp = endif -SUBDIRS = gpgscm ${openpgp} . pkits +SUBDIRS = gpgscm ${openpgp} . migrations pkits GPGSM = ../sm/gpgsm diff --git a/tests/migrations/Makefile.am b/tests/migrations/Makefile.am index 0f581c270..baba00acf 100644 --- a/tests/migrations/Makefile.am +++ b/tests/migrations/Makefile.am @@ -26,10 +26,12 @@ include $(top_srcdir)/am/cmacros.am AM_CFLAGS = -TESTS_ENVIRONMENT = GPG_AGENT_INFO= LC_ALL=C +TESTS_ENVIRONMENT = GPG_AGENT_INFO= LC_ALL=C \ + PATH=../gpgscm:$(PATH) \ + GPGSCM_PATH=$(top_srcdir)/tests/gpgscm:$(top_srcdir)/tests/migrations -TESTS = from-classic.test \ - extended-private-key-format.test +TESTS = from-classic.scm \ + extended-private-key-format.scm TEST_FILES = from-classic.gpghome/pubring.gpg.asc \ from-classic.gpghome/secring.gpg.asc \ diff --git a/tests/migrations/common.scm b/tests/migrations/common.scm new file mode 100644 index 000000000..e13f9751e --- /dev/null +++ b/tests/migrations/common.scm @@ -0,0 +1,40 @@ +;; 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/>. + +(if (string=? "" (getenv "srcdir")) + (error "not called from make")) + +(setenv "GNUPGHOME" "" #t) + +(define (qualify executable) + (string-append executable (getenv "EXEEXT"))) + +;; We may not use a relative name for gpg-agent. +(define GPG-AGENT (qualify (string-append (getcwd) "/../../agent/gpg-agent"))) +(define GPG `(,(qualify (string-append (getcwd) "/../../g10/gpg")) + --no-permission-warning --no-greeting + --no-secmem-warning --batch + ,(string-append "--agent-program=" GPG-AGENT + "|--debug-quick-random"))) + +(define (dearmor source-name sink-name) + (pipe:do + (pipe:open source-name (logior O_RDONLY O_BINARY)) + (pipe:spawn `(,@GPG --dearmor)) + (pipe:write-to sink-name + (logior O_WRONLY O_CREAT O_BINARY) + #o600))) diff --git a/tests/migrations/extended-private-key-format.scm b/tests/migrations/extended-private-key-format.scm new file mode 100755 index 000000000..d4a942253 --- /dev/null +++ b/tests/migrations/extended-private-key-format.scm @@ -0,0 +1,56 @@ +#!/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 "common.scm")) + +(define src-gpghome (in-srcdir "extended-private-key-format.gpghome")) + +(define (setup) + (for-each-p' + "Preparing home directory" + (lambda (f) (dearmor f (basename-suffix f ".asc"))) + (lambda (f) (basename-suffix f ".asc")) + (glob (string-append src-gpghome "/*.asc"))) + + (mkdir "private-keys-v1.d" "-rwx") + (for-each-p' + "Preparing private-keys-v1.d directory" + (lambda (f) (dearmor f (string-append "private-keys-v1.d/" + (basename-suffix f ".asc")))) + (lambda (f) (basename-suffix f ".asc")) + (glob (string-append src-gpghome "/private-keys-v1.d/*.asc"))) + + (setenv "GNUPGHOME" (getcwd) #t)) + +(define (trigger-migration) + (call-check `(,@GPG --list-secret-keys))) + +(define (assert-keys-usable) + (for-each + (lambda (keyid) + (catch (error "Key not found:" keyid) + (call-check `(,@GPG --list-secret-keys ,keyid)))) + '("C40FDECF" "ECABF51D"))) + +(info "Testing the extended private key format ...") +(with-temporary-working-directory + (setup) + (assert-keys-usable)) + +;; XXX try changing a key, and check that the format is not changed. diff --git a/tests/migrations/extended-private-key-format.test b/tests/migrations/extended-private-key-format.test deleted file mode 100755 index 9c373e877..000000000 --- a/tests/migrations/extended-private-key-format.test +++ /dev/null @@ -1,57 +0,0 @@ -#!/bin/sh -# Copyright 2016 g10 Code GmbH -# -# This file is free software; as a special exception the author gives -# unlimited permission to copy and/or distribute it, with or without -# modifications, as long as this notice is preserved. This file is -# distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY, to the extent permitted by law; without even the implied -# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - -if [ -z "$srcdir" ]; then - echo "not called from make" >&2 - exit 1 -fi - -unset GNUPGHOME -set -e - -# (We may not use a relative name for gpg-agent.) -GPG_AGENT="$(cd ../../agent && /bin/pwd)/gpg-agent" -GPG="../../g10/gpg --no-permission-warning --no-greeting --no-secmem-warning ---batch --agent-program=${GPG_AGENT}|--debug-quick-random" - -TEST="extended-private-key-format" - -setup_home() -{ - XGNUPGHOME="`mktemp -d`" - mkdir -p "$XGNUPGHOME/private-keys-v1.d" - for F in $srcdir/$TEST.gpghome/*.asc; do - $GPG --dearmor <"$F" >"$XGNUPGHOME/`basename $F .asc`" - done - for F in $srcdir/$TEST.gpghome/private-keys-v1.d/*.asc; do - $GPG --dearmor <"$F" >"$XGNUPGHOME/private-keys-v1.d/`basename $F .asc`" - done - chmod go-rwx $XGNUPGHOME/* $XGNUPGHOME/*/* - export GNUPGHOME="$XGNUPGHOME" -} - -cleanup_home() -{ - rm -rf -- "$XGNUPGHOME" -} - -assert_keys_usable() -{ - for KEY in C40FDECF ECABF51D; do - $GPG --list-secret-keys $KEY >/dev/null - done -} - -setup_home -assert_keys_usable -cleanup_home - - -# XXX try changing a key, and check that the format is not changed. diff --git a/tests/migrations/from-classic.scm b/tests/migrations/from-classic.scm new file mode 100755 index 000000000..6b98eeb7f --- /dev/null +++ b/tests/migrations/from-classic.scm @@ -0,0 +1,65 @@ +#!/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 "common.scm")) + +(define src-gpghome (in-srcdir "from-classic.gpghome")) + +(define (setup) + (for-each-p' + "Preparing home directory" + (lambda (f) (dearmor f (basename-suffix f ".asc"))) + (lambda (f) (basename-suffix f ".asc")) + (glob (string-append src-gpghome "/*.asc"))) + (setenv "GNUPGHOME" (getcwd) #t)) + +(define (trigger-migration) + (call-check `(,@GPG --list-secret-keys))) + +(define (assert-migrated) + (unless (file-exists? ".gpg-v21-migrated") + (error "Not migrated")) + + (for-each + (lambda (keyid) + (catch (error "Key not found:" keyid) + (call-check `(,@GPG --list-secret-keys ,keyid)))) + '("D74C5F22" "C40FDECF" "ECABF51D"))) + +(info "Testing a clean migration ...") +(with-temporary-working-directory + (setup) + (trigger-migration) + (assert-migrated)) + +(info "Testing a migration with existing private-keys-v1.d ...") +(with-temporary-working-directory + (setup) + (mkdir "private-keys-v1.d" "-rwx") + (trigger-migration) + (assert-migrated)) + +(info "Testing a migration with existing but weird private-keys-v1.d ...") +(with-temporary-working-directory + (setup) + (mkdir "private-keys-v1.d" "") + (trigger-migration) + (assert-migrated)) + +;; XXX Check a case where the migration fails. diff --git a/tests/migrations/from-classic.test b/tests/migrations/from-classic.test deleted file mode 100755 index 9b81d452b..000000000 --- a/tests/migrations/from-classic.test +++ /dev/null @@ -1,77 +0,0 @@ -#!/bin/sh -# Copyright 2016 g10 Code GmbH -# -# This file is free software; as a special exception the author gives -# unlimited permission to copy and/or distribute it, with or without -# modifications, as long as this notice is preserved. This file is -# distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY, to the extent permitted by law; without even the implied -# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - -if [ -z "$srcdir" ]; then - echo "not called from make" >&2 - exit 1 -fi - -unset GNUPGHOME -set -e - -# (We may not use a relative name for gpg-agent.) -GPG_AGENT="$(cd ../../agent && /bin/pwd)/gpg-agent" -GPG="../../g10/gpg --no-permission-warning --no-greeting --no-secmem-warning ---batch --agent-program=${GPG_AGENT}|--debug-quick-random" - -TEST="from-classic" - -setup_home() -{ - XGNUPGHOME="`mktemp -d`" - rm -rf -- scratch - mkdir -p "$XGNUPGHOME" - for F in $srcdir/$TEST.gpghome/*.asc; do - $GPG --dearmor <"$F" >"$XGNUPGHOME/`basename $F .asc`" - done - chmod go-rwx $XGNUPGHOME/* - export GNUPGHOME="$XGNUPGHOME" -} - -cleanup_home() -{ - rm -rf -- "$XGNUPGHOME" -} - -trigger_migration() -{ - $GPG --list-secret-keys >/dev/null 2>&1 -} - -assert_migrated() -{ - test -f $GNUPGHOME/.gpg-v21-migrated - - for KEY in D74C5F22 C40FDECF ECABF51D; do - $GPG --list-secret-keys $KEY >/dev/null - done -} - -setup_home -trigger_migration -assert_migrated -cleanup_home - -# Test with an existing private-keys-v1.d. -setup_home -mkdir "$GNUPGHOME/private-keys-v1.d" -trigger_migration -assert_migrated -cleanup_home - -# Test with an existing private-keys-v1.d with weird permissions. -setup_home -mkdir "$GNUPGHOME/private-keys-v1.d" -chmod 0 "$GNUPGHOME/private-keys-v1.d" -trigger_migration -assert_migrated -cleanup_home - -# XXX Check a case where the migration fails. |