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