@@ -239,6 +239,7 @@ def test_secret_manager_service_client_client_options(
239239 quota_project_id = None ,
240240 client_info = transports .base .DEFAULT_CLIENT_INFO ,
241241 always_use_jwt_access = True ,
242+ api_audience = None ,
242243 )
243244
244245 # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is
@@ -256,6 +257,7 @@ def test_secret_manager_service_client_client_options(
256257 quota_project_id = None ,
257258 client_info = transports .base .DEFAULT_CLIENT_INFO ,
258259 always_use_jwt_access = True ,
260+ api_audience = None ,
259261 )
260262
261263 # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is
@@ -273,6 +275,7 @@ def test_secret_manager_service_client_client_options(
273275 quota_project_id = None ,
274276 client_info = transports .base .DEFAULT_CLIENT_INFO ,
275277 always_use_jwt_access = True ,
278+ api_audience = None ,
276279 )
277280
278281 # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT has
@@ -302,6 +305,25 @@ def test_secret_manager_service_client_client_options(
302305 quota_project_id = "octopus" ,
303306 client_info = transports .base .DEFAULT_CLIENT_INFO ,
304307 always_use_jwt_access = True ,
308+ api_audience = None ,
309+ )
310+ # Check the case api_endpoint is provided
311+ options = client_options .ClientOptions (
312+ api_audience = "https://language.googleapis.com"
313+ )
314+ with mock .patch .object (transport_class , "__init__" ) as patched :
315+ patched .return_value = None
316+ client = client_class (client_options = options , transport = transport_name )
317+ patched .assert_called_once_with (
318+ credentials = None ,
319+ credentials_file = None ,
320+ host = client .DEFAULT_ENDPOINT ,
321+ scopes = None ,
322+ client_cert_source_for_mtls = None ,
323+ quota_project_id = None ,
324+ client_info = transports .base .DEFAULT_CLIENT_INFO ,
325+ always_use_jwt_access = True ,
326+ api_audience = "https://language.googleapis.com" ,
305327 )
306328
307329
@@ -379,6 +401,7 @@ def test_secret_manager_service_client_mtls_env_auto(
379401 quota_project_id = None ,
380402 client_info = transports .base .DEFAULT_CLIENT_INFO ,
381403 always_use_jwt_access = True ,
404+ api_audience = None ,
382405 )
383406
384407 # Check the case ADC client cert is provided. Whether client cert is used depends on
@@ -413,6 +436,7 @@ def test_secret_manager_service_client_mtls_env_auto(
413436 quota_project_id = None ,
414437 client_info = transports .base .DEFAULT_CLIENT_INFO ,
415438 always_use_jwt_access = True ,
439+ api_audience = None ,
416440 )
417441
418442 # Check the case client_cert_source and ADC client cert are not provided.
@@ -435,6 +459,7 @@ def test_secret_manager_service_client_mtls_env_auto(
435459 quota_project_id = None ,
436460 client_info = transports .base .DEFAULT_CLIENT_INFO ,
437461 always_use_jwt_access = True ,
462+ api_audience = None ,
438463 )
439464
440465
@@ -553,6 +578,7 @@ def test_secret_manager_service_client_client_options_scopes(
553578 quota_project_id = None ,
554579 client_info = transports .base .DEFAULT_CLIENT_INFO ,
555580 always_use_jwt_access = True ,
581+ api_audience = None ,
556582 )
557583
558584
@@ -591,6 +617,7 @@ def test_secret_manager_service_client_client_options_credentials_file(
591617 quota_project_id = None ,
592618 client_info = transports .base .DEFAULT_CLIENT_INFO ,
593619 always_use_jwt_access = True ,
620+ api_audience = None ,
594621 )
595622
596623
@@ -611,6 +638,7 @@ def test_secret_manager_service_client_client_options_from_dict():
611638 quota_project_id = None ,
612639 client_info = transports .base .DEFAULT_CLIENT_INFO ,
613640 always_use_jwt_access = True ,
641+ api_audience = None ,
614642 )
615643
616644
@@ -649,6 +677,7 @@ def test_secret_manager_service_client_create_channel_credentials_file(
649677 quota_project_id = None ,
650678 client_info = transports .base .DEFAULT_CLIENT_INFO ,
651679 always_use_jwt_access = True ,
680+ api_audience = None ,
652681 )
653682
654683 # test that the credentials from file are saved and used as the credentials.
@@ -4797,6 +4826,28 @@ def test_secret_manager_service_transport_auth_adc(transport_class):
47974826 )
47984827
47994828
4829+ @pytest .mark .parametrize (
4830+ "transport_class" ,
4831+ [
4832+ transports .SecretManagerServiceGrpcTransport ,
4833+ transports .SecretManagerServiceGrpcAsyncIOTransport ,
4834+ ],
4835+ )
4836+ def test_secret_manager_service_transport_auth_gdch_credentials (transport_class ):
4837+ host = "https://language.com"
4838+ api_audience_tests = [None , "https://language2.com" ]
4839+ api_audience_expect = [host , "https://language2.com" ]
4840+ for t , e in zip (api_audience_tests , api_audience_expect ):
4841+ with mock .patch .object (google .auth , "default" , autospec = True ) as adc :
4842+ gdch_mock = mock .MagicMock ()
4843+ type(gdch_mock ).with_gdch_audience = mock .PropertyMock (
4844+ return_value = gdch_mock
4845+ )
4846+ adc .return_value = (gdch_mock , None )
4847+ transport_class (host = host , api_audience = t )
4848+ gdch_mock .with_gdch_audience .assert_called_once_with (e )
4849+
4850+
48004851@pytest .mark .parametrize (
48014852 "transport_class,grpc_helpers" ,
48024853 [
@@ -5318,4 +5369,5 @@ def test_api_key_credentials(client_class, transport_class):
53185369 quota_project_id = None ,
53195370 client_info = transports .base .DEFAULT_CLIENT_INFO ,
53205371 always_use_jwt_access = True ,
5372+ api_audience = None ,
53215373 )
0 commit comments