]> git.saurik.com Git - apt.git/blame - test/integration/test-apt-key
Merge branch 'debian/sid' into debian/experimental
[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
25b86db1 20 testfileequal './aptkey.list' "$1"
0dae96a2
DK
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
25b86db1 38 testsuccessequal 'gpg: key DBAC8DAE: "Joe Sixpack (APT Testcases Dummy) <joe@example.org>" not changed
93d0d08c
DK
39gpg: Total number processed: 1
40gpg: unchanged: 1' aptkey --fakeroot update
80f3aeb0 41
0dae96a2 42 testaptkeys 'pub 2048R/DBAC8DAE 2010-08-18'
04937adc 43
e52aad52 44 testfailure test -e rootdir/etc/apt/trusted.gpg
93d0d08c 45 testsuccess aptkey --fakeroot add ./keys/rexexpired.pub
8b32e72c
DK
46 msgtest 'Check if trusted.gpg is created with permissions set to' '0644'
47 if [ "$(stat -c '%a' rootdir/etc/apt/trusted.gpg )" = '644' ]; then
48 msgpass
49 else
50 msgfail
51 fi
04937adc 52
0dae96a2 53 testaptkeys 'pub 2048R/27CE74F9 2013-07-12 [expired: 2013-07-13]
93d0d08c 54pub 2048R/DBAC8DAE 2010-08-18'
04937adc 55
38005d8b
DK
56 msgtest 'Check that Sixpack key can be' 'exported'
57 aptkey export 'Sixpack' > aptkey.export
58 aptkey --keyring rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg exportall > aptkey.exportall
59 testsuccess --nomsg cmp aptkey.export aptkey.exportall
60 testsuccess test -s aptkey.export
61 testsuccess test -s aptkey.exportall
62
93d0d08c
DK
63 msgtest 'Execute update again to trigger removal of' 'Rex Expired key'
64 testsuccess --nomsg aptkey --fakeroot update
65
0dae96a2 66 testaptkeys 'pub 2048R/DBAC8DAE 2010-08-18'
93d0d08c
DK
67
68 msgtest "Try to remove a key which exists, but isn't in the" 'forced keyring'
69 testsuccess --nomsg aptkey --fakeroot --keyring rootdir/etc/apt/trusted.gpg del DBAC8DAE
70
0dae96a2 71 testaptkeys 'pub 2048R/DBAC8DAE 2010-08-18'
93d0d08c
DK
72
73 testsuccess aptkey --fakeroot del DBAC8DAE
74 testempty aptkey list
75
05f64ca2
DK
76 msgtest 'Test key removal with' 'lowercase key ID' #keylength somewher between 8byte and short
77 cleanplate
78 cp -a keys/joesixpack.pub rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg
79 testsuccess --nomsg aptkey --fakeroot del d141dbac8dae
80 testempty aptkey list
81
93d0d08c
DK
82 msgtest 'Test key removal with' 'single key in real file'
83 cleanplate
84 cp -a keys/joesixpack.pub rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg
85 testsuccess --nomsg aptkey --fakeroot del DBAC8DAE
86 testempty aptkey list
e52aad52 87 testfailure test -e rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg
93d0d08c
DK
88 testsuccess cmp keys/joesixpack.pub rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg~
89
29f1b977
JM
90 msgtest 'Test key removal with' 'long key ID'
91 cleanplate
92 cp -a keys/joesixpack.pub rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg
93 testsuccess --nomsg aptkey --fakeroot del 5A90D141DBAC8DAE
94 testempty aptkey list
e52aad52 95 testfailure test -e rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg
29f1b977
JM
96 testsuccess cmp keys/joesixpack.pub rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg~
97
ba72845c
DK
98 msgtest 'Test key removal with' 'fingerprint'
99 cleanplate
100 cp -a keys/joesixpack.pub rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg
101 testsuccess --nomsg aptkey --fakeroot del 34A8E9D18DB320F367E8EAA05A90D141DBAC8DAE
102 testempty aptkey list
e52aad52 103 testfailure test -e rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg
ba72845c
DK
104 testsuccess cmp keys/joesixpack.pub rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg~
105
93d0d08c
DK
106 msgtest 'Test key removal with' 'single key in softlink'
107 cleanplate
108 ln -s $(readlink -f ./keys/joesixpack.pub) rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg
109 testsuccess --nomsg aptkey --fakeroot del DBAC8DAE
110 testempty aptkey list
e52aad52 111 testfailure test -e rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg
93d0d08c
DK
112 testsuccess test -L rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg~
113
114 cleanplate
115 testsuccess aptkey --fakeroot add ./keys/joesixpack.pub
116 testsuccess aptkey --fakeroot add ./keys/marvinparanoid.pub
0dae96a2 117 testaptkeys 'pub 2048R/DBAC8DAE 2010-08-18
93d0d08c
DK
118pub 2048R/528144E2 2011-01-16'
119 cp -a rootdir/etc/apt/trusted.gpg keys/testcase-multikey.pub # store for reuse
120
121 msgtest 'Test key removal with' 'multi key in real file'
122 cleanplate
123 cp -a keys/testcase-multikey.pub rootdir/etc/apt/trusted.gpg.d/multikey.gpg
124 testsuccess --nomsg aptkey --fakeroot del DBAC8DAE
0dae96a2 125 testaptkeys 'pub 2048R/528144E2 2011-01-16'
93d0d08c
DK
126 testsuccess cmp keys/testcase-multikey.pub rootdir/etc/apt/trusted.gpg.d/multikey.gpg~
127
128 msgtest 'Test key removal with' 'multi key in softlink'
129 cleanplate
130 ln -s $(readlink -f ./keys/testcase-multikey.pub) rootdir/etc/apt/trusted.gpg.d/multikey.gpg
131 testsuccess --nomsg aptkey --fakeroot del DBAC8DAE
0dae96a2 132 testaptkeys 'pub 2048R/528144E2 2011-01-16'
93d0d08c 133 testsuccess cmp keys/testcase-multikey.pub rootdir/etc/apt/trusted.gpg.d/multikey.gpg~
e52aad52 134 testfailure test -L rootdir/etc/apt/trusted.gpg.d/multikey.gpg
93d0d08c
DK
135 testsuccess test -L rootdir/etc/apt/trusted.gpg.d/multikey.gpg~
136
137 msgtest 'Test key removal with' 'multiple files including key'
138 cleanplate
139 cp -a keys/joesixpack.pub rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg
140 cp -a keys/testcase-multikey.pub rootdir/etc/apt/trusted.gpg.d/multikey.gpg
141 testsuccess --nomsg aptkey --fakeroot del DBAC8DAE
0dae96a2 142 testaptkeys 'pub 2048R/528144E2 2011-01-16'
e52aad52 143 testfailure test -e rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg
93d0d08c
DK
144 testsuccess cmp keys/joesixpack.pub rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg~
145 testsuccess cmp keys/testcase-multikey.pub rootdir/etc/apt/trusted.gpg.d/multikey.gpg~
0dae96a2
DK
146
147 cleanplate
148 cp -a keys/joesixpack.pub rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg
149 cp -a keys/testcase-multikey.pub rootdir/etc/apt/trusted.gpg.d/multikey.gpg
150 testaptkeys 'pub 2048R/DBAC8DAE 2010-08-18
151pub 2048R/DBAC8DAE 2010-08-18
152pub 2048R/528144E2 2011-01-16'
153 msgtest 'Test merge-back of' 'added keys'
154 testsuccess --nomsg aptkey adv --batch --yes --import keys/rexexpired.pub
155 testaptkeys 'pub 2048R/27CE74F9 2013-07-12 [expired: 2013-07-13]
156pub 2048R/DBAC8DAE 2010-08-18
157pub 2048R/DBAC8DAE 2010-08-18
158pub 2048R/528144E2 2011-01-16'
159
160 msgtest 'Test merge-back of' 'removed keys'
161 testsuccess --nomsg aptkey adv --batch --yes --delete-keys 27CE74F9
162 testaptkeys 'pub 2048R/DBAC8DAE 2010-08-18
163pub 2048R/DBAC8DAE 2010-08-18
164pub 2048R/528144E2 2011-01-16'
165
166 msgtest 'Test merge-back of' 'removed duplicate keys'
167 testsuccess --nomsg aptkey adv --batch --yes --delete-keys DBAC8DAE
168 testaptkeys 'pub 2048R/528144E2 2011-01-16'
93d0d08c 169}
04937adc 170
93d0d08c
DK
171setupgpgcommand() {
172 echo "APT::Key::GPGCommand \"$1\";" > rootdir/etc/apt/apt.conf.d/00gpgcmd
173 msgtest 'Test that apt-key uses for the following tests command' "$1"
174 aptkey adv --version >aptkey.version 2>&1
175 if grep -q "^Executing: $1 --" aptkey.version; then
176 msgpass
177 else
178 cat aptkey.version
179 msgfail
180 fi
04937adc
DK
181}
182
93d0d08c
DK
183# run with default (whatever this is)
184testrun
185# run with …
186setupgpgcommand 'gpg'
187testrun
188setupgpgcommand 'gpg2'
189testrun
05f64ca2 190