]> git.saurik.com Git - apt.git/blame_incremental - test/integration/test-bug-595691-empty-and-broken-archive-files
suggest xz-utils instead of bzip2 and lzma
[apt.git] / test / integration / test-bug-595691-empty-and-broken-archive-files
... / ...
CommitLineData
1#!/bin/sh
2set -e
3
4TESTDIR=$(readlink -f $(dirname $0))
5. $TESTDIR/framework
6setupenvironment
7configarchitecture "i386"
8
9buildaptarchive
10touch aptarchive/Packages
11setupflataptarchive
12
13testaptgetupdate() {
14 rm -rf rootdir/var/lib/apt
15 aptget update 2>> testaptgetupdate.diff >> testaptgetupdate.diff || true
16 sed -i -e '/^Fetched / d' -e '/Ign / d' -e 's#\[[0-9]* [kMGTPY]*B\]#\[\]#' testaptgetupdate.diff
17 GIVEN="$1"
18 shift
19 msgtest "Test for correctness of" "apt-get update with $*"
20 if [ -z "$GIVEN" ]; then
21 echo -n "" | checkdiff - testaptgetupdate.diff && msgpass || msgfail
22 else
23 echo "$GIVEN" | checkdiff - testaptgetupdate.diff && msgpass || msgfail
24 fi
25 rm testaptgetupdate.diff
26}
27
28createemptyarchive() {
29 find aptarchive/ \( -name "Packages*" -o -name "en*" \) -type f -delete
30 if [ "en" = "$1" ]; then
31 echo -n "" | $COMPRESSOR > aptarchive/Packages.$COMPRESS
32 fi
33 touch aptarchive/Packages
34 echo -n "" | $COMPRESSOR > aptarchive/${1}.$COMPRESS
35 generatereleasefiles
36 signreleasefiles
37 rm -f aptarchive/Packages
38}
39
40createemptyfile() {
41 find aptarchive/ \( -name "Packages*" -o -name "en*" \) -type f -delete
42 if [ "en" = "$1" ]; then
43 echo -n "" | $COMPRESSOR > aptarchive/Packages.$COMPRESS
44 fi
45 touch aptarchive/Packages aptarchive/${1}.$COMPRESS
46 generatereleasefiles
47 signreleasefiles
48 rm -f aptarchive/Packages
49}
50
51setupcompressor() {
52 COMPRESSOR="$1"
53 case $COMPRESSOR in
54 gzip) COMPRESS="gz";;
55 bzip2) COMPRESS="bz2";;
56 lzma) COMPRESS="lzma";;
57 xz) COMPRESS="xz";;
58 esac
59 echo "Acquire::CompressionTypes::Order { \"${COMPRESS}\"; };
60Dir::Bin::uncompressed \"/does/not/exist\";
61Dir::Bin::gzip \"/does/not/exist\";
62Dir::Bin::bzip2 \"/does/not/exist\";
63Dir::Bin::lzma \"/does/not/exist\";
64Dir::Bin::xz \"/does/not/exist\";" > rootdir/etc/apt/apt.conf.d/00compressor
65 if [ -e "/bin/${COMPRESSOR}" ]; then
66 echo "Dir::Bin::${COMPRESSOR} \"/bin/${COMPRESSOR}\";" >> rootdir/etc/apt/apt.conf.d/00compressor
67 elif [ -e "/usr/bin/${COMPRESSOR}" ]; then
68 echo "Dir::Bin::${COMPRESSOR} \"/usr/bin/${COMPRESSOR}\";" >> rootdir/etc/apt/apt.conf.d/00compressor
69 else
70 msgtest "Test for availability of compressor" "${COMPRESSOR}"
71 msgfail
72 exit 1
73 fi
74}
75
76testoverfile() {
77 setupcompressor "$1"
78
79 createemptyfile 'en'
80 testaptgetupdate "Get:1 file: InRelease []
81Reading package lists..." "empty file en.$COMPRESS over file"
82
83 createemptyarchive 'en'
84 testaptgetupdate "Get:1 file: InRelease []
85Reading package lists..." "empty archive en.$COMPRESS over file"
86
87 createemptyarchive 'Packages'
88 # FIXME: Why omits the file transport the Packages Get line?
89 #Get:3 file: Packages []
90 testaptgetupdate "Get:1 file: InRelease []
91Reading package lists..." "empty archive Packages.$COMPRESS over file"
92
93 createemptyfile 'Packages'
94 testaptgetupdate "Get:1 file: InRelease []
95Err file: Packages
96 Empty files can't be valid archives
97W: Failed to fetch ${COMPRESSOR}:$(readlink -f aptarchive/Packages.$COMPRESS) Empty files can't be valid archives
98
99E: Some index files failed to download. They have been ignored, or old ones used instead." "empty file Packages.$COMPRESS over file"
100}
101
102testoverhttp() {
103 setupcompressor "$1"
104
105 createemptyfile 'en'
106 testaptgetupdate "Get:1 http://localhost InRelease []
107Get:2 http://localhost Packages []
108Get:3 http://localhost Translation-en
109Reading package lists..." "empty file en.$COMPRESS over http"
110
111 createemptyarchive 'en'
112 testaptgetupdate "Get:1 http://localhost InRelease []
113Get:2 http://localhost Packages []
114Get:3 http://localhost Translation-en []
115Reading package lists..." "empty archive en.$COMPRESS over http"
116
117 createemptyarchive 'Packages'
118 testaptgetupdate "Get:1 http://localhost InRelease []
119Get:2 http://localhost Packages []
120Reading package lists..." "empty archive Packages.$COMPRESS over http"
121
122 createemptyfile 'Packages'
123 #FIXME: we should response with a good error message instead
124 testaptgetupdate "Get:1 http://localhost InRelease []
125Get:2 http://localhost Packages
126Err http://localhost Packages
127 Empty files can't be valid archives
128W: Failed to fetch ${COMPRESSOR}:$(readlink -f rootdir/var/lib/apt/lists/partial/localhost:8080_Packages) Empty files can't be valid archives
129
130E: Some index files failed to download. They have been ignored, or old ones used instead." "empty file Packages.$COMPRESS over http"
131}
132
133for COMPRESSOR in 'gzip' 'bzip2' 'lzma' 'xz'; do testoverfile $COMPRESSOR; done
134
135# do the same again with http instead of file
136changetowebserver
137
138for COMPRESSOR in 'gzip' 'bzip2' 'lzma' 'xz'; do testoverhttp $COMPRESSOR; done