@@ -671,3 +671,65 @@ async def test_init_with_connection_with_auth_override_disabled_and_custom_auth(
671671 assert (await toolset .get_tools ())[0 ]._operation == "EXECUTE_ACTION"
672672 assert not (await toolset .get_tools ())[0 ]._auth_scheme
673673 assert not (await toolset .get_tools ())[0 ]._auth_credential
674+
675+
676+ @pytest .mark .asyncio
677+ async def test_get_tools_uses_exchanged_auth_credential_when_available (
678+ project ,
679+ location ,
680+ mock_integration_client ,
681+ mock_connections_client ,
682+ mock_openapi_action_spec_parser ,
683+ connection_details_auth_override_enabled ,
684+ ):
685+ connection_name = "test-connection"
686+ actions_list = ["create" ]
687+ mock_connections_client .return_value .get_connection_details .return_value = (
688+ connection_details_auth_override_enabled
689+ )
690+
691+ oauth2_data_google_cloud = {
692+ "type" : "oauth2" ,
693+ "flows" : {
694+ "authorizationCode" : {
695+ "authorizationUrl" : "https://test-url/o/oauth2/auth" ,
696+ "tokenUrl" : "https://test-url/token" ,
697+ "scopes" : {
698+ "https://test-url/auth/test-scope" : "test scope" ,
699+ },
700+ }
701+ },
702+ }
703+
704+ oauth2_scheme = dict_to_auth_scheme (oauth2_data_google_cloud )
705+ raw_auth_credential = AuthCredential (
706+ auth_type = AuthCredentialTypes .OAUTH2 ,
707+ oauth2 = OAuth2Auth (
708+ client_id = "test-client-id" ,
709+ client_secret = "test-client-secret" ,
710+ ),
711+ )
712+
713+ toolset = ApplicationIntegrationToolset (
714+ project ,
715+ location ,
716+ connection = connection_name ,
717+ actions = actions_list ,
718+ auth_scheme = oauth2_scheme ,
719+ auth_credential = raw_auth_credential ,
720+ )
721+
722+ exchanged_auth_credential = AuthCredential (
723+ auth_type = AuthCredentialTypes .OAUTH2 ,
724+ oauth2 = OAuth2Auth (
725+ client_id = "test-client-id" ,
726+ client_secret = "test-client-secret" ,
727+ access_token = "exchanged-access-token" ,
728+ ),
729+ )
730+ toolset ._auth_config .exchanged_auth_credential = exchanged_auth_credential
731+
732+ tools = await toolset .get_tools ()
733+
734+ assert len (tools ) == 1
735+ assert tools [0 ]._auth_credential == exchanged_auth_credential
0 commit comments