diff --git a/README.md b/README.md index f1cc5ab..f62cd79 100644 --- a/README.md +++ b/README.md @@ -47,8 +47,8 @@ Die Dokumentation ist nach Themen in Unterordner `docs/` aufgeteilt: 2. Keycloak-Provider bauen: `./gradlew :keycloak-provider:keycloakProviderJar` 3. Stack starten: `docker-compose up -d` 4. Proxy lokal starten (Profil `local`) -5. Im IDP https://idp.element.traefik.me/admin mit (`admin`/ `admin`) einloggen und im `pgk` Realm neue User anlegen. -5. Unter https://element.traefik.me mit diesen Usern anmelden und loslegen. +5. Im IDP https://idp.traefik.me/admin mit (`admin`/ `admin`) einloggen und im `pgk` Realm neue User anlegen. +6. Unter https://element.traefik.me mit diesen Usern anmelden und loslegen. Ausführliche Schritte: [docs/setup.md](docs/setup.md). diff --git a/build.gradle.kts b/build.gradle.kts index e0f3184..2fd2d9a 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -15,7 +15,7 @@ */ plugins { - id("org.springframework.boot") version "4.1.0" + id("org.springframework.boot") version "4.1.2" id("io.spring.dependency-management") version "1.1.7" kotlin("jvm") version "2.3.10" kotlin("plugin.spring") version "2.3.10" diff --git a/config/squid/conf/Dockerfile b/config/squid/conf/Dockerfile new file mode 100644 index 0000000..3e46226 --- /dev/null +++ b/config/squid/conf/Dockerfile @@ -0,0 +1,5 @@ +FROM ubuntu/squid:latest + +RUN apt-get update \ + && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends python3 \ + && rm -rf /var/lib/apt/lists/* \ diff --git a/config/squid/conf/matrix_origin_helper.py b/config/squid/conf/matrix_origin_helper.py new file mode 100644 index 0000000..ae94c98 --- /dev/null +++ b/config/squid/conf/matrix_origin_helper.py @@ -0,0 +1,105 @@ +#!/usr/bin/env python3 +""" +Squid external ACL helper: allow only if the Matrix federation +Authorization header's origin= is in a dstdomain-style whitelist. +The whitelist is read once at startup; Squid restarts helpers on reconfigure. + +Input (per line): +Output (per line): OK|ERR log= +""" + + +# Copyright 2026 MA 01 - Wien Digital +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import re +import sys +from urllib.parse import unquote + +WHITELIST = "/etc/squid/dynamic/whitelist.txt" + +SCHEME = re.compile(r"^\s*X-Matrix\s+(.*)$", re.I | re.S) +PARAM = re.compile(r'([A-Za-z_][A-Za-z0-9_-]*)\s*=\s*("(?:[^"\\]|\\.)*"|[^,\s"]*)') +HOST_OK = re.compile(r"^[a-z0-9]([a-z0-9.-]*[a-z0-9])?$") + + +def load_whitelist(path): + """dstdomain semantics: 'example.org' = exact, '.example.org' = domain + subdomains.""" + exact, suffix = set(), set() + try: + with open(path, encoding="utf-8") as f: + for line in f: + entry = line.split("#", 1)[0].strip().lower().rstrip(".") + if not entry: + continue + if entry.startswith("."): + suffix.add(entry[1:]) + else: + exact.add(entry) + except OSError as e: + # Fail closed: empty list denies everything, but say why + print(f"whitelist unreadable: {e}", file=sys.stderr, flush=True) + print(f"whitelist loaded: {len(exact)} exact, {len(suffix)} suffix entries", + file=sys.stderr, flush=True) + return exact, suffix + + +def allows(host, exact, suffix): + if host in exact or host in suffix: + return True + labels = host.split(".") + return any(".".join(labels[i:]) in suffix for i in range(1, len(labels))) + + +def extract_origin(header): + """Return (origin_host, None) or (None, reason).""" + if not header or header == "-": + return None, "no-auth-header" + m = SCHEME.match(header) + if not m: + return None, "not-x-matrix" + origins = [v for k, v in PARAM.findall(m.group(1)) if k.lower() == "origin"] + if len(origins) != 1: # none, or duplicated/smuggled + return None, "origin-count-%d" % len(origins) + origin = origins[0].strip('"').strip().lower() + if origin.startswith("["): + return None, "ip-literal" + host, sep, port = origin.rpartition(":") + if sep and port.isdigit(): + origin = host + origin = origin.rstrip(".") + if not HOST_OK.match(origin): + return None, "bad-origin" + return origin, None + + +def main(): + exact, suffix = load_whitelist(WHITELIST) + for line in sys.stdin: + try: + origin, err = extract_origin(unquote(line.rstrip("\r\n"))) + if err: + reply = "ERR log=%s" % err + elif allows(origin, exact, suffix): + reply = "OK log=allowed:%s" % origin + else: + reply = "ERR log=denied:%s" % origin + except Exception as e: # always fail closed + print(f"helper error: {e!r}", file=sys.stderr, flush=True) + reply = "ERR log=helper-error" + print(reply, flush=True) + + +if __name__ == "__main__": + main() diff --git a/config/squid/conf/squid.conf b/config/squid/conf/squid.conf index 0b93b3f..04b63eb 100644 --- a/config/squid/conf/squid.conf +++ b/config/squid/conf/squid.conf @@ -1,16 +1,40 @@ -acl inbound_whitelist dst 172.16.0.0/12 +# ---------- ACLs ---------- acl outbound_whitelist dstdomain "/etc/squid/dynamic/whitelist.txt" acl federation_ports port 8448 443 acl CONNECT method CONNECT -http_access deny !inbound_whitelist +# Reverse-proxy ACLs +acl reverse_port localport 3129 +acl matrix-inbound dstdomain matrix.traefik.me +# Inbound federation origin check +external_acl_type matrix_origin ttl=0 negative_ttl=0 children-max=5 children-startup=1 %>ha{Authorization} /usr/local/bin/matrix_origin_helper.py +acl fed_origin_ok external matrix_origin +# Unauthenticated endpoints remote servers must be able to reach +acl fed_public_paths urlpath_regex -i ^/_matrix/key/v2/server(/|$) ^/_matrix/federation/v1/version$ + +# ---------- Ports ---------- +# Forward proxy (outbound CONNECT), unchanged +http_port 3128 +# Reverse proxy / accelerator for Traefik -> Matrix +http_port 3129 accel vhost defaultsite=matrix.traefik.me + +# ---------- Origin server ---------- +cache_peer matrix parent 8448 0 no-query originserver name=matrix login=PASSTHRU + +cache_peer_access matrix allow reverse_port matrix-inbound +cache_peer_access matrix deny all +never_direct allow matrix-inbound + +# ---------- Access rules ---------- +http_access allow reverse_port matrix-inbound fed_public_paths +http_access allow reverse_port matrix-inbound fed_origin_ok + http_access allow CONNECT outbound_whitelist federation_ports http_access deny all -http_port 3128 cache deny all acl denied http_status 403 logformat pgk timestamp=%tl actor=%>a action=%rm "%rm %ru HTTP/%rv" %>Hs % { val upstream = invitationForwardPort.forwardInvite( - roomId, eventId, request.requestURI, authorization, body + roomId, eventId, request.requestURI, request.serverName, request.requestURL.toString(), authorization, body ) ResponseEntity.status(upstream.statusCode).contentType(MediaType.APPLICATION_JSON).body(upstream.body) } diff --git a/src/main/kotlin/io/cloudflight/pgk/proxy/invitation/adapter/outbound/OutgoingUrlMapper.kt b/src/main/kotlin/io/cloudflight/pgk/proxy/invitation/adapter/outbound/OutgoingUrlMapper.kt new file mode 100644 index 0000000..8ddf74a --- /dev/null +++ b/src/main/kotlin/io/cloudflight/pgk/proxy/invitation/adapter/outbound/OutgoingUrlMapper.kt @@ -0,0 +1,39 @@ +/* + * Copyright 2026 MA 01 - Wien Digital + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.cloudflight.pgk.proxy.invitation.adapter.outbound + +import org.springframework.context.annotation.Primary +import org.springframework.context.annotation.Profile +import org.springframework.stereotype.Component + +interface OutgoingUrlMapper { + fun mapToOutgoingUrl(url: String): String +} + +@Component +@Profile("local") +@Primary +internal class LocalOutgoingUrlMapper : OutgoingUrlMapper { + // override the http in the local dev setup because the PGK proxy runs outside the docker network + // but the matrix servers assume the federation is routed internally + override fun mapToOutgoingUrl(url: String): String = url.replaceFirst("http", "https") +} + +@Component +internal class DefaultOutgoingUrlMapper : OutgoingUrlMapper { + override fun mapToOutgoingUrl(url: String): String = url +} diff --git a/src/main/kotlin/io/cloudflight/pgk/proxy/invitation/adapter/outbound/SynapseInvitationForwardAdapter.kt b/src/main/kotlin/io/cloudflight/pgk/proxy/invitation/adapter/outbound/SynapseInvitationForwardAdapter.kt index 8ef912c..6ab1492 100644 --- a/src/main/kotlin/io/cloudflight/pgk/proxy/invitation/adapter/outbound/SynapseInvitationForwardAdapter.kt +++ b/src/main/kotlin/io/cloudflight/pgk/proxy/invitation/adapter/outbound/SynapseInvitationForwardAdapter.kt @@ -17,13 +17,11 @@ package io.cloudflight.pgk.proxy.invitation.adapter.outbound import io.cloudflight.pgk.proxy.config.ProxyProperties -import io.cloudflight.pgk.proxy.invitation.mapper.InvitationRequestMapper import io.cloudflight.pgk.proxy.invitation.port.InvitationForwardPort import io.cloudflight.pgk.proxy.shared.events.InvitationForwardFailedEvent import io.cloudflight.pgk.proxy.shared.events.InvitationForwardedEvent import org.springframework.context.ApplicationEventPublisher import org.springframework.http.HttpHeaders -import org.springframework.http.HttpStatus import org.springframework.http.MediaType import org.springframework.http.ResponseEntity import org.springframework.stereotype.Component @@ -47,7 +45,7 @@ import java.net.URI class SynapseInvitationForwardAdapter( private val restClient: RestClient, private val applicationEvents: ApplicationEventPublisher, - private val requestMapper: InvitationRequestMapper, + private val outgoingUrlMapper: OutgoingUrlMapper, private val properties: ProxyProperties ) : InvitationForwardPort { @@ -55,17 +53,15 @@ class SynapseInvitationForwardAdapter( roomId: String, eventId: String, originalUri: String, + originalServerName: String, + originalUrl: String, authorization: String?, body: String, ): ResponseEntity { - val destination = try { - requestMapper.fromPdu(body).recipient.domain + val destination = if (isInboundRequest(originalServerName)) { buildDestination(originalUri) - } catch (e: IllegalArgumentException) { - applicationEvents.publishEvent( - InvitationForwardFailedEvent(roomId, eventId, "unknown", "invite PDU has no recipient") - ) - return ResponseEntity.status(HttpStatus.BAD_GATEWAY).build() + } else { + outgoingUrlMapper.mapToOutgoingUrl(originalUrl) } return try { val request = restClient.put() @@ -96,6 +92,9 @@ class SynapseInvitationForwardAdapter( } } + private fun isInboundRequest(originalServerName: String): Boolean = + originalServerName == properties.federation.matrixDomain + private fun buildDestination(originalUri: String): String = properties.federation.forwardBaseUrl.trimEnd('/') + originalUri } diff --git a/src/main/kotlin/io/cloudflight/pgk/proxy/invitation/port/InvitationForwardPort.kt b/src/main/kotlin/io/cloudflight/pgk/proxy/invitation/port/InvitationForwardPort.kt index dfed18e..ee8b7eb 100644 --- a/src/main/kotlin/io/cloudflight/pgk/proxy/invitation/port/InvitationForwardPort.kt +++ b/src/main/kotlin/io/cloudflight/pgk/proxy/invitation/port/InvitationForwardPort.kt @@ -23,6 +23,8 @@ interface InvitationForwardPort { roomId: String, eventId: String, originalUri: String, + originalServerName: String, + originalUrl: String, authorization: String?, body: String, ): ResponseEntity diff --git a/src/main/resources/application-local.yml b/src/main/resources/application-local.yml index 63d708f..f12d970 100644 --- a/src/main/resources/application-local.yml +++ b/src/main/resources/application-local.yml @@ -4,4 +4,4 @@ pgk: fhir: base-url: http://localhost:8081/fhir federation: - forward-base-url: http://localhost:18009 + forward-base-url: http://localhost:18008 diff --git a/src/test/kotlin/io/cloudflight/pgk/proxy/invitation/adapter/inbound/InvitationControllerTest.kt b/src/test/kotlin/io/cloudflight/pgk/proxy/invitation/adapter/inbound/InvitationControllerTest.kt index 820ff92..e530da7 100644 --- a/src/test/kotlin/io/cloudflight/pgk/proxy/invitation/adapter/inbound/InvitationControllerTest.kt +++ b/src/test/kotlin/io/cloudflight/pgk/proxy/invitation/adapter/inbound/InvitationControllerTest.kt @@ -44,6 +44,8 @@ class InvitationControllerTest { private val roomId = "testroom" private val eventId = "inviteevent" private val originalUri = "/_matrix/federation/v2/invite/$roomId/$eventId" + private val serverName = "matrix.destination.org" + private val url = "http://$serverName$originalUri" private val body = """{"origin":"matrix.pgk.example","event":{"type":"m.room.member"}}""" private val authorization = "Bearer s3cret" @@ -59,17 +61,38 @@ class InvitationControllerTest { fun returns200AndForwardsWhenAllowed() { whenever(invitationControlService.evaluateInvitation(body)) .thenReturn(InvitationEvaluation.Allowed) - whenever(invitationForwardPort.forwardInvite(roomId, eventId, originalUri, authorization, body)) + whenever( + invitationForwardPort.forwardInvite( + roomId, + eventId, + originalUri, + serverName, + url, + authorization, + body + ) + ) .thenReturn(ResponseEntity.ok("forwarded")) - mockMvc.perform(put("/_matrix/federation/v2/invite/$roomId/$eventId") - .header("Authorization", authorization) - .contentType("application/json") - .content(body)) + mockMvc.perform( + put("/_matrix/federation/v2/invite/$roomId/$eventId") + .header("Authorization", authorization) + .header("Host", serverName) + .contentType("application/json") + .content(body) + ) .andExpect(status().isOk) verify(invitationControlService).evaluateInvitation(body) - verify(invitationForwardPort).forwardInvite(roomId, eventId, originalUri, authorization, body) + verify(invitationForwardPort).forwardInvite( + roomId, + eventId, + originalUri, + serverName, + url, + authorization, + body + ) } @Test @@ -77,13 +100,23 @@ class InvitationControllerTest { fun returnsForwardingResultWhenAllowed() { whenever(invitationControlService.evaluateInvitation(body)) .thenReturn(InvitationEvaluation.Allowed) - whenever(invitationForwardPort.forwardInvite(roomId, eventId, originalUri, authorization, body)) + whenever(invitationForwardPort.forwardInvite( + roomId, + eventId, + originalUri, + serverName, + url, + authorization, + body)) .thenReturn(ResponseEntity.status(500).body("boom")) - mockMvc.perform(put("/_matrix/federation/v2/invite/$roomId/$eventId") - .header("Authorization", authorization) - .contentType("application/json") - .content(body)) + mockMvc.perform( + put("/_matrix/federation/v2/invite/$roomId/$eventId") + .header("Authorization", authorization) + .header("Host", serverName) + .contentType("application/json") + .content(body) + ) .andExpect(status().isInternalServerError) } @@ -93,13 +126,15 @@ class InvitationControllerTest { whenever(invitationControlService.evaluateInvitation(body)) .thenReturn(InvitationEvaluation.Denied(DenialReason.FEDERATION_POLICY)) - mockMvc.perform(put("/_matrix/federation/v2/invite/$roomId/$eventId") - .contentType("application/json") - .content(body)) + mockMvc.perform( + put("/_matrix/federation/v2/invite/$roomId/$eventId") + .contentType("application/json") + .content(body) + ) .andExpect(status().isForbidden) .andExpect(content().json("""{"errcode": "M_FORBIDDEN", "error": "Invite not allowed by policy"}""")) - verify(invitationForwardPort, never()).forwardInvite(any(), any(), any(), any(), any()) + verify(invitationForwardPort, never()).forwardInvite(any(), any(), any(), any(), any(),any(), any()) } @Test @@ -108,12 +143,14 @@ class InvitationControllerTest { whenever(invitationControlService.evaluateInvitation(body)) .thenReturn(InvitationEvaluation.Denied(DenialReason.PERSONAL_BLACKLIST)) - mockMvc.perform(put("/_matrix/federation/v2/invite/$roomId/$eventId") - .contentType("application/json") - .content(body)) + mockMvc.perform( + put("/_matrix/federation/v2/invite/$roomId/$eventId") + .contentType("application/json") + .content(body) + ) .andExpect(status().isForbidden) .andExpect(content().json("""{"errcode": "M_FORBIDDEN", "error": "Invitation blocked by user policy."}""")) - verify(invitationForwardPort, never()).forwardInvite(any(), any(), any(), any(), any()) + verify(invitationForwardPort, never()).forwardInvite(any(), any(), any(), any(), any(), any(), any()) } } diff --git a/src/test/kotlin/io/cloudflight/pgk/proxy/invitation/adapter/outbound/SynapseInvitationForwardAdapterTest.kt b/src/test/kotlin/io/cloudflight/pgk/proxy/invitation/adapter/outbound/SynapseInvitationForwardAdapterTest.kt index 0b44c13..cd5695a 100644 --- a/src/test/kotlin/io/cloudflight/pgk/proxy/invitation/adapter/outbound/SynapseInvitationForwardAdapterTest.kt +++ b/src/test/kotlin/io/cloudflight/pgk/proxy/invitation/adapter/outbound/SynapseInvitationForwardAdapterTest.kt @@ -44,13 +44,18 @@ class SynapseInvitationForwardAdapterTest { private val applicationEvents: ApplicationEventPublisher = mock() - private val inviteBody = """{"origin":"matrix.traefik.me","event":{"sender":"@alice:matrix.traefik.me","state_key":"@bob:matrix.traefik.me"}}""" + private val inviteBody = + """{"origin":"matrix.traefik.me","event":{"sender":"@alice:matrix.traefik.me","state_key":"@bob:matrix.traefik.me"}}""" - private fun adapterWithServer(): Pair { + private fun adapterWithServer( + outgoingUrlMapper: OutgoingUrlMapper = DefaultOutgoingUrlMapper() + ): Pair { val builder = RestClient.builder() val server = MockRestServiceServer.bindTo(builder).build() - val properties = ProxyProperties(federation = ProxyProperties.FederationProperties(forwardBaseUrl = "http://synapse:8008")) - val adapter = SynapseInvitationForwardAdapter(builder.build(), applicationEvents, InvitationRequestMapper(), properties) + val properties = + ProxyProperties(federation = ProxyProperties.FederationProperties(forwardBaseUrl = "http://synapse:8008")) + val adapter = + SynapseInvitationForwardAdapter(builder.build(), applicationEvents, outgoingUrlMapper, properties) return adapter to server } @@ -67,7 +72,13 @@ class SynapseInvitationForwardAdapterTest { .andRespond(withSuccess("""{"event":{},"origin":"matrix.traefik.me"}""", MediaType.APPLICATION_JSON)) val response = adapter.forwardInvite( - "room1", "evt1", "/_matrix/federation/v2/invite/room1/evt1", "Bearer s3cret", inviteBody + "room1", + "evt1", + "/_matrix/federation/v2/invite/room1/evt1", + "matrix.traefik.me", + "https://matrix.traefik.me/_matrix/federation/v2/invite/room1/evt1", + "Bearer s3cret", + inviteBody ) assertEquals(200, response.statusCode.value()) @@ -89,7 +100,13 @@ class SynapseInvitationForwardAdapterTest { .andRespond(withSuccess("""{"event":{},"origin":"matrix.traefik.me"}""", MediaType.APPLICATION_JSON)) val response = adapter.forwardInvite( - "!room:example.com", "evt?1", originalUri, "Bearer s3cret", inviteBody + "!room:example.com", + "evt?1", + originalUri, + "matrix.traefik.me", + "https://matrix.traefik.me/_matrix/federation/v2/invite/room1/evt1", + "Bearer s3cret", + inviteBody ) assertEquals(200, response.statusCode.value()) @@ -97,36 +114,113 @@ class SynapseInvitationForwardAdapterTest { } @Test - @DisplayName("returns 502 and publishes a failure event when the invite PDU has no recipient") - fun returns502WhenPduHasNoRecipient() { + @DisplayName("returns 500 and publishes a failure event when forwarding fails") + fun returns500AndPublishesFailureWhenSynapseUnreachable() { + val (adapter, server) = adapterWithServer() + + server.expect(requestTo("http://synapse:8008/_matrix/federation/v2/invite/room1/evt1")) + .andExpect(method(HttpMethod.PUT)) + .andRespond(withServerError()) + + val response = adapter.forwardInvite( + "room1", + "evt1", + "/_matrix/federation/v2/invite/room1/evt1", + "matrix.traefik.me", + "https://matrix.traefik.me/_matrix/federation/v2/invite/room1/evt1", + "Bearer s3cret", + inviteBody + ) + + assertEquals(500, response.statusCode.value()) + server.verify() + verify(applicationEvents).publishEvent(any()) + } + + @Test + @DisplayName("forwards an outgoing invite to the URL returned by the outgoing URL mapper") + fun forwardsOutgoingInviteToMappedOutgoingUrl() { val (adapter, server) = adapterWithServer() + server.expect(requestTo("https://partner.traefik.me/_matrix/federation/v2/invite/room1/evt1")) + .andExpect(method(HttpMethod.PUT)) + .andExpect(content().contentType(MediaType.APPLICATION_JSON)) + .andExpect(content().string(inviteBody)) + .andRespond(withSuccess("""{"event":{},"origin":"matrix.traefik.me"}""", MediaType.APPLICATION_JSON)) + + val response = adapter.forwardInvite( + "room1", + "evt1", + "/_matrix/federation/v2/invite/room1/evt1", + "partner.traefik.me", + "https://partner.traefik.me/_matrix/federation/v2/invite/room1/evt1", + null, + inviteBody + ) + + assertEquals(200, response.statusCode.value()) + server.verify() + verify(applicationEvents).publishEvent( + argWhere { + it.roomId == "room1" && it.eventId == "evt1" && it.statusCode == 200 && + it.target == "https://partner.traefik.me/_matrix/federation/v2/invite/room1/evt1" + } + ) + } + + @Test + @DisplayName("applies the local URL mapper to outgoing invites, rewriting http to https") + fun forwardsOutgoingInviteThroughLocalOutgoingUrlMapper() { + val (adapter, server) = adapterWithServer(LocalOutgoingUrlMapper()) + + server.expect(requestTo("https://partner.traefik.me/_matrix/federation/v2/invite/room1/evt1")) + .andExpect(method(HttpMethod.PUT)) + .andRespond(withSuccess("""{"event":{},"origin":"matrix.traefik.me"}""", MediaType.APPLICATION_JSON)) + val response = adapter.forwardInvite( - "room1", "evt1", "/_matrix/federation/v2/invite/room1/evt1", "Bearer s3cret", """{"origin":"matrix.traefik.me"}""" + "room1", + "evt1", + "/_matrix/federation/v2/invite/room1/evt1", + "partner.traefik.me", + "http://partner.traefik.me/_matrix/federation/v2/invite/room1/evt1", + null, + inviteBody ) - assertEquals(502, response.statusCode.value()) + assertEquals(200, response.statusCode.value()) server.verify() verify(applicationEvents).publishEvent( - argWhere { it.roomId == "room1" && it.eventId == "evt1" } + argWhere { + it.target == "https://partner.traefik.me/_matrix/federation/v2/invite/room1/evt1" + } ) } @Test - @DisplayName("returns 500 and publishes a failure event when forwarding fails") - fun returns500AndPublishesFailureWhenSynapseUnreachable() { + @DisplayName("reports a failure for an outgoing invite against the mapped outgoing URL") + fun returns500AndPublishesFailureForOutgoingInvite() { val (adapter, server) = adapterWithServer() - server.expect(requestTo("http://synapse:8008/_matrix/federation/v2/invite/room1/evt1")) + server.expect(requestTo("https://partner.traefik.me/_matrix/federation/v2/invite/room1/evt1")) .andExpect(method(HttpMethod.PUT)) .andRespond(withServerError()) val response = adapter.forwardInvite( - "room1", "evt1", "/_matrix/federation/v2/invite/room1/evt1", "Bearer s3cret", inviteBody + "room1", + "evt1", + "/_matrix/federation/v2/invite/room1/evt1", + "partner.traefik.me", + "https://partner.traefik.me/_matrix/federation/v2/invite/room1/evt1", + null, + inviteBody ) assertEquals(500, response.statusCode.value()) server.verify() - verify(applicationEvents).publishEvent(any()) + verify(applicationEvents).publishEvent( + argWhere { + it.target == "https://partner.traefik.me/_matrix/federation/v2/invite/room1/evt1" + } + ) } }