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

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