]> git.saurik.com Git - apt.git/blame - test/integration/test-apt-update-rollback
fix testcase expecting incorrect remove log from dpkg
[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
4dbfe436 22 setupaptarchive --no-update
e05672e8
MV
23}
24
25add_new_package() {
63c71412
DK
26 insertpackage 'unstable' 'new' 'all' '1.0'
27 insertsource 'unstable' 'new' 'all' '1.0'
e05672e8 28
4dbfe436 29 setupaptarchive --no-update "$@"
e05672e8
MV
30}
31
32break_repository_sources_index() {
0340069c 33 mv "$APTARCHIVE/dists/unstable/main/source/Sources.gz" "$APTARCHIVE/dists/unstable/main/source/Sources.gz.orig"
63c71412 34 printf 'xxx' > "$APTARCHIVE/dists/unstable/main/source/Sources"
4dbfe436 35 compressfile "$APTARCHIVE/dists/unstable/main/source/Sources" "$@"
e05672e8
MV
36}
37
4dbfe436 38start_with_good_inrelease() {
e05672e8 39 create_fresh_archive
4dbfe436 40 testsuccess aptget update
846bc058 41 listcurrentlistsdirectory > lists.before
561a3557
JAK
42 testsuccessequal 'dpkg/now 1.16.2+fake all [installed,local]
43old/unstable 1.0 all' apt list -qq
4dbfe436 44}
e05672e8 45
4dbfe436
DK
46test_inrelease_to_new_inrelease() {
47 msgmsg 'Test InRelease to new InRelease works fine'
48 start_with_good_inrelease
80976dd5 49
4dbfe436 50 add_new_package '+1hour'
80976dd5 51 testsuccess aptget update -o Debug::Acquire::Transaction=1
561a3557
JAK
52 testsuccessequal 'dpkg/now 1.16.2+fake all [installed,local]
53new/unstable 1.0 all
2b0660b5 54old/unstable 1.0 all' apt list -qq
e05672e8
MV
55}
56
57test_inrelease_to_broken_hash_reverts_all() {
4dbfe436
DK
58 msgmsg 'Test InRelease to broken InRelease reverts everything'
59 start_with_good_inrelease
60
61 add_new_package '+1hour'
e05672e8 62 # break the Sources file
4dbfe436 63 break_repository_sources_index '+1hour'
e05672e8
MV
64
65 # test the error condition
f695e761 66 testfailureequal "E: Failed to fetch file:${APTARCHIVE}/dists/unstable/main/source/Sources.gz Hash Sum mismatch
0340069c 67 Hashes of expected file:
d3003692 68 - Checksum-FileSize:$(stat -c '%s' 'aptarchive/dists/unstable/main/source/Sources.gz.orig') [weak]
0340069c
DK
69 - SHA256:$(sha256sum 'aptarchive/dists/unstable/main/source/Sources.gz.orig' | cut -d' ' -f 1)
70 Hashes of received file:
71 - SHA256:$(sha256sum 'aptarchive/dists/unstable/main/source/Sources.gz' | cut -d' ' -f 1)
d3003692 72 - Checksum-FileSize:$(stat -c '%s' 'aptarchive/dists/unstable/main/source/Sources.gz') [weak]
0340069c
DK
73 Last modification reported: $(lastmodification 'aptarchive/dists/unstable/main/source/Sources.gz')
74 Release file created at: $(releasefiledate 'aptarchive/dists/unstable/InRelease')
e05672e8
MV
75E: Some index files failed to download. They have been ignored, or old ones used instead." aptget update -qq
76 # ensure that the Packages file is also rolled back
846bc058 77 testfileequal lists.before "$(listcurrentlistsdirectory)"
25b86db1 78 testfailureequal "E: Unable to locate package new" aptget install new -s -qq
e05672e8
MV
79}
80
4dbfe436
DK
81test_inrelease_to_valid_release() {
82 msgmsg 'Test InRelease to valid Release'
83 start_with_good_inrelease
84
85 add_new_package '+1hour'
86 # switch to a unsigned repo now
5a23c56d 87 rm -f "$APTARCHIVE/dists/unstable/InRelease" "$APTARCHIVE/dists/unstable/Release.gpg"
e05672e8 88
bca84917 89 # update fails
1da3b7b8 90 testfailureequal "E: The repository 'file:${APTARCHIVE} unstable Release' is no longer signed." aptget update -qq
e05672e8 91
846bc058
DK
92 # test that security downgrade was not successful
93 testfileequal lists.before "$(listcurrentlistsdirectory)"
e05672e8 94 testsuccess aptget install old -s
bca84917 95 testfailure aptget install new -s
63c71412
DK
96 testnotempty find "${ROOTDIR}/var/lib/apt/lists" -name '*_InRelease'
97 testempty find "${ROOTDIR}/var/lib/apt/lists" -name '*_Release'
e05672e8
MV
98}
99
4dbfe436
DK
100test_inrelease_to_release_reverts_all() {
101 msgmsg 'Test InRelease to broken Release reverts everything'
102 start_with_good_inrelease
e05672e8 103
4dbfe436
DK
104 # switch to a unsigned repo now
105 add_new_package '+1hour'
5a23c56d 106 rm -f "$APTARCHIVE/dists/unstable/InRelease" "$APTARCHIVE/dists/unstable/Release.gpg"
4dbfe436 107
e05672e8 108 # break it
4dbfe436 109 break_repository_sources_index '+1hour'
e05672e8
MV
110
111 # ensure error
1da3b7b8 112 testfailureequal "E: The repository 'file:${APTARCHIVE} unstable Release' is no longer signed." aptget update -qq # -o Debug::acquire::transaction=1
e05672e8
MV
113
114 # ensure that the Packages file is also rolled back
846bc058 115 testfileequal lists.before "$(listcurrentlistsdirectory)"
e05672e8
MV
116 testsuccess aptget install old -s
117 testfailure aptget install new -s
63c71412
DK
118 testnotempty find "${ROOTDIR}/var/lib/apt/lists" -name '*_InRelease'
119 testempty find "${ROOTDIR}/var/lib/apt/lists" -name '*_Release'
e05672e8
MV
120}
121
122test_unauthenticated_to_invalid_inrelease() {
4dbfe436 123 msgmsg 'Test UnAuthenticated to invalid InRelease reverts everything'
e05672e8 124 create_fresh_archive
5a23c56d 125 rm -f "$APTARCHIVE/dists/unstable/InRelease" "$APTARCHIVE/dists/unstable/Release.gpg"
4dbfe436 126
4fa34122 127 testwarning aptget update --allow-insecure-repositories
846bc058 128 listcurrentlistsdirectory > lists.before
25b86db1 129 testfailureequal "WARNING: The following packages cannot be authenticated!
e05672e8 130 old
b381a482 131E: There were unauthenticated packages and -y was used without --allow-unauthenticated" aptget install -qq -y old
4dbfe436 132
e05672e8 133 # go to authenticated but not correct
4dbfe436
DK
134 add_new_package '+1hour'
135 break_repository_sources_index '+1hour'
e05672e8 136
f695e761 137 testfailureequal "E: Failed to fetch file:$APTARCHIVE/dists/unstable/main/source/Sources.gz Hash Sum mismatch
0340069c 138 Hashes of expected file:
d3003692 139 - Checksum-FileSize:$(stat -c '%s' 'aptarchive/dists/unstable/main/source/Sources.gz.orig') [weak]
0340069c
DK
140 - SHA256:$(sha256sum 'aptarchive/dists/unstable/main/source/Sources.gz.orig' | cut -d' ' -f 1)
141 Hashes of received file:
142 - SHA256:$(sha256sum 'aptarchive/dists/unstable/main/source/Sources.gz' | cut -d' ' -f 1)
d3003692 143 - Checksum-FileSize:$(stat -c '%s' 'aptarchive/dists/unstable/main/source/Sources.gz') [weak]
0340069c
DK
144 Last modification reported: $(lastmodification 'aptarchive/dists/unstable/main/source/Sources.gz')
145 Release file created at: $(releasefiledate 'aptarchive/dists/unstable/InRelease')
e05672e8
MV
146E: Some index files failed to download. They have been ignored, or old ones used instead." aptget update -qq
147
846bc058 148 testfileequal lists.before "$(listcurrentlistsdirectory)"
63c71412 149 testempty find "${ROOTDIR}/var/lib/apt/lists" -maxdepth 1 -name '*_InRelease'
25b86db1 150 testfailureequal "WARNING: The following packages cannot be authenticated!
e05672e8 151 old
b381a482 152E: There were unauthenticated packages and -y was used without --allow-unauthenticated" aptget install -qq -y old
e05672e8
MV
153}
154
c5fced38 155test_inrelease_to_unauth_inrelease() {
4dbfe436
DK
156 msgmsg 'Test InRelease to InRelease without good sig'
157 start_with_good_inrelease
158
9d653a6d 159 signreleasefiles 'Marvin Paranoid'
4dbfe436 160
1da3b7b8 161 testwarningequal "W: An error occurred during the signature verification. The repository is not updated and the previous index files will be used. GPG error: file:${APTARCHIVE} unstable InRelease: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY E8525D47528144E2
4dbfe436 162W: Failed to fetch file:$APTARCHIVE/dists/unstable/InRelease The following signatures couldn't be verified because the public key is not available: NO_PUBKEY E8525D47528144E2
21638c3a
MV
163W: Some index files failed to download. They have been ignored, or old ones used instead." aptget update -qq
164
846bc058 165 testfileequal lists.before "$(listcurrentlistsdirectory)"
63c71412 166 testnotempty find "${ROOTDIR}/var/lib/apt/lists" -name '*_InRelease'
c5fced38
MV
167}
168
7abcfdde
MV
169test_inrelease_to_broken_gzip() {
170 msgmsg "Test InRelease to broken gzip"
4dbfe436
DK
171 start_with_good_inrelease
172
8d041b4f
DK
173 break_repository_sources_index '+1hour'
174 generatereleasefiles '+2hours'
175 signreleasefiles
176
4dbfe436 177 # append junk at the end of the compressed file
63c71412
DK
178 echo "lala" >> "$APTARCHIVE/dists/unstable/main/source/Sources.gz"
179 touch -d '+2min' "$APTARCHIVE/dists/unstable/main/source/Sources.gz"
4dbfe436 180 # remove uncompressed file to avoid fallback
63c71412 181 rm "$APTARCHIVE/dists/unstable/main/source/Sources"
7abcfdde
MV
182
183 testfailure aptget update
8d041b4f 184 testsuccess grep 'Hash Sum mismatch' rootdir/tmp/testfailure.output
846bc058 185 testfileequal lists.before "$(listcurrentlistsdirectory)"
7abcfdde
MV
186}
187
3abb6a6a
DK
188TESTDIR="$(readlink -f "$(dirname "$0")")"
189. "$TESTDIR/framework"
e05672e8
MV
190
191setupenvironment
192configarchitecture "i386"
5a23c56d 193export APT_DONT_SIGN='Release.gpg'
e05672e8 194
63c71412
DK
195APTARCHIVE="$(readlink -f ./aptarchive)"
196ROOTDIR="${TMPWORKINGDIRECTORY}/rootdir"
197APTARCHIVE_LISTS="$(echo "$APTARCHIVE" | tr "/" "_" )"
e05672e8
MV
198
199# test the following cases:
4dbfe436 200# - InRelease -> broken InRelease revert to previous state
e05672e8
MV
201# - empty lists dir and broken remote leaves nothing on the system
202# - InRelease -> hashsum mismatch for one file reverts all files to previous state
203# - Release/Release.gpg -> hashsum mismatch
204# - InRelease -> Release with hashsum mismatch revert entire state and kills Release
205# - Release -> InRelease with broken Sig/Hash removes InRelease
206# going from Release/Release.gpg -> InRelease and vice versa
207# - unauthenticated -> invalid InRelease
208
67f2f9e2 209# stuff to do:
4dbfe436 210# - ims-hit
67f2f9e2
MV
211# - gzip-index tests
212
e05672e8
MV
213test_inrelease_to_new_inrelease
214test_inrelease_to_broken_hash_reverts_all
4dbfe436
DK
215test_inrelease_to_valid_release
216test_inrelease_to_release_reverts_all
6d979490 217test_unauthenticated_to_invalid_inrelease
c5fced38 218test_inrelease_to_unauth_inrelease
7abcfdde 219test_inrelease_to_broken_gzip