test-ubuntu-bug-1098738-apt-get-source-md5sum 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  1. #!/bin/sh
  2. set -e
  3. TESTDIR="$(readlink -f "$(dirname "$0")")"
  4. . "$TESTDIR/framework"
  5. setupenvironment
  6. configarchitecture 'native'
  7. cat > aptarchive/Sources <<EOF
  8. Package: pkg-md5-ok
  9. Binary: pkg-md5-ok
  10. Version: 1.0
  11. Maintainer: Joe Sixpack <joe@example.org>
  12. Architecture: all
  13. Files:
  14. 9604ba9427a280db542279d9ed78400b 3 pkg-md5-ok_1.0.dsc
  15. db5570bf61464b46e2bde31ed61a7dc6 3 pkg-md5-ok_1.0.tar.gz
  16. Package: pkg-sha1-ok
  17. Binary: pkg-sha1-ok
  18. Version: 1.0
  19. Maintainer: Joe Sixpack <joe@example.org>
  20. Architecture: all
  21. Files:
  22. 324f464e6151a92cf57b26ef95dcfcf2059a8c44 3 pkg-sha1-ok_1.0.dsc
  23. 680254bad1d7ca0d65ec46aaa315d363abf6a50a 3 pkg-sha1-ok_1.0.tar.gz
  24. Package: pkg-sha256-ok
  25. Binary: pkg-sha256-ok
  26. Version: 1.0
  27. Maintainer: Joe Sixpack <joe@example.org>
  28. Architecture: all
  29. Files:
  30. 9604ba9427a280db542279d9ed78400b 3 pkg-sha256-ok_1.0.dsc
  31. db5570bf61464b46e2bde31ed61a7dc6 3 pkg-sha256-ok_1.0.tar.gz
  32. Checksums-Sha1:
  33. 324f464e6151a92cf57b26ef95dcfcf2059a8c44 3 pkg-sha256-ok_1.0.dsc
  34. 680254bad1d7ca0d65ec46aaa315d363abf6a50a 3 pkg-sha256-ok_1.0.tar.gz
  35. Checksums-Sha256:
  36. 943d3bf22ac661fb0f59bc4ff68cc12b04ff17a838dfcc2537008eb9c7f3770a 3 pkg-sha256-ok_1.0.dsc
  37. 90aebae315675cbf04612de4f7d5874850f48e0b8dd82becbeaa47ca93f5ebfb 3 pkg-sha256-ok_1.0.tar.gz
  38. Package: pkg-size-bad
  39. Binary: pkg-size-bad
  40. Version: 1.0
  41. Maintainer: Joe Sixpack <joe@example.org>
  42. Architecture: all
  43. Checksums-Sha256:
  44. 943d3bf22ac661fb0f59bc4ff68cc12b04ff17a838dfcc2537008eb9c7f3770a 2 pkg-size-bad_1.0.dsc
  45. 90aebae315675cbf04612de4f7d5874850f48e0b8dd82becbeaa47ca93f5ebfb 4 pkg-size-bad_1.0.tar.gz
  46. Package: pkg-sha256-bad
  47. Binary: pkg-sha256-bad
  48. Version: 1.0
  49. Maintainer: Joe Sixpack <joe@example.org>
  50. Architecture: all
  51. Files:
  52. 9604ba9427a280db542279d9ed78400b 3 pkg-sha256-bad_1.0.dsc
  53. db5570bf61464b46e2bde31ed61a7dc6 3 pkg-sha256-bad_1.0.tar.gz
  54. Checksums-Sha1:
  55. 324f464e6151a92cf57b26ef95dcfcf2059a8c44 3 pkg-sha256-bad_1.0.dsc
  56. 680254bad1d7ca0d65ec46aaa315d363abf6a50a 3 pkg-sha256-bad_1.0.tar.gz
  57. Checksums-Sha256:
  58. aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa 3 pkg-sha256-bad_1.0.dsc
  59. bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb 3 pkg-sha256-bad_1.0.tar.gz
  60. Package: pkg-md5-bad
  61. Binary: pkg-md5-bad
  62. Version: 1.0
  63. Maintainer: Joe Sixpack <joe@example.org>
  64. Architecture: all
  65. Files:
  66. aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa 3 pkg-md5-bad_1.0.dsc
  67. bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb 3 pkg-md5-bad_1.0.tar.gz
  68. Package: pkg-no-md5
  69. Binary: pkg-no-md5
  70. Version: 1.0
  71. Maintainer: Joe Sixpack <joe@example.org>
  72. Architecture: all
  73. Checksums-Sha1:
  74. 324f464e6151a92cf57b26ef95dcfcf2059a8c44 3 pkg-no-md5_1.0.dsc
  75. 680254bad1d7ca0d65ec46aaa315d363abf6a50a 3 pkg-no-md5_1.0.tar.gz
  76. Checksums-Sha256:
  77. 943d3bf22ac661fb0f59bc4ff68cc12b04ff17a838dfcc2537008eb9c7f3770a 3 pkg-no-md5_1.0.dsc
  78. 90aebae315675cbf04612de4f7d5874850f48e0b8dd82becbeaa47ca93f5ebfb 3 pkg-no-md5_1.0.tar.gz
  79. Package: pkg-mixed-ok
  80. Binary: pkg-mixed-ok
  81. Version: 1.0
  82. Maintainer: Joe Sixpack <joe@example.org>
  83. Architecture: all
  84. Checksums-Sha1:
  85. 680254bad1d7ca0d65ec46aaa315d363abf6a50a 3 pkg-mixed-ok_1.0.tar.gz
  86. Checksums-Sha256:
  87. 943d3bf22ac661fb0f59bc4ff68cc12b04ff17a838dfcc2537008eb9c7f3770a 3 pkg-mixed-ok_1.0.dsc
  88. Package: pkg-mixed-sha1-bad
  89. Binary: pkg-mixed-sha1-bad
  90. Version: 1.0
  91. Maintainer: Joe Sixpack <joe@example.org>
  92. Architecture: all
  93. Checksums-Sha1:
  94. aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa 3 pkg-mixed-sha1-bad_1.0.dsc
  95. Checksums-Sha256:
  96. 90aebae315675cbf04612de4f7d5874850f48e0b8dd82becbeaa47ca93f5ebfb 3 pkg-mixed-sha1-bad_1.0.tar.gz
  97. Package: pkg-mixed-sha2-bad
  98. Binary: pkg-mixed-sha2-bad
  99. Version: 1.0
  100. Maintainer: Joe Sixpack <joe@example.org>
  101. Architecture: all
  102. Checksums-Sha1:
  103. 324f464e6151a92cf57b26ef95dcfcf2059a8c44 3 pkg-mixed-sha2-bad_1.0.dsc
  104. Checksums-Sha256:
  105. bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb 3 pkg-mixed-sha2-bad_1.0.tar.gz
  106. Package: pkg-md5-disagree
  107. Binary: pkg-md5-disagree
  108. Version: 1.0
  109. Maintainer: Joe Sixpack <joe@example.org>
  110. Architecture: all
  111. Files:
  112. 9604ba9427a280db542279d9ed78400b 3 pkg-md5-disagree_1.0.dsc
  113. db5570bf61464b46e2bde31ed61a7dc6 3 pkg-md5-disagree_1.0.tar.gz
  114. aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa 3 pkg-md5-disagree_1.0.dsc
  115. bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb 3 pkg-md5-disagree_1.0.tar.gz
  116. Package: pkg-md5-agree
  117. Binary: pkg-md5-agree
  118. Version: 1.0
  119. Maintainer: Joe Sixpack <joe@example.org>
  120. Architecture: all
  121. Files:
  122. 9604ba9427a280db542279d9ed78400b 3 pkg-md5-agree_1.0.dsc
  123. db5570bf61464b46e2bde31ed61a7dc6 3 pkg-md5-agree_1.0.tar.gz
  124. db5570bf61464b46e2bde31ed61a7dc6 3 pkg-md5-agree_1.0.tar.gz
  125. 9604ba9427a280db542279d9ed78400b 3 pkg-md5-agree_1.0.dsc
  126. Package: pkg-sha256-disagree
  127. Binary: pkg-sha256-disagree
  128. Version: 1.0
  129. Maintainer: Joe Sixpack <joe@example.org>
  130. Architecture: all
  131. Files:
  132. 9604ba9427a280db542279d9ed78400b 3 pkg-sha256-disagree_1.0.dsc
  133. db5570bf61464b46e2bde31ed61a7dc6 3 pkg-sha256-disagree_1.0.tar.gz
  134. Checksums-Sha1:
  135. 324f464e6151a92cf57b26ef95dcfcf2059a8c44 3 pkg-sha256-disagree_1.0.dsc
  136. 680254bad1d7ca0d65ec46aaa315d363abf6a50a 3 pkg-sha256-disagree_1.0.tar.gz
  137. Checksums-Sha256:
  138. 943d3bf22ac661fb0f59bc4ff68cc12b04ff17a838dfcc2537008eb9c7f3770a 3 pkg-sha256-disagree_1.0.dsc
  139. 90aebae315675cbf04612de4f7d5874850f48e0b8dd82becbeaa47ca93f5ebfb 3 pkg-sha256-disagree_1.0.tar.gz
  140. aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa 3 pkg-sha256-disagree_1.0.dsc
  141. bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb 3 pkg-sha256-disagree_1.0.tar.gz
  142. EOF
  143. # create fetchable files
  144. for x in 'pkg-md5-ok' 'pkg-sha1-ok' 'pkg-sha256-ok' 'pkg-sha256-bad' 'pkg-no-md5' \
  145. 'pkg-mixed-ok' 'pkg-mixed-sha1-bad' 'pkg-mixed-sha2-bad' \
  146. 'pkg-md5-agree' 'pkg-md5-disagree' 'pkg-sha256-disagree' \
  147. 'pkg-md5-bad' 'pkg-size-bad'; do
  148. echo -n 'dsc' > aptarchive/${x}_1.0.dsc
  149. echo -n 'tar' > aptarchive/${x}_1.0.tar.gz
  150. done
  151. setupaptarchive --no-update
  152. changetowebserver
  153. testsuccess aptget update
  154. cd downloaded
  155. testok() {
  156. rm -f ${1}_1.0.dsc ${1}_1.0.tar.gz
  157. testsuccessequal "Reading package lists...
  158. Need to get 6 B of source archives.
  159. Get:1 http://localhost:${APTHTTPPORT} $1 1.0 (dsc) [3 B]
  160. Get:2 http://localhost:${APTHTTPPORT} $1 1.0 (tar) [3 B]
  161. Download complete and in download only mode" aptget source -d "$@"
  162. msgtest 'Files were successfully downloaded for' "$1"
  163. testsuccess --nomsg test -e ${1}_1.0.dsc -a -e ${1}_1.0.tar.gz
  164. rm -f ${1}_1.0.dsc ${1}_1.0.tar.gz
  165. }
  166. testkeep() {
  167. echo -n 'dsc' > ${1}_1.0.dsc
  168. echo -n 'tar' > ${1}_1.0.tar.gz
  169. testsuccessequal "Reading package lists...
  170. Skipping already downloaded file '${1}_1.0.dsc'
  171. Skipping already downloaded file '${1}_1.0.tar.gz'
  172. Need to get 0 B of source archives.
  173. Download complete and in download only mode" aptget source -d "$@"
  174. msgtest 'Files already downloaded are kept for' "$1"
  175. testsuccess --nomsg test -e ${1}_1.0.dsc -a -e ${1}_1.0.tar.gz
  176. rm -f ${1}_1.0.dsc ${1}_1.0.tar.gz
  177. }
  178. testnohash() {
  179. #FIXME: Maybe we should fail in this case instead of skipping
  180. rm -f ${1}_1.0.dsc ${1}_1.0.tar.gz
  181. testsuccessequal "Reading package lists...
  182. Skipping download of file '${1}_1.0.dsc' as requested hashsum is not available for authentication
  183. Skipping download of file '${1}_1.0.tar.gz' as requested hashsum is not available for authentication
  184. Need to get 0 B of source archives.
  185. Download complete and in download only mode" aptget source -d "$@"
  186. msgtest 'Files are not downloaded for' "$1"
  187. testfailure --nomsg test -e ${1}_1.0.dsc -o -e ${1}_1.0.tar.gz
  188. }
  189. testmismatch() {
  190. rm -f ${1}_1.0.dsc ${1}_1.0.tar.gz
  191. local FAILURE
  192. if [ "$1" = 'pkg-size-bad' ]; then
  193. FAILURE="Reading package lists...
  194. Need to get 6 B of source archives.
  195. Get:1 http://localhost:${APTHTTPPORT} $1 1.0 (dsc) [2 B]
  196. Err:1 http://localhost:${APTHTTPPORT} $1 1.0 (dsc)
  197. Writing more data than expected (3 > 2)
  198. Get:2 http://localhost:${APTHTTPPORT} $1 1.0 (tar) [4 B]
  199. Err:2 http://localhost:${APTHTTPPORT} $1 1.0 (tar)
  200. Hash Sum mismatch
  201. E: Failed to fetch http://localhost:${APTHTTPPORT}/${1}_1.0.dsc Writing more data than expected (3 > 2)
  202. E: Failed to fetch http://localhost:${APTHTTPPORT}/${1}_1.0.tar.gz Hash Sum mismatch
  203. E: Failed to fetch some archives."
  204. else
  205. FAILURE="Reading package lists...
  206. Need to get 6 B of source archives.
  207. Get:1 http://localhost:${APTHTTPPORT} $1 1.0 (dsc) [3 B]
  208. Err:1 http://localhost:${APTHTTPPORT} $1 1.0 (dsc)
  209. Hash Sum mismatch
  210. Get:2 http://localhost:${APTHTTPPORT} $1 1.0 (tar) [3 B]
  211. Err:2 http://localhost:${APTHTTPPORT} $1 1.0 (tar)
  212. Hash Sum mismatch
  213. E: Failed to fetch http://localhost:${APTHTTPPORT}/${1}_1.0.dsc Hash Sum mismatch
  214. E: Failed to fetch http://localhost:${APTHTTPPORT}/${1}_1.0.tar.gz Hash Sum mismatch
  215. E: Failed to fetch some archives."
  216. fi
  217. testfailureequal "$FAILURE" aptget source -d "$@"
  218. msgtest 'Files were not download as they have hashsum mismatches for' "$1"
  219. testfailure --nomsg test -e ${1}_1.0.dsc -a -e ${1}_1.0.tar.gz
  220. if [ "$2" != '--allow-unauthenticated' ]; then
  221. rm -f ${1}_1.0.dsc ${1}_1.0.tar.gz
  222. testsuccessequal "Reading package lists...
  223. Skipping download of file '${1}_1.0.dsc' as requested hashsum is not available for authentication
  224. Skipping download of file '${1}_1.0.tar.gz' as requested hashsum is not available for authentication
  225. Need to get 0 B of source archives.
  226. Download complete and in download only mode" aptget source -d "$@" -o Acquire::ForceHash=ROT26
  227. msgtest 'Files were not download as hash is unavailable for' "$1"
  228. testfailure --nomsg test -e ${1}_1.0.dsc -a -e ${1}_1.0.tar.gz
  229. fi
  230. if [ "$1" != 'pkg-size-bad' ]; then
  231. rm -f ${1}_1.0.dsc ${1}_1.0.tar.gz
  232. testsuccessequal "Reading package lists...
  233. Need to get 6 B of source archives.
  234. Get:1 http://localhost:${APTHTTPPORT} $1 1.0 (dsc) [3 B]
  235. Get:2 http://localhost:${APTHTTPPORT} $1 1.0 (tar) [3 B]
  236. Download complete and in download only mode" aptget source --allow-unauthenticated -d "$@" -o Acquire::ForceHash=ROT26
  237. msgtest 'Files were downloaded unauthenticated as user allowed it' "$1"
  238. testsuccess --nomsg test -e ${1}_1.0.dsc -a -e ${1}_1.0.tar.gz
  239. fi
  240. }
  241. testnohash pkg-md5-ok
  242. testnohash pkg-sha1-ok
  243. testok pkg-sha256-ok
  244. testkeep pkg-sha256-ok
  245. # pkg-sha256-bad has a bad SHA sum, but good MD5 sum. If apt is
  246. # checking the best available hash (as it should), this will trigger
  247. # a hash mismatch.
  248. testmismatch pkg-sha256-bad
  249. testok pkg-sha256-bad -o Acquire::ForceHash=MD5Sum
  250. testnohash pkg-md5-bad
  251. testmismatch pkg-md5-bad --allow-unauthenticated
  252. testmismatch pkg-size-bad
  253. # not having MD5 sum doesn't mean the file doesn't exist at all …
  254. testok pkg-no-md5
  255. testok pkg-no-md5 -o Acquire::ForceHash=SHA256
  256. testsuccessequal "Reading package lists...
  257. Skipping download of file 'pkg-no-md5_1.0.dsc' as requested hashsum is not available for authentication
  258. Skipping download of file 'pkg-no-md5_1.0.tar.gz' as requested hashsum is not available for authentication
  259. Need to get 0 B of source archives.
  260. Download complete and in download only mode" aptget source -d pkg-no-md5 -o Acquire::ForceHash=MD5Sum
  261. msgtest 'Files were not download as MD5 is not available for this package' 'pkg-no-md5'
  262. testfailure --nomsg test -e pkg-no-md5_1.0.dsc -a -e pkg-no-md5_1.0.tar.gz
  263. # deal with cases in which we haven't for all files the same checksum type
  264. # mostly pathologic as this shouldn't happen, but just to be sure
  265. testsuccessequal "Reading package lists...
  266. Skipping download of file 'pkg-mixed-ok_1.0.tar.gz' as requested hashsum is not available for authentication
  267. Need to get 3 B of source archives.
  268. Get:1 http://localhost:${APTHTTPPORT} pkg-mixed-ok 1.0 (dsc) [3 B]
  269. Download complete and in download only mode" aptget source -d pkg-mixed-ok
  270. testsuccessequal "Reading package lists...
  271. Skipping download of file 'pkg-mixed-sha1-bad_1.0.dsc' as requested hashsum is not available for authentication
  272. Need to get 3 B of source archives.
  273. Get:1 http://localhost:${APTHTTPPORT} pkg-mixed-sha1-bad 1.0 (tar) [3 B]
  274. Download complete and in download only mode" aptget source -d pkg-mixed-sha1-bad
  275. msgtest 'Only tar file is downloaded as the dsc has hashsum mismatch' 'pkg-mixed-sha1-bad'
  276. testsuccess --nomsg test ! -e pkg-mixed-sha1-bad_1.0.dsc -a -e pkg-mixed-sha1-bad_1.0.tar.gz
  277. testfailureequal "Reading package lists...
  278. Skipping download of file 'pkg-mixed-sha2-bad_1.0.dsc' as requested hashsum is not available for authentication
  279. Need to get 3 B of source archives.
  280. Get:1 http://localhost:${APTHTTPPORT} pkg-mixed-sha2-bad 1.0 (tar) [3 B]
  281. Err:1 http://localhost:${APTHTTPPORT} pkg-mixed-sha2-bad 1.0 (tar)
  282. Hash Sum mismatch
  283. E: Failed to fetch http://localhost:${APTHTTPPORT}/pkg-mixed-sha2-bad_1.0.tar.gz Hash Sum mismatch
  284. E: Failed to fetch some archives." aptget source -d pkg-mixed-sha2-bad
  285. # it gets even more pathologic: multiple entries for one file, some even disagreeing!
  286. testnohash pkg-md5-agree
  287. testfailureequal 'Reading package lists...
  288. E: Error parsing checksum in Files of source package pkg-md5-disagree' aptget source -d pkg-md5-disagree
  289. testfailureequal 'Reading package lists...
  290. E: Error parsing checksum in Checksums-SHA256 of source package pkg-sha256-disagree' aptget source -d pkg-sha256-disagree