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