at master 2.7 kB view raw
1{ pkgs, ... }: 2let 3 name = "conduit"; 4in 5{ 6 name = "matrix-conduit"; 7 8 nodes = { 9 conduit = args: { 10 services.matrix-conduit = { 11 enable = true; 12 settings.global.server_name = name; 13 settings.global.allow_registration = true; 14 extraEnvironment.RUST_BACKTRACE = "yes"; 15 }; 16 services.nginx = { 17 enable = true; 18 virtualHosts.${name} = { 19 enableACME = false; 20 forceSSL = false; 21 enableSSL = false; 22 23 locations."/_matrix" = { 24 proxyPass = "http://[::1]:6167"; 25 }; 26 }; 27 }; 28 networking.firewall.allowedTCPPorts = [ 80 ]; 29 }; 30 client = 31 { pkgs, ... }: 32 { 33 environment.systemPackages = [ 34 (pkgs.writers.writePython3Bin "do_test" { libraries = [ pkgs.python3Packages.matrix-nio ]; } '' 35 import asyncio 36 37 from nio import AsyncClient 38 39 40 async def main() -> None: 41 # Connect to conduit 42 client = AsyncClient("http://conduit:80", "alice") 43 44 # Register as user alice 45 response = await client.register("alice", "my-secret-password") 46 47 # Log in as user alice 48 response = await client.login("my-secret-password") 49 50 # Create a new room 51 response = await client.room_create(federate=False) 52 room_id = response.room_id 53 54 # Join the room 55 response = await client.join(room_id) 56 57 # Send a message to the room 58 response = await client.room_send( 59 room_id=room_id, 60 message_type="m.room.message", 61 content={ 62 "msgtype": "m.text", 63 "body": "Hello conduit!" 64 } 65 ) 66 67 # Sync responses 68 response = await client.sync(timeout=30000) 69 70 # Check the message was received by conduit 71 last_message = response.rooms.join[room_id].timeline.events[-1].body 72 assert last_message == "Hello conduit!" 73 74 # Leave the room 75 response = await client.room_leave(room_id) 76 77 # Close the client 78 await client.close() 79 80 asyncio.get_event_loop().run_until_complete(main()) 81 '') 82 ]; 83 }; 84 }; 85 86 testScript = '' 87 start_all() 88 89 with subtest("start conduit"): 90 conduit.wait_for_unit("conduit.service") 91 conduit.wait_for_open_port(80) 92 93 with subtest("ensure messages can be exchanged"): 94 client.succeed("do_test") 95 ''; 96}