1 import ../make-test-python.nix (
4 homeserverUrl = "http://homeserver:8008";
6 private_key = pkgs.runCommand "matrix_key.pem" {
7 buildInputs = [ pkgs.dendrite ];
8 } "generate-keys --private-key $out";
12 meta = with pkgs.lib; {
13 maintainers = teams.matrix.members;
17 homeserver = { pkgs, ... }: {
20 loadCredential = [ "test_private_key:${private_key}" ];
21 openRegistration = true;
23 global.server_name = "test-dendrite-server.com";
24 global.private_key = "$CREDENTIALS_DIRECTORY/test_private_key";
25 client_api.registration_disabled = false;
29 networking.firewall.allowedTCPPorts = [ 8008 ];
32 client = { pkgs, ... }: {
33 environment.systemPackages = [
35 pkgs.writers.writePython3Bin "do_test"
36 { libraries = [ pkgs.python3Packages.matrix-nio ]; } ''
39 from nio import AsyncClient
42 async def main() -> None:
44 client = AsyncClient("http://homeserver:8008", "alice")
46 # Register as user alice
47 response = await client.register("alice", "my-secret-password")
49 # Log in as user alice
50 response = await client.login("my-secret-password")
53 response = await client.room_create(federate=False)
54 room_id = response.room_id
57 response = await client.join(room_id)
59 # Send a message to the room
60 response = await client.room_send(
62 message_type="m.room.message",
65 "body": "Hello world!"
70 response = await client.sync(timeout=30000)
72 # Check the message was received by dendrite
73 last_message = response.rooms.join[room_id].timeline.events[-1].body
74 assert last_message == "Hello world!"
77 response = await client.room_leave(room_id)
82 asyncio.get_event_loop().run_until_complete(main())
92 with subtest("start the homeserver"):
93 homeserver.wait_for_unit("dendrite.service")
94 homeserver.wait_for_open_port(8008)
96 with subtest("ensure messages can be exchanged"):
97 client.succeed("do_test")