at 18.09-beta 2.6 kB view raw
1import ./make-test.nix { 2 name = "prosody"; 3 4 machine = { pkgs, ... }: { 5 services.prosody = { 6 enable = true; 7 # TODO: use a self-signed certificate 8 c2sRequireEncryption = false; 9 }; 10 environment.systemPackages = let 11 sendMessage = pkgs.writeScriptBin "send-message" '' 12 #!/usr/bin/env python3 13 # Based on the sleekxmpp send_client example, look there for more details: 14 # https://github.com/fritzy/SleekXMPP/blob/develop/examples/send_client.py 15 import sleekxmpp 16 17 class SendMsgBot(sleekxmpp.ClientXMPP): 18 """ 19 A basic SleekXMPP bot that will log in, send a message, 20 and then log out. 21 """ 22 def __init__(self, jid, password, recipient, message): 23 sleekxmpp.ClientXMPP.__init__(self, jid, password) 24 25 self.recipient = recipient 26 self.msg = message 27 28 self.add_event_handler("session_start", self.start, threaded=True) 29 30 def start(self, event): 31 self.send_presence() 32 self.get_roster() 33 34 self.send_message(mto=self.recipient, 35 mbody=self.msg, 36 mtype='chat') 37 38 self.disconnect(wait=True) 39 40 41 if __name__ == '__main__': 42 xmpp = SendMsgBot("test1@localhost", "test1", "test2@localhost", "Hello World!") 43 xmpp.register_plugin('xep_0030') # Service Discovery 44 xmpp.register_plugin('xep_0199') # XMPP Ping 45 46 # TODO: verify certificate 47 # If you want to verify the SSL certificates offered by a server: 48 # xmpp.ca_certs = "path/to/ca/cert" 49 50 if xmpp.connect(('localhost', 5222)): 51 xmpp.process(block=True) 52 else: 53 print("Unable to connect.") 54 sys.exit(1) 55 ''; 56 in [ (pkgs.python3.withPackages (ps: [ ps.sleekxmpp ])) sendMessage ]; 57 }; 58 59 testScript = '' 60 $machine->waitForUnit('prosody.service'); 61 $machine->succeed('prosodyctl status') =~ /Prosody is running/; 62 63 # set password to 'test' (it's asked twice) 64 $machine->succeed('yes test1 | prosodyctl adduser test1@localhost'); 65 # set password to 'y' 66 $machine->succeed('yes | prosodyctl adduser test2@localhost'); 67 # correct password to 'test2' 68 $machine->succeed('yes test2 | prosodyctl passwd test2@localhost'); 69 70 $machine->succeed("send-message"); 71 72 $machine->succeed('prosodyctl deluser test1@localhost'); 73 $machine->succeed('prosodyctl deluser test2@localhost'); 74 ''; 75}