From 0f4ec63a9f5a61eeb80c97338c476feba088fb0e Mon Sep 17 00:00:00 2001 From: Marie PUPO JEAMMET Date: Tue, 1 Jul 2025 19:11:03 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B(webhooks)=20fix=20special=20case?= =?UTF-8?q?=20for=20tchap=20integration?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit we want to use Tchap integration server for our own preprod but it doesn't follow the same url naming convention as the other Tchap instances, so it requires a special treatment. This quick fix should do it. --- src/backend/core/tests/utils/test_webhooks_matrix_client.py | 3 +++ src/backend/core/utils/matrix.py | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/backend/core/tests/utils/test_webhooks_matrix_client.py b/src/backend/core/tests/utils/test_webhooks_matrix_client.py index d4b8aac..3503faf 100644 --- a/src/backend/core/tests/utils/test_webhooks_matrix_client.py +++ b/src/backend/core/tests/utils/test_webhooks_matrix_client.py @@ -230,6 +230,9 @@ def test_matrix_webhook__override_secret_for_tchap(): headers = responses.calls[0].request.headers assert "TCHAP_TOKEN" in headers["Authorization"] + # Check correctly inferred base url from room_id + assert "matrix.home_server" in responses.calls[0].request.url + ## KICK @responses.activate diff --git a/src/backend/core/utils/matrix.py b/src/backend/core/utils/matrix.py index 4cacd30..70223a1 100644 --- a/src/backend/core/utils/matrix.py +++ b/src/backend/core/utils/matrix.py @@ -45,7 +45,7 @@ class MatrixAPIClient: """Returns room id from webhook url.""" room_id = webhook_url.split("/room/")[1] base_url = room_id.split(":")[1] - if "tchap.gouv.fr" in webhook_url: + if "tchap.gouv.fr" in webhook_url and "i.tchap.gouv.fr" not in webhook_url: base_url = f"matrix.{base_url}" return f"https://{base_url}/_matrix/client/v3/rooms/{room_id}"