]> git.saurik.com Git - apt.git/blob - test/integration/test-apt-update-rollback
fix transactionid passing
[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 copy:${APTARCHIVE}/dists/unstable/main/source/Sources Hash Sum mismatch
65
66 W: Failed to fetch copy:${APTARCHIVE}/dists/unstable/main/binary-i386/Packages
67
68 E: Some index files failed to download. They have been ignored, or old ones used instead." aptget update -qq
69 # ensure that the Packages file is also rolled back
70 testequal "E: Unable to locate package new" aptget install new -s -qq
71 }
72
73 test_inreleae_to_valid_release() {
74 msgmsg "Test InRelease to valid Release"
75 create_fresh_archive
76 add_new_package
77 # switch to a unsinged repo now
78 rm $APTARCHIVE/dists/unstable/InRelease
79 rm $APTARCHIVE/dists/unstable/Release.gpg
80 avoid_ims_hit
81
82 # update works
83 testsuccess aptget update -o Debug::Acquire::Transaction=1
84
85 # test that we can install the new packages but do no longer have a sig
86 testsuccess aptget install old -s
87 testsuccess aptget install new -s
88 testfailure ls $ROOTDIR/var/lib/apt/lists/*_InRelease
89 testfailure ls $ROOTDIR/var/lib/apt/lists/*_Release.gpg
90 testsuccess ls $ROOTDIR/var/lib/apt/lists/*_Release
91 }
92
93 test_inreleae_to_release_reverts_all() {
94 msgmsg "Test InRelease to broken Release reverts everything"
95 create_fresh_archive
96
97 # switch to a unsinged repo now
98 add_new_package
99 rm $APTARCHIVE/dists/unstable/InRelease
100 rm $APTARCHIVE/dists/unstable/Release.gpg
101 # break it
102 break_repository_sources_index
103
104 # ensure error
105 testequal "W: Failed to fetch file:$APTARCHIVE/dists/unstable/InRelease
106
107 W: Failed to fetch file:$APTARCHIVE/dists/unstable/Release
108
109 W: Failed to fetch file:$APTARCHIVE/dists/unstable/Release.gpg
110
111 W: Failed to fetch copy:$APTARCHIVE/dists/unstable/main/source/Sources Hash Sum mismatch
112
113 W: Failed to fetch copy:$APTARCHIVE/dists/unstable/main/binary-i386/Packages
114
115 E: Some index files failed to download. They have been ignored, or old ones used instead." aptget update -qq # -o Debug::acquire::transaction=1
116
117 # ensure that the Packages file is also rolled back
118 testsuccess aptget install old -s
119 testfailure aptget install new -s
120 testsuccess ls $ROOTDIR/var/lib/apt/lists/*_InRelease
121 testfailure ls $ROOTDIR/var/lib/apt/lists/*_Release
122 }
123
124 test_unauthenticated_to_invalid_inrelease() {
125 msgmsg "Test UnAuthenticated to invalid InRelease reverts everything"
126 create_fresh_archive
127 rm $APTARCHIVE/dists/unstable/InRelease
128 rm $APTARCHIVE/dists/unstable/Release.gpg
129 avoid_ims_hit
130
131 testsuccess aptget update -qq
132 testequal "WARNING: The following packages cannot be authenticated!
133 old
134 E: There are problems and -y was used without --force-yes" aptget install -qq -y old
135
136 # go to authenticated but not correct
137 add_new_package
138 break_repository_sources_index
139
140 testequal "W: Failed to fetch file:$APTARCHIVE/dists/unstable/InRelease
141
142 W: Failed to fetch copy:$APTARCHIVE/dists/unstable/main/source/Sources Hash Sum mismatch
143
144 W: Failed to fetch copy:$APTARCHIVE/dists/unstable/main/binary-i386/Packages
145
146 E: Some index files failed to download. They have been ignored, or old ones used instead." aptget update -qq
147
148 testfailure ls rootdir/var/lib/apt/lists/*_InRelease
149 testequal "WARNING: The following packages cannot be authenticated!
150 old
151 E: There are problems and -y was used without --force-yes" aptget install -qq -y old
152 }
153
154 test_inrelease_to_unauth_inrelease() {
155 msgmsg "Test InRelease to InRelease without sig"
156 create_fresh_archive
157 signreleasefiles 'Marvin Paranoid'
158 avoid_ims_hit
159
160 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
161
162 W: Failed to fetch file:$APTARCHIVE/dists/unstable/InRelease
163
164 W: Some index files failed to download. They have been ignored, or old ones used instead." aptget update -qq
165
166 testsuccess ls rootdir/var/lib/apt/lists/*_InRelease
167 }
168
169 TESTDIR=$(readlink -f $(dirname $0))
170 . $TESTDIR/framework
171
172 setupenvironment
173 configarchitecture "i386"
174
175 # setup the archive and ensure we have a single package that installs fine
176 setupaptarchive
177 APTARCHIVE=$(readlink -f ./aptarchive)
178 ROOTDIR=${TMPWORKINGDIRECTORY}/rootdir
179 APTARCHIVE_LISTS="$(echo $APTARCHIVE | tr "/" "_" )"
180
181 # test the following cases:
182 # - InRelease -> broken InRelease revert to previous state
183 # - empty lists dir and broken remote leaves nothing on the system
184 # - InRelease -> hashsum mismatch for one file reverts all files to previous state
185 # - Release/Release.gpg -> hashsum mismatch
186 # - InRelease -> Release with hashsum mismatch revert entire state and kills Release
187 # - Release -> InRelease with broken Sig/Hash removes InRelease
188 # going from Release/Release.gpg -> InRelease and vice versa
189 # - unauthenticated -> invalid InRelease
190
191 test_inrelease_to_new_inrelease
192 test_inrelease_to_broken_hash_reverts_all
193
194 test_inreleae_to_valid_release
195 test_inreleae_to_release_reverts_all
196
197 test_unauthenticated_to_invalid_inrelease
198
199 test_inrelease_to_unauth_inrelease