mirror of
https://github.com/encounter/adk-python.git
synced 2026-07-09 18:19:28 -07:00
chore: Add base credential service interface (WIP)
PiperOrigin-RevId: 771358480
This commit is contained in:
committed by
Copybara-Service
parent
b51a1f45fd
commit
8ebf229c47
@@ -68,10 +68,28 @@ def auth_config(oauth2_auth_scheme, oauth2_credentials):
|
||||
)
|
||||
|
||||
|
||||
def test_get_credential_key(auth_config):
|
||||
@pytest.fixture
|
||||
def auth_config_with_key(oauth2_auth_scheme, oauth2_credentials):
|
||||
"""Create an AuthConfig for testing."""
|
||||
|
||||
return AuthConfig(
|
||||
auth_scheme=oauth2_auth_scheme,
|
||||
raw_auth_credential=oauth2_credentials,
|
||||
credential_key="test_key",
|
||||
)
|
||||
|
||||
|
||||
def test_custom_credential_key(auth_config_with_key):
|
||||
"""Test using custom credential key."""
|
||||
|
||||
key = auth_config_with_key.credential_key
|
||||
assert key == "test_key"
|
||||
|
||||
|
||||
def test_credential_key(auth_config):
|
||||
"""Test generating a unique credential key."""
|
||||
|
||||
key = auth_config.get_credential_key()
|
||||
key = auth_config.credential_key
|
||||
assert key.startswith("adk_oauth2_")
|
||||
assert "_oauth2_" in key
|
||||
|
||||
@@ -80,8 +98,8 @@ def test_get_credential_key_with_extras(auth_config):
|
||||
"""Test generating a key when model_extra exists."""
|
||||
# Add model_extra to test cleanup
|
||||
|
||||
original_key = auth_config.get_credential_key()
|
||||
key = auth_config.get_credential_key()
|
||||
original_key = auth_config.credential_key
|
||||
key = auth_config.credential_key
|
||||
|
||||
auth_config.auth_scheme.model_extra["extra_field"] = "value"
|
||||
auth_config.raw_auth_credential.model_extra["extra_field"] = "value"
|
||||
|
||||
@@ -387,7 +387,7 @@ class TestGetAuthResponse:
|
||||
state = MockState()
|
||||
|
||||
# Store a credential in the state
|
||||
credential_key = auth_config.get_credential_key()
|
||||
credential_key = auth_config.credential_key
|
||||
state["temp:" + credential_key] = oauth2_credentials_with_auth_uri
|
||||
|
||||
result = handler.get_auth_response(state)
|
||||
@@ -418,7 +418,7 @@ class TestParseAndStoreAuthResponse:
|
||||
|
||||
handler.parse_and_store_auth_response(state)
|
||||
|
||||
credential_key = auth_config.get_credential_key()
|
||||
credential_key = auth_config.credential_key
|
||||
assert (
|
||||
state["temp:" + credential_key] == auth_config.exchanged_auth_credential
|
||||
)
|
||||
@@ -436,7 +436,7 @@ class TestParseAndStoreAuthResponse:
|
||||
|
||||
handler.parse_and_store_auth_response(state)
|
||||
|
||||
credential_key = auth_config_with_exchanged.get_credential_key()
|
||||
credential_key = auth_config_with_exchanged.credential_key
|
||||
assert state["temp:" + credential_key] == mock_exchange_token.return_value
|
||||
assert mock_exchange_token.called
|
||||
|
||||
|
||||
Reference in New Issue
Block a user