🐛(webhook) fix error raised when no secret
Our Tchap webhook contains no secret (as a dedicated access token is provided) This lead to an error upon trying to join rooms.
This commit is contained in:
committed by
Marie
parent
f30398fbc7
commit
10dcdfc8c2
@@ -138,7 +138,7 @@ def test_matrix_webhook__override_secret_for_tchap():
|
|||||||
webhook = factories.TeamWebhookFactory(
|
webhook = factories.TeamWebhookFactory(
|
||||||
protocol=WebhookProtocolChoices.MATRIX,
|
protocol=WebhookProtocolChoices.MATRIX,
|
||||||
url="https://www.tchap.gouv.fr/#/room/room_id:home_server",
|
url="https://www.tchap.gouv.fr/#/room/room_id:home_server",
|
||||||
secret="secret-about-to-be-overridden",
|
secret=None,
|
||||||
)
|
)
|
||||||
|
|
||||||
# Mock successful responses
|
# Mock successful responses
|
||||||
|
|||||||
@@ -34,9 +34,12 @@ class MatrixAPIClient:
|
|||||||
def get_headers(self, webhook):
|
def get_headers(self, webhook):
|
||||||
"""Build header dict from webhook object."""
|
"""Build header dict from webhook object."""
|
||||||
headers = {"Content-Type": "application/json"}
|
headers = {"Content-Type": "application/json"}
|
||||||
token = webhook.secret if webhook.secret else None
|
|
||||||
if "tchap.gouv.fr" in webhook.url:
|
if "tchap.gouv.fr" in webhook.url:
|
||||||
token = settings.TCHAP_ACCESS_TOKEN
|
token = settings.TCHAP_ACCESS_TOKEN
|
||||||
|
elif webhook.secret:
|
||||||
|
token = webhook.secret
|
||||||
|
else:
|
||||||
|
raise ValueError("Please configure this webhook's secret access token.")
|
||||||
headers["Authorization"] = f"Bearer {token}"
|
headers["Authorization"] = f"Bearer {token}"
|
||||||
return headers
|
return headers
|
||||||
|
|
||||||
@@ -58,9 +61,6 @@ class MatrixAPIClient:
|
|||||||
def join_room(self, webhook):
|
def join_room(self, webhook):
|
||||||
"""Accept invitation to the room. As of today, it is a mandatory step
|
"""Accept invitation to the room. As of today, it is a mandatory step
|
||||||
to make sure our account will be able to invite/remove users."""
|
to make sure our account will be able to invite/remove users."""
|
||||||
if webhook.secret is None:
|
|
||||||
raise ValueError("Please configure this webhook's secret access token.")
|
|
||||||
|
|
||||||
return session.post(
|
return session.post(
|
||||||
f"{self._get_room_url(webhook.url)}/join",
|
f"{self._get_room_url(webhook.url)}/join",
|
||||||
json={},
|
json={},
|
||||||
|
|||||||
Reference in New Issue
Block a user