You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

108 lines
2.9 KiB

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