cups.scm 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2020 Marius Bakke <mbakke@fastmail.com>
  3. ;;;
  4. ;;; This file is part of GNU Guix.
  5. ;;;
  6. ;;; GNU Guix is free software; you can redistribute it and/or modify it
  7. ;;; under the terms of the GNU General Public License as published by
  8. ;;; the Free Software Foundation; either version 3 of the License, or (at
  9. ;;; your option) any later version.
  10. ;;;
  11. ;;; GNU Guix is distributed in the hope that it will be useful, but
  12. ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
  13. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. ;;; GNU General Public License for more details.
  15. ;;;
  16. ;;; You should have received a copy of the GNU General Public License
  17. ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
  18. (define-module (gnu tests cups)
  19. #:use-module (gnu tests)
  20. #:use-module (gnu system)
  21. #:use-module (gnu system vm)
  22. #:use-module (gnu services)
  23. #:use-module (gnu services cups)
  24. #:use-module (gnu services networking)
  25. #:use-module (guix gexp)
  26. #:use-module (guix store)
  27. #:use-module (guix monads)
  28. #:export (%test-cups))
  29. ;;;
  30. ;;; Test the Common Unix Printing System.
  31. ;;;
  32. (define* (run-cups-test os-configuration #:optional (cups-port 631))
  33. (define os
  34. (marionette-operating-system os-configuration
  35. #:imported-modules '((gnu services herd))))
  36. (define forwarded-port 8080)
  37. (define vm
  38. (virtual-machine
  39. (operating-system os)
  40. (port-forwardings `((,forwarded-port . ,cups-port)))))
  41. (define test
  42. (with-imported-modules '((gnu build marionette))
  43. #~(begin
  44. (use-modules (gnu build marionette)
  45. (srfi srfi-11) (srfi srfi-64)
  46. (web client) (web response))
  47. (define marionette
  48. (make-marionette (list #$vm)))
  49. (test-runner-current (system-test-runner #$output))
  50. (test-begin "cups")
  51. ;; Wait for the web interface to become ready.
  52. (wait-for-tcp-port #$cups-port marionette)
  53. (test-equal "http-get default page"
  54. 200
  55. (let-values
  56. (((response text)
  57. (http-get #$(simple-format
  58. #f "http://localhost:~A/" forwarded-port)
  59. #:decode-body? #t)))
  60. (response-code response)))
  61. (test-equal "http-get admin page"
  62. 200
  63. (let-values
  64. (((response text)
  65. (http-get #$(simple-format
  66. #f "http://localhost:~A/admin" forwarded-port)
  67. #:decode-body? #t)))
  68. (response-code response)))
  69. (test-end))))
  70. (gexp->derivation "cups-test" test))
  71. (define %cups-os
  72. (simple-operating-system
  73. (service dhcp-client-service-type)
  74. (service cups-service-type
  75. (cups-configuration
  76. (web-interface? #t)
  77. ;; Listen on all interfaces instead of just localhost so we
  78. ;; can access the web interface "remotely".
  79. (listen '("*:631" "/var/run/cups/cups.sock"))
  80. ;; Add access controls for the Qemu-managed network.
  81. (location-access-controls
  82. (list (location-access-control
  83. (path "/")
  84. (access-controls '("Order allow,deny"
  85. "Allow from 10.0.0.0/8")))
  86. (location-access-control
  87. (path "/admin")
  88. (access-controls '("Order allow,deny"
  89. "Allow from 10.0.0.0/8")))
  90. (location-access-control
  91. (path "/admin/conf")
  92. (access-controls '("Order allow,deny"
  93. "AuthType Basic"
  94. "Require user @SYSTEM"
  95. "Allow localhost")))))))))
  96. (define %test-cups
  97. (system-test
  98. (name "cups")
  99. (description "Test the CUPS print server")
  100. (value (run-cups-test %cups-os))))