about summary refs log tree commit diff
path: root/nixos/tests
diff options
context:
space:
mode:
authorRobin Gloster <mail@glob.in>2018-03-22 14:12:57 +0100
committerGitHub <noreply@github.com>2018-03-22 14:12:57 +0100
commit76ea0e1b2e0f5b4fd7ab6c43ae5704918bf3413c (patch)
tree9794c7f9833dac879a538e22daf0b67d0943785d /nixos/tests
parent7b539c06297f1ca84e475fb1018fe50114f2447e (diff)
parentfaaf32a0ee3ed3693e87def1fabd6b8a89e29a41 (diff)
downloadnixlib-76ea0e1b2e0f5b4fd7ab6c43ae5704918bf3413c.tar
nixlib-76ea0e1b2e0f5b4fd7ab6c43ae5704918bf3413c.tar.gz
nixlib-76ea0e1b2e0f5b4fd7ab6c43ae5704918bf3413c.tar.bz2
nixlib-76ea0e1b2e0f5b4fd7ab6c43ae5704918bf3413c.tar.lz
nixlib-76ea0e1b2e0f5b4fd7ab6c43ae5704918bf3413c.tar.xz
nixlib-76ea0e1b2e0f5b4fd7ab6c43ae5704918bf3413c.tar.zst
nixlib-76ea0e1b2e0f5b4fd7ab6c43ae5704918bf3413c.zip
Merge pull request #32960 from florianjacob/prosody-0.10
Prosody 0.10.0
Diffstat (limited to 'nixos/tests')
-rw-r--r--nixos/tests/prosody.nix75
1 files changed, 75 insertions, 0 deletions
diff --git a/nixos/tests/prosody.nix b/nixos/tests/prosody.nix
new file mode 100644
index 000000000000..fcebfaf74e12
--- /dev/null
+++ b/nixos/tests/prosody.nix
@@ -0,0 +1,75 @@
+import ./make-test.nix {
+  name = "prosody";
+
+  machine = { config, pkgs, ... }: {
+    services.prosody = {
+      enable = true;
+      # TODO: use a self-signed certificate
+      c2sRequireEncryption = false;
+    };
+    environment.systemPackages = let
+      sendMessage = pkgs.writeScriptBin "send-message" ''
+        #!/usr/bin/env python3
+        # 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("test1@localhost", "test1", "test2@localhost", "Hello World!")
+            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(('localhost', 5222)):
+                xmpp.process(block=True)
+            else:
+                print("Unable to connect.")
+                sys.exit(1)
+      '';
+    in [ (pkgs.python3.withPackages (ps: [ ps.sleekxmpp ])) sendMessage ];
+  };
+
+  testScript = ''
+    $machine->waitForUnit('prosody.service');
+    $machine->succeed('prosodyctl status') =~ /Prosody is running/;
+
+    # set password to 'test' (it's asked twice)
+    $machine->succeed('yes test1 | prosodyctl adduser test1@localhost');
+    # set password to 'y'
+    $machine->succeed('yes | prosodyctl adduser test2@localhost');
+    # correct password to 'test2'
+    $machine->succeed('yes test2 | prosodyctl passwd test2@localhost');
+
+    $machine->succeed("send-message");
+
+    $machine->succeed('prosodyctl deluser test1@localhost');
+    $machine->succeed('prosodyctl deluser test2@localhost');
+  '';
+}