]> git.saurik.com Git - apt.git/blame - test/integration/test-apt-update-rollback
fix transactionid passing
[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
62 testequal "W: Failed to fetch file:${APTARCHIVE}/dists/unstable/InRelease
63
64W: Failed to fetch copy:${APTARCHIVE}/dists/unstable/main/source/Sources Hash Sum mismatch
65
66W: Failed to fetch copy:${APTARCHIVE}/dists/unstable/main/binary-i386/Packages
67
68E: 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
73test_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
93test_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
107W: Failed to fetch file:$APTARCHIVE/dists/unstable/Release
108
109W: Failed to fetch file:$APTARCHIVE/dists/unstable/Release.gpg
110
111W: Failed to fetch copy:$APTARCHIVE/dists/unstable/main/source/Sources Hash Sum mismatch
112
113W: Failed to fetch copy:$APTARCHIVE/dists/unstable/main/binary-i386/Packages
114
115E: 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
124test_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
134E: 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
6d979490
MV
140 testequal "W: Failed to fetch file:$APTARCHIVE/dists/unstable/InRelease
141
e05672e8
MV
142W: Failed to fetch copy:$APTARCHIVE/dists/unstable/main/source/Sources Hash Sum mismatch
143
6d979490
MV
144W: Failed to fetch copy:$APTARCHIVE/dists/unstable/main/binary-i386/Packages
145
e05672e8
MV
146E: 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
151E: There are problems and -y was used without --force-yes" aptget install -qq -y old
152}
153
c5fced38
MV
154test_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
21638c3a 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
c5fced38 161
21638c3a 162W: Failed to fetch file:$APTARCHIVE/dists/unstable/InRelease
c5fced38 163
21638c3a
MV
164W: 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
c5fced38
MV
167}
168
e05672e8
MV
169TESTDIR=$(readlink -f $(dirname $0))
170. $TESTDIR/framework
171
172setupenvironment
173configarchitecture "i386"
174
175# setup the archive and ensure we have a single package that installs fine
176setupaptarchive
177APTARCHIVE=$(readlink -f ./aptarchive)
178ROOTDIR=${TMPWORKINGDIRECTORY}/rootdir
179APTARCHIVE_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
191test_inrelease_to_new_inrelease
192test_inrelease_to_broken_hash_reverts_all
193
194test_inreleae_to_valid_release
195test_inreleae_to_release_reverts_all
196
6d979490 197test_unauthenticated_to_invalid_inrelease
c5fced38
MV
198
199test_inrelease_to_unauth_inrelease