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