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