-
Notifications
You must be signed in to change notification settings - Fork 2.6k
fix #3845 #3847
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
Open
guillaumeblaquiere
wants to merge
18
commits into
google:main
Choose a base branch
from
guillaumeblaquiere:fix-3845
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
fix #3845 #3847
Changes from 11 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
006d547
fix: solve #3845
guillaumeblaquiere b6cb922
chore: autoformat
guillaumeblaquiere 5e7effb
Merge branch 'main' into fix-3845
guillaumeblaquiere a4fb713
Update src/google/adk/auth/auth_tool.py
guillaumeblaquiere f339c50
Update src/google/adk/auth/credential_manager.py
guillaumeblaquiere 752d42d
Merge branch 'main' into fix-3845
guillaumeblaquiere 4636a5b
fix: with gemini recommendation
guillaumeblaquiere 9e8d85d
test: add new test
guillaumeblaquiere 428cd57
Update src/google/adk/auth/credential_manager.py
guillaumeblaquiere facc6f4
fix: move import to the top
guillaumeblaquiere 962dcde
fix: follow gemini advices
guillaumeblaquiere 2e01565
Update src/google/adk/auth/credential_manager.py
guillaumeblaquiere 65c40e5
fix: local import to avoid circular dependencies
guillaumeblaquiere adb85b7
Merge branch 'main' into fix-3845
guillaumeblaquiere 63830a6
Merge branch 'main' into fix-3845
guillaumeblaquiere d6a049d
fix: test
guillaumeblaquiere ee9b052
Merge branch 'main' into fix-3845
guillaumeblaquiere 34ae26a
Merge branch 'main' into fix-3845
guillaumeblaquiere File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -0,0 +1,131 @@ | ||
| # Copyright 2025 Google LLC | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| import unittest | ||
| from unittest.mock import AsyncMock | ||
| from unittest.mock import MagicMock | ||
| from unittest.mock import Mock | ||
| from unittest.mock import patch | ||
|
|
||
| from google.adk.auth.auth_credential import AuthCredential | ||
| from google.adk.auth.auth_credential import AuthCredentialTypes | ||
| from google.adk.auth.auth_credential import OAuth2Auth | ||
| from google.adk.auth.auth_handler import AuthHandler | ||
| from google.adk.auth.auth_tool import AuthConfig | ||
| from google.adk.auth.credential_manager import CredentialManager | ||
| import pytest | ||
|
|
||
|
|
||
| class TestAuthHandlerSecrets: | ||
|
|
||
| @pytest.fixture(autouse=True) | ||
| def clear_credential_manager_secrets(self): | ||
| """Clear CredentialManager secrets buffer before/after each test.""" | ||
| CredentialManager._CLIENT_SECRETS = {} | ||
| yield | ||
| CredentialManager._CLIENT_SECRETS = {} | ||
|
|
||
|
|
||
| @pytest.mark.asyncio | ||
| async def test_exchange_auth_token_restores_and_reredacts_secret(self): | ||
| client_id = "test_client_id" | ||
| secret = "super_secret_value" | ||
|
|
||
| # Setup secure storage | ||
| CredentialManager._CLIENT_SECRETS[client_id] = secret | ||
|
|
||
| # Create credential with redacted secret | ||
| credential = AuthCredential( | ||
| auth_type=AuthCredentialTypes.OAUTH2, | ||
| oauth2=OAuth2Auth(client_id=client_id, client_secret="<redacted>"), | ||
| ) | ||
|
|
||
| auth_config = Mock(spec=AuthConfig) | ||
| auth_config.exchanged_auth_credential = credential | ||
| auth_config.auth_scheme = Mock() | ||
|
|
||
| handler = AuthHandler(auth_config) | ||
|
|
||
| # Mock exchanger | ||
| mock_exchanger = AsyncMock() | ||
|
|
||
| # Check secret inside exchange | ||
| def check_secret(cred, scheme): | ||
| assert cred.oauth2.client_secret == secret | ||
| return cred | ||
|
|
||
| mock_exchanger.exchange.side_effect = check_secret | ||
|
|
||
| with patch( | ||
| "google.adk.auth.auth_handler.OAuth2CredentialExchanger", | ||
| return_value=mock_exchanger, | ||
| ): | ||
| await handler.exchange_auth_token() | ||
|
|
||
| # Verify secret is re-redacted | ||
| assert credential.oauth2.client_secret == "<redacted>" | ||
|
|
||
| def test_generate_auth_uri_uses_restored_secret(self): | ||
| client_id = "test_client_id" | ||
| secret = "super_secret_value" | ||
|
|
||
| # Setup secure storage | ||
| CredentialManager._CLIENT_SECRETS[client_id] = secret | ||
|
|
||
| # Create credential with redacted secret | ||
| credential = AuthCredential( | ||
| auth_type=AuthCredentialTypes.OAUTH2, | ||
| oauth2=OAuth2Auth( | ||
| client_id=client_id, | ||
| client_secret="<redacted>", | ||
| redirect_uri="http://localhost/callback", | ||
| ), | ||
| ) | ||
|
|
||
| auth_config = Mock(spec=AuthConfig) | ||
| auth_config.raw_auth_credential = credential | ||
| auth_config.auth_scheme = Mock() | ||
| # Mock flows for scopes | ||
| auth_config.auth_scheme.flows.implicit = None | ||
| auth_config.auth_scheme.flows.clientCredentials = None | ||
| auth_config.auth_scheme.flows.password = None | ||
| auth_config.auth_scheme.flows.authorizationCode.scopes = {"scope": "desc"} | ||
| auth_config.auth_scheme.flows.authorizationCode.authorizationUrl = ( | ||
| "http://auth" | ||
| ) | ||
|
|
||
| handler = AuthHandler(auth_config) | ||
|
|
||
| # Mock OAuth2Session | ||
| with ( | ||
| patch("google.adk.auth.auth_handler.OAuth2Session") as mock_session_cls, | ||
| patch("google.adk.auth.auth_handler.AUTHLIB_AVAILABLE", True), | ||
| ): | ||
|
|
||
| mock_session = Mock() | ||
| mock_session.create_authorization_url.return_value = ( | ||
| "http://auth?param=1", | ||
| "state", | ||
| ) | ||
| mock_session_cls.return_value = mock_session | ||
|
|
||
| handler.generate_auth_uri() | ||
|
|
||
| # Verify session was created with the REAL secret, not redacted one | ||
| mock_session_cls.assert_called_with( | ||
| client_id, | ||
| secret, | ||
| scope="scope", | ||
| redirect_uri="http://localhost/callback", | ||
| ) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.