diff options
author | bojeil-google <bojeil-google@users.noreply.github.com> | 2021-08-17 15:56:39 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-08-17 15:56:39 -0700 |
commit | 4e0fb1cee78ee56b878b6e12be3b3c58df242b05 (patch) | |
tree | a90eff5981def0c40403685d5bedc4a015ca8248 | |
parent | 71cb0118419ba07d386199befa3ac2efd9cdad3b (diff) | |
download | google-auth-library-python-4e0fb1cee78ee56b878b6e12be3b3c58df242b05.tar.gz |
fix: aws path normalization in windows (#842)
Path normalization for the canonical_uri was broken in windows.
This is because we were using `os.path.normpath`.
This normalizes "/" paths to "\\" in Windows OS.
Confirmed the fix is working in Windows.
-rw-r--r-- | google/auth/aws.py | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/google/auth/aws.py b/google/auth/aws.py index 2f2a135..c8deee7 100644 --- a/google/auth/aws.py +++ b/google/auth/aws.py @@ -45,6 +45,7 @@ import json import os import re import urllib +from urllib.parse import urljoin from google.auth import _helpers from google.auth import environment_vars @@ -112,13 +113,17 @@ class RequestSigner(object): additional_headers = additional_headers or {} uri = urllib.parse.urlparse(url) + # Normalize the URL path. This is needed for the canonical_uri. + # os.path.normpath can't be used since it normalizes "/" paths + # to "\\" in Windows OS. + normalized_uri = urllib.parse.urlparse(urljoin(url, uri.path)) # Validate provided URL. if not uri.hostname or uri.scheme != "https": raise ValueError("Invalid AWS service URL") header_map = _generate_authentication_header_map( host=uri.hostname, - canonical_uri=os.path.normpath(uri.path or "/"), + canonical_uri=normalized_uri.path or "/", canonical_querystring=_get_canonical_querystring(uri.query), method=method, region=self._region_name, |