]>
Commit | Line | Data |
---|---|---|
1 | #!/bin/sh | |
2 | set -e | |
3 | ||
4 | # apt-key is a shell script, so relatively prune to be effected by 'crazy' things: | |
5 | # confuses config parser as there exists no way of escaping " currently. | |
6 | #TMPDIR="$(mktemp -d)/This is \"fü\$\$ing cràzy\", \$(man man | head -n1 | cut -d' ' -f 1)\$!" | |
7 | # gpg doesn't like | in path names – documented e.g. in the man gpg2 --agent-program | |
8 | #TMPDIR="$(mktemp -d)/This is fü\$\$ing cràzy, \$(man man | head -n1 | cut -d' ' -f 1)\$!" | |
9 | TMPDIR_ADD="This is fü\$\$ing cràzy, \$(apt -v)\$!" | |
10 | ||
11 | TESTDIR="$(readlink -f "$(dirname "$0")")" | |
12 | . "$TESTDIR/framework" | |
13 | ||
14 | setupenvironment | |
15 | configarchitecture 'amd64' | |
16 | ||
17 | # start from a clean plate again | |
18 | cleanplate() { | |
19 | rm -rf rootdir/etc/apt/trusted.gpg.d/ rootdir/etc/apt/trusted.gpg | |
20 | mkdir rootdir/etc/apt/trusted.gpg.d/ | |
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 | testaptkeys 'Joe Sixpack' | |
36 | ||
37 | testsuccessequal 'gpg: key DBAC8DAE: "Joe Sixpack (APT Testcases Dummy) <joe@example.org>" not changed | |
38 | gpg: Total number processed: 1 | |
39 | gpg: unchanged: 1' aptkey --fakeroot update | |
40 | ||
41 | testaptkeys 'Joe Sixpack' | |
42 | testfailure test -e rootdir/etc/apt/trusted.gpg | |
43 | ||
44 | testsuccess aptkey --fakeroot add ./keys/rexexpired.pub | |
45 | msgtest 'Check if trusted.gpg is created with permissions set to' '0644' | |
46 | if [ "$(stat -c '%a' rootdir/etc/apt/trusted.gpg )" = '644' ]; then | |
47 | msgpass | |
48 | else | |
49 | msgfail | |
50 | fi | |
51 | ||
52 | testaptkeys 'Rex Expired' 'Joe Sixpack' | |
53 | ||
54 | msgtest 'Check that Sixpack key can be' 'exported' | |
55 | aptkey export 'Sixpack' > aptkey.export | |
56 | aptkey --keyring rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg exportall > aptkey.exportall | |
57 | testsuccess --nomsg cmp aptkey.export aptkey.exportall | |
58 | testsuccess test -s aptkey.export | |
59 | testsuccess test -s aptkey.exportall | |
60 | ||
61 | msgtest 'Execute update again to trigger removal of' 'Rex Expired key' | |
62 | testsuccess --nomsg aptkey --fakeroot update | |
63 | ||
64 | testaptkeys 'Joe Sixpack' | |
65 | ||
66 | msgtest "Try to remove a key which exists, but isn't in the" 'forced keyring' | |
67 | testsuccess --nomsg aptkey --fakeroot --keyring rootdir/etc/apt/trusted.gpg del DBAC8DAE | |
68 | ||
69 | testaptkeys 'Joe Sixpack' | |
70 | ||
71 | testsuccess aptkey --fakeroot del DBAC8DAE | |
72 | testempty aptkey list | |
73 | ||
74 | msgtest 'Test key removal with' 'lowercase key ID' #keylength somewhere between 8byte and short | |
75 | cleanplate | |
76 | cp -a keys/joesixpack.pub rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg | |
77 | testsuccess --nomsg aptkey --fakeroot del d141dbac8dae | |
78 | testempty aptkey list | |
79 | ||
80 | msgtest 'Test key removal with' 'single key in real file' | |
81 | cleanplate | |
82 | cp -a keys/joesixpack.pub rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg | |
83 | testsuccess --nomsg aptkey --fakeroot del DBAC8DAE | |
84 | testempty aptkey list | |
85 | testfailure test -e rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg | |
86 | testsuccess cmp keys/joesixpack.pub rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg~ | |
87 | ||
88 | msgtest 'Test key removal with' 'different key specs' | |
89 | cleanplate | |
90 | cp -a keys/joesixpack.pub rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg | |
91 | cp -a keys/marvinparanoid.pub rootdir/etc/apt/trusted.gpg.d/marvinparanoid.gpg | |
92 | testsuccess --nomsg aptkey --fakeroot del 0xDBAC8DAE 528144E2 | |
93 | testempty aptkey list | |
94 | testfailure test -e rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg | |
95 | testsuccess cmp keys/joesixpack.pub rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg~ | |
96 | testfailure test -e rootdir/etc/apt/trusted.gpg.d/marvinparanoid.gpg | |
97 | testsuccess cmp keys/marvinparanoid.pub rootdir/etc/apt/trusted.gpg.d/marvinparanoid.gpg~ | |
98 | ||
99 | msgtest 'Test key removal with' 'long key ID' | |
100 | cleanplate | |
101 | cp -a keys/joesixpack.pub rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg | |
102 | testsuccess --nomsg aptkey --fakeroot del 5A90D141DBAC8DAE | |
103 | testempty aptkey list | |
104 | testfailure test -e rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg | |
105 | testsuccess cmp keys/joesixpack.pub rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg~ | |
106 | ||
107 | msgtest 'Test key removal with' 'fingerprint' | |
108 | cleanplate | |
109 | cp -a keys/joesixpack.pub rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg | |
110 | testsuccess --nomsg aptkey --fakeroot del 34A8E9D18DB320F367E8EAA05A90D141DBAC8DAE | |
111 | testempty aptkey list | |
112 | testfailure test -e rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg | |
113 | testsuccess cmp keys/joesixpack.pub rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg~ | |
114 | ||
115 | msgtest 'Test key removal with' 'single key in softlink' | |
116 | cleanplate | |
117 | ln -s "$(readlink -f ./keys/joesixpack.pub)" rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg | |
118 | testsuccess --nomsg aptkey --fakeroot del DBAC8DAE | |
119 | testempty aptkey list | |
120 | testfailure test -e rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg | |
121 | testsuccess test -L rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg~ | |
122 | ||
123 | cleanplate | |
124 | testsuccess aptkey --fakeroot add ./keys/joesixpack.pub | |
125 | ln -sf "$(readlink -f ./keys/marvinparanoid.pub)" "./keys/marvin paránöid.pub" | |
126 | testsuccess aptkey --fakeroot add "./keys/marvin paránöid.pub" | |
127 | testaptkeys 'Joe Sixpack' 'Marvin Paranoid' | |
128 | cp -a rootdir/etc/apt/trusted.gpg keys/testcase-multikey.pub # store for reuse | |
129 | ||
130 | msgtest 'Test key removal with' 'multi key in real file' | |
131 | cleanplate | |
132 | cp -a keys/testcase-multikey.pub rootdir/etc/apt/trusted.gpg.d/multikey.gpg | |
133 | testsuccess --nomsg aptkey --fakeroot del DBAC8DAE | |
134 | testaptkeys 'Marvin Paranoid' | |
135 | testsuccess cmp keys/testcase-multikey.pub rootdir/etc/apt/trusted.gpg.d/multikey.gpg~ | |
136 | ||
137 | msgtest 'Test key removal with' 'multi key in softlink' | |
138 | cleanplate | |
139 | ln -s "$(readlink -f ./keys/testcase-multikey.pub)" rootdir/etc/apt/trusted.gpg.d/multikey.gpg | |
140 | testsuccess --nomsg aptkey --fakeroot del DBAC8DAE | |
141 | testaptkeys 'Marvin Paranoid' | |
142 | testsuccess cmp keys/testcase-multikey.pub rootdir/etc/apt/trusted.gpg.d/multikey.gpg~ | |
143 | testfailure test -L rootdir/etc/apt/trusted.gpg.d/multikey.gpg | |
144 | testsuccess test -L rootdir/etc/apt/trusted.gpg.d/multikey.gpg~ | |
145 | ||
146 | msgtest 'Test key removal with' 'multiple files including key' | |
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 | testsuccess --nomsg aptkey --fakeroot del DBAC8DAE | |
151 | testaptkeys 'Marvin Paranoid' | |
152 | testfailure test -e rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg | |
153 | testsuccess cmp keys/joesixpack.pub rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg~ | |
154 | testsuccess cmp keys/testcase-multikey.pub rootdir/etc/apt/trusted.gpg.d/multikey.gpg~ | |
155 | ||
156 | cleanplate | |
157 | cp -a keys/joesixpack.pub rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg | |
158 | cp -a keys/testcase-multikey.pub rootdir/etc/apt/trusted.gpg.d/multikey.gpg | |
159 | testaptkeys 'Joe Sixpack' 'Joe Sixpack' 'Marvin Paranoid' | |
160 | msgtest 'Test merge-back of' 'added keys' | |
161 | testsuccess --nomsg aptkey adv --batch --yes --import keys/rexexpired.pub | |
162 | testaptkeys 'Rex Expired' 'Joe Sixpack' 'Joe Sixpack' 'Marvin Paranoid' | |
163 | ||
164 | msgtest 'Test merge-back of' 'removed keys' | |
165 | testsuccess --nomsg aptkey adv --batch --yes --delete-keys 27CE74F9 | |
166 | testaptkeys 'Joe Sixpack' 'Joe Sixpack' 'Marvin Paranoid' | |
167 | ||
168 | msgtest 'Test merge-back of' 'removed duplicate keys' | |
169 | testsuccess --nomsg aptkey adv --batch --yes --delete-keys DBAC8DAE | |
170 | testaptkeys 'Marvin Paranoid' | |
171 | ||
172 | cleanplate | |
173 | cp -a keys/joesixpack.pub rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg | |
174 | cp -a keys/testcase-multikey.pub rootdir/etc/apt/trusted.gpg.d/multikey.gpg | |
175 | msgtest 'Test signing a file' 'with a key' | |
176 | echo 'Verify me. This is my signature.' > signature | |
177 | testsuccess --nomsg aptkey --quiet --keyring keys/marvinparanoid.pub --secret-keyring keys/marvinparanoid.sec --readonly \ | |
178 | adv --batch --yes --default-key 'Marvin' --armor --detach-sign --sign --output signature.gpg signature | |
179 | testsuccess test -s signature.gpg -a -s signature | |
180 | ||
181 | ||
182 | for GPGV in '' 'gpgv' 'gpgv2'; do | |
183 | echo "APT::Key::GPGVCommand \"$GPGV\";" > rootdir/etc/apt/apt.conf.d/00gpgvcmd | |
184 | ||
185 | msgtest 'Test verify a file' 'with all keys' | |
186 | testsuccess --nomsg aptkey --quiet --readonly verify signature.gpg signature | |
187 | ||
188 | msgtest 'Test verify a file' 'with good keyring' | |
189 | testsuccess --nomsg aptkey --quiet --readonly --keyring keys/testcase-multikey.pub verify signature.gpg signature | |
190 | ||
191 | msgtest 'Test fail verify a file' 'with bad keyring' | |
192 | testfailure --nomsg aptkey --quiet --readonly --keyring keys/joesixpack.pub verify signature.gpg signature | |
193 | ||
194 | msgtest 'Test fail verify a file' 'with non-existing keyring' | |
195 | testfailure --nomsg aptkey --quiet --readonly --keyring keys/does-not-exist.pub verify signature.gpg signature | |
196 | testfailure test -e keys/does-not-exist.pub | |
197 | ||
198 | # note: this isn't how apts gpgv method implements keyid for verify | |
199 | msgtest 'Test verify a file' 'with good keyid' | |
200 | testsuccess --nomsg aptkey --quiet --readonly --keyid 'Paranoid' verify signature.gpg signature | |
201 | ||
202 | msgtest 'Test fail verify a file' 'with bad keyid' | |
203 | testfailure --nomsg aptkey --quiet --readonly --keyid 'Sixpack' verify signature.gpg signature | |
204 | ||
205 | msgtest 'Test fail verify a file' 'with non-existing keyid' | |
206 | testfailure --nomsg aptkey --quiet --readonly --keyid 'Kalnischkies' verify signature.gpg signature | |
207 | ||
208 | msgtest 'Test verify fails on' 'bad file' | |
209 | echo 'lalalalala' > signature2 | |
210 | testfailure --nomsg aptkey --quiet --readonly verify signature.gpg signature2 | |
211 | done | |
212 | } | |
213 | ||
214 | setupgpgcommand() { | |
215 | echo "APT::Key::GPGCommand \"$1\";" > rootdir/etc/apt/apt.conf.d/00gpgcmd | |
216 | msgmsg 'Force tests to be run with' "$1" | |
217 | testsuccess aptkey --readonly adv --version | |
218 | cp rootdir/tmp/testsuccess.output aptkey.version | |
219 | testsuccess grep "^gpg (GnuPG) $2\." aptkey.version | |
220 | } | |
221 | ||
222 | # run with default (whatever this is) | |
223 | testrun | |
224 | # run with … | |
225 | setupgpgcommand 'gpg' '1' | |
226 | testrun | |
227 | setupgpgcommand 'gpg2' '2' | |
228 | testrun |