]> git.saurik.com Git - apt.git/blob - test/integration/test-apt-key
fix foldmarkers in fileutl.cc
[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 test ! -e rootdir/etc/apt/trusted.gpg
45 testsuccess aptkey --fakeroot add ./keys/rexexpired.pub
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
52
53 testaptkeys 'pub 2048R/27CE74F9 2013-07-12 [expired: 2013-07-13]
54 pub 2048R/DBAC8DAE 2010-08-18'
55
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
63 msgtest 'Execute update again to trigger removal of' 'Rex Expired key'
64 testsuccess --nomsg aptkey --fakeroot update
65
66 testaptkeys 'pub 2048R/DBAC8DAE 2010-08-18'
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
71 testaptkeys 'pub 2048R/DBAC8DAE 2010-08-18'
72
73 testsuccess aptkey --fakeroot del DBAC8DAE
74 testempty aptkey list
75
76 msgtest 'Test key removal with' 'single key in real file'
77 cleanplate
78 cp -a keys/joesixpack.pub rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg
79 testsuccess --nomsg aptkey --fakeroot del DBAC8DAE
80 testempty aptkey list
81 testsuccess test ! -e rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg
82 testsuccess cmp keys/joesixpack.pub rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg~
83
84 msgtest 'Test key removal with' 'long key ID'
85 cleanplate
86 cp -a keys/joesixpack.pub rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg
87 testsuccess --nomsg aptkey --fakeroot del 5A90D141DBAC8DAE
88 testempty aptkey list
89 testsuccess test ! -e rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg
90 testsuccess cmp keys/joesixpack.pub rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg~
91
92 msgtest 'Test key removal with' 'fingerprint'
93 cleanplate
94 cp -a keys/joesixpack.pub rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg
95 testsuccess --nomsg aptkey --fakeroot del 34A8E9D18DB320F367E8EAA05A90D141DBAC8DAE
96 testempty aptkey list
97 testsuccess test ! -e rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg
98 testsuccess cmp keys/joesixpack.pub rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg~
99
100 msgtest 'Test key removal with' 'single key in softlink'
101 cleanplate
102 ln -s $(readlink -f ./keys/joesixpack.pub) rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg
103 testsuccess --nomsg aptkey --fakeroot del DBAC8DAE
104 testempty aptkey list
105 testsuccess test ! -e rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg
106 testsuccess test -L rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg~
107
108 cleanplate
109 testsuccess aptkey --fakeroot add ./keys/joesixpack.pub
110 testsuccess aptkey --fakeroot add ./keys/marvinparanoid.pub
111 testaptkeys 'pub 2048R/DBAC8DAE 2010-08-18
112 pub 2048R/528144E2 2011-01-16'
113 cp -a rootdir/etc/apt/trusted.gpg keys/testcase-multikey.pub # store for reuse
114
115 msgtest 'Test key removal with' 'multi key in real file'
116 cleanplate
117 cp -a 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
122 msgtest 'Test key removal with' 'multi key in softlink'
123 cleanplate
124 ln -s $(readlink -f ./keys/testcase-multikey.pub) rootdir/etc/apt/trusted.gpg.d/multikey.gpg
125 testsuccess --nomsg aptkey --fakeroot del DBAC8DAE
126 testaptkeys 'pub 2048R/528144E2 2011-01-16'
127 testsuccess cmp keys/testcase-multikey.pub rootdir/etc/apt/trusted.gpg.d/multikey.gpg~
128 testsuccess test ! -L rootdir/etc/apt/trusted.gpg.d/multikey.gpg
129 testsuccess test -L rootdir/etc/apt/trusted.gpg.d/multikey.gpg~
130
131 msgtest 'Test key removal with' 'multiple files including key'
132 cleanplate
133 cp -a keys/joesixpack.pub rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg
134 cp -a keys/testcase-multikey.pub rootdir/etc/apt/trusted.gpg.d/multikey.gpg
135 testsuccess --nomsg aptkey --fakeroot del DBAC8DAE
136 testaptkeys 'pub 2048R/528144E2 2011-01-16'
137 testsuccess test ! -e rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg
138 testsuccess cmp keys/joesixpack.pub rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg~
139 testsuccess cmp keys/testcase-multikey.pub rootdir/etc/apt/trusted.gpg.d/multikey.gpg~
140
141 cleanplate
142 cp -a keys/joesixpack.pub rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg
143 cp -a keys/testcase-multikey.pub rootdir/etc/apt/trusted.gpg.d/multikey.gpg
144 testaptkeys 'pub 2048R/DBAC8DAE 2010-08-18
145 pub 2048R/DBAC8DAE 2010-08-18
146 pub 2048R/528144E2 2011-01-16'
147 msgtest 'Test merge-back of' 'added keys'
148 testsuccess --nomsg aptkey adv --batch --yes --import keys/rexexpired.pub
149 testaptkeys 'pub 2048R/27CE74F9 2013-07-12 [expired: 2013-07-13]
150 pub 2048R/DBAC8DAE 2010-08-18
151 pub 2048R/DBAC8DAE 2010-08-18
152 pub 2048R/528144E2 2011-01-16'
153
154 msgtest 'Test merge-back of' 'removed keys'
155 testsuccess --nomsg aptkey adv --batch --yes --delete-keys 27CE74F9
156 testaptkeys 'pub 2048R/DBAC8DAE 2010-08-18
157 pub 2048R/DBAC8DAE 2010-08-18
158 pub 2048R/528144E2 2011-01-16'
159
160 msgtest 'Test merge-back of' 'removed duplicate keys'
161 testsuccess --nomsg aptkey adv --batch --yes --delete-keys DBAC8DAE
162 testaptkeys 'pub 2048R/528144E2 2011-01-16'
163 }
164
165 setupgpgcommand() {
166 echo "APT::Key::GPGCommand \"$1\";" > rootdir/etc/apt/apt.conf.d/00gpgcmd
167 msgtest 'Test that apt-key uses for the following tests command' "$1"
168 aptkey adv --version >aptkey.version 2>&1
169 if grep -q "^Executing: $1 --" aptkey.version; then
170 msgpass
171 else
172 cat aptkey.version
173 msgfail
174 fi
175 }
176
177 # run with default (whatever this is)
178 testrun
179 # run with …
180 setupgpgcommand 'gpg'
181 testrun
182 setupgpgcommand 'gpg2'
183 testrun