Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 36 additions & 22 deletions autotest/gcore/vsiaz.py
Original file line number Diff line number Diff line change
Expand Up @@ -2397,29 +2397,25 @@ def test_vsiaz_imds_authentication_expiration():
):

handler = webserver.SequentialHandler()
handler.add(
"GET",
"/metadata/identity/oauth2/token?api-version=2018-02-01&resource=https%3A%2F%2Fstorage.azure.com%2F",
200,
{},
"""{
"access_token": "my_bearer",
"expires_on": "1000",
}""",
expected_headers={"Metadata": "true"},
)

def add_get_token():
handler.add(
"GET",
"/metadata/identity/oauth2/token?api-version=2018-02-01&resource=https%3A%2F%2Fstorage.azure.com%2F",
200,
{},
"""{
"access_token": "my_bearer",
"expires_on": "1000",
}""",
expected_headers={"Metadata": "true"},
)

add_get_token()
# Credentials requested again since they are expired
handler.add(
"GET",
"/metadata/identity/oauth2/token?api-version=2018-02-01&resource=https%3A%2F%2Fstorage.azure.com%2F",
200,
{},
"""{
"access_token": "my_bearer",
"expires_on": "1000",
}""",
expected_headers={"Metadata": "true"},
)
add_get_token()
add_get_token()
add_get_token()
handler.add(
"GET",
"/azure/blob/myaccount/az_fake_bucket/resource",
Expand Down Expand Up @@ -2723,6 +2719,24 @@ def test_vsiaz_workload_identity_managed_authentication_expiration():
expected_headers={"Content-Type": "application/x-www-form-urlencoded"},
expected_body=b"client_assertion=content_of_AZURE_FEDERATED_TOKEN_FILE&client_assertion_type=urn:ietf:params:oauth:client-assertion-type:jwt-bearer&client_id=client_id_value&grant_type=client_credentials&scope=https://storage.azure.com/.default",
)
handler.add(
"POST",
"/tenant_id/oauth2/v2.0/token",
200,
{},
"""{"access_token": "my_bearer2", "expires_in": "10"}""",
expected_headers={"Content-Type": "application/x-www-form-urlencoded"},
expected_body=b"client_assertion=content_of_AZURE_FEDERATED_TOKEN_FILE&client_assertion_type=urn:ietf:params:oauth:client-assertion-type:jwt-bearer&client_id=client_id_value&grant_type=client_credentials&scope=https://storage.azure.com/.default",
)
handler.add(
"POST",
"/tenant_id/oauth2/v2.0/token",
200,
{},
"""{"access_token": "my_bearer2", "expires_in": "10"}""",
expected_headers={"Content-Type": "application/x-www-form-urlencoded"},
expected_body=b"client_assertion=content_of_AZURE_FEDERATED_TOKEN_FILE&client_assertion_type=urn:ietf:params:oauth:client-assertion-type:jwt-bearer&client_id=client_id_value&grant_type=client_credentials&scope=https://storage.azure.com/.default",
)

handler.add(
"GET",
Expand Down
43 changes: 20 additions & 23 deletions autotest/gcore/vsigs.py
Original file line number Diff line number Diff line change
Expand Up @@ -1786,30 +1786,27 @@ def method(request):
request.wfile.write("""foo""".encode("ascii"))

handler = webserver.SequentialHandler()

def add_get_token():
handler.add(
"GET",
"/computeMetadata/v1/instance/service-accounts/default/token",
200,
{},
"""{
"access_token" : "ACCESS_TOKEN",
"token_type" : "Bearer",
"expires_in" : 0,
}""",
)

# First time is used when trying to establish if GCE authentication is available
handler.add(
"GET",
"/computeMetadata/v1/instance/service-accounts/default/token",
200,
{},
"""{
"access_token" : "ACCESS_TOKEN",
"token_type" : "Bearer",
"expires_in" : 0,
}""",
)
# Second time is needed because f the access to th file
handler.add(
"GET",
"/computeMetadata/v1/instance/service-accounts/default/token",
200,
{},
"""{
"access_token" : "ACCESS_TOKEN",
"token_type" : "Bearer",
"expires_in" : 0,
}""",
)
add_get_token()
# Second time is needed because of the access to the file
add_get_token()
# A couple more because VSICurlFilesystemHandlerBase::Open() use GetURLFromFilename()
add_get_token()
add_get_token()
handler.add("GET", "/gs_fake_bucket/resource", custom_method=method)
with webserver.install_http_handler(handler):
f = open_for_read("/vsigs/gs_fake_bucket/resource")
Expand Down
Loading
Loading