@@ -0,0 +1,162 @@
1+import ./make-test-python.nix ({ pkgs, ... }:
3+ homeserverUrl = "http://homeserver:8448";
6+ name = "matrix-appservice-irc";
8+ maintainers = pkgs.matrix-appservice-irc.meta.maintainers;
12+ homeserver = { pkgs, ... }: {
13+ # We'll switch to this once the config is copied into place
14+ specialisation.running.configuration = {
15+ services.matrix-synapse = {
17+ database_type = "sqlite3";
18+ app_service_config_files = [ "/registration.yml" ];
20+ enable_registration = true;
23+ # The default but tls=false
28+ { "compress" = true; "names" = [ "client" "webclient" ]; }
29+ { "compress" = false; "names" = [ "federation" ]; }
33+ "x_forwarded" = false;
38+ networking.firewall.allowedTCPPorts = [ 8448 ];
42+ ircd = { pkgs, ... }: {
48+ Info = Server Info Text
59+ networking.firewall.allowedTCPPorts = [ 6667 ];
62+ appservice = { pkgs, ... }: {
63+ services.matrix-appservice-irc = {
65+ registrationUrl = "http://appservice:8009";
68+ homeserver.url = homeserverUrl;
69+ homeserver.domain = "homeserver";
71+ ircService.servers."ircd" = {
76+ aliasTemplate = "#irc_$CHANNEL";
82+ networking.firewall.allowedTCPPorts = [ 8009 ];
85+ client = { pkgs, ... }: {
86+ environment.systemPackages = [
87+ (pkgs.writers.writePython3Bin "do_test"
88+ { libraries = [ pkgs.python3Packages.matrix-client ]; } ''
90+ from matrix_client.client import MatrixClient
91+ from time import sleep
93+ matrix = MatrixClient("${homeserverUrl}")
94+ matrix.register_with_password(username="alice", password="foobar")
96+ irc = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
97+ irc.connect(("ircd", 6667))
98+ irc.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
99+ irc.send(b"USER bob bob bob :bob\n")
100+ irc.send(b"NICK bob\n")
102+ m_room = matrix.join_room("#irc_#test:homeserver")
103+ irc.send(b"JOIN #test\n")
105+ # plenty of time for the joins to happen
108+ m_room.send_text("hi from matrix")
109+ irc.send(b"PRIVMSG #test :hi from irc \r\n")
111+ print("Waiting for irc message...")
113+ buf = irc.recv(10000)
114+ if b"hi from matrix" in buf:
117+ print("Waiting for matrix message...")
120+ def callback(room, e):
121+ if "hi from irc" in e['content']['body']:
125+ m_room.add_listener(callback, "m.room.message")
126+ matrix.listen_forever()
136+ ircd.wait_for_unit("ngircd.service")
137+ ircd.wait_for_open_port(6667)
139+ with subtest("start the appservice"):
140+ appservice.wait_for_unit("matrix-appservice-irc.service")
141+ appservice.wait_for_open_port(8009)
143+ with subtest("copy the registration file"):
144+ appservice.copy_from_vm("/var/lib/matrix-appservice-irc/registration.yml")
145+ homeserver.copy_from_host(
146+ pathlib.Path(os.environ.get("out", os.getcwd())) / "registration.yml", "/"
148+ homeserver.succeed("chmod 444 /registration.yml")
150+ with subtest("start the homeserver"):
152+ "/run/current-system/specialisation/running/bin/switch-to-configuration test >&2"
155+ homeserver.wait_for_unit("matrix-synapse.service")
156+ homeserver.wait_for_open_port(8448)
158+ with subtest("ensure messages can be exchanged"):
159+ client.succeed("do_test")