at master 4.3 kB view raw
1{ lib, pkgs, ... }: 2let 3 name = "tuwunel"; 4in 5{ 6 inherit name; 7 8 nodes = { 9 # Host1 is a fresh install of tuwunel 10 host1 = { 11 services.matrix-tuwunel = { 12 enable = true; 13 settings.global = { 14 server_name = name; 15 address = [ "0.0.0.0" ]; 16 allow_registration = true; 17 yes_i_am_very_very_sure_i_want_an_open_registration_server_prone_to_abuse = true; 18 }; 19 extraEnvironment.RUST_BACKTRACE = "yes"; 20 }; 21 networking.firewall.allowedTCPPorts = [ 6167 ]; 22 }; 23 24 # Host2 was upgraded from the matrix-conduit service 25 host2 = { 26 users.users.conduit = { 27 group = "conduit"; 28 home = "/var/lib/matrix-conduit"; 29 isSystemUser = true; 30 }; 31 users.groups.conduit = { }; 32 services.matrix-tuwunel = { 33 enable = true; 34 user = "conduit"; 35 group = "conduit"; 36 stateDirectory = "matrix-conduit"; 37 settings.global = { 38 server_name = name; 39 address = [ "0.0.0.0" ]; 40 allow_registration = true; 41 yes_i_am_very_very_sure_i_want_an_open_registration_server_prone_to_abuse = true; 42 }; 43 extraEnvironment.RUST_BACKTRACE = "yes"; 44 }; 45 networking.firewall.allowedTCPPorts = [ 6167 ]; 46 }; 47 48 client = 49 { pkgs, ... }: 50 { 51 environment.systemPackages = [ 52 (pkgs.writers.writePython3Bin "do_test" { libraries = [ pkgs.python3Packages.matrix-nio ]; } '' 53 import asyncio 54 import nio 55 import sys 56 57 58 async def main(host) -> None: 59 # Connect to server 60 client = nio.AsyncClient(f"http://{host}:6167", "alice") 61 62 # Register as user alice 63 response = await client.register("alice", "my-secret-password") 64 65 # Log in as user alice 66 response = await client.login("my-secret-password") 67 68 # Create a new room 69 response = await client.room_create(federate=False) 70 print("Matrix room create response:", response) 71 assert isinstance(response, nio.RoomCreateResponse) 72 room_id = response.room_id 73 74 # Join the room 75 response = await client.join(room_id) 76 print("Matrix join response:", response) 77 assert isinstance(response, nio.JoinResponse) 78 79 # Send a message to the room 80 response = await client.room_send( 81 room_id=room_id, 82 message_type="m.room.message", 83 content={ 84 "msgtype": "m.text", 85 "body": "Hello matrix!" 86 } 87 ) 88 print("Matrix room send response:", response) 89 assert isinstance(response, nio.RoomSendResponse) 90 91 # Sync responses 92 response = await client.sync(timeout=30000) 93 print("Matrix sync response:", response) 94 assert isinstance(response, nio.SyncResponse) 95 96 # Check the message was received by server 97 last_message = response.rooms.join[room_id].timeline.events[-1].body 98 assert last_message == "Hello matrix!" 99 100 # Leave the room 101 response = await client.room_leave(room_id) 102 print("Matrix room leave response:", response) 103 assert isinstance(response, nio.RoomLeaveResponse) 104 105 # Close the client 106 await client.close() 107 108 109 if __name__ == "__main__": 110 asyncio.run(main(sys.argv[1])) 111 '') 112 ]; 113 }; 114 }; 115 116 testScript = '' 117 start_all() 118 119 with subtest("start tuwunel on host1"): 120 host1.wait_for_unit("tuwunel.service") 121 host1.wait_for_open_port(6167) 122 123 with subtest("start tuwunel on host2"): 124 host1.wait_for_unit("tuwunel.service") 125 host1.wait_for_open_port(6167) 126 127 with subtest("ensure messages can be sent to servers"): 128 client.succeed("do_test host1 >&2") 129 client.succeed("do_test host2 >&2") 130 ''; 131 132 meta.maintainers = with lib.maintainers; [ 133 scvalex 134 ]; 135}