cups.scm 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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. (mkdir #$output)
  50. (chdir #$output)
  51. (test-begin "cups")
  52. ;; Wait for the web interface to become ready.
  53. (wait-for-tcp-port #$cups-port marionette)
  54. (test-equal "http-get default page"
  55. 200
  56. (let-values
  57. (((response text)
  58. (http-get #$(simple-format
  59. #f "http://localhost:~A/" forwarded-port)
  60. #:decode-body? #t)))
  61. (response-code response)))
  62. (test-equal "http-get admin page"
  63. 200
  64. (let-values
  65. (((response text)
  66. (http-get #$(simple-format
  67. #f "http://localhost:~A/admin" forwarded-port)
  68. #:decode-body? #t)))
  69. (response-code response)))
  70. (test-end)
  71. (exit (= (test-runner-fail-count (test-runner-current)) 0)))))
  72. (gexp->derivation "cups-test" test))
  73. (define %cups-os
  74. (simple-operating-system
  75. (service dhcp-client-service-type)
  76. (service cups-service-type
  77. (cups-configuration
  78. (web-interface? #t)
  79. ;; Listen on all interfaces instead of just localhost so we
  80. ;; can access the web interface "remotely".
  81. (listen '("*:631" "/var/run/cups/cups.sock"))
  82. ;; Add access controls for the Qemu-managed network.
  83. (location-access-controls
  84. (list (location-access-control
  85. (path "/")
  86. (access-controls '("Order allow,deny"
  87. "Allow from 10.0.0.0/8")))
  88. (location-access-control
  89. (path "/admin")
  90. (access-controls '("Order allow,deny"
  91. "Allow from 10.0.0.0/8")))
  92. (location-access-control
  93. (path "/admin/conf")
  94. (access-controls '("Order allow,deny"
  95. "AuthType Basic"
  96. "Require user @SYSTEM"
  97. "Allow localhost")))))))))
  98. (define %test-cups
  99. (system-test
  100. (name "cups")
  101. (description "Test the CUPS print server")
  102. (value (run-cups-test %cups-os))))