-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add default impl to handle token challenges (#37652)
* Add default impl to handle token challenges * update version * update * update * update * update * Update sdk/core/azure-core/azure/core/pipeline/policies/_utils.py Co-authored-by: Paul Van Eck <[email protected]> * Update sdk/core/azure-core/azure/core/pipeline/policies/_utils.py Co-authored-by: Paul Van Eck <[email protected]> * update * Update sdk/core/azure-core/tests/test_utils.py Co-authored-by: Paul Van Eck <[email protected]> * Update sdk/core/azure-core/azure/core/pipeline/policies/_utils.py Co-authored-by: Paul Van Eck <[email protected]> * update --------- Co-authored-by: Paul Van Eck <[email protected]>
- Loading branch information
1 parent
37a2e61
commit 55632a7
Showing
6 changed files
with
225 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,7 @@ | |
import pytest | ||
from azure.core.utils import case_insensitive_dict | ||
from azure.core.utils._utils import get_running_async_lock | ||
from azure.core.pipeline.policies._utils import parse_retry_after | ||
from azure.core.pipeline.policies._utils import parse_retry_after, get_challenge_parameter | ||
|
||
|
||
@pytest.fixture() | ||
|
@@ -146,3 +146,58 @@ def test_parse_retry_after(): | |
assert ret == 0 | ||
ret = parse_retry_after("0.9") | ||
assert ret == 0.9 | ||
|
||
|
||
def test_get_challenge_parameter(): | ||
headers = { | ||
"WWW-Authenticate": 'Bearer authorization_uri="https://login.microsoftonline.com/tenant-id", resource="https://vault.azure.net"' | ||
} | ||
assert ( | ||
get_challenge_parameter(headers, "Bearer", "authorization_uri") == "https://login.microsoftonline.com/tenant-id" | ||
) | ||
assert get_challenge_parameter(headers, "Bearer", "resource") == "https://vault.azure.net" | ||
assert get_challenge_parameter(headers, "Bearer", "foo") is None | ||
|
||
headers = { | ||
"WWW-Authenticate": 'Bearer realm="", authorization_uri="https://login.microsoftonline.com/common/oauth2/authorize", error="insufficient_claims", claims="eyJhY2Nlc3NfdG9rZW4iOnsibmJmIjp7ImVzc2VudGlhbCI6dHJ1ZSwidmFsdWUiOiIxNzI2MDc3NTk1In0sInhtc19jYWVlcnJvciI6eyJ2YWx1ZSI6IjEwMDEyIn19fQ=="' | ||
} | ||
assert ( | ||
get_challenge_parameter(headers, "Bearer", "authorization_uri") | ||
== "https://login.microsoftonline.com/common/oauth2/authorize" | ||
) | ||
assert get_challenge_parameter(headers, "Bearer", "error") == "insufficient_claims" | ||
assert ( | ||
get_challenge_parameter(headers, "Bearer", "claims") | ||
== "eyJhY2Nlc3NfdG9rZW4iOnsibmJmIjp7ImVzc2VudGlhbCI6dHJ1ZSwidmFsdWUiOiIxNzI2MDc3NTk1In0sInhtc19jYWVlcnJvciI6eyJ2YWx1ZSI6IjEwMDEyIn19fQ==" | ||
) | ||
|
||
|
||
def test_get_challenge_parameter_not_found(): | ||
headers = { | ||
"WWW-Authenticate": 'Pop authorization_uri="https://login.microsoftonline.com/tenant-id", resource="https://vault.azure.net"' | ||
} | ||
assert get_challenge_parameter(headers, "Bearer", "resource") is None | ||
|
||
|
||
def test_get_multi_challenge_parameter(): | ||
headers = { | ||
"WWW-Authenticate": 'Bearer authorization_uri="https://login.microsoftonline.com/tenant-id", resource="https://vault.azure.net" Bearer authorization_uri="https://login.microsoftonline.com/tenant-id", resource="https://vault.azure.net"' | ||
} | ||
assert ( | ||
get_challenge_parameter(headers, "Bearer", "authorization_uri") == "https://login.microsoftonline.com/tenant-id" | ||
) | ||
assert get_challenge_parameter(headers, "Bearer", "resource") == "https://vault.azure.net" | ||
assert get_challenge_parameter(headers, "Bearer", "foo") is None | ||
|
||
headers = { | ||
"WWW-Authenticate": 'Digest realm="[email protected]", qop="auth,auth-int", nonce="123456abcdefg", opaque="123456", Bearer realm="", authorization_uri="https://login.microsoftonline.com/common/oauth2/authorize", error="insufficient_claims", claims="eyJhY2Nlc3NfdG9rZW4iOnsibmJmIjp7ImVzc2VudGlhbCI6dHJ1ZSwidmFsdWUiOiIxNzI2MDc3NTk1In0sInhtc19jYWVlcnJvciI6eyJ2YWx1ZSI6IjEwMDEyIn19fQ=="' | ||
} | ||
assert ( | ||
get_challenge_parameter(headers, "Bearer", "authorization_uri") | ||
== "https://login.microsoftonline.com/common/oauth2/authorize" | ||
) | ||
assert get_challenge_parameter(headers, "Bearer", "error") == "insufficient_claims" | ||
assert ( | ||
get_challenge_parameter(headers, "Bearer", "claims") | ||
== "eyJhY2Nlc3NfdG9rZW4iOnsibmJmIjp7ImVzc2VudGlhbCI6dHJ1ZSwidmFsdWUiOiIxNzI2MDc3NTk1In0sInhtc19jYWVlcnJvciI6eyJ2YWx1ZSI6IjEwMDEyIn19fQ==" | ||
) |