]> git.saurik.com Git - apt.git/blame - test/integration/test-apt-key
miscellaneous small cleanups in apt-key
[apt.git] / test / integration / test-apt-key
CommitLineData
80f3aeb0
DK
1#!/bin/sh
2set -e
3
4TESTDIR=$(readlink -f $(dirname $0))
5. $TESTDIR/framework
6
7setupenvironment
8configarchitecture 'amd64'
9
93d0d08c
DK
10# start from a clean plate again
11cleanplate() {
12 rm -rf rootdir/etc/apt/trusted.gpg.d/ rootdir/etc/apt/trusted.gpg
13 mkdir rootdir/etc/apt/trusted.gpg.d/
14}
80f3aeb0 15
0dae96a2
DK
16testaptkeys() {
17 if ! aptkey list | grep '^pub' > aptkey.list; then
18 echo -n > aptkey.list
19 fi
20 testequal "$1" cat ./aptkey.list
21}
22
80f3aeb0
DK
23echo 'APT::Key::ArchiveKeyring "./keys/joesixpack.pub";
24APT::Key::RemovedKeys "./keys/rexexpired.pub";' > rootdir/etc/apt/apt.conf.d/aptkey.conf
25
93d0d08c
DK
26testrun() {
27 cleanplate
28 ln -sf ${TMPWORKINGDIRECTORY}/keys/joesixpack.pub rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg
80f3aeb0 29
93d0d08c
DK
30 msgtest 'Check that paths in list output are not' 'double-slashed'
31 aptkey list 2>&1 | grep -q '//' && msgfail || msgpass
80f3aeb0 32
93d0d08c
DK
33 msgtest 'Check that paths in finger output are not' 'double-slashed'
34 aptkey finger 2>&1 | grep -q '//' && msgfail || msgpass
80f3aeb0 35
0dae96a2 36 testaptkeys 'pub 2048R/DBAC8DAE 2010-08-18'
80f3aeb0 37
93d0d08c
DK
38 testequal 'gpg: key DBAC8DAE: "Joe Sixpack (APT Testcases Dummy) <joe@example.org>" not changed
39gpg: Total number processed: 1
40gpg: unchanged: 1' aptkey --fakeroot update
80f3aeb0 41
0dae96a2 42 testaptkeys 'pub 2048R/DBAC8DAE 2010-08-18'
04937adc 43
93d0d08c 44 testsuccess aptkey --fakeroot add ./keys/rexexpired.pub
04937adc 45
0dae96a2 46 testaptkeys 'pub 2048R/27CE74F9 2013-07-12 [expired: 2013-07-13]
93d0d08c 47pub 2048R/DBAC8DAE 2010-08-18'
04937adc 48
38005d8b
DK
49 msgtest 'Check that Sixpack key can be' 'exported'
50 aptkey export 'Sixpack' > aptkey.export
51 aptkey --keyring rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg exportall > aptkey.exportall
52 testsuccess --nomsg cmp aptkey.export aptkey.exportall
53 testsuccess test -s aptkey.export
54 testsuccess test -s aptkey.exportall
55
93d0d08c
DK
56 msgtest 'Execute update again to trigger removal of' 'Rex Expired key'
57 testsuccess --nomsg aptkey --fakeroot update
58
0dae96a2 59 testaptkeys 'pub 2048R/DBAC8DAE 2010-08-18'
93d0d08c
DK
60
61 msgtest "Try to remove a key which exists, but isn't in the" 'forced keyring'
62 testsuccess --nomsg aptkey --fakeroot --keyring rootdir/etc/apt/trusted.gpg del DBAC8DAE
63
0dae96a2 64 testaptkeys 'pub 2048R/DBAC8DAE 2010-08-18'
93d0d08c
DK
65
66 testsuccess aptkey --fakeroot del DBAC8DAE
67 testempty aptkey list
68
69 msgtest 'Test key removal with' 'single key in real file'
70 cleanplate
71 cp -a keys/joesixpack.pub rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg
72 testsuccess --nomsg aptkey --fakeroot del DBAC8DAE
73 testempty aptkey list
74 testsuccess test ! -e rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg
75 testsuccess cmp keys/joesixpack.pub rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg~
76
ba72845c
DK
77 msgtest 'Test key removal with' 'fingerprint'
78 cleanplate
79 cp -a keys/joesixpack.pub rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg
80 testsuccess --nomsg aptkey --fakeroot del 34A8E9D18DB320F367E8EAA05A90D141DBAC8DAE
81 testempty aptkey list
82 testsuccess test ! -e rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg
83 testsuccess cmp keys/joesixpack.pub rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg~
84
93d0d08c
DK
85 msgtest 'Test key removal with' 'single key in softlink'
86 cleanplate
87 ln -s $(readlink -f ./keys/joesixpack.pub) rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg
88 testsuccess --nomsg aptkey --fakeroot del DBAC8DAE
89 testempty aptkey list
90 testsuccess test ! -e rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg
91 testsuccess test -L rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg~
92
93 cleanplate
94 testsuccess aptkey --fakeroot add ./keys/joesixpack.pub
95 testsuccess aptkey --fakeroot add ./keys/marvinparanoid.pub
0dae96a2 96 testaptkeys 'pub 2048R/DBAC8DAE 2010-08-18
93d0d08c
DK
97pub 2048R/528144E2 2011-01-16'
98 cp -a rootdir/etc/apt/trusted.gpg keys/testcase-multikey.pub # store for reuse
99
100 msgtest 'Test key removal with' 'multi key in real file'
101 cleanplate
102 cp -a keys/testcase-multikey.pub rootdir/etc/apt/trusted.gpg.d/multikey.gpg
103 testsuccess --nomsg aptkey --fakeroot del DBAC8DAE
0dae96a2 104 testaptkeys 'pub 2048R/528144E2 2011-01-16'
93d0d08c
DK
105 testsuccess cmp keys/testcase-multikey.pub rootdir/etc/apt/trusted.gpg.d/multikey.gpg~
106
107 msgtest 'Test key removal with' 'multi key in softlink'
108 cleanplate
109 ln -s $(readlink -f ./keys/testcase-multikey.pub) rootdir/etc/apt/trusted.gpg.d/multikey.gpg
110 testsuccess --nomsg aptkey --fakeroot del DBAC8DAE
0dae96a2 111 testaptkeys 'pub 2048R/528144E2 2011-01-16'
93d0d08c
DK
112 testsuccess cmp keys/testcase-multikey.pub rootdir/etc/apt/trusted.gpg.d/multikey.gpg~
113 testsuccess test ! -L rootdir/etc/apt/trusted.gpg.d/multikey.gpg
114 testsuccess test -L rootdir/etc/apt/trusted.gpg.d/multikey.gpg~
115
116 msgtest 'Test key removal with' 'multiple files including key'
117 cleanplate
118 cp -a keys/joesixpack.pub rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg
119 cp -a keys/testcase-multikey.pub rootdir/etc/apt/trusted.gpg.d/multikey.gpg
120 testsuccess --nomsg aptkey --fakeroot del DBAC8DAE
0dae96a2 121 testaptkeys 'pub 2048R/528144E2 2011-01-16'
93d0d08c
DK
122 testsuccess test ! -e rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg
123 testsuccess cmp keys/joesixpack.pub rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg~
124 testsuccess cmp keys/testcase-multikey.pub rootdir/etc/apt/trusted.gpg.d/multikey.gpg~
0dae96a2
DK
125
126 cleanplate
127 cp -a keys/joesixpack.pub rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg
128 cp -a keys/testcase-multikey.pub rootdir/etc/apt/trusted.gpg.d/multikey.gpg
129 testaptkeys 'pub 2048R/DBAC8DAE 2010-08-18
130pub 2048R/DBAC8DAE 2010-08-18
131pub 2048R/528144E2 2011-01-16'
132 msgtest 'Test merge-back of' 'added keys'
133 testsuccess --nomsg aptkey adv --batch --yes --import keys/rexexpired.pub
134 testaptkeys 'pub 2048R/27CE74F9 2013-07-12 [expired: 2013-07-13]
135pub 2048R/DBAC8DAE 2010-08-18
136pub 2048R/DBAC8DAE 2010-08-18
137pub 2048R/528144E2 2011-01-16'
138
139 msgtest 'Test merge-back of' 'removed keys'
140 testsuccess --nomsg aptkey adv --batch --yes --delete-keys 27CE74F9
141 testaptkeys 'pub 2048R/DBAC8DAE 2010-08-18
142pub 2048R/DBAC8DAE 2010-08-18
143pub 2048R/528144E2 2011-01-16'
144
145 msgtest 'Test merge-back of' 'removed duplicate keys'
146 testsuccess --nomsg aptkey adv --batch --yes --delete-keys DBAC8DAE
147 testaptkeys 'pub 2048R/528144E2 2011-01-16'
93d0d08c 148}
04937adc 149
93d0d08c
DK
150setupgpgcommand() {
151 echo "APT::Key::GPGCommand \"$1\";" > rootdir/etc/apt/apt.conf.d/00gpgcmd
152 msgtest 'Test that apt-key uses for the following tests command' "$1"
153 aptkey adv --version >aptkey.version 2>&1
154 if grep -q "^Executing: $1 --" aptkey.version; then
155 msgpass
156 else
157 cat aptkey.version
158 msgfail
159 fi
04937adc
DK
160}
161
93d0d08c
DK
162# run with default (whatever this is)
163testrun
164# run with …
165setupgpgcommand 'gpg'
166testrun
167setupgpgcommand 'gpg2'
168testrun