gnu: python-aiohttp-socks: Update to 0.7.1.
[jackhill/guix/guix.git] / gnu / tests / samba.scm
1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2022 Simon Streit <simon@netpanic.org>
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 samba)
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 networking)
25 #:use-module (gnu services samba)
26 #:use-module (gnu packages samba)
27 #:use-module (guix gexp)
28 #:use-module (guix store)
29 #:export (%test-samba
30 %test-wsdd))
31
32 \f
33 ;;;
34 ;;; The Samba service.
35 ;;;
36
37 (define %samba-os
38 (let ((base-os (simple-operating-system
39 (simple-service 'create-target-directory activation-service-type
40 #~(begin
41 (mkdir-p "/srv/samba/guest")
42 (chown "/srv/samba/guest"
43 (passwd:uid (getpw "nobody"))
44 (passwd:gid (getpw "nobody")))))
45 (service dhcp-client-service-type)
46 (service samba-service-type
47 (samba-configuration
48 (config-file (plain-file "smb.conf" "
49 [global]
50 workgroup = WORKGROUP
51 server string = Samba Server
52 server role = standalone server
53 log file = /var/log/samba/log.%m
54 logging = file
55
56 [guest]
57 path = /srv/samba/guest
58 read only = no
59 guest ok = yes
60 guest only = yes
61 ")))))))
62 (operating-system
63 (inherit base-os)
64 (packages (cons samba (operating-system-packages base-os))))))
65
66 (define* (run-samba-test)
67 "Return a test of an OS running Samba service."
68
69 (define vm
70 (virtual-machine
71 (operating-system (marionette-operating-system
72 %samba-os
73 #:imported-modules '((gnu services herd))))
74 (port-forwardings '((8135 . 135)
75 (8137 . 137)
76 (8138 . 138)
77 (8445 . 445)))))
78
79 (define test
80 (with-imported-modules '((gnu build marionette))
81 #~(begin
82 (use-modules (gnu build marionette)
83 (srfi srfi-26)
84 (srfi srfi-64))
85
86 (define marionette
87 (make-marionette '(#$vm)))
88
89 (test-runner-current (system-test-runner #$output))
90 (test-begin "samba")
91
92 (test-assert "samba-smbd running"
93 (marionette-eval
94 '(begin
95 (use-modules (gnu services herd))
96 (start-service 'samba-smbd))
97 marionette))
98
99 (test-assert "samba-nmbd running"
100 (marionette-eval
101 '(begin
102 (use-modules (gnu services herd))
103 (start-service 'samba-nmbd))
104 marionette))
105
106 (test-assert "samba-winbindd running"
107 (marionette-eval
108 '(begin
109 (use-modules (gnu services herd))
110 (start-service 'samba-winbindd))
111 marionette))
112
113 (test-assert "smbd service process id"
114 (let ((pid
115 (number->string (wait-for-file "/var/run/samba/smbd.pid"
116 marionette))))
117 (marionette-eval `(file-exists? (string-append "/proc/" ,pid))
118 marionette)))
119
120 (test-assert "nmbd service process id"
121 (let ((pid
122 (number->string (wait-for-file "/var/run/samba/nmbd.pid"
123 marionette))))
124 (marionette-eval `(file-exists? (string-append "/proc/" ,pid))
125 marionette)))
126
127 (test-assert "winbindd service process id"
128 (let ((pid
129 (number->string (wait-for-file "/var/run/samba/winbindd.pid"
130 marionette))))
131 (marionette-eval `(file-exists? (string-append "/proc/" ,pid))
132 marionette)))
133
134 (test-assert "samba-smbd is listening for peers"
135 (wait-for-tcp-port 445 marionette))
136
137 (test-equal "smbclient connect"
138 0
139 (marionette-eval
140 '(system* #$(file-append samba "/bin/smbclient")
141 "--list=localhost" "--no-pass")
142 marionette))
143
144 (test-equal "smbclient connect"
145 0
146 (marionette-eval
147 '(system* #$(file-append samba "/bin/smbclient")
148 "--list=localhost" "--no-pass")
149 marionette))
150
151 (test-end))))
152
153 (gexp->derivation "samba-test" test))
154
155 (define %test-samba
156 (system-test
157 (name "samba")
158 (description "Connect to a running Samba daemon.")
159 (value (run-samba-test))))
160
161 \f
162 ;;;
163 ;;; The wsdd service.
164 ;;;
165
166 (define %wsdd-os
167 (let ((base-os (simple-operating-system
168 (service dhcp-client-service-type)
169 (service wsdd-service-type))))
170 (operating-system
171 (inherit base-os)
172 (packages (cons wsdd (operating-system-packages base-os))))))
173
174 (define* (run-wsdd-test)
175 "Return a test of an OS running wsdd service."
176
177 (define vm
178 (virtual-machine
179 (operating-system (marionette-operating-system
180 %wsdd-os
181 #:imported-modules '((gnu services herd))))
182 (port-forwardings '((3702 . 3702)
183 (5357 . 5357)))))
184
185 (define test
186 (with-imported-modules '((gnu build marionette))
187 #~(begin
188 (use-modules (gnu build marionette)
189 (srfi srfi-26)
190 (srfi srfi-64))
191
192 (define marionette
193 (make-marionette '(#$vm)))
194
195 (test-runner-current (system-test-runner #$output))
196 (test-begin "wsdd")
197
198 ;; Here shall be more tests to begin with.
199
200 (test-assert "wsdd running"
201 (marionette-eval
202 '(begin
203 (use-modules (gnu services herd))
204 (start-service 'wsdd))
205 marionette))
206
207 (test-end))))
208
209 (gexp->derivation "wsdd-test" test))
210
211 (define %test-wsdd
212 (system-test
213 (name "wsdd")
214 (description "Connect to a running wsdd daemon.")
215 (value (run-wsdd-test))))