Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
ccd64b9
Add tests
mccoyp Sep 12, 2024
34fcfed
Implement CAE support
mccoyp Sep 12, 2024
d07e0a5
Share implementation across libraries
mccoyp Sep 13, 2024
84351af
Enable CAE; provide claims only in challenges
mccoyp Sep 18, 2024
c22cb08
Update tests for success scenarios
mccoyp Sep 19, 2024
d854071
Handle non-consecutive challenges (in Keys)
mccoyp Sep 19, 2024
6c19bbc
Cover invalid challenge flows
mccoyp Sep 20, 2024
c919056
Handle (in)valid challenge flows
mccoyp Sep 20, 2024
ff731e8
Share updates across libraries
mccoyp Sep 20, 2024
237c57b
Fix spelling, pylint
mccoyp Sep 20, 2024
013673b
Update changelogs
mccoyp Sep 26, 2024
5da13ff
Update tests for feedback
mccoyp Sep 26, 2024
36cb9fd
Use super() instead of private attribute
mccoyp Sep 26, 2024
f9ff176
Add live test; assert scope
mccoyp Sep 26, 2024
bf8f054
Fix auth policy to send scope correctly
mccoyp Sep 26, 2024
850e6e8
Async tests; sync challenge policy code
mccoyp Sep 26, 2024
e78d4e9
Ensure no re-sending claims in tests
mccoyp Oct 3, 2024
1a6c9f7
Fix policy to handle KV -> KV challenge
mccoyp Oct 3, 2024
3fad4db
Share bug fix across libraries
mccoyp Oct 3, 2024
ba2a954
Clarify test variable names
mccoyp Oct 4, 2024
92c6704
Correctly handle token refreshes
mccoyp Oct 5, 2024
8e65726
Bump Core dep for SupportsTokenInfo protocol support
mccoyp Oct 8, 2024
93c7eaa
(Async)SupportsTokenInfo support/tests
mccoyp Oct 8, 2024
bf25378
Pylint
mccoyp Oct 8, 2024
3cb6481
Mention Core bump, enable_cae kwarg in changelogs
mccoyp Oct 16, 2024
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
Prev Previous commit
Next Next commit
Add live test; assert scope
  • Loading branch information
mccoyp committed Oct 7, 2024
commit f9ff1765c092bf29ad593e338d6db94ba9b4e20f
36 changes: 32 additions & 4 deletions sdk/keyvault/azure-keyvault-keys/tests/test_challenge_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
from devtools_testutils import recorded_by_proxy

import pytest
from azure.core.credentials import AccessToken
from azure.core.exceptions import ServiceRequestError
from azure.core.credentials import AccessToken, TokenCredential
from azure.core.exceptions import ClientAuthenticationError, ServiceRequestError
from azure.core.pipeline import Pipeline
from azure.core.pipeline.policies import SansIOHTTPPolicy
from azure.core.rest import HttpRequest
Expand Down Expand Up @@ -69,6 +69,32 @@ def test_multitenant_authentication(self, client, is_hsm, **kwargs):
else:
os.environ.pop("AZURE_TENANT_ID")

@pytest.mark.skip("Manual test for specific, CAE-enabled environments.")
@pytest.mark.live_test_only
def test_cae_live(self, **kwargs):
class CredentialWrapper(TokenCredential):
def __init__(self, credential):
self._credential = credential
self._claims = None

def get_token(self, *scopes, **kwargs):
assert kwargs["enable_cae"] == True
if kwargs.get("claims"):
# We should only receive claims once; subsequent challenges should be returned to the caller
assert self._claims is None
self._claims = kwargs["claims"]
return self._credential.get_token(*scopes, **kwargs)

credential = self.get_credential(KeyClient)
wrapped = CredentialWrapper(credential)
client = KeyClient(vault_url=os.environ["AZURE_KEYVAULT_URL"], credential=wrapped)
try:
client.create_rsa_key("key-name") # Basic request meant to just trigger CAE challenges
# Test environment may continuously return claims challenges; a second consecutive challenge will raise
except ClientAuthenticationError as e:
assert "continuous access evaluation" in str(e).lower()
assert wrapped._claims is not None # Ensure we passed a claim to a token request

def empty_challenge_cache(fn):
@functools.wraps(fn)
def wrapper(**kwargs):
Expand Down Expand Up @@ -588,9 +614,10 @@ def send(request):
return kv_challenge
raise ValueError("unexpected request")

def get_token(*_, **kwargs):
def get_token(*scopes, **kwargs):
assert kwargs.get("enable_cae") == True
assert kwargs.get("tenant_id") == tenant
assert scopes[0] == resource + "/.default"
# Response to KV challenge
if Requests.count == 1:
assert kwargs.get("claims") == None
Expand Down Expand Up @@ -669,9 +696,10 @@ def send(request):
return claims_challenge
raise ValueError("unexpected request")

def get_token(*_, **kwargs):
def get_token(*scopes, **kwargs):
assert kwargs.get("enable_cae") == True
assert kwargs.get("tenant_id") == tenant
assert scopes[0] == resource + "/.default"
# Response to KV challenge
if Requests.count == 1:
assert kwargs.get("claims") == None
Expand Down