test-authentication-basic 3.0 KB

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