]> git.saurik.com Git - apt.git/blobdiff - test/integration/test-apt-key
acquire: Use priority queues and a 3 stage pipeline design
[apt.git] / test / integration / test-apt-key
index e777de1a44535750f76281d59e21d4b998ccdd18..96cfe41fa62c1686c0374695fdbc2f3b74dca391 100755 (executable)
@@ -41,7 +41,9 @@ APT::Key::RemovedKeys \"${KEYDIR}/rexexpired.pub\";" > "${ROOTDIR}/etc/apt/apt.c
        msgtest 'Check that paths in finger output are not' 'double-slashed'
        testfailure --nomsg grep '//' "${ROOTDIR}/tmp/testsuccess.output"
 
        msgtest 'Check that paths in finger output are not' 'double-slashed'
        testfailure --nomsg grep '//' "${ROOTDIR}/tmp/testsuccess.output"
 
-       testsuccessequal 'gpg: key DBAC8DAE: "Joe Sixpack (APT Testcases Dummy) <joe@example.org>" not changed
+       testequalor2 'gpg: key DBAC8DAE: "Joe Sixpack (APT Testcases Dummy) <joe@example.org>" not changed
+gpg: Total number processed: 1
+gpg:              unchanged: 1' 'gpg: key 5A90D141DBAC8DAE: "Joe Sixpack (APT Testcases Dummy) <joe@example.org>" not changed
 gpg: Total number processed: 1
 gpg:              unchanged: 1' aptkey --fakeroot update
 
 gpg: Total number processed: 1
 gpg:              unchanged: 1' aptkey --fakeroot update
 
@@ -79,6 +81,20 @@ gpg:              unchanged: 1' aptkey --fakeroot update
        testsuccess --nomsg aptkey --fakeroot del d141dbac8dae
        testempty aptkey list
 
        testsuccess --nomsg aptkey --fakeroot del d141dbac8dae
        testempty aptkey list
 
+       if [ "$(id -u)" != '0' ]; then
+               msgtest 'Test key removal with' 'unreadable key'
+               cleanplate
+               cp -a "${KEYDIR}/joesixpack.pub" "${ROOTDIR}/etc/apt/trusted.gpg.d/joesixpack.gpg"
+               echo 'foobar' > "${ROOTDIR}/etc/apt/trusted.gpg.d/unreadablekey.gpg"
+               chmod 000 "${ROOTDIR}/etc/apt/trusted.gpg.d/unreadablekey.gpg"
+               testwarning --nomsg aptkey --fakeroot del d141dbac8dae
+               testwarning aptkey list
+               chmod 644 "${ROOTDIR}/etc/apt/trusted.gpg.d/unreadablekey.gpg"
+               rm -f "${ROOTDIR}/etc/apt/trusted.gpg.d/unreadablekey.gpg"
+               grep -v '^W: ' "${ROOTDIR}/tmp/testwarning.output" > "${ROOTDIR}/aptkeylist.output" || true
+               testempty cat "${ROOTDIR}/aptkeylist.output"
+       fi
+
        msgtest 'Test key removal with' 'single key in real file'
        cleanplate
        cp -a "${KEYDIR}/joesixpack.pub" "${ROOTDIR}/etc/apt/trusted.gpg.d/joesixpack.gpg"
        msgtest 'Test key removal with' 'single key in real file'
        cleanplate
        cp -a "${KEYDIR}/joesixpack.pub" "${ROOTDIR}/etc/apt/trusted.gpg.d/joesixpack.gpg"
@@ -114,6 +130,14 @@ gpg:              unchanged: 1' aptkey --fakeroot update
        testfailure test -e "${ROOTDIR}/etc/apt/trusted.gpg.d/joesixpack.gpg"
        testsuccess cmp "${KEYDIR}/joesixpack.pub" "${ROOTDIR}/etc/apt/trusted.gpg.d/joesixpack.gpg~"
 
        testfailure test -e "${ROOTDIR}/etc/apt/trusted.gpg.d/joesixpack.gpg"
        testsuccess cmp "${KEYDIR}/joesixpack.pub" "${ROOTDIR}/etc/apt/trusted.gpg.d/joesixpack.gpg~"
 
+       msgtest 'Test key removal with' 'spaced fingerprint'
+       cleanplate
+       cp -a "${KEYDIR}/joesixpack.pub" "${ROOTDIR}/etc/apt/trusted.gpg.d/joesixpack.gpg"
+       testsuccess --nomsg aptkey --fakeroot del '34A8 E9D1 8DB3 20F3 67E8 EAA0 5A90 D141 DBAC 8DAE'
+       testempty aptkey list
+       testfailure test -e "${ROOTDIR}/etc/apt/trusted.gpg.d/joesixpack.gpg"
+       testsuccess cmp "${KEYDIR}/joesixpack.pub" "${ROOTDIR}/etc/apt/trusted.gpg.d/joesixpack.gpg~"
+
        msgtest 'Test key removal with' 'single key in softlink'
        cleanplate
        ln -s "$(readlink -f "${KEYDIR}/joesixpack.pub")" "${ROOTDIR}/etc/apt/trusted.gpg.d/joesixpack.gpg"
        msgtest 'Test key removal with' 'single key in softlink'
        cleanplate
        ln -s "$(readlink -f "${KEYDIR}/joesixpack.pub")" "${ROOTDIR}/etc/apt/trusted.gpg.d/joesixpack.gpg"
@@ -185,12 +209,23 @@ gpg:              unchanged: 1' aptkey --fakeroot update
        msgtest 'Test verify a file' 'with no sig'
        testfailure --nomsg aptkey --quiet --readonly --keyring "${KEYDIR}/testcase-multikey.pub" verify "${SIGNATURE}" "${SIGNATURE}2"
 
        msgtest 'Test verify a file' 'with no sig'
        testfailure --nomsg aptkey --quiet --readonly --keyring "${KEYDIR}/testcase-multikey.pub" verify "${SIGNATURE}" "${SIGNATURE}2"
 
-       for GPGV in '' 'gpgv' 'gpgv2'; do
+       for GPGV in '' 'gpgv' 'gpgv1' 'gpgv2'; do
                echo "APT::Key::GPGVCommand \"$GPGV\";" > "${ROOTDIR}/etc/apt/apt.conf.d/00gpgvcmd"
                echo "APT::Key::GPGVCommand \"$GPGV\";" > "${ROOTDIR}/etc/apt/apt.conf.d/00gpgvcmd"
+               if [ -n "$GPGV" ] && ! command dpkg -l gnupg1 2>&1 | grep -q '^ii'; then continue; fi
 
                msgtest 'Test verify a file' 'with all keys'
                testsuccess --nomsg aptkey --quiet --readonly verify "${SIGNATURE}.gpg" "${SIGNATURE}"
 
 
                msgtest 'Test verify a file' 'with all keys'
                testsuccess --nomsg aptkey --quiet --readonly verify "${SIGNATURE}.gpg" "${SIGNATURE}"
 
+               if [ "$(id -u)" != '0' ]; then
+                       msgtest 'Test verify a file' 'with unreadable key'
+                       echo 'foobar' > "${ROOTDIR}/etc/apt/trusted.gpg.d/unreadablekey.gpg"
+                       chmod 000 "${ROOTDIR}/etc/apt/trusted.gpg.d/unreadablekey.gpg"
+                       testwarning --nomsg aptkey --quiet --readonly verify "${SIGNATURE}.gpg" "${SIGNATURE}"
+                       testwarning aptkey list
+                       chmod 644 "${ROOTDIR}/etc/apt/trusted.gpg.d/unreadablekey.gpg"
+                       rm -f "${ROOTDIR}/etc/apt/trusted.gpg.d/unreadablekey.gpg"
+               fi
+
                msgtest 'Test verify a file' 'with good keyring'
                testsuccess --nomsg aptkey --quiet --readonly --keyring "${KEYDIR}/testcase-multikey.pub" verify "${SIGNATURE}.gpg" "${SIGNATURE}"
 
                msgtest 'Test verify a file' 'with good keyring'
                testsuccess --nomsg aptkey --quiet --readonly --keyring "${KEYDIR}/testcase-multikey.pub" verify "${SIGNATURE}.gpg" "${SIGNATURE}"
 
@@ -229,8 +264,9 @@ gpg:              unchanged: 1' aptkey --fakeroot update
                adv --batch --yes -u 'Marvin' -u 'Joe' --armor --detach-sign --sign --output "${SIGNATURE}.gpg" "${SIGNATURE}"
        testsuccess test -s "${SIGNATURE}.gpg" -a -s "${SIGNATURE}"
 
                adv --batch --yes -u 'Marvin' -u 'Joe' --armor --detach-sign --sign --output "${SIGNATURE}.gpg" "${SIGNATURE}"
        testsuccess test -s "${SIGNATURE}.gpg" -a -s "${SIGNATURE}"
 
-       for GPGV in '' 'gpgv' 'gpgv2'; do
+       for GPGV in '' 'gpgv' 'gpgv1' 'gpgv2'; do
                echo "APT::Key::GPGVCommand \"$GPGV\";" > "${ROOTDIR}/etc/apt/apt.conf.d/00gpgvcmd"
                echo "APT::Key::GPGVCommand \"$GPGV\";" > "${ROOTDIR}/etc/apt/apt.conf.d/00gpgvcmd"
+               if [ -n "$GPGV" ] && ! command dpkg -l gnupg1 2>&1 | grep -q '^ii'; then continue; fi
 
                msgtest 'Test verify a doublesigned file' 'with all keys'
                testsuccess --nomsg aptkey --quiet --readonly verify "${SIGNATURE}.gpg" "${SIGNATURE}"
 
                msgtest 'Test verify a doublesigned file' 'with all keys'
                testsuccess --nomsg aptkey --quiet --readonly verify "${SIGNATURE}.gpg" "${SIGNATURE}"
@@ -265,11 +301,25 @@ gpg:              unchanged: 1' aptkey --fakeroot update
 }
 
 setupgpgcommand() {
 }
 
 setupgpgcommand() {
-       echo "APT::Key::GPGCommand \"$1\";" > "${ROOTDIR}/etc/apt/apt.conf.d/00gpgcmd"
-       msgmsg 'Force tests to be run with' "$1"
+       local GPGEXE;
+       if command dpkg -l gnupg1 2>&1 | grep -q '^ii'; then
+               if [ "$1" = '1' ]; then
+                       GPGEXE='gpg1'
+               else
+                       GPGEXE='gpg'
+               fi
+       else
+               if [ "$1" = '1' ]; then
+                       GPGEXE='gpg'
+               else
+                       GPGEXE='gpg2'
+               fi
+       fi
+       msgmsg 'Force tests to be run with' "$GPGEXE"
+       echo "APT::Key::GPGCommand \"$GPGEXE\";" > "${ROOTDIR}/etc/apt/apt.conf.d/00gpgcmd"
        testsuccess aptkey --readonly adv --version
        cp "${ROOTDIR}/tmp/testsuccess.output" "${TMPWORKINGDIRECTORY}/aptkey.version"
        testsuccess aptkey --readonly adv --version
        cp "${ROOTDIR}/tmp/testsuccess.output" "${TMPWORKINGDIRECTORY}/aptkey.version"
-       testsuccess grep "^gpg (GnuPG) $2\." "${TMPWORKINGDIRECTORY}/aptkey.version"
+       testsuccess grep "^gpg (GnuPG) $1\." "${TMPWORKINGDIRECTORY}/aptkey.version"
 }
 
 # run with default (whatever this is) in current CWD with relative paths
 }
 
 # run with default (whatever this is) in current CWD with relative paths
@@ -285,7 +335,7 @@ cd inaccessible
 chmod 600 ../inaccessible
 testfilestats "${TMPWORKINGDIRECTORY}/inaccessible" '%a' '=' '600'
 
 chmod 600 ../inaccessible
 testfilestats "${TMPWORKINGDIRECTORY}/inaccessible" '%a' '=' '600'
 
-setupgpgcommand 'gpg' '1'
+setupgpgcommand '1'
 testrun
 testrun
-setupgpgcommand 'gpg2' '2'
+setupgpgcommand '2'
 testrun
 testrun