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>
5 ;;; This file is part of GNU Guix.
7 ;;; GNU Guix is free software; you can redistribute it and/or modify it
8 ;;; under the terms of the GNU General Public License as published by
9 ;;; the Free Software Foundation; either version 3 of the License, or (at
10 ;;; your option) any later version.
12 ;;; GNU Guix is distributed in the hope that it will be useful, but
13 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
14 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 ;;; GNU General Public License for more details.
17 ;;; You should have received a copy of the GNU General Public License
18 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
20 (define-module (gnu tests messaging)
21 #:use-module (gnu tests)
22 #:use-module (gnu system)
23 #:use-module (gnu system vm)
24 #:use-module (gnu services)
25 #:use-module (gnu services messaging)
26 #:use-module (gnu services networking)
27 #:use-module (gnu packages messaging)
28 #:use-module (guix gexp)
29 #:use-module (guix store)
30 #:use-module (guix modules)
31 #:export (%test-prosody
34 (define (run-xmpp-test name xmpp-service pid-file create-account)
35 "Run a test of an OS running XMPP-SERVICE, which writes its PID to PID-FILE."
37 (marionette-operating-system
38 (simple-operating-system (service dhcp-client-service-type)
40 #:imported-modules '((gnu services herd))))
47 (port-forwardings `((,port . 5222)))))
49 (define username "alice")
50 (define server "localhost")
51 (define jid (string-append username "@" server))
52 (define password "correct horse battery staple")
53 (define message "hello world")
54 (define witness "/tmp/freetalk-witness")
60 (define (handle-received-message time from nickname message)
61 (define (touch file-name)
62 (call-with-output-file file-name (const #t)))
63 (when (equal? message #$message)
65 (add-hook! ft-message-receive-hook handle-received-message)
68 (ft-set-password! #$password)
69 (ft-set-server! #$server)
73 (ft-send-message #$jid #$message)
79 (with-imported-modules '((gnu build marionette))
81 (use-modules (gnu build marionette)
85 (make-marionette (list #$vm)))
87 (define (host-wait-for-file file)
88 ;; Wait until FILE exists in the host.
90 (cond ((file-exists? file)
97 (error "file didn't show up" file)))))
104 ;; Wait for XMPP service to be up and running.
105 (test-assert "service running"
108 (use-modules (gnu services herd))
109 (start-service 'xmpp-daemon))
112 ;; Check XMPP service's PID.
113 (test-assert "service process id"
114 (let ((pid (number->string (wait-for-file #$pid-file
116 (marionette-eval `(file-exists? (string-append "/proc/" ,pid))
119 ;; Alice sends an XMPP message to herself, with Freetalk.
120 (test-assert "client-to-server communication"
121 (let ((freetalk-bin (string-append #$freetalk "/bin/freetalk")))
122 (marionette-eval '(system* #$create-account #$jid #$password)
124 ;; Freetalk requires write access to $HOME.
125 (setenv "HOME" "/tmp")
126 (system* freetalk-bin "-s" #$script.ft)
127 (host-wait-for-file #$witness)))
130 (exit (= (test-runner-fail-count (test-runner-current)) 0)))))
132 (gexp->derivation name test))
134 (define %create-prosody-account
138 (use-modules (ice-9 match))
139 (match (command-line)
140 ((command jid password)
141 (let ((password-input (format #f "\"~a~%~a\"" password password))
142 (prosodyctl #$(file-append prosody "/bin/prosodyctl")))
144 `("echo" ,password-input "|" ,prosodyctl "adduser" ,jid)
147 (define %test-prosody
148 (let* ((config (prosody-configuration
149 (disable-sasl-mechanisms '())
152 (virtualhost-configuration
153 (domain "localhost")))))))
156 (description "Connect to a running Prosody daemon.")
157 (value (run-xmpp-test name
158 (service prosody-service-type config)
159 (prosody-configuration-pidfile config)
160 %create-prosody-account)))))
167 (define (run-bitlbee-test)
169 (marionette-operating-system
170 (simple-operating-system (service dhcp-client-service-type)
171 (service bitlbee-service-type
172 (bitlbee-configuration
173 (interface "0.0.0.0"))))
174 #:imported-modules (source-module-closure
175 '((gnu services herd)))))
179 (operating-system os)
180 (port-forwardings `((6667 . 6667)))))
183 (with-imported-modules '((gnu build marionette))
185 (use-modules (ice-9 rdelim)
187 (gnu build marionette))
190 (make-marionette (list #$vm)))
195 (test-begin "bitlbee")
197 (test-assert "service started"
200 (use-modules (gnu services herd))
201 (start-service 'bitlbee))
204 (test-equal "valid PID"
205 #$(file-append bitlbee "/sbin/bitlbee")
208 (use-modules (srfi srfi-1)
212 (find (lambda (service)
214 (live-service-provision service)))
215 (current-services))))
216 (and (pk 'bitlbee-service bitlbee)
217 (let ((pid (live-service-running bitlbee)))
218 (readlink (string-append "/proc/"
223 (test-assert "connect"
224 (let* ((address (make-socket-address AF_INET INADDR_LOOPBACK
226 (sock (socket AF_INET SOCK_STREAM 0)))
227 (connect sock address)
228 ;; See <https://tools.ietf.org/html/rfc1459>.
229 (->bool (string-contains (pk 'message (read-line sock))
233 (exit (= (test-runner-fail-count (test-runner-current)) 0)))))
235 (gexp->derivation "bitlbee-test" test))
237 (define %test-bitlbee
240 (description "Connect to a BitlBee IRC server.")
241 (value (run-bitlbee-test))))