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