From 90a0be276e38e889a5086f8fd233d5b25e19965e Mon Sep 17 00:00:00 2001 From: "gcf-owl-bot[bot]" <78513119+gcf-owl-bot[bot]@users.noreply.github.com> Date: Sat, 24 Jul 2021 10:16:15 +0000 Subject: [PATCH] fix: enable self signed jwt for grpc (#192) PiperOrigin-RevId: 386504689 Source-Link: https://github.com/googleapis/googleapis/commit/762094a99ac6e03a17516b13dfbef37927267a70 Source-Link: https://github.com/googleapis/googleapis-gen/commit/6bfc480e1a161d5de121c2bcc3745885d33b265a --- .../services/data_catalog/client.py | 4 +++ .../services/policy_tag_manager/client.py | 4 +++ .../client.py | 4 +++ .../services/data_catalog/client.py | 4 +++ .../services/policy_tag_manager/client.py | 4 +++ .../client.py | 4 +++ .../gapic/datacatalog_v1/test_data_catalog.py | 29 ++++++++++------ .../datacatalog_v1/test_policy_tag_manager.py | 31 ++++++++++------- .../test_policy_tag_manager_serialization.py | 34 ++++++++++--------- .../datacatalog_v1beta1/test_data_catalog.py | 29 ++++++++++------ .../test_policy_tag_manager.py | 31 ++++++++++------- .../test_policy_tag_manager_serialization.py | 34 ++++++++++--------- 12 files changed, 132 insertions(+), 80 deletions(-) diff --git a/google/cloud/datacatalog_v1/services/data_catalog/client.py b/google/cloud/datacatalog_v1/services/data_catalog/client.py index 62453c6f..d693de0f 100644 --- a/google/cloud/datacatalog_v1/services/data_catalog/client.py +++ b/google/cloud/datacatalog_v1/services/data_catalog/client.py @@ -453,6 +453,10 @@ def __init__( client_cert_source_for_mtls=client_cert_source_func, quota_project_id=client_options.quota_project_id, client_info=client_info, + always_use_jwt_access=( + Transport == type(self).get_transport_class("grpc") + or Transport == type(self).get_transport_class("grpc_asyncio") + ), ) def search_catalog( diff --git a/google/cloud/datacatalog_v1/services/policy_tag_manager/client.py b/google/cloud/datacatalog_v1/services/policy_tag_manager/client.py index 0b852753..3af5da93 100644 --- a/google/cloud/datacatalog_v1/services/policy_tag_manager/client.py +++ b/google/cloud/datacatalog_v1/services/policy_tag_manager/client.py @@ -374,6 +374,10 @@ def __init__( client_cert_source_for_mtls=client_cert_source_func, quota_project_id=client_options.quota_project_id, client_info=client_info, + always_use_jwt_access=( + Transport == type(self).get_transport_class("grpc") + or Transport == type(self).get_transport_class("grpc_asyncio") + ), ) def create_taxonomy( diff --git a/google/cloud/datacatalog_v1/services/policy_tag_manager_serialization/client.py b/google/cloud/datacatalog_v1/services/policy_tag_manager_serialization/client.py index c0339ae5..37b72a56 100644 --- a/google/cloud/datacatalog_v1/services/policy_tag_manager_serialization/client.py +++ b/google/cloud/datacatalog_v1/services/policy_tag_manager_serialization/client.py @@ -353,6 +353,10 @@ def __init__( client_cert_source_for_mtls=client_cert_source_func, quota_project_id=client_options.quota_project_id, client_info=client_info, + always_use_jwt_access=( + Transport == type(self).get_transport_class("grpc") + or Transport == type(self).get_transport_class("grpc_asyncio") + ), ) def import_taxonomies( diff --git a/google/cloud/datacatalog_v1beta1/services/data_catalog/client.py b/google/cloud/datacatalog_v1beta1/services/data_catalog/client.py index 859478ff..ad541e19 100644 --- a/google/cloud/datacatalog_v1beta1/services/data_catalog/client.py +++ b/google/cloud/datacatalog_v1beta1/services/data_catalog/client.py @@ -426,6 +426,10 @@ def __init__( client_cert_source_for_mtls=client_cert_source_func, quota_project_id=client_options.quota_project_id, client_info=client_info, + always_use_jwt_access=( + Transport == type(self).get_transport_class("grpc") + or Transport == type(self).get_transport_class("grpc_asyncio") + ), ) def search_catalog( diff --git a/google/cloud/datacatalog_v1beta1/services/policy_tag_manager/client.py b/google/cloud/datacatalog_v1beta1/services/policy_tag_manager/client.py index de1c2893..e94c8efe 100644 --- a/google/cloud/datacatalog_v1beta1/services/policy_tag_manager/client.py +++ b/google/cloud/datacatalog_v1beta1/services/policy_tag_manager/client.py @@ -369,6 +369,10 @@ def __init__( client_cert_source_for_mtls=client_cert_source_func, quota_project_id=client_options.quota_project_id, client_info=client_info, + always_use_jwt_access=( + Transport == type(self).get_transport_class("grpc") + or Transport == type(self).get_transport_class("grpc_asyncio") + ), ) def create_taxonomy( diff --git a/google/cloud/datacatalog_v1beta1/services/policy_tag_manager_serialization/client.py b/google/cloud/datacatalog_v1beta1/services/policy_tag_manager_serialization/client.py index db07f881..3b80951b 100644 --- a/google/cloud/datacatalog_v1beta1/services/policy_tag_manager_serialization/client.py +++ b/google/cloud/datacatalog_v1beta1/services/policy_tag_manager_serialization/client.py @@ -353,6 +353,10 @@ def __init__( client_cert_source_for_mtls=client_cert_source_func, quota_project_id=client_options.quota_project_id, client_info=client_info, + always_use_jwt_access=( + Transport == type(self).get_transport_class("grpc") + or Transport == type(self).get_transport_class("grpc_asyncio") + ), ) def import_taxonomies( diff --git a/tests/unit/gapic/datacatalog_v1/test_data_catalog.py b/tests/unit/gapic/datacatalog_v1/test_data_catalog.py index ea8f174c..e65c0b33 100644 --- a/tests/unit/gapic/datacatalog_v1/test_data_catalog.py +++ b/tests/unit/gapic/datacatalog_v1/test_data_catalog.py @@ -127,16 +127,6 @@ def test_data_catalog_client_from_service_account_info(client_class): assert client.transport._host == "datacatalog.googleapis.com:443" -@pytest.mark.parametrize("client_class", [DataCatalogClient, DataCatalogAsyncClient,]) -def test_data_catalog_client_service_account_always_use_jwt(client_class): - with mock.patch.object( - service_account.Credentials, "with_always_use_jwt_access", create=True - ) as use_jwt: - creds = service_account.Credentials(None, None, None) - client = client_class(credentials=creds) - use_jwt.assert_not_called() - - @pytest.mark.parametrize( "transport_class,transport_name", [ @@ -144,7 +134,7 @@ def test_data_catalog_client_service_account_always_use_jwt(client_class): (transports.DataCatalogGrpcAsyncIOTransport, "grpc_asyncio"), ], ) -def test_data_catalog_client_service_account_always_use_jwt_true( +def test_data_catalog_client_service_account_always_use_jwt( transport_class, transport_name ): with mock.patch.object( @@ -154,6 +144,13 @@ def test_data_catalog_client_service_account_always_use_jwt_true( transport = transport_class(credentials=creds, always_use_jwt_access=True) use_jwt.assert_called_once_with(True) + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=False) + use_jwt.assert_not_called() + @pytest.mark.parametrize("client_class", [DataCatalogClient, DataCatalogAsyncClient,]) def test_data_catalog_client_from_service_account_file(client_class): @@ -230,6 +227,7 @@ def test_data_catalog_client_client_options( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is @@ -246,6 +244,7 @@ def test_data_catalog_client_client_options( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is @@ -262,6 +261,7 @@ def test_data_catalog_client_client_options( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT has @@ -290,6 +290,7 @@ def test_data_catalog_client_client_options( client_cert_source_for_mtls=None, quota_project_id="octopus", client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) @@ -354,6 +355,7 @@ def test_data_catalog_client_mtls_env_auto( client_cert_source_for_mtls=expected_client_cert_source, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) # Check the case ADC client cert is provided. Whether client cert is used depends on @@ -387,6 +389,7 @@ def test_data_catalog_client_mtls_env_auto( client_cert_source_for_mtls=expected_client_cert_source, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) # Check the case client_cert_source and ADC client cert are not provided. @@ -408,6 +411,7 @@ def test_data_catalog_client_mtls_env_auto( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) @@ -438,6 +442,7 @@ def test_data_catalog_client_client_options_scopes( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) @@ -468,6 +473,7 @@ def test_data_catalog_client_client_options_credentials_file( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) @@ -485,6 +491,7 @@ def test_data_catalog_client_client_options_from_dict(): client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) diff --git a/tests/unit/gapic/datacatalog_v1/test_policy_tag_manager.py b/tests/unit/gapic/datacatalog_v1/test_policy_tag_manager.py index 3d0742bb..6379b5bd 100644 --- a/tests/unit/gapic/datacatalog_v1/test_policy_tag_manager.py +++ b/tests/unit/gapic/datacatalog_v1/test_policy_tag_manager.py @@ -130,18 +130,6 @@ def test_policy_tag_manager_client_from_service_account_info(client_class): assert client.transport._host == "datacatalog.googleapis.com:443" -@pytest.mark.parametrize( - "client_class", [PolicyTagManagerClient, PolicyTagManagerAsyncClient,] -) -def test_policy_tag_manager_client_service_account_always_use_jwt(client_class): - with mock.patch.object( - service_account.Credentials, "with_always_use_jwt_access", create=True - ) as use_jwt: - creds = service_account.Credentials(None, None, None) - client = client_class(credentials=creds) - use_jwt.assert_not_called() - - @pytest.mark.parametrize( "transport_class,transport_name", [ @@ -149,7 +137,7 @@ def test_policy_tag_manager_client_service_account_always_use_jwt(client_class): (transports.PolicyTagManagerGrpcAsyncIOTransport, "grpc_asyncio"), ], ) -def test_policy_tag_manager_client_service_account_always_use_jwt_true( +def test_policy_tag_manager_client_service_account_always_use_jwt( transport_class, transport_name ): with mock.patch.object( @@ -159,6 +147,13 @@ def test_policy_tag_manager_client_service_account_always_use_jwt_true( transport = transport_class(credentials=creds, always_use_jwt_access=True) use_jwt.assert_called_once_with(True) + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=False) + use_jwt.assert_not_called() + @pytest.mark.parametrize( "client_class", [PolicyTagManagerClient, PolicyTagManagerAsyncClient,] @@ -239,6 +234,7 @@ def test_policy_tag_manager_client_client_options( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is @@ -255,6 +251,7 @@ def test_policy_tag_manager_client_client_options( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is @@ -271,6 +268,7 @@ def test_policy_tag_manager_client_client_options( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT has @@ -299,6 +297,7 @@ def test_policy_tag_manager_client_client_options( client_cert_source_for_mtls=None, quota_project_id="octopus", client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) @@ -375,6 +374,7 @@ def test_policy_tag_manager_client_mtls_env_auto( client_cert_source_for_mtls=expected_client_cert_source, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) # Check the case ADC client cert is provided. Whether client cert is used depends on @@ -408,6 +408,7 @@ def test_policy_tag_manager_client_mtls_env_auto( client_cert_source_for_mtls=expected_client_cert_source, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) # Check the case client_cert_source and ADC client cert are not provided. @@ -429,6 +430,7 @@ def test_policy_tag_manager_client_mtls_env_auto( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) @@ -459,6 +461,7 @@ def test_policy_tag_manager_client_client_options_scopes( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) @@ -489,6 +492,7 @@ def test_policy_tag_manager_client_client_options_credentials_file( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) @@ -508,6 +512,7 @@ def test_policy_tag_manager_client_client_options_from_dict(): client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) diff --git a/tests/unit/gapic/datacatalog_v1/test_policy_tag_manager_serialization.py b/tests/unit/gapic/datacatalog_v1/test_policy_tag_manager_serialization.py index 46dcfccc..8a0e69a0 100644 --- a/tests/unit/gapic/datacatalog_v1/test_policy_tag_manager_serialization.py +++ b/tests/unit/gapic/datacatalog_v1/test_policy_tag_manager_serialization.py @@ -132,21 +132,6 @@ def test_policy_tag_manager_serialization_client_from_service_account_info( assert client.transport._host == "datacatalog.googleapis.com:443" -@pytest.mark.parametrize( - "client_class", - [PolicyTagManagerSerializationClient, PolicyTagManagerSerializationAsyncClient,], -) -def test_policy_tag_manager_serialization_client_service_account_always_use_jwt( - client_class, -): - with mock.patch.object( - service_account.Credentials, "with_always_use_jwt_access", create=True - ) as use_jwt: - creds = service_account.Credentials(None, None, None) - client = client_class(credentials=creds) - use_jwt.assert_not_called() - - @pytest.mark.parametrize( "transport_class,transport_name", [ @@ -154,7 +139,7 @@ def test_policy_tag_manager_serialization_client_service_account_always_use_jwt( (transports.PolicyTagManagerSerializationGrpcAsyncIOTransport, "grpc_asyncio"), ], ) -def test_policy_tag_manager_serialization_client_service_account_always_use_jwt_true( +def test_policy_tag_manager_serialization_client_service_account_always_use_jwt( transport_class, transport_name ): with mock.patch.object( @@ -164,6 +149,13 @@ def test_policy_tag_manager_serialization_client_service_account_always_use_jwt_ transport = transport_class(credentials=creds, always_use_jwt_access=True) use_jwt.assert_called_once_with(True) + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=False) + use_jwt.assert_not_called() + @pytest.mark.parametrize( "client_class", @@ -255,6 +247,7 @@ def test_policy_tag_manager_serialization_client_client_options( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is @@ -271,6 +264,7 @@ def test_policy_tag_manager_serialization_client_client_options( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is @@ -287,6 +281,7 @@ def test_policy_tag_manager_serialization_client_client_options( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT has @@ -315,6 +310,7 @@ def test_policy_tag_manager_serialization_client_client_options( client_cert_source_for_mtls=None, quota_project_id="octopus", client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) @@ -391,6 +387,7 @@ def test_policy_tag_manager_serialization_client_mtls_env_auto( client_cert_source_for_mtls=expected_client_cert_source, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) # Check the case ADC client cert is provided. Whether client cert is used depends on @@ -424,6 +421,7 @@ def test_policy_tag_manager_serialization_client_mtls_env_auto( client_cert_source_for_mtls=expected_client_cert_source, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) # Check the case client_cert_source and ADC client cert are not provided. @@ -445,6 +443,7 @@ def test_policy_tag_manager_serialization_client_mtls_env_auto( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) @@ -479,6 +478,7 @@ def test_policy_tag_manager_serialization_client_client_options_scopes( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) @@ -513,6 +513,7 @@ def test_policy_tag_manager_serialization_client_client_options_credentials_file client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) @@ -532,6 +533,7 @@ def test_policy_tag_manager_serialization_client_client_options_from_dict(): client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) diff --git a/tests/unit/gapic/datacatalog_v1beta1/test_data_catalog.py b/tests/unit/gapic/datacatalog_v1beta1/test_data_catalog.py index 39c0388e..53c3e1ac 100644 --- a/tests/unit/gapic/datacatalog_v1beta1/test_data_catalog.py +++ b/tests/unit/gapic/datacatalog_v1beta1/test_data_catalog.py @@ -128,16 +128,6 @@ def test_data_catalog_client_from_service_account_info(client_class): assert client.transport._host == "datacatalog.googleapis.com:443" -@pytest.mark.parametrize("client_class", [DataCatalogClient, DataCatalogAsyncClient,]) -def test_data_catalog_client_service_account_always_use_jwt(client_class): - with mock.patch.object( - service_account.Credentials, "with_always_use_jwt_access", create=True - ) as use_jwt: - creds = service_account.Credentials(None, None, None) - client = client_class(credentials=creds) - use_jwt.assert_not_called() - - @pytest.mark.parametrize( "transport_class,transport_name", [ @@ -145,7 +135,7 @@ def test_data_catalog_client_service_account_always_use_jwt(client_class): (transports.DataCatalogGrpcAsyncIOTransport, "grpc_asyncio"), ], ) -def test_data_catalog_client_service_account_always_use_jwt_true( +def test_data_catalog_client_service_account_always_use_jwt( transport_class, transport_name ): with mock.patch.object( @@ -155,6 +145,13 @@ def test_data_catalog_client_service_account_always_use_jwt_true( transport = transport_class(credentials=creds, always_use_jwt_access=True) use_jwt.assert_called_once_with(True) + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=False) + use_jwt.assert_not_called() + @pytest.mark.parametrize("client_class", [DataCatalogClient, DataCatalogAsyncClient,]) def test_data_catalog_client_from_service_account_file(client_class): @@ -231,6 +228,7 @@ def test_data_catalog_client_client_options( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is @@ -247,6 +245,7 @@ def test_data_catalog_client_client_options( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is @@ -263,6 +262,7 @@ def test_data_catalog_client_client_options( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT has @@ -291,6 +291,7 @@ def test_data_catalog_client_client_options( client_cert_source_for_mtls=None, quota_project_id="octopus", client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) @@ -355,6 +356,7 @@ def test_data_catalog_client_mtls_env_auto( client_cert_source_for_mtls=expected_client_cert_source, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) # Check the case ADC client cert is provided. Whether client cert is used depends on @@ -388,6 +390,7 @@ def test_data_catalog_client_mtls_env_auto( client_cert_source_for_mtls=expected_client_cert_source, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) # Check the case client_cert_source and ADC client cert are not provided. @@ -409,6 +412,7 @@ def test_data_catalog_client_mtls_env_auto( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) @@ -439,6 +443,7 @@ def test_data_catalog_client_client_options_scopes( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) @@ -469,6 +474,7 @@ def test_data_catalog_client_client_options_credentials_file( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) @@ -486,6 +492,7 @@ def test_data_catalog_client_client_options_from_dict(): client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) diff --git a/tests/unit/gapic/datacatalog_v1beta1/test_policy_tag_manager.py b/tests/unit/gapic/datacatalog_v1beta1/test_policy_tag_manager.py index 1b988778..2359794a 100644 --- a/tests/unit/gapic/datacatalog_v1beta1/test_policy_tag_manager.py +++ b/tests/unit/gapic/datacatalog_v1beta1/test_policy_tag_manager.py @@ -128,18 +128,6 @@ def test_policy_tag_manager_client_from_service_account_info(client_class): assert client.transport._host == "datacatalog.googleapis.com:443" -@pytest.mark.parametrize( - "client_class", [PolicyTagManagerClient, PolicyTagManagerAsyncClient,] -) -def test_policy_tag_manager_client_service_account_always_use_jwt(client_class): - with mock.patch.object( - service_account.Credentials, "with_always_use_jwt_access", create=True - ) as use_jwt: - creds = service_account.Credentials(None, None, None) - client = client_class(credentials=creds) - use_jwt.assert_not_called() - - @pytest.mark.parametrize( "transport_class,transport_name", [ @@ -147,7 +135,7 @@ def test_policy_tag_manager_client_service_account_always_use_jwt(client_class): (transports.PolicyTagManagerGrpcAsyncIOTransport, "grpc_asyncio"), ], ) -def test_policy_tag_manager_client_service_account_always_use_jwt_true( +def test_policy_tag_manager_client_service_account_always_use_jwt( transport_class, transport_name ): with mock.patch.object( @@ -157,6 +145,13 @@ def test_policy_tag_manager_client_service_account_always_use_jwt_true( transport = transport_class(credentials=creds, always_use_jwt_access=True) use_jwt.assert_called_once_with(True) + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=False) + use_jwt.assert_not_called() + @pytest.mark.parametrize( "client_class", [PolicyTagManagerClient, PolicyTagManagerAsyncClient,] @@ -237,6 +232,7 @@ def test_policy_tag_manager_client_client_options( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is @@ -253,6 +249,7 @@ def test_policy_tag_manager_client_client_options( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is @@ -269,6 +266,7 @@ def test_policy_tag_manager_client_client_options( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT has @@ -297,6 +295,7 @@ def test_policy_tag_manager_client_client_options( client_cert_source_for_mtls=None, quota_project_id="octopus", client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) @@ -373,6 +372,7 @@ def test_policy_tag_manager_client_mtls_env_auto( client_cert_source_for_mtls=expected_client_cert_source, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) # Check the case ADC client cert is provided. Whether client cert is used depends on @@ -406,6 +406,7 @@ def test_policy_tag_manager_client_mtls_env_auto( client_cert_source_for_mtls=expected_client_cert_source, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) # Check the case client_cert_source and ADC client cert are not provided. @@ -427,6 +428,7 @@ def test_policy_tag_manager_client_mtls_env_auto( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) @@ -457,6 +459,7 @@ def test_policy_tag_manager_client_client_options_scopes( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) @@ -487,6 +490,7 @@ def test_policy_tag_manager_client_client_options_credentials_file( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) @@ -506,6 +510,7 @@ def test_policy_tag_manager_client_client_options_from_dict(): client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) diff --git a/tests/unit/gapic/datacatalog_v1beta1/test_policy_tag_manager_serialization.py b/tests/unit/gapic/datacatalog_v1beta1/test_policy_tag_manager_serialization.py index 4e87e942..2c2d54b9 100644 --- a/tests/unit/gapic/datacatalog_v1beta1/test_policy_tag_manager_serialization.py +++ b/tests/unit/gapic/datacatalog_v1beta1/test_policy_tag_manager_serialization.py @@ -132,21 +132,6 @@ def test_policy_tag_manager_serialization_client_from_service_account_info( assert client.transport._host == "datacatalog.googleapis.com:443" -@pytest.mark.parametrize( - "client_class", - [PolicyTagManagerSerializationClient, PolicyTagManagerSerializationAsyncClient,], -) -def test_policy_tag_manager_serialization_client_service_account_always_use_jwt( - client_class, -): - with mock.patch.object( - service_account.Credentials, "with_always_use_jwt_access", create=True - ) as use_jwt: - creds = service_account.Credentials(None, None, None) - client = client_class(credentials=creds) - use_jwt.assert_not_called() - - @pytest.mark.parametrize( "transport_class,transport_name", [ @@ -154,7 +139,7 @@ def test_policy_tag_manager_serialization_client_service_account_always_use_jwt( (transports.PolicyTagManagerSerializationGrpcAsyncIOTransport, "grpc_asyncio"), ], ) -def test_policy_tag_manager_serialization_client_service_account_always_use_jwt_true( +def test_policy_tag_manager_serialization_client_service_account_always_use_jwt( transport_class, transport_name ): with mock.patch.object( @@ -164,6 +149,13 @@ def test_policy_tag_manager_serialization_client_service_account_always_use_jwt_ transport = transport_class(credentials=creds, always_use_jwt_access=True) use_jwt.assert_called_once_with(True) + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=False) + use_jwt.assert_not_called() + @pytest.mark.parametrize( "client_class", @@ -255,6 +247,7 @@ def test_policy_tag_manager_serialization_client_client_options( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is @@ -271,6 +264,7 @@ def test_policy_tag_manager_serialization_client_client_options( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is @@ -287,6 +281,7 @@ def test_policy_tag_manager_serialization_client_client_options( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT has @@ -315,6 +310,7 @@ def test_policy_tag_manager_serialization_client_client_options( client_cert_source_for_mtls=None, quota_project_id="octopus", client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) @@ -391,6 +387,7 @@ def test_policy_tag_manager_serialization_client_mtls_env_auto( client_cert_source_for_mtls=expected_client_cert_source, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) # Check the case ADC client cert is provided. Whether client cert is used depends on @@ -424,6 +421,7 @@ def test_policy_tag_manager_serialization_client_mtls_env_auto( client_cert_source_for_mtls=expected_client_cert_source, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) # Check the case client_cert_source and ADC client cert are not provided. @@ -445,6 +443,7 @@ def test_policy_tag_manager_serialization_client_mtls_env_auto( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) @@ -479,6 +478,7 @@ def test_policy_tag_manager_serialization_client_client_options_scopes( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) @@ -513,6 +513,7 @@ def test_policy_tag_manager_serialization_client_client_options_credentials_file client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) @@ -532,6 +533,7 @@ def test_policy_tag_manager_serialization_client_client_options_from_dict(): client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, )