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