1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2017, 2018 Clément Lassieur <clement@lassieur.org>
3 ;;; Copyright © 2017, 2018 Ludovic Courtès <ludo@gnu.org>
4 ;;; Copyright © 2018 Efraim Flashner <efraim@flashner.co.il>
6 ;;; This file is part of GNU Guix.
8 ;;; GNU Guix is free software; you can redistribute it and/or modify it
9 ;;; under the terms of the GNU General Public License as published by
10 ;;; the Free Software Foundation; either version 3 of the License, or (at
11 ;;; your option) any later version.
13 ;;; GNU Guix is distributed in the hope that it will be useful, but
14 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
15 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ;;; GNU General Public License for more details.
18 ;;; You should have received a copy of the GNU General Public License
19 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
21 (define-module (gnu tests messaging)
22 #:use-module (gnu tests)
23 #:use-module (gnu system)
24 #:use-module (gnu system vm)
25 #:use-module (gnu services)
26 #:use-module (gnu services messaging)
27 #:use-module (gnu services networking)
28 #:use-module (gnu packages messaging)
29 #:use-module (guix gexp)
30 #:use-module (guix store)
31 #:use-module (guix modules)
32 #:export (%test-prosody
36 (define (run-xmpp-test name xmpp-service pid-file create-account)
37 "Run a test of an OS running XMPP-SERVICE, which writes its PID to PID-FILE."
39 (marionette-operating-system
40 (simple-operating-system (service dhcp-client-service-type)
42 #:imported-modules '((gnu services herd))))
49 (port-forwardings `((,port . 5222)))))
51 (define username "alice")
52 (define server "localhost")
53 (define jid (string-append username "@" server))
54 (define password "correct horse battery staple")
55 (define message "hello world")
56 (define witness "/tmp/freetalk-witness")
62 (define (handle-received-message time from nickname message)
63 (define (touch file-name)
64 (call-with-output-file file-name (const #t)))
65 (when (equal? message #$message)
67 (add-hook! ft-message-receive-hook handle-received-message)
70 (ft-set-password! #$password)
71 (ft-set-server! #$server)
75 (ft-send-message #$jid #$message)
81 (with-imported-modules '((gnu build marionette))
83 (use-modules (gnu build marionette)
87 (make-marionette (list #$vm)))
89 (define (host-wait-for-file file)
90 ;; Wait until FILE exists in the host.
92 (cond ((file-exists? file)
99 (error "file didn't show up" file)))))
106 ;; Wait for XMPP service to be up and running.
107 (test-assert "service running"
110 (use-modules (gnu services herd))
111 (start-service 'xmpp-daemon))
114 ;; Check XMPP service's PID.
115 (test-assert "service process id"
116 (let ((pid (number->string (wait-for-file #$pid-file
118 (marionette-eval `(file-exists? (string-append "/proc/" ,pid))
121 ;; Alice sends an XMPP message to herself, with Freetalk.
122 (test-assert "client-to-server communication"
123 (let ((freetalk-bin (string-append #$freetalk "/bin/freetalk")))
124 (marionette-eval '(system* #$create-account #$jid #$password)
126 ;; Freetalk requires write access to $HOME.
127 (setenv "HOME" "/tmp")
128 (system* freetalk-bin "-s" #$script.ft)
129 (host-wait-for-file #$witness)))
132 (exit (= (test-runner-fail-count (test-runner-current)) 0)))))
134 (gexp->derivation name test))
136 (define %create-prosody-account
140 (use-modules (ice-9 match))
141 (match (command-line)
142 ((command jid password)
143 (let ((password-input (format #f "\"~a~%~a\"" password password))
144 (prosodyctl #$(file-append prosody "/bin/prosodyctl")))
146 `("echo" ,password-input "|" ,prosodyctl "adduser" ,jid)
149 (define %test-prosody
150 (let* ((config (prosody-configuration
151 (disable-sasl-mechanisms '())
154 (virtualhost-configuration
155 (domain "localhost")))))))
158 (description "Connect to a running Prosody daemon.")
159 (value (run-xmpp-test name
160 (service prosody-service-type config)
161 (prosody-configuration-pidfile config)
162 %create-prosody-account)))))
169 (define (run-bitlbee-test)
171 (marionette-operating-system
172 (simple-operating-system (service dhcp-client-service-type)
173 (service bitlbee-service-type
174 (bitlbee-configuration
175 (interface "0.0.0.0"))))
176 #:imported-modules (source-module-closure
177 '((gnu services herd)))))
181 (operating-system os)
182 (port-forwardings `((6667 . 6667)))))
185 (with-imported-modules '((gnu build marionette))
187 (use-modules (ice-9 rdelim)
189 (gnu build marionette))
192 (make-marionette (list #$vm)))
197 (test-begin "bitlbee")
199 (test-assert "service started"
202 (use-modules (gnu services herd))
203 (start-service 'bitlbee))
206 (test-equal "valid PID"
207 #$(file-append bitlbee "/sbin/bitlbee")
210 (use-modules (srfi srfi-1)
214 (find (lambda (service)
216 (live-service-provision service)))
217 (current-services))))
218 (and (pk 'bitlbee-service bitlbee)
219 (let ((pid (live-service-running bitlbee)))
220 (readlink (string-append "/proc/"
225 (test-assert "connect"
226 (let* ((address (make-socket-address AF_INET INADDR_LOOPBACK
228 (sock (socket AF_INET SOCK_STREAM 0)))
229 (connect sock address)
230 ;; See <https://tools.ietf.org/html/rfc1459>.
231 (->bool (string-contains (pk 'message (read-line sock))
235 (exit (= (test-runner-fail-count (test-runner-current)) 0)))))
237 (gexp->derivation "bitlbee-test" test))
239 (define %test-bitlbee
242 (description "Connect to a BitlBee IRC server.")
243 (value (run-bitlbee-test))))
245 (define (run-quassel-test)
247 (marionette-operating-system
248 (simple-operating-system (service dhcp-client-service-type)
249 (service quassel-service-type))
250 #:imported-modules (source-module-closure
251 '((gnu services herd)))))
255 (operating-system os)
256 (port-forwardings `((4242 . 4242)))))
259 (with-imported-modules '((gnu build marionette))
261 (use-modules (srfi srfi-64)
262 (gnu build marionette))
265 (make-marionette (list #$vm)))
270 (test-begin "quassel")
272 (test-assert "service started"
275 (use-modules (gnu services herd))
276 (start-service 'quassel))
279 (test-assert "certificate file"
281 '(file-exists? "/var/lib/quassel/quasselCert.pem")
285 (exit (= (test-runner-fail-count (test-runner-current)) 0)))))
287 (gexp->derivation "quassel-test" test))
289 (define %test-quassel
292 (description "Connect to a quassel IRC server.")
293 (value (run-quassel-test))))