]> git.saurik.com Git - apt.git/blob - test/integration/test-apt-update-rollback
check hashes of compressed files as well
[apt.git] / test / integration / test-apt-update-rollback
1 #!/bin/sh
2 #
3 # test that apt-get update is transactional
4 #
5 set -e
6
7 avoid_ims_hit() {
8 touch -d '+1hour' aptarchive/dists/unstable/main/binary-i386/Packages*
9 touch -d '+1hour' aptarchive/dists/unstable/main/source/Sources*
10 touch -d '+1hour' aptarchive/dists/unstable/*Release*
11
12 touch -d '-1hour' rootdir/var/lib/apt/lists/*
13 }
14
15 create_fresh_archive()
16 {
17 rm -rf aptarchive/*
18 rm -f rootdir/var/lib/apt/lists/_* rootdir/var/lib/apt/lists/partial/*
19
20 insertpackage 'unstable' 'old' 'all' '1.0'
21
22 setupaptarchive
23 }
24
25 add_new_package() {
26 insertpackage "unstable" "new" "all" "1.0"
27 insertsource "unstable" "new" "all" "1.0"
28
29 setupaptarchive --no-update
30
31 avoid_ims_hit
32 }
33
34 break_repository_sources_index() {
35 printf "xxx" > $APTARCHIVE/dists/unstable/main/source/Sources
36 gzip -c $APTARCHIVE/dists/unstable/main/source/Sources > \
37 $APTARCHIVE/dists/unstable/main/source/Sources.gz
38 avoid_ims_hit
39 }
40
41 test_inrelease_to_new_inrelease() {
42 msgmsg "Test InRelease to new InRelease works fine"
43 create_fresh_archive
44 testequal "old/unstable 1.0 all" apt list -q
45
46 add_new_package
47
48 testsuccess aptget update -o Debug::Acquire::Transaction=1
49
50 testequal "new/unstable 1.0 all
51 old/unstable 1.0 all" apt list -q
52 }
53
54 test_inrelease_to_broken_hash_reverts_all() {
55 msgmsg "Test InRelease to broken InRelease reverts everything"
56 create_fresh_archive
57 add_new_package
58 # break the Sources file
59 break_repository_sources_index
60
61 # test the error condition
62 testequal "W: Failed to fetch file:${APTARCHIVE}/dists/unstable/InRelease
63
64 W: Failed to fetch file:${APTARCHIVE}/dists/unstable/main/source/Sources Hash Sum mismatch
65
66 E: Some index files failed to download. They have been ignored, or old ones used instead." aptget update -qq
67 # ensure that the Packages file is also rolled back
68 testequal "E: Unable to locate package new" aptget install new -s -qq
69 }
70
71 test_inreleae_to_valid_release() {
72 msgmsg "Test InRelease to valid Release"
73 create_fresh_archive
74 add_new_package
75 # switch to a unsinged repo now
76 rm $APTARCHIVE/dists/unstable/InRelease
77 rm $APTARCHIVE/dists/unstable/Release.gpg
78 avoid_ims_hit
79
80 # update works
81 testsuccess aptget update -o Debug::Acquire::Transaction=1
82
83 # test that we can install the new packages but do no longer have a sig
84 testsuccess aptget install old -s
85 testsuccess aptget install new -s
86 testfailure ls $ROOTDIR/var/lib/apt/lists/*_InRelease
87 testfailure ls $ROOTDIR/var/lib/apt/lists/*_Release.gpg
88 testsuccess ls $ROOTDIR/var/lib/apt/lists/*_Release
89 }
90
91 test_inreleae_to_release_reverts_all() {
92 msgmsg "Test InRelease to broken Release reverts everything"
93 create_fresh_archive
94
95 # switch to a unsinged repo now
96 add_new_package
97 rm $APTARCHIVE/dists/unstable/InRelease
98 rm $APTARCHIVE/dists/unstable/Release.gpg
99 # break it
100 break_repository_sources_index
101
102 # ensure error
103 testequal "W: Failed to fetch file:$APTARCHIVE/dists/unstable/InRelease
104
105 W: Failed to fetch file:$APTARCHIVE/dists/unstable/Release
106
107 W: Failed to fetch file:$APTARCHIVE/dists/unstable/Release.gpg
108
109 W: Failed to fetch file:$APTARCHIVE/dists/unstable/main/source/Sources Hash Sum mismatch
110
111 E: Some index files failed to download. They have been ignored, or old ones used instead." aptget update -qq # -o Debug::acquire::transaction=1
112
113 # ensure that the Packages file is also rolled back
114 testsuccess aptget install old -s
115 testfailure aptget install new -s
116 testsuccess ls $ROOTDIR/var/lib/apt/lists/*_InRelease
117 testfailure ls $ROOTDIR/var/lib/apt/lists/*_Release
118 }
119
120 test_unauthenticated_to_invalid_inrelease() {
121 msgmsg "Test UnAuthenticated to invalid InRelease reverts everything"
122 create_fresh_archive
123 rm $APTARCHIVE/dists/unstable/InRelease
124 rm $APTARCHIVE/dists/unstable/Release.gpg
125 avoid_ims_hit
126
127 testsuccess aptget update -qq
128 testequal "WARNING: The following packages cannot be authenticated!
129 old
130 E: There are problems and -y was used without --force-yes" aptget install -qq -y old
131
132 # go to authenticated but not correct
133 add_new_package
134 break_repository_sources_index
135
136 testequal "W: Failed to fetch file:$APTARCHIVE/dists/unstable/InRelease
137
138 W: Failed to fetch file:$APTARCHIVE/dists/unstable/main/source/Sources Hash Sum mismatch
139
140 E: Some index files failed to download. They have been ignored, or old ones used instead." aptget update -qq
141
142 testfailure ls rootdir/var/lib/apt/lists/*_InRelease
143 testequal "WARNING: The following packages cannot be authenticated!
144 old
145 E: There are problems and -y was used without --force-yes" aptget install -qq -y old
146 }
147
148 test_inrelease_to_unauth_inrelease() {
149 msgmsg "Test InRelease to InRelease without sig"
150 create_fresh_archive
151 signreleasefiles 'Marvin Paranoid'
152 avoid_ims_hit
153
154 testequal "W: An error occurred during the signature verification. The repository is not updated and the previous index files will be used. GPG error: file: unstable InRelease: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY E8525D47528144E2
155
156 W: Failed to fetch file:$APTARCHIVE/dists/unstable/InRelease
157
158 W: Some index files failed to download. They have been ignored, or old ones used instead." aptget update -qq
159
160 testsuccess ls rootdir/var/lib/apt/lists/*_InRelease
161 }
162
163 test_inrelease_to_broken_gzip() {
164 msgmsg "Test InRelease to broken gzip"
165 create_fresh_archive
166 # append junk at the end of the gzip, this
167 echo "lala" >> $APTARCHIVE/dists/unstable/main/source/Sources.gz
168 # remove uncompressed file, otherwise apt will just fallback fetching
169 # that
170 rm $APTARCHIVE/dists/unstable/main/source/Sources
171 avoid_ims_hit
172
173 testfailure aptget update
174 }
175
176 TESTDIR=$(readlink -f $(dirname $0))
177 . $TESTDIR/framework
178
179 setupenvironment
180 configarchitecture "i386"
181
182 # setup the archive and ensure we have a single package that installs fine
183 setupaptarchive
184 APTARCHIVE=$(readlink -f ./aptarchive)
185 ROOTDIR=${TMPWORKINGDIRECTORY}/rootdir
186 APTARCHIVE_LISTS="$(echo $APTARCHIVE | tr "/" "_" )"
187
188 # test the following cases:
189 # - InRelease -> broken InRelease revert to previous state
190 # - empty lists dir and broken remote leaves nothing on the system
191 # - InRelease -> hashsum mismatch for one file reverts all files to previous state
192 # - Release/Release.gpg -> hashsum mismatch
193 # - InRelease -> Release with hashsum mismatch revert entire state and kills Release
194 # - Release -> InRelease with broken Sig/Hash removes InRelease
195 # going from Release/Release.gpg -> InRelease and vice versa
196 # - unauthenticated -> invalid InRelease
197
198 test_inrelease_to_new_inrelease
199 test_inrelease_to_broken_hash_reverts_all
200 test_inreleae_to_valid_release
201 test_inreleae_to_release_reverts_all
202 test_unauthenticated_to_invalid_inrelease
203 test_inrelease_to_unauth_inrelease
204 test_inrelease_to_broken_gzip