Skip to content

Commit

Permalink
Set SanitizedResponse content to bytes instead of string
Browse files Browse the repository at this point in the history
The `content` property of a `Response` object is expected to always be
bytes (the `text` property should be a string).

This change fixes an issue where consumers of the library that were
returned a `SanitizedResponse` object could fail because they expected
the `content` attribute of it to be bytes instead of a string.

Signed-off-by: Carey Metcalfe <[email protected]>
  • Loading branch information
pR0Ps authored and jborean93 committed Feb 16, 2024
1 parent 84e052b commit f978789
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion requests_gssapi/gssapi_.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def __init__(self, response):
self.connection = response.connection
self._content_consumed = True

self._content = ""
self._content = b""
self.cookies = cookiejar_from_dict({})
self.headers = CaseInsensitiveDict()
self.headers['content-length'] = '0'
Expand Down
13 changes: 7 additions & 6 deletions test_requests_gssapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ def test_authenticate_user(self):
response.headers = {'www-authenticate': b64_negotiate_token}
response.status_code = 401
response.connection = connection
response._content = ""
response._content = b""
response.raw = raw
auth = requests_gssapi.HTTPKerberosAuth()
r = auth.authenticate_user(response)
Expand Down Expand Up @@ -201,7 +201,7 @@ def test_handle_401(self):
response.headers = {'www-authenticate': b64_negotiate_token}
response.status_code = 401
response.connection = connection
response._content = ""
response._content = b""
response.raw = raw
auth = requests_gssapi.HTTPKerberosAuth()
r = auth.handle_401(response)
Expand Down Expand Up @@ -375,7 +375,8 @@ def test_handle_response_500_mutual_auth_required_failure(self):
self.assertEqual(r.url, response_500.url)
self.assertEqual(r.reason, response_500.reason)
self.assertEqual(r.connection, response_500.connection)
self.assertEqual(r.content, '')
self.assertEqual(r.content, b"")
self.assertEqual(r.text, "")
self.assertNotEqual(r.cookies, response_500.cookies)

self.assertFalse(fail_resp.called)
Expand Down Expand Up @@ -436,7 +437,7 @@ def test_handle_response_401(self):
response.headers = {'www-authenticate': b64_negotiate_token}
response.status_code = 401
response.connection = connection
response._content = ""
response._content = b""
response.raw = raw

auth = requests_gssapi.HTTPKerberosAuth()
Expand Down Expand Up @@ -482,7 +483,7 @@ def connection_send(self, *args, **kwargs):
response.headers = {'www-authenticate': b64_negotiate_token}
response.status_code = 401
response.connection = connection
response._content = ""
response._content = b""
response.raw = raw

auth = requests_gssapi.HTTPKerberosAuth()
Expand Down Expand Up @@ -534,7 +535,7 @@ def test_delegation(self):
response.headers = {'www-authenticate': b64_negotiate_token}
response.status_code = 401
response.connection = connection
response._content = ""
response._content = b""
response.raw = raw
auth = requests_gssapi.HTTPKerberosAuth(service="HTTP",
delegate=True)
Expand Down

0 comments on commit f978789

Please sign in to comment.