Skip to content

Commit

Permalink
Merge pull request #5551 from nyaruka/fix-log-missing-response
Browse files Browse the repository at this point in the history
Fix displaying the log missing HTTP response
  • Loading branch information
rowanseymour authored Oct 16, 2024
2 parents 36b34ab + 99ca427 commit f8b59ae
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
4 changes: 3 additions & 1 deletion temba/channels/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -944,7 +944,9 @@ def get_display(self, *, anonymize: bool, urn) -> dict:
# out of an abundance of caution, check that we're not returning one of our own credential values
for log in data["http_logs"]:
for secret in self.channel.type.get_redact_values(self.channel):
assert secret not in log["url"] and secret not in log["request"] and secret not in log["response"]
assert (
secret not in log["url"] and secret not in log["request"] and secret not in log.get("response", "")
)

return data

Expand Down
26 changes: 18 additions & 8 deletions temba/channels/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -1451,16 +1451,25 @@ def test_get_display(self):
)

def test_get_display_timed_out(self):
channel = self.create_channel("TG", "Telegram", "mybot")
contact = self.create_contact("Fred Jones", urns=["telegram:74747474"])
channel = self.create_channel(
"D3C",
"360Dialog channel",
address="1234",
country="BR",
config={
Channel.CONFIG_BASE_URL: "https://waba-v2.360dialog.io",
Channel.CONFIG_AUTH_TOKEN: "123456789",
},
)
contact = self.create_contact("Bob", urns=["whatsapp:75757575"])
log = ChannelLog.objects.create(
channel=channel,
log_type=ChannelLog.LOG_TYPE_MSG_SEND,
is_error=True,
http_logs=[
{
"url": "https://telegram.com/send?to=74747474",
"request": 'POST https://telegram.com/send?to=74747474 HTTP/1.1\r\n\r\n{"to":"74747474"}',
"url": "https://waba-v2.360dialog.io/send?to=75757575",
"request": 'POST https://waba-v2.360dialog.io/send?to=75757575 HTTP/1.1\r\n\r\n{"to":"75757575"}',
"elapsed_ms": 30001,
"retries": 0,
"created_on": "2022-08-17T14:07:30Z",
Expand All @@ -1476,8 +1485,8 @@ def test_get_display_timed_out(self):
"type": "msg_send",
"http_logs": [
{
"url": "https://telegram.com/send?to=74747474",
"request": 'POST https://telegram.com/send?to=74747474 HTTP/1.1\r\n\r\n{"to":"74747474"}',
"url": "https://waba-v2.360dialog.io/send?to=75757575",
"request": 'POST https://waba-v2.360dialog.io/send?to=75757575 HTTP/1.1\r\n\r\n{"to":"75757575"}',
"elapsed_ms": 30001,
"retries": 0,
"created_on": "2022-08-17T14:07:30Z",
Expand All @@ -1489,14 +1498,15 @@ def test_get_display_timed_out(self):
},
log.get_display(anonymize=False, urn=msg_out.contact_urn),
)

self.assertEqual(
{
"uuid": str(log.uuid),
"type": "msg_send",
"http_logs": [
{
"url": "https://telegram.com/send?to=********",
"request": 'POST https://telegram.com/send?to=******** HTTP/1.1\r\n\r\n{"to":"********"}',
"url": "https://waba-v2.360dialog.io/send?to=********",
"request": 'POST https://waba-v2.360dialog.io/send?to=******** HTTP/1.1\r\n\r\n{"to":"********"}',
"response": "",
"elapsed_ms": 30001,
"retries": 0,
Expand Down

0 comments on commit f8b59ae

Please sign in to comment.