Skip to content

Commit 183547d

Browse files
chore: skip authorization key in headers
1 parent 0b76acf commit 183547d

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

tests/unit/http/test_http_client.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,24 @@ def test_str(self):
312312
)
313313
self.assertEqual(expected, req.__str__())
314314

315+
def test_str_excludes_authorization_header(self):
316+
req = Request(
317+
method="POST",
318+
url="https://api.twilio.com/2010-04-01/Accounts.json",
319+
params={"PageSize": "1"},
320+
data={"FriendlyName": "My New Account"},
321+
headers={
322+
"Authorization": "Bearer secret-token",
323+
"X-Custom-Header": "Value"
324+
},
325+
)
326+
expected = (
327+
"POST https://api.twilio.com/2010-04-01/Accounts.json?PageSize=1\n"
328+
' -d "FriendlyName=My New Account"\n'
329+
' -H "X-Custom-Header: Value"'
330+
)
331+
self.assertEqual(expected, req.__str__())
332+
315333

316334
class MyVersion(Version):
317335
def __init__(self, domain):

twilio/http/request.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def __str__(self) -> str:
7171
headers = ""
7272
if self.headers and self.headers != Match.ANY:
7373
headers = "\n{}".format(
74-
"\n".join(' -H "{}: {}"'.format(k, v) for k, v in self.headers.items())
74+
"\n".join(' -H "{}: {}"'.format(k, v) for k, v in self.headers.items() if k.lower() != "authorization")
7575
)
7676

7777
return "{method} {url}{params}{data}{headers}".format(

0 commit comments

Comments
 (0)