]> git.saurik.com Git - apt.git/blob - test/integration/test-apt-helper
support multiple fingerprints in signed-by
[apt.git] / test / integration / test-apt-helper
1 #!/bin/sh
2 set -e
3
4 TESTDIR="$(readlink -f "$(dirname "$0")")"
5 . "$TESTDIR/framework"
6
7 setupenvironment
8 configarchitecture 'i386'
9
10 changetohttpswebserver
11
12 echo 'foo' > aptarchive/foo
13 echo 'bar' > aptarchive/foo2
14
15 test_apt_helper_download() {
16 msgmsg 'Test with' "$1"
17
18 msgtest 'apt-file download-file' 'md5sum'
19 testsuccess --nomsg apthelper download-file "${1}/foo" './downloaded/foo2' 'MD5Sum:d3b07384d113edec49eaa6238ad5ff00'
20 testfileequal ./downloaded/foo2 'foo'
21
22 msgtest 'apt-file download-file' 'sha1'
23 testsuccess --nomsg apthelper download-file "${1}/foo" './downloaded/foo1' 'SHA1:f1d2d2f924e986ac86fdf7b36c94bcdf32beec15'
24 testfileequal ./downloaded/foo1 'foo'
25
26 msgtest 'apt-file download-file' 'sha256'
27 testsuccess --nomsg apthelper download-file "${1}/foo" './downloaded/foo3' 'SHA256:b5bb9d8014a0f9b1d61e21e796d78dccdf1352f23cd32812f4850b878ae4944c'
28 testfileequal ./downloaded/foo3 'foo'
29
30 msgtest 'apt-file download-file' 'no-hash'
31 testsuccess --nomsg apthelper download-file "${1}/foo" './downloaded/foo4'
32 testfileequal ./downloaded/foo4 'foo'
33
34 msgtest 'apt-file download-file' 'wrong md5sum'
35 testfailure --nomsg apthelper -qq download-file "${1}/foo" './downloaded/foo5' 'MD5Sum:aabbcc'
36 testfileequal rootdir/tmp/testfailure.output "E: Failed to fetch ${1}/foo Hash Sum mismatch
37 Hashes of expected file:
38 - MD5Sum:aabbcc
39 Hashes of received file:
40 - SHA512:0cf9180a764aba863a67b6d72f0918bc131c6772642cb2dce5a34f0a702f9470ddc2bf125c12198b1995c233c34b4afd346c54a2334c350a948a51b6e8b4e6b6
41 - SHA256:b5bb9d8014a0f9b1d61e21e796d78dccdf1352f23cd32812f4850b878ae4944c
42 - SHA1:f1d2d2f924e986ac86fdf7b36c94bcdf32beec15
43 - MD5Sum:d3b07384d113edec49eaa6238ad5ff00
44 - Checksum-FileSize:4
45 Last modification reported: $(lastmodification 'aptarchive/foo')
46 E: Download Failed"
47 testfileequal ./downloaded/foo5.FAILED 'foo'
48
49 msgtest 'apt-file download-file' 'wrong sha256'
50 testfailure --nomsg apthelper -qq download-file "${1}/foo" './downloaded/foo6' 'SHA256:aabbcc'
51 testfileequal rootdir/tmp/testfailure.output "E: Failed to fetch ${1}/foo Hash Sum mismatch
52 Hashes of expected file:
53 - SHA256:aabbcc
54 Hashes of received file:
55 - SHA256:b5bb9d8014a0f9b1d61e21e796d78dccdf1352f23cd32812f4850b878ae4944c
56 - Checksum-FileSize:4
57 Last modification reported: $(lastmodification 'aptarchive/foo')
58 E: Download Failed"
59 testfileequal './downloaded/foo6.FAILED' 'foo'
60
61 msgtest 'apt-file download-file' 'sha256 sha1'
62 testsuccess --nomsg apthelper download-file "${1}/foo" './downloaded/foo8' 'SHA256:b5bb9d8014a0f9b1d61e21e796d78dccdf1352f23cd32812f4850b878ae4944c' \
63 "${1}/foo2" './downloaded/foo7' 'SHA1:e242ed3bffccdf271b7fbaf34ed72d089537b42f'
64 testfileequal './downloaded/foo8' 'foo'
65 testfileequal './downloaded/foo7' 'bar'
66
67 msgtest 'apt-file download-file' 'md5sum sha1'
68 testsuccess --nomsg apthelper download-file "${1}/foo" './downloaded/foo9' 'MD5Sum:d3b07384d113edec49eaa6238ad5ff00' \
69 "${1}/foo2" './downloaded/foo10' 'SHA1:e242ed3bffccdf271b7fbaf34ed72d089537b42f'
70 testfileequal './downloaded/foo9' 'foo'
71 testfileequal './downloaded/foo10' 'bar'
72 }
73
74 test_apt_helper_detect_proxy() {
75 # no proxy
76 testsuccessequal "Using proxy '' for URL 'http://example.com/'" apthelper auto-detect-proxy http://example.com/
77
78
79 # http auto detect proxy script
80 cat > apt-proxy-detect <<'EOF'
81 #!/bin/sh -e
82 echo "http://some-proxy"
83 EOF
84 chmod 755 apt-proxy-detect
85 echo "Acquire::http::Proxy-Auto-Detect \"$(pwd)/apt-proxy-detect\";" > rootdir/etc/apt/apt.conf.d/02proxy-detect
86
87 testsuccessequal "Using proxy 'http://some-proxy' for URL 'http://www.example.com/'" apthelper auto-detect-proxy http://www.example.com
88
89
90 # https auto detect proxy script
91 cat > apt-proxy-detect <<'EOF'
92 #!/bin/sh -e
93 echo "https://https-proxy"
94 EOF
95 chmod 755 apt-proxy-detect
96 echo "Acquire::https::Proxy-Auto-Detect \"$(pwd)/apt-proxy-detect\";" > rootdir/etc/apt/apt.conf.d/02proxy-detect
97
98 testsuccessequal "Using proxy 'https://https-proxy' for URL 'https://ssl.example.com/'" apthelper auto-detect-proxy https://ssl.example.com
99 }
100
101 test_apt_helper_download "http://localhost:${APTHTTPPORT}"
102 test_apt_helper_download "https://localhost:${APTHTTPSPORT}"
103 test_apt_helper_detect_proxy
104
105 # test failure modes
106 testfailureequal 'E: Invalid operation download' apthelper download
107 testfailureequal 'E: Must specify at least one pair url/filename' apthelper download-file
108 testfailureequal 'E: Must specify at least one pair url/filename' apthelper download-file 'http://example.org/'
109 testfailureequal 'E: Need one URL as argument' apthelper auto-detect-proxy
110 testfailureequal 'E: Must specify at least one SRV record' apthelper srv-lookup
111 testfailureequal 'E: GetSrvRec failed for localhost' apthelper -q=1 srv-lookup 'localhost'
112 testfailureequal "E: GetSrvRec failed for localhost:${APTHTTPPORT}" apthelper -q=1 srv-lookup "localhost:${APTHTTPPORT}"
113 testfailureequal "E: GetSrvRec failed for localhost:${APTHTTPSPORT}" apthelper -q=1 srv-lookup "localhost:${APTHTTPSPORT}"