fix: always pass body of type bytes to `google.auth.transport.Request` (#421)
[`google.auth.transport.Request`](https://google-auth.readthedocs.io/en/latest/reference/google.auth.transport.html#google.auth.transport.Request) says that the body should be of type bytes. Some of our code was passing in strings as reported in #318.
In practice this was not causing issues, as the two http transports [requests](https://google-auth.readthedocs.io/en/latest/reference/google.auth.transport.requests.html) and [urllib3](https://google-auth.readthedocs.io/en/latest/reference/google.auth.transport.urllib3.html) are able to handle bodies passed as strings.
diff --git a/tests/oauth2/test__client.py b/tests/oauth2/test__client.py
index 9cf59eb..052390a 100644
--- a/tests/oauth2/test__client.py
+++ b/tests/oauth2/test__client.py
@@ -96,7 +96,7 @@
method="POST",
url="http://example.com",
headers={"content-type": "application/x-www-form-urlencoded"},
- body="test=params",
+ body="test=params".encode("utf-8"),
)
# Check result
@@ -131,7 +131,7 @@
def verify_request_params(request, params):
- request_body = request.call_args[1]["body"]
+ request_body = request.call_args[1]["body"].decode("utf-8")
request_params = urllib.parse.parse_qs(request_body)
for key, value in six.iteritems(params):