2014-10-23 10:42:18 +02:00
#!/bin/sh
set -e
2015-12-15 17:20:26 +01:00
TESTDIR = " $( readlink -f " $( dirname " $0 " ) " ) "
. " $TESTDIR /framework"
2014-10-23 10:42:18 +02:00
setupenvironment
configarchitecture 'i386'
insertpackage 'unstable' 'foo' 'all' '1'
setupaptarchive --no-update
2016-03-18 11:37:31 +01:00
changetohttpswebserver --authorization= " $( printf '%s' 'star@irc:hunter2' | base64 ) "
2014-10-23 10:42:18 +02:00
echo 'See, when YOU type hunter2, it shows to us as *******' > aptarchive/bash
2017-07-07 16:24:21 +02:00
echo 'Debug::Acquire::netrc "true";' > rootdir/etc/apt/apt.conf.d/netrcdebug.conf
2014-10-23 10:42:18 +02:00
testauthfailure() {
testfailure apthelper download-file " ${ 1 } /bash" ./downloaded/bash
# crappy test, but http and https output are wastely different…
testsuccess grep 401 rootdir/tmp/testfailure.output
2014-10-25 13:37:05 +02:00
testfailure test -s ./downloaded/bash
2014-10-23 10:42:18 +02:00
}
testauthsuccess() {
testsuccess apthelper download-file " ${ 1 } /bash" ./downloaded/bash
testfileequal ./downloaded/bash " $( cat aptarchive/bash) "
2014-11-17 22:54:29 +01:00
testfilestats ./downloaded/bash '%U:%G:%a' '=' " ${ TEST_DEFAULT_USER } : ${ TEST_DEFAULT_GROUP } :644"
2014-10-23 10:42:18 +02:00
rm -f ./downloaded/bash
# lets see if got/retains acceptable permissions
if [ -n " $AUTHCONF " ] ; then
if [ " $( id -u) " = '0' ] ; then
2016-08-25 15:35:32 +02:00
testfilestats " $AUTHCONF " '%U:%G:%a' '=' "_apt: $( id -gn) :600"
2014-10-23 10:42:18 +02:00
else
2014-11-17 22:54:29 +01:00
testfilestats " $AUTHCONF " '%U:%G:%a' '=' " ${ TEST_DEFAULT_USER } : ${ TEST_DEFAULT_GROUP } :600"
2014-10-23 10:42:18 +02:00
fi
fi
rm -rf rootdir/var/lib/apt/lists
2017-07-14 17:07:22 +02:00
if expr index " $1 " '@' >/dev/null; then
testsuccesswithnotice aptget update
else
testsuccess aptget update
fi
2015-03-10 00:59:44 +01:00
testsuccessequal 'Reading package lists...
2014-10-23 10:42:18 +02:00
Building dependency tree...
The following NEW packages will be installed:
foo
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Inst foo (1 unstable [all])
Conf foo (1 unstable [all])' aptget install foo -s
}
authfile() {
2018-12-03 17:39:03 +01:00
local AUTHCONF = " ${ 2 :- rootdir /etc/apt/auth.conf } "
mkdir -p " $( dirname " $AUTHCONF " ) "
2014-10-23 10:42:18 +02:00
rm -f " $AUTHCONF "
printf '%s' " $1 " > " $AUTHCONF "
chmod 600 " $AUTHCONF "
}
runtest() {
# unauthorized fails
authfile ''
testauthfailure " $1 "
2019-12-02 11:46:49 +01:00
protocol = " ${ 1 %%://* } "
2014-10-23 10:42:18 +02:00
# good auth
2019-12-02 11:46:49 +01:00
authfile "machine ${ protocol } ://localhost
2016-03-18 11:37:31 +01:00
login star@irc
2019-12-02 11:46:49 +01:00
password hunter2"
2014-10-23 10:42:18 +02:00
testauthsuccess " $1 "
# bad auth
2019-12-02 11:46:49 +01:00
authfile "machine ${ protocol } ://localhost
2014-10-23 10:42:18 +02:00
login anonymous
2019-12-02 11:46:49 +01:00
password hunter2"
2014-10-23 10:42:18 +02:00
testauthfailure " $1 "
# 2 stanzas: unmatching + good auth
2019-12-02 11:46:49 +01:00
authfile "machine ${ protocol } ://debian.org
2014-10-23 10:42:18 +02:00
login debian
password jessie
2019-12-02 11:46:49 +01:00
machine ${ protocol } ://localhost
2016-03-18 11:37:31 +01:00
login star@irc
2019-12-02 11:46:49 +01:00
password hunter2"
2014-10-23 10:42:18 +02:00
testauthsuccess " $1 "
2018-12-03 17:39:03 +01:00
2019-12-02 11:46:49 +01:00
# no protocol specifier
authfile "machine localhost
login star@irc
password hunter2"
if [ " $protocol " = "https" ] ; then
testauthsuccess " $1 "
else
2019-12-04 13:58:38 +01:00
testfailure apthelper download-file " ${ 1 } /bash" ./downloaded/bash
testsuccessequal "W: ${ 1 } /bash: ${ TMPWORKINGDIRECTORY } /rootdir/etc/apt/auth.conf: Credentials for localhost match, but the protocol is not encrypted. Annotate with http:// to use." grep "Credentials.*match" rootdir/tmp/testfailure.output
2019-12-02 11:46:49 +01:00
testauthfailure " $1 "
fi
# wrong protocol specifier
if [ " $protocol " = "https" ] ; then
authfile "machine http://localhost
login star@irc
password hunter2"
else
authfile "machine https://localhost
login star@irc
password hunter2"
fi
testauthfailure " $1 "
2018-12-03 17:39:03 +01:00
# delete file, make sure it fails; add auth.conf.d snippet, works again.
rm rootdir/etc/apt/auth.conf
testauthfailure " $1 "
2019-12-02 11:46:49 +01:00
authfile "machine ${ protocol } ://localhost
2018-12-03 17:39:03 +01:00
login star@irc
2019-12-02 11:46:49 +01:00
password hunter2" rootdir/etc/apt/auth.conf.d/myauth.conf
2018-12-03 17:39:03 +01:00
testauthsuccess " $1 "
rm rootdir/etc/apt/auth.conf.d/myauth.conf
2014-10-23 10:42:18 +02:00
}
msgmsg 'server basic auth'
2015-09-15 00:33:12 +02:00
rewritesourceslist "http://localhost: ${ APTHTTPPORT } "
runtest "http://localhost: ${ APTHTTPPORT } "
2016-03-18 11:37:31 +01:00
rewritesourceslist "http://star%40irc:hunter2@localhost: ${ APTHTTPPORT } "
authfile ''
testauthsuccess "http://star%40irc:hunter2@localhost: ${ APTHTTPPORT } "
2015-09-15 00:33:12 +02:00
rewritesourceslist "https://localhost: ${ APTHTTPSPORT } "
runtest "https://localhost: ${ APTHTTPSPORT } "
rewritesourceslist "http://localhost: ${ APTHTTPPORT } "
2014-10-23 10:42:18 +02:00
msgmsg 'proxy to server basic auth'
webserverconfig 'aptwebserver::request::absolute' 'uri'
2017-07-07 21:59:01 +02:00
# using ip instead of localhost avoids picking up the auth for the repo
# for the proxy as well as we serve them both over the same server…
export http_proxy = "http://127.0.0.1: ${ APTHTTPPORT } "
2015-09-15 00:33:12 +02:00
runtest "http://localhost: ${ APTHTTPPORT } "
2014-10-23 10:42:18 +02:00
unset http_proxy
msgmsg 'proxy basic auth to server basic auth'
webserverconfig 'aptwebserver::proxy-authorization' " $( printf 'moon:deer2' | base64) "
2015-09-15 00:33:12 +02:00
export http_proxy = "http://moon:deer2@localhost: ${ APTHTTPPORT } "
runtest "http://localhost: ${ APTHTTPPORT } "
2014-10-23 10:42:18 +02:00
msgmsg 'proxy basic auth to server'
authfile ''
webserverconfig 'aptwebserver::authorization' ''
2015-09-15 00:33:12 +02:00
testauthsuccess "http://localhost: ${ APTHTTPPORT } "