| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | |
| 12 | |
| 13 | |
| 14 | |
| 15 | |
| 16 | |
| 17 | |
| 18 |
|
| 19 | (define-module (gnu tests cups)
|
| 20 | #:use-module (gnu tests)
|
| 21 | #:use-module (gnu system)
|
| 22 | #:use-module (gnu system vm)
|
| 23 | #:use-module (gnu services)
|
| 24 | #:use-module (gnu services cups)
|
| 25 | #:use-module (gnu services networking)
|
| 26 | #:use-module (guix gexp)
|
| 27 | #:use-module (guix store)
|
| 28 | #:use-module (guix monads)
|
| 29 | #:export (%test-cups))
|
| 30 |
|
| 31 | |
| 32 | |
| 33 | |
| 34 |
|
| 35 | (define* (run-cups-test os-configuration #:optional (cups-port 631))
|
| 36 | (define os
|
| 37 | (marionette-operating-system os-configuration
|
| 38 | #:imported-modules '((gnu services herd))))
|
| 39 |
|
| 40 | (define forwarded-port 8080)
|
| 41 |
|
| 42 | (define vm
|
| 43 | (virtual-machine
|
| 44 | (operating-system os)
|
| 45 | (port-forwardings `((,forwarded-port . ,cups-port)))))
|
| 46 |
|
| 47 | (define test
|
| 48 | (with-imported-modules '((gnu build marionette))
|
| 49 | #~(begin
|
| 50 | (use-modules (gnu build marionette)
|
| 51 | (srfi srfi-11) (srfi srfi-64)
|
| 52 | (web client) (web response))
|
| 53 |
|
| 54 | (define marionette
|
| 55 | (make-marionette (list #$vm)))
|
| 56 |
|
| 57 | (test-runner-current (system-test-runner #$output))
|
| 58 | (test-begin "cups")
|
| 59 |
|
| 60 | |
| 61 | (wait-for-tcp-port #$cups-port marionette)
|
| 62 |
|
| 63 | (test-equal "http-get default page"
|
| 64 | 200
|
| 65 | (let-values
|
| 66 | (((response text)
|
| 67 | (http-get #$(simple-format
|
| 68 | #f "http://localhost:~A/" forwarded-port)
|
| 69 | #:decode-body? #t)))
|
| 70 | (response-code response)))
|
| 71 |
|
| 72 | (test-equal "http-get admin page"
|
| 73 | 200
|
| 74 | (let-values
|
| 75 | (((response text)
|
| 76 | (http-get #$(simple-format
|
| 77 | #f "http://localhost:~A/admin" forwarded-port)
|
| 78 | #:decode-body? #t)))
|
| 79 | (response-code response)))
|
| 80 |
|
| 81 | (test-end))))
|
| 82 |
|
| 83 | (gexp->derivation "cups-test" test))
|
| 84 |
|
| 85 | (define %cups-os
|
| 86 | (simple-operating-system
|
| 87 | (service dhcpcd-service-type)
|
| 88 | (service cups-service-type
|
| 89 | (cups-configuration
|
| 90 | (web-interface? #t)
|
| 91 | |
| 92 | |
| 93 | (listen '("*:631" "/var/run/cups/cups.sock"))
|
| 94 | |
| 95 | (location-access-controls
|
| 96 | (list (location-access-control
|
| 97 | (path "/")
|
| 98 | (access-controls '("Order allow,deny"
|
| 99 | "Allow from 10.0.0.0/8")))
|
| 100 | (location-access-control
|
| 101 | (path "/admin")
|
| 102 | (access-controls '("Order allow,deny"
|
| 103 | "Allow from 10.0.0.0/8")))
|
| 104 | (location-access-control
|
| 105 | (path "/admin/conf")
|
| 106 | (access-controls '("Order allow,deny"
|
| 107 | "AuthType Basic"
|
| 108 | "Require user @SYSTEM"
|
| 109 | "Allow localhost")))))))))
|
| 110 |
|
| 111 | (define %test-cups
|
| 112 | (system-test
|
| 113 | (name "cups")
|
| 114 | (description "Test the CUPS print server")
|
| 115 | (value (run-cups-test %cups-os))))
|
| 116 |
|