summaryrefslogtreecommitdiffstats
path: root/nixos/tests
diff options
context:
space:
mode:
authorFlorian Klink <flokli@flokli.de>2020-05-01 20:07:13 +0200
committerGitHub <noreply@github.com>2020-05-01 20:07:13 +0200
commite148a72377a45a9e101b0f83518e73ce7cf01e22 (patch)
tree24aff80dc1da562479a8e259aea5756a3052d21b /nixos/tests
parent32fbb42ba72bf65926da7502ae3833ddb0d05e94 (diff)
parentf5b1e6bc215bf82d4a294891e7c4a2b178122731 (diff)
Merge pull request #86067 from NinjaTrappeur/nin-sane-prosody-defaults
nixos/prosody: make module defaults comply with XEP-0423
Diffstat (limited to 'nixos/tests')
-rw-r--r--nixos/tests/xmpp/prosody.nix85
-rw-r--r--nixos/tests/xmpp/xmpp-sendmessage.nix105
2 files changed, 125 insertions, 65 deletions
diff --git a/nixos/tests/xmpp/prosody.nix b/nixos/tests/xmpp/prosody.nix
index 9d1374bff6bd..e7755e24bab4 100644
--- a/nixos/tests/xmpp/prosody.nix
+++ b/nixos/tests/xmpp/prosody.nix
@@ -1,27 +1,80 @@
-import ../make-test-python.nix {
- name = "prosody";
+let
+ cert = pkgs: pkgs.runCommandNoCC "selfSignedCerts" { buildInputs = [ pkgs.openssl ]; } ''
+ openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -nodes -subj '/CN=example.com/CN=uploads.example.com/CN=conference.example.com'
+ mkdir -p $out
+ cp key.pem cert.pem $out
+ '';
+ createUsers = pkgs: pkgs.writeScriptBin "create-prosody-users" ''
+ #!${pkgs.bash}/bin/bash
+ set -e
+
+ # Creates and set password for the 2 xmpp test users.
+ #
+ # Doing that in a bash script instead of doing that in the test
+ # script allow us to easily provision the users when running that
+ # test interactively.
+
+ prosodyctl register cthon98 example.com nothunter2
+ prosodyctl register azurediamond example.com hunter2
+ '';
+ delUsers = pkgs: pkgs.writeScriptBin "delete-prosody-users" ''
+ #!${pkgs.bash}/bin/bash
+ set -e
+
+ # Deletes the test users.
+ #
+ # Doing that in a bash script instead of doing that in the test
+ # script allow us to easily provision the users when running that
+ # test interactively.
+ prosodyctl deluser cthon98@example.com
+ prosodyctl deluser azurediamond@example.com
+ '';
+in import ../make-test-python.nix {
+ name = "prosody";
nodes = {
- client = { nodes, pkgs, ... }: {
+ client = { nodes, pkgs, config, ... }: {
+ security.pki.certificateFiles = [ "${cert pkgs}/cert.pem" ];
+ console.keyMap = "fr-bepo";
+ networking.extraHosts = ''
+ ${nodes.server.config.networking.primaryIPAddress} example.com
+ ${nodes.server.config.networking.primaryIPAddress} conference.example.com
+ ${nodes.server.config.networking.primaryIPAddress} uploads.example.com
+ '';
environment.systemPackages = [
(pkgs.callPackage ./xmpp-sendmessage.nix { connectTo = nodes.server.config.networking.primaryIPAddress; })
];
};
server = { config, pkgs, ... }: {
+ security.pki.certificateFiles = [ "${cert pkgs}/cert.pem" ];
+ console.keyMap = "fr-bepo";
networking.extraHosts = ''
${config.networking.primaryIPAddress} example.com
+ ${config.networking.primaryIPAddress} conference.example.com
+ ${config.networking.primaryIPAddress} uploads.example.com
'';
networking.firewall.enable = false;
+ environment.systemPackages = [
+ (createUsers pkgs)
+ (delUsers pkgs)
+ ];
services.prosody = {
enable = true;
- # TODO: use a self-signed certificate
- c2sRequireEncryption = false;
- extraConfig = ''
- storage = "sql"
- '';
- virtualHosts.test = {
+ ssl.cert = "${cert pkgs}/cert.pem";
+ ssl.key = "${cert pkgs}/key.pem";
+ virtualHosts.example = {
domain = "example.com";
enabled = true;
+ ssl.cert = "${cert pkgs}/cert.pem";
+ ssl.key = "${cert pkgs}/key.pem";
+ };
+ muc = [
+ {
+ domain = "conference.example.com";
+ }
+ ];
+ uploadHttp = {
+ domain = "uploads.example.com";
};
};
};
@@ -31,16 +84,8 @@ import ../make-test-python.nix {
server.wait_for_unit("prosody.service")
server.succeed('prosodyctl status | grep "Prosody is running"')
- # set password to 'nothunter2' (it's asked twice)
- server.succeed("yes nothunter2 | prosodyctl adduser cthon98@example.com")
- # set password to 'y'
- server.succeed("yes | prosodyctl adduser azurediamond@example.com")
- # correct password to "hunter2"
- server.succeed("yes hunter2 | prosodyctl passwd azurediamond@example.com")
-
- client.succeed("send-message")
-
- server.succeed("prosodyctl deluser cthon98@example.com")
- server.succeed("prosodyctl deluser azurediamond@example.com")
+ server.succeed("create-prosody-users")
+ client.succeed('send-message 2>&1 | grep "XMPP SCRIPT TEST SUCCESS"')
+ server.succeed("delete-prosody-users")
'';
}
diff --git a/nixos/tests/xmpp/xmpp-sendmessage.nix b/nixos/tests/xmpp/xmpp-sendmessage.nix
index 2a075a018134..349b9c6f38e4 100644
--- a/nixos/tests/xmpp/xmpp-sendmessage.nix
+++ b/nixos/tests/xmpp/xmpp-sendmessage.nix
@@ -1,46 +1,61 @@
-{ writeScriptBin, python3, connectTo ? "localhost" }:
-writeScriptBin "send-message" ''
- #!${(python3.withPackages (ps: [ ps.sleekxmpp ])).interpreter}
- # Based on the sleekxmpp send_client example, look there for more details:
- # https://github.com/fritzy/SleekXMPP/blob/develop/examples/send_client.py
- import sleekxmpp
-
- class SendMsgBot(sleekxmpp.ClientXMPP):
- """
- A basic SleekXMPP bot that will log in, send a message,
- and then log out.
- """
- def __init__(self, jid, password, recipient, message):
- sleekxmpp.ClientXMPP.__init__(self, jid, password)
-
- self.recipient = recipient
- self.msg = message
-
- self.add_event_handler("session_start", self.start, threaded=True)
-
- def start(self, event):
- self.send_presence()
- self.get_roster()
-
- self.send_message(mto=self.recipient,
- mbody=self.msg,
- mtype='chat')
-
- self.disconnect(wait=True)
-
-
- if __name__ == '__main__':
- xmpp = SendMsgBot("cthon98@example.com", "nothunter2", "azurediamond@example.com", "hey, if you type in your pw, it will show as stars")
- xmpp.register_plugin('xep_0030') # Service Discovery
- xmpp.register_plugin('xep_0199') # XMPP Ping
-
- # TODO: verify certificate
- # If you want to verify the SSL certificates offered by a server:
- # xmpp.ca_certs = "path/to/ca/cert"
-
- if xmpp.connect(('${connectTo}', 5222)):
- xmpp.process(block=True)
- else:
- print("Unable to connect.")
- sys.exit(1)
+{ writeScriptBin, writeText, python3, connectTo ? "localhost" }:
+let
+ dummyFile = writeText "dummy-file" ''
+ Dear dog,
+
+ Please find this *really* important attachment.
+
+ Yours truly,
+ John
+ '';
+in writeScriptBin "send-message" ''
+#!${(python3.withPackages (ps: [ ps.slixmpp ])).interpreter}
+import logging
+import sys
+from types import MethodType
+
+from slixmpp import ClientXMPP
+from slixmpp.exceptions import IqError, IqTimeout
+
+
+class CthonTest(ClientXMPP):
+
+ def __init__(self, jid, password):
+ ClientXMPP.__init__(self, jid, password)
+ self.add_event_handler("session_start", self.session_start)
+
+ async def session_start(self, event):
+ log = logging.getLogger(__name__)
+ self.send_presence()
+ self.get_roster()
+ # Sending a test message
+ self.send_message(mto="azurediamond@example.com", mbody="Hello, this is dog.", mtype="chat")
+ log.info('Message sent')
+
+ # Test http upload (XEP_0363)
+ def timeout_callback(arg):
+ log.error("ERROR: Cannot upload file. XEP_0363 seems broken")
+ sys.exit(1)
+ url = await self['xep_0363'].upload_file("${dummyFile}",timeout=10, timeout_callback=timeout_callback)
+ log.info('Upload success!')
+ # Test MUC
+ self.plugin['xep_0045'].join_muc('testMucRoom', 'cthon98', wait=True)
+ log.info('MUC join success!')
+ log.info('XMPP SCRIPT TEST SUCCESS')
+ self.disconnect(wait=True)
+
+
+if __name__ == '__main__':
+ logging.basicConfig(level=logging.DEBUG,
+ format='%(levelname)-8s %(message)s')
+
+ ct = CthonTest('cthon98@example.com', 'nothunter2')
+ ct.register_plugin('xep_0071')
+ ct.register_plugin('xep_0128')
+ # HTTP Upload
+ ct.register_plugin('xep_0363')
+ # MUC
+ ct.register_plugin('xep_0045')
+ ct.connect(("server", 5222))
+ ct.process(forever=False)
''