]> git.saurik.com Git - apt.git/blame - test/integration/test-authentication-basic
test-apt-download-progress: Allow smaller progress change
[apt.git] / test / integration / test-authentication-basic
CommitLineData
b0314abb
DK
1#!/bin/sh
2set -e
3
4TESTDIR=$(readlink -f $(dirname $0))
5. $TESTDIR/framework
6
7setupenvironment
8configarchitecture 'i386'
9
10insertpackage 'unstable' 'foo' 'all' '1'
11setupaptarchive --no-update
87d6947d 12exit
b0314abb
DK
13
14changetohttpswebserver --authorization="$(printf '%s' 'star:hunter2' | base64 )"
15
16echo 'See, when YOU type hunter2, it shows to us as *******' > aptarchive/bash
17
18testauthfailure() {
19 testfailure apthelper download-file "${1}/bash" ./downloaded/bash
20 # crappy test, but http and https output are wastely different…
21 testsuccess grep 401 rootdir/tmp/testfailure.output
e52aad52 22 testfailure test -s ./downloaded/bash
b0314abb
DK
23}
24
25testauthsuccess() {
26 testsuccess apthelper download-file "${1}/bash" ./downloaded/bash
27 testfileequal ./downloaded/bash "$(cat aptarchive/bash)"
4bb006d1 28 testfilestats ./downloaded/bash '%U:%G:%a' '=' "${TEST_DEFAULT_USER}:${TEST_DEFAULT_GROUP}:644"
b0314abb
DK
29 rm -f ./downloaded/bash
30
31 # lets see if got/retains acceptable permissions
32 if [ -n "$AUTHCONF" ]; then
33 if [ "$(id -u)" = '0' ]; then
34 testfilestats "$AUTHCONF" '%U:%G:%a' '=' "_apt:root:600"
35 else
4bb006d1 36 testfilestats "$AUTHCONF" '%U:%G:%a' '=' "${TEST_DEFAULT_USER}:${TEST_DEFAULT_GROUP}:600"
b0314abb
DK
37 fi
38 fi
39
40 rm -rf rootdir/var/lib/apt/lists
41 testsuccess aptget update
25b86db1 42 testsuccessequal 'Reading package lists...
b0314abb
DK
43Building dependency tree...
44The following NEW packages will be installed:
45 foo
460 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
47Inst foo (1 unstable [all])
48Conf foo (1 unstable [all])' aptget install foo -s
49}
50
51authfile() {
52 local AUTHCONF='rootdir/etc/apt/auth.conf'
53 rm -f "$AUTHCONF"
54 printf '%s' "$1" > "$AUTHCONF"
55 chmod 600 "$AUTHCONF"
56}
57
58runtest() {
59 # unauthorized fails
60 authfile ''
61 testauthfailure "$1"
62
63 # good auth
64 authfile 'machine localhost
65login star
66password hunter2'
67 testauthsuccess "$1"
68
69 # bad auth
70 authfile 'machine localhost
71login anonymous
72password hunter2'
73 testauthfailure "$1"
74
75 # 2 stanzas: unmatching + good auth
76 authfile 'machine debian.org
77login debian
78password jessie
79
80machine localhost
81login star
82password hunter2'
83 testauthsuccess "$1"
84}
85
86msgmsg 'server basic auth'
6c0765c0
DK
87rewritesourceslist "http://localhost:${APTHTTPPORT}"
88runtest "http://localhost:${APTHTTPPORT}"
89rewritesourceslist "https://localhost:${APTHTTPSPORT}"
90runtest "https://localhost:${APTHTTPSPORT}"
91rewritesourceslist "http://localhost:${APTHTTPPORT}"
b0314abb
DK
92
93msgmsg 'proxy to server basic auth'
94webserverconfig 'aptwebserver::request::absolute' 'uri'
6c0765c0
DK
95export http_proxy="http://localhost:${APTHTTPPORT}"
96runtest "http://localhost:${APTHTTPPORT}"
b0314abb
DK
97unset http_proxy
98
99msgmsg 'proxy basic auth to server basic auth'
100webserverconfig 'aptwebserver::proxy-authorization' "$(printf 'moon:deer2' | base64)"
6c0765c0
DK
101export http_proxy="http://moon:deer2@localhost:${APTHTTPPORT}"
102runtest "http://localhost:${APTHTTPPORT}"
b0314abb
DK
103
104msgmsg 'proxy basic auth to server'
105authfile ''
106webserverconfig 'aptwebserver::authorization' ''
6c0765c0 107testauthsuccess "http://localhost:${APTHTTPPORT}"