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