Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: aws path normalization in windows #842

Merged
merged 2 commits into from Aug 17, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 6 additions & 1 deletion google/auth/aws.py
Expand Up @@ -45,6 +45,7 @@
import os
import re
import urllib
from urllib.parse import urljoin

from google.auth import _helpers
from google.auth import environment_vars
Expand Down Expand Up @@ -112,13 +113,17 @@ def get_request_options(
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,
Expand Down