diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-15 20:32:59 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-15 20:32:59 +0000 |
commit | 4d57e0a8dab2139a631a21aab862487481548702 (patch) | |
tree | f7cea0b9939e2ecb7a301de6c83bada29452046d /test/test_debsign | |
parent | Initial commit. (diff) | |
download | devscripts-4d57e0a8dab2139a631a21aab862487481548702.tar.xz devscripts-4d57e0a8dab2139a631a21aab862487481548702.zip |
Adding upstream version 2.23.7.upstream/2.23.7upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'test/test_debsign')
-rwxr-xr-x | test/test_debsign | 114 |
1 files changed, 114 insertions, 0 deletions
diff --git a/test/test_debsign b/test/test_debsign new file mode 100755 index 0000000..9c7ccf5 --- /dev/null +++ b/test/test_debsign @@ -0,0 +1,114 @@ +#!/bin/sh + +# Copyright (C) 2018, Chris Lamb <lamby@debian.org> +# +# This program 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 2 of the License, or +# (at your option) any later version. +# +# This program 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/>. + +set -u + +WORKDIR="$(readlink -f "${0%/*}")" + +if test "${1:-}" = --installed; then + COMMAND="debsign --no-conf" + shift +else + COMMAND="$WORKDIR/../scripts/debsign.sh --no-conf" +fi + +GPG=gpg +GPGHOME=$(mktemp -d -p /tmp gpg.XXXXX) +if ! command -v $GPG >/dev/null 2>&1; then + echo "$GPG missing" + GPG=gpg2 + if ! command -v $GPG >/dev/null 2>&1; then + echo "$GPG missing" + exit 1 + fi +fi + +oneTimeSetUp () { + $GPG -v --homedir "$GPGHOME" --no-options -q --batch --no-default-keyring \ + --output $GPGHOME/secring.gpg --dearmor $WORKDIR/debsign/private_key.asc + + $GPG -v --homedir "$GPGHOME" --no-options -q --batch --no-default-keyring \ + --output $GPGHOME/pubring.gpg --dearmor $WORKDIR/debsign/public_key.asc + + export GNUPGHOME=$GPGHOME +} + +oneTimeTearDown () { + gpgconf --homedir "$GPGHOME" --verbose --kill gpg-agent + rm -rf "$GPGHOME" +} + +setUp() { + TEMPDIR=$(mktemp -d -p /tmp debsign.XXXXX) + cp $WORKDIR/debsign/* $TEMPDIR + CHANGES=$(echo $TEMPDIR/*changes) +} + +tearDown() { + rm -rf $TEMPDIR +} + +assertSigned() { + expected=$1 + shift + $COMMAND "$@" $CHANGES >$TEMPDIR/stdout 2>$TEMPDIR/stderr + rc=$? + assertEquals 'error code' $expected $rc +} + +testEmailKeyID () { + assertSigned 0 -k none@debian.org +} + +testShortKeyID () { + assertSigned 1 -k 72543FAF + assertTrue 'error not seen' "grep -q 'short key ID' $TEMPDIR/stderr" +} + +testPrefixedShortKeyID () { + assertSigned 1 -k 0x72543FAF + assertTrue 'error not seen' "grep -q 'short key ID' $TEMPDIR/stderr" +} + +testLongKeyID() { + assertSigned 0 -k C77E2D6872543FAF + assertTrue 'not signed' "grep -q 'BEGIN PGP SIGNATURE' $CHANGES" +} + +testPrefixedLongKeyID() { + assertSigned 0 -k 0xC77E2D6872543FAF + assertTrue 'not signed' "grep -q 'BEGIN PGP SIGNATURE' $CHANGES" +} + +testFingerprintKeyID () { + assertSigned 0 -k CF218F0E7EABF584B7E20402C77E2D6872543FAF +} + +testUnknownKeyID () { + assertSigned 2 -k AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + assertTrue 'warning not seen' "grep -q 'No secret key' $TEMPDIR/stderr" +} + +testNameKeyID () { + assertSigned 0 -k 'uscan test key (no secret)' +} + +testFullNameAsKeyID () { + assertSigned 0 -k 'uscan test key (no secret) <none@debian.org>' +} + +. shunit2 |