projects/guix·blob master · refs

405 lines · 16.8 KiB

1;;; GNU Guix --- Functional package management for GNU
2;;; Copyright © 2021, 2022, 2023 Maxim Cournoyer <[email protected]>.
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 telephony)
20 #:use-module (gnu)
21 #:use-module (gnu packages)
22 #:use-module (gnu packages guile)
23 #:use-module (gnu packages guile-xyz)
24 #:use-module (gnu tests)
25 #:use-module (gnu system vm)
26 #:use-module (gnu services)
27 #:use-module (gnu services dbus)
28 #:use-module (gnu services networking)
29 #:use-module (gnu services ssh)
30 #:use-module (gnu services telephony)
31 #:use-module (guix gexp)
32 #:use-module (guix modules)
33 #:export (%test-jami
34 %test-jami-provisioning
35 %test-jami-provisioning-partial))
36
37;;;
38;;; Jami daemon.
39;;;
40
41(define %jami-account-content-sexp
42 (call-with-input-file
43 (search-path %load-path "gnu/tests/data/jami-dummy-account.dat")
44 read))
45
46(define %dummy-jami-account-archive
47 ;; A Jami account archive is a gzipped JSON file.
48 (computed-file
49 "dummy-jami-account.gz"
50 (with-extensions (list guile-json-4 guile-zlib)
51 #~(begin
52 (use-modules (json) (zlib))
53 (let ((port (open-output-file #$output)))
54 (call-with-gzip-output-port port
55 (lambda (port)
56 (scm->json '#$%jami-account-content-sexp port))))))))
57
58(define %allowed-contacts '("1dbcb0f5f37324228235564b79f2b9737e9a008f"
59 "2dbcb0f5f37324228235564b79f2b9737e9a008f"))
60
61(define %moderators '("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
62 "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"))
63
64(define %dummy-jami-account (jami-account
65 (archive %dummy-jami-account-archive)
66 (allowed-contacts %allowed-contacts)
67 (moderators %moderators)
68 (rendezvous-point? #t)
69 (peer-discovery? #f)
70 (bootstrap-hostnames '("bootstrap.me"
71 "fallback.another.host"))
72 (name-server-uri "https://my.name.server")))
73
74;;; Like %dummy-jami-account, but with allowed-contacts and moderators left
75;;; unset (thus taking the value *unspecified*).
76(define %dummy-jami-account-partial
77 (jami-account
78 (archive %dummy-jami-account-archive)
79 (rendezvous-point? #t)
80 (peer-discovery? #f)
81 (bootstrap-hostnames '("bootstrap.me"
82 "fallback.another.host"))
83 (name-server-uri "https://my.name.server")))
84
85(define* (make-jami-os #:key provisioning? partial?)
86 (operating-system
87 (host-name "jami")
88 (timezone "America/Montreal")
89 (locale "en_US.UTF-8")
90
91 (bootloader (bootloader-configuration
92 (bootloader grub-bootloader)
93 (targets '("/dev/sdX"))))
94 (file-systems (cons (file-system
95 (device (file-system-label "my-root"))
96 (mount-point "/")
97 (type "ext4"))
98 %base-file-systems))
99 (firmware '())
100
101 (services (cons* (service jami-service-type
102 (if provisioning?
103 (jami-configuration
104 (debug? #t)
105 (accounts
106 (list (if partial?
107 %dummy-jami-account-partial
108 %dummy-jami-account))))
109 (jami-configuration
110 (debug? #t))))
111 (service dbus-root-service-type)
112 ;; The following services/packages are added for
113 ;; debugging purposes.
114 (service dhcpcd-service-type)
115 (service openssh-service-type
116 (openssh-configuration
117 (permit-root-login #t)
118 (allow-empty-passwords? #t)))
119 %base-services))
120 (packages (cons* (specification->package "recutils")
121 (specification->package "strace")
122 %base-packages))))
123
124(define %jami-os
125 (make-jami-os))
126
127(define %jami-os-provisioning
128 (make-jami-os #:provisioning? #t))
129
130(define %jami-os-provisioning-partial
131 (make-jami-os #:provisioning? #t #:partial? #t))
132
133(define* (run-jami-test #:key provisioning? partial?)
134 "Run tests in %JAMI-OS. When PROVISIONING? is true, test the accounts
135provisioning feature of the service. When PARTIAL? is #t, some fields of the
136jami account used as part of the jami configuration are left *unspecified*."
137 (define os (marionette-operating-system
138 (if provisioning?
139 (if partial?
140 %jami-os-provisioning-partial
141 %jami-os-provisioning)
142 %jami-os)
143 #:imported-modules '((gnu services herd)
144 (guix combinators)
145 (gnu build jami-service)
146 (gnu build dbus-service))))
147 (define vm (virtual-machine
148 (operating-system os)
149 (memory-size 512)))
150
151 (define username (assoc-ref %jami-account-content-sexp
152 "Account.username"))
153
154 (define test
155 (with-imported-modules (source-module-closure
156 '((gnu build marionette)))
157 #~(begin
158 (use-modules (srfi srfi-64)
159 (gnu build marionette))
160
161 (define marionette
162 (make-marionette (list #$vm)))
163
164 (test-runner-current (system-test-runner #$output))
165 (test-begin "jami")
166
167 (test-assert "d-bus tooling loaded"
168 ;; Add Guile-AC-D-Bus and related libraries to the marionette's
169 ;; search path.
170 (marionette-eval
171 '(let ((libraries '(#$guile-ac-d-bus
172 #$guile-packrat))) ;used by ac-d-bus
173 (setenv "DBUS_SESSION_BUS_ADDRESS" "unix:path=/var/run/jami/bus")
174 (set! %load-path
175 (append %load-path
176 (map (lambda (directory)
177 (string-append directory
178 "/share/guile/site/"
179 (effective-version)))
180 libraries)))
181 (set! %load-compiled-path
182 (append %load-compiled-path
183 (map (lambda (directory)
184 (string-append directory
185 "/lib/guile/3.0/site-ccache"))
186 libraries)))
187 %load-path)
188 marionette))
189
190 (test-assert "dbus session is up"
191 (and (marionette-eval
192 '(begin
193 (use-modules (gnu services herd))
194 (wait-for-service 'jami-dbus-session #:timeout 40))
195 marionette)
196 (wait-for-unix-socket "/var/run/jami/bus"
197 marionette)))
198
199 (test-assert "service is running"
200 (marionette-eval
201 '(begin
202 (use-modules (gnu build jami-service)
203 (gnu services herd))
204
205 (wait-for-service 'jami #:timeout 40)
206 (jami-service-available?))
207 marionette))
208
209 (test-assert "service can be stopped"
210 (marionette-eval
211 '(begin
212 (use-modules (gnu build dbus-service)
213 (gnu build jami-service)
214 (gnu services herd)
215 (rnrs base))
216 (assert (jami-service-available?))
217
218 (stop-service 'jami)
219
220 (with-retries 20 1 (not (jami-service-available?))))
221 marionette))
222
223 (test-assert "service can be restarted"
224 (marionette-eval
225 '(begin
226 (use-modules (gnu build dbus-service)
227 (gnu build jami-service)
228 (gnu services herd)
229 (rnrs base) )
230 ;; Start the service.
231 (start-service 'jami)
232 (with-retries 40 1 (jami-service-available?))
233 ;; Restart the service.
234 (restart-service 'jami)
235 (with-retries 40 1 (jami-service-available?)))
236 marionette))
237
238 (unless #$provisioning? (test-skip 1))
239 (test-assert "jami accounts provisioning, account present"
240 (marionette-eval
241 '(begin
242 (use-modules (gnu build dbus-service)
243 (gnu services herd)
244 (rnrs base))
245 ;; Accounts take some time to appear after being added.
246 (with-retries 40 1
247 (with-shepherd-action 'jami ('list-accounts) results
248 (let ((account (assoc-ref (car results) #$username)))
249 (assert (string=? #$username
250 (assoc-ref account
251 "Account.username")))))))
252 marionette))
253
254 (unless #$(and provisioning? (not partial?)) (test-skip 1))
255 (test-assert "jami accounts provisioning, allowed-contacts"
256 (marionette-eval
257 '(begin
258 (use-modules (gnu services herd)
259 (rnrs base)
260 (srfi srfi-1))
261
262 ;; Public mode is disabled.
263 (with-shepherd-action 'jami ('list-account-details)
264 results
265 (let ((account (assoc-ref (car results) #$username)))
266 (assert (string=? "false"
267 (assoc-ref account
268 "DHT.PublicInCalls")))))
269
270 ;; Allowed contacts match those declared in the configuration.
271 (with-shepherd-action 'jami ('list-contacts) results
272 (let ((contacts (assoc-ref (car results) #$username)))
273 (assert (lset= string-ci=? contacts '#$%allowed-contacts)))))
274 marionette))
275
276 (unless #$(and provisioning? (not partial?)) (test-skip 1))
277 (test-assert "jami accounts provisioning, moderators"
278 (marionette-eval
279 '(begin
280 (use-modules (gnu services herd)
281 (rnrs base)
282 (srfi srfi-1))
283
284 ;; Moderators match those declared in the configuration.
285 (with-shepherd-action 'jami ('list-moderators) results
286 (let ((moderators (assoc-ref (car results) #$username)))
287 (assert (lset= string-ci=? moderators '#$%moderators))))
288
289 ;; Moderators can be added via the Shepherd action.
290 (with-shepherd-action 'jami
291 ('add-moderator "cccccccccccccccccccccccccccccccccccccccc"
292 #$username) results
293 (let ((moderators (car results)))
294 (assert (lset= string-ci=? moderators
295 (cons "cccccccccccccccccccccccccccccccccccccccc"
296 '#$%moderators))))))
297 marionette))
298
299 (unless #$provisioning? (test-skip 1))
300 (test-assert "jami service actions, ban/unban contacts"
301 (marionette-eval
302 '(begin
303 (use-modules (gnu services herd)
304 (ice-9 match)
305 (rnrs base)
306 (srfi srfi-1))
307
308 ;; Globally ban a contact.
309 (with-shepherd-action 'jami
310 ('ban-contact "1dbcb0f5f37324228235564b79f2b9737e9a008f") _
311 (with-shepherd-action 'jami ('list-banned-contacts) results
312 (every (match-lambda
313 ((username . banned-contacts)
314 (member "1dbcb0f5f37324228235564b79f2b9737e9a008f"
315 banned-contacts)))
316 (car results))))
317
318 ;; Ban a contact for a single account.
319 (with-shepherd-action 'jami
320 ('ban-contact "dddddddddddddddddddddddddddddddddddddddd"
321 #$username) _
322 (with-shepherd-action 'jami ('list-banned-contacts) results
323 (every (match-lambda
324 ((username . banned-contacts)
325 (let ((found? (member "dddddddddddddddddddddddddddddddddddddddd"
326 banned-contacts)))
327 (if (string=? #$username username)
328 found?
329 (not found?)))))
330 (car results)))))
331 marionette))
332
333 (unless #$provisioning? (test-skip 1))
334 (test-assert "jami service actions, enable/disable accounts"
335 (marionette-eval
336 '(begin
337 (use-modules (gnu services herd)
338 (rnrs base))
339
340 (with-shepherd-action 'jami
341 ('disable-account #$username) _
342 (with-shepherd-action 'jami ('list-accounts) results
343 (let ((account (assoc-ref (car results) #$username)))
344 (assert (string= "false"
345 (assoc-ref account "Account.enable"))))))
346
347 (with-shepherd-action 'jami
348 ('enable-account #$username) _
349 (with-shepherd-action 'jami ('list-accounts) results
350 (let ((account (assoc-ref (car results) #$username)))
351 (assert (string= "true"
352 (assoc-ref account "Account.enable")))))))
353 marionette))
354
355 (unless #$provisioning? (test-skip 1))
356 (test-assert "jami account parameters"
357 (marionette-eval
358 '(begin
359 (use-modules (gnu services herd)
360 (rnrs base)
361 (srfi srfi-1))
362
363 (with-shepherd-action 'jami ('list-account-details) results
364 (let ((account-details (assoc-ref (car results)
365 #$username)))
366 (assert (lset<=
367 equal?
368 '(("Account.hostname" .
369 "bootstrap.me;fallback.another.host")
370 ("Account.peerDiscovery" . "false")
371 ("Account.rendezVous" . "true")
372 ("RingNS.uri" . "https://my.name.server"))
373 account-details)))))
374 marionette))
375
376 (test-end))))
377
378 (gexp->derivation (if provisioning?
379 (if partial?
380 "jami-provisioning-partial-test"
381 "jami-provisioning-test")
382 "jami-test")
383 test))
384
385(define %test-jami
386 (system-test
387 (name "jami")
388 (description "Basic tests for the jami service.")
389 (value (run-jami-test))))
390
391(define %test-jami-provisioning
392 (system-test
393 (name "jami-provisioning")
394 (description "Provisioning test for the jami service.")
395 (value (run-jami-test #:provisioning? #t))))
396
397;;; This test verifies that <jami-account> values can be left unspecified
398;;; without causing any issue (see: https://issues.guix.gnu.org/56799).
399(define %test-jami-provisioning-partial
400 (system-test
401 (name "jami-provisioning-partial")
402 (description "Provisioning test for the jami service, when some of the
403'maybe' fields aren't provided (such that their value end up being
404*unspecified*.")
405 (value (run-jami-test #:provisioning? #t #:partial? #t))))