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.
 
 
 
 
 
 

107 lines
2.7 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. changetohttpswebserver --authorization="$(printf '%s' 'star: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. testsuccess 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' '=' "${USER}:${USER}: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:root:600"
  26. else
  27. testfilestats "$AUTHCONF" '%U:%G:%a' '=' "${USER}:${USER}:600"
  28. fi
  29. fi
  30. rm -rf rootdir/var/lib/apt/lists
  31. testsuccess aptget update
  32. testequal '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
  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
  66. password hunter2'
  67. testauthsuccess "$1"
  68. }
  69. msgmsg 'server basic auth'
  70. rewritesourceslist 'http://localhost:8080'
  71. runtest 'http://localhost:8080'
  72. rewritesourceslist 'https://localhost:4433'
  73. runtest 'https://localhost:4433'
  74. rewritesourceslist 'http://localhost:8080'
  75. msgmsg 'proxy to server basic auth'
  76. webserverconfig 'aptwebserver::request::absolute' 'uri'
  77. export http_proxy='http://localhost:8080'
  78. runtest 'http://localhost:8080'
  79. unset http_proxy
  80. msgmsg 'proxy basic auth to server basic auth'
  81. webserverconfig 'aptwebserver::proxy-authorization' "$(printf 'moon:deer2' | base64)"
  82. export http_proxy='http://moon:deer2@localhost:8080'
  83. runtest 'http://localhost:8080'
  84. msgmsg 'proxy basic auth to server'
  85. authfile ''
  86. webserverconfig 'aptwebserver::authorization' ''
  87. testauthsuccess 'http://localhost:8080'