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