1
0
mirror of git://git.gnupg.org/gnupg.git synced 2024-12-22 10:19:57 +01:00

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>
This commit is contained in:
Justus Winter 2016-06-21 18:10:18 +02:00
parent c5e0ca5a59
commit f548383d9a
8 changed files with 168 additions and 138 deletions

View File

@ -1905,6 +1905,7 @@ doc/Makefile
tests/Makefile
tests/gpgscm/Makefile
tests/openpgp/Makefile
tests/migrations/Makefile
tests/pkits/Makefile
g10/gpg.w32-manifest
])

View File

@ -25,7 +25,7 @@ else
openpgp =
endif
SUBDIRS = gpgscm ${openpgp} . pkits
SUBDIRS = gpgscm ${openpgp} . migrations pkits
GPGSM = ../sm/gpgsm

View File

@ -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 \

View File

@ -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)))

View File

@ -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.

View File

@ -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.

View File

@ -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.

View File

@ -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.