From 1964469b55f50effe0e5d164a0d04232441c2502 Mon Sep 17 00:00:00 2001 From: Shubham Tiwari Date: Thu, 9 Oct 2025 18:25:51 +0530 Subject: [PATCH 1/3] chore: remove auth from request.__str__() --- tests/unit/http/test_http_client.py | 20 ++++++++++++++++++++ twilio/http/request.py | 7 +------ 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/tests/unit/http/test_http_client.py b/tests/unit/http/test_http_client.py index 8484e57b17..5947182b6f 100644 --- a/tests/unit/http/test_http_client.py +++ b/tests/unit/http/test_http_client.py @@ -10,6 +10,7 @@ from twilio.base.version import Version from twilio.http.http_client import TwilioHttpClient from twilio.http.response import Response +from twilio.http.request import Request class TestHttpClientRequest(unittest.TestCase): @@ -293,6 +294,25 @@ def test_session_not_preserved(self): self.assertEqual(response_2.content, "response_2") +class TestTwilioRequest(unittest.TestCase): + def test_str(self): + + req = Request( + method="POST", + url="https://api.twilio.com/2010-04-01/Accounts.json", + auth=("AC123", "token"), + params={"PageSize": "1"}, + data={"FriendlyName": "My New Account"}, + headers={"X-Custom-Header": "Value"}, + ) + expected = ( + "POST https://api.twilio.com/2010-04-01/Accounts.json?PageSize=1\n" + " -d \"FriendlyName=My New Account\"\n" + " -H \"X-Custom-Header: Value\"" + ) + self.assertEqual(expected, req.__str__()) + + class MyVersion(Version): def __init__(self, domain): super().__init__(domain, "v1") diff --git a/twilio/http/request.py b/twilio/http/request.py index e75cf12b0d..9205dbc8ab 100644 --- a/twilio/http/request.py +++ b/twilio/http/request.py @@ -56,10 +56,6 @@ def __eq__(self, other) -> bool: ) def __str__(self) -> str: - auth = "" - if self.auth and self.auth != Match.ANY: - auth = "{} ".format(self.auth) - params = "" if self.params and self.params != Match.ANY: params = "?{}".format(urlencode(self.params, doseq=True)) @@ -78,8 +74,7 @@ def __str__(self) -> str: "\n".join(' -H "{}: {}"'.format(k, v) for k, v in self.headers.items()) ) - return "{auth}{method} {url}{params}{data}{headers}".format( - auth=auth, + return "{method} {url}{params}{data}{headers}".format( method=self.method, url=self.url, params=params, From 0b76acfd8c4c095cd5a3809f1ae3807b53863ca5 Mon Sep 17 00:00:00 2001 From: Shubham Tiwari Date: Thu, 9 Oct 2025 18:25:51 +0530 Subject: [PATCH 2/3] chore: remove auth from request.__str__() --- tests/unit/http/test_http_client.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/unit/http/test_http_client.py b/tests/unit/http/test_http_client.py index 5947182b6f..aa054dd557 100644 --- a/tests/unit/http/test_http_client.py +++ b/tests/unit/http/test_http_client.py @@ -307,8 +307,8 @@ def test_str(self): ) expected = ( "POST https://api.twilio.com/2010-04-01/Accounts.json?PageSize=1\n" - " -d \"FriendlyName=My New Account\"\n" - " -H \"X-Custom-Header: Value\"" + ' -d "FriendlyName=My New Account"\n' + ' -H "X-Custom-Header: Value"' ) self.assertEqual(expected, req.__str__()) From 183547d10fea6b74b658caf4bb2e5c60158581e1 Mon Sep 17 00:00:00 2001 From: Shubham Tiwari Date: Mon, 13 Oct 2025 16:06:21 +0530 Subject: [PATCH 3/3] chore: skip authorization key in headers --- tests/unit/http/test_http_client.py | 18 ++++++++++++++++++ twilio/http/request.py | 2 +- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/tests/unit/http/test_http_client.py b/tests/unit/http/test_http_client.py index aa054dd557..aa41045ea2 100644 --- a/tests/unit/http/test_http_client.py +++ b/tests/unit/http/test_http_client.py @@ -312,6 +312,24 @@ def test_str(self): ) self.assertEqual(expected, req.__str__()) + def test_str_excludes_authorization_header(self): + req = Request( + method="POST", + url="https://api.twilio.com/2010-04-01/Accounts.json", + params={"PageSize": "1"}, + data={"FriendlyName": "My New Account"}, + headers={ + "Authorization": "Bearer secret-token", + "X-Custom-Header": "Value" + }, + ) + expected = ( + "POST https://api.twilio.com/2010-04-01/Accounts.json?PageSize=1\n" + ' -d "FriendlyName=My New Account"\n' + ' -H "X-Custom-Header: Value"' + ) + self.assertEqual(expected, req.__str__()) + class MyVersion(Version): def __init__(self, domain): diff --git a/twilio/http/request.py b/twilio/http/request.py index 9205dbc8ab..2bb592fdb6 100644 --- a/twilio/http/request.py +++ b/twilio/http/request.py @@ -71,7 +71,7 @@ def __str__(self) -> str: headers = "" if self.headers and self.headers != Match.ANY: headers = "\n{}".format( - "\n".join(' -H "{}: {}"'.format(k, v) for k, v in self.headers.items()) + "\n".join(' -H "{}: {}"'.format(k, v) for k, v in self.headers.items() if k.lower() != "authorization") ) return "{method} {url}{params}{data}{headers}".format(