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