8000 fix: enable self signed jwt for grpc (#47) · googleapis/python-domains@d4b8730 · GitHub
[go: up one dir, main page]

Skip to content
This repository was archived by the owner on Jul 6, 2023. It is now read-only.

Commit d4b8730

Browse files
fix: enable self signed jwt for grpc (#47)
PiperOrigin-RevId: 386504689 Source-Link: googleapis/googleapis@762094a Source-Link: https://github.com/googleapis/googleapis-gen/commit/6bfc480e1a161d5de121c2bcc3745885d33b265a
1 parent 1fb4c6a commit d4b8730

File tree

2 files changed

+22
-13
lines changed

2 files changed

+22
-13
lines changed

google/cloud/domains_v1beta1/services/domains/client.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,10 @@ def __init__(
350350
client_cert_source_for_mtls=client_cert_source_func,
351351
quota_project_id=client_options.quota_project_id,
352352
client_info=client_info,
353+
always_use_jwt_access=(
354+
Transport == type(self).get_transport_class("grpc")
355+
or Transport == type(self).get_transport_class("grpc_asyncio")
356+
),
353357
)
354358

355359
def search_domains(

tests/unit/gapic/domains_v1beta1/test_domains.py

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -118,33 +118,28 @@ def test_domains_client_from_service_account_info(client_class):
118118
assert client.transport._host == "domains.googleapis.com:443"
119119

120120

121-
@pytest.mark.parametrize("client_class", [DomainsClient, DomainsAsyncClient,])
122-
def test_domains_client_service_account_always_use_jwt(client_class):
123-
with mock.patch.object(
124-
service_account.Credentials, "with_always_use_jwt_access", create=True
125-
) as use_jwt:
126-
creds = service_account.Credentials(None, None, None)
127-
client = client_class(credentials=creds)
128-
use_jwt.assert_not_called()
129-
130-
131121
@pytest.mark.parametrize(
132122
"transport_class,transport_name",
133123
[
134124
(transports.DomainsGrpcTransport, "grpc"),
135125
(transports.DomainsGrpcAsyncIOTransport, "grpc_asyncio"),
136126
],
137127
)
138-
def test_domains_client_service_account_always_use_jwt_true(
139-
transport_class, transport_name
140-
):
128+
def test_domains_client_service_account_always_use_jwt(transport_class, transport_name):
141129
with mock.patch.object(
142130
service_account.Credentials, "with_always_use_jwt_access", create=True
143131
) as use_jwt:
144132
creds = service_account.Credentials(None, None, None)
145133
transport = transport_class(credentials=creds, always_use_jwt_access=True)
146134
use_jwt.assert_called_once_with(True)
147135

136+
with mock.patch.object(
137+
service_account.Credentials, "with_always_use_jwt_access", create=True
138+
) as use_jwt:
139+
creds = service_account.Credentials(None, None, None)
140+
transport = transport_class(credentials=creds, always_use_jwt_access=False)
141+
use_jwt.assert_not_called()
142+
148143

149144
@pytest.mark.parametrize("client_class", [DomainsClient, DomainsAsyncClient,])
150145
def test_domains_client_from_service_account_file(client_class):
@@ -213,6 +208,7 @@ def test_domains_client_client_options(client_class, transport_class, transport_
213208
client_cert_source_for_mtls=None,
214209
quota_project_id=None,
215210
client_info=transports.base.DEFAULT_CLIENT_INFO,
211+
always_use_jwt_access=True,
216212
)
217213

218214
# Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is
@@ -229,6 +225,7 @@ def test_domains_client_client_options(client_class, transport_class, transport_
229225
client_cert_source_for_mtls=None,
230226
quota_project_id=None,
231227
client_info=transports.base.DEFAULT_CLIENT_INFO,
228+
always_use_jwt_access=True,
232229
)
233230

234231
# Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is
@@ -245,6 +242,7 @@ def test_domains_client_client_options(client_class, transport_class, transport_
245242
client_cert_source_for_mtls=None,
246243
quota_project_id=None,
247244
client_info=transports.base.DEFAULT_CLIENT_INFO,
245+
always_use_jwt_access=True,
248246
)
249247

250248
# Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT has
@@ -273,6 +271,7 @@ def test_domains_client_client_options(client_class, transport_class, transport_
273271
client_cert_source_for_mtls=None,
274272
quota_project_id="octopus",
275273
client_info=transports.base.DEFAULT_CLIENT_INFO,
274+
always_use_jwt_access=True,
276275
)
277276

278277

@@ -335,6 +334,7 @@ def test_domains_client_mtls_env_auto(
335334
client_cert_source_for_mtls=expected_client_cert_source,
336335
quota_project_id=None,
337336
client_info=transports.base.DEFAULT_CLIENT_INFO,
337+
always_use_jwt_access=True,
338338
)
339339

340340
# Check the case ADC client cert is provided. Whether client cert is used depends on
@@ -368,6 +368,7 @@ def test_domains_client_mtls_env_auto(
368368
client_cert_source_for_mtls=expected_client_cert_source,
369369
quota_project_id=None,
370370
client_info=transports.base.DEFAULT_CLIENT_INFO,
371+
always_use_jwt_access=True,
371372
)
372373

373374
# Check the case client_cert_source and ADC client cert are not provided.
@@ -389,6 +390,7 @@ def test_domains_client_mtls_env_auto(
389390
client_cert_source_for_mtls=None,
390391
quota_project_id=None,
391392
client_info=transports.base.DEFAULT_CLIENT_INFO,
393+
always_use_jwt_access=True,
392394
)
393395

394396

@@ -415,6 +417,7 @@ def test_domains_client_client_options_scopes(
415417
client_cert_source_for_mtls=None,
416418
quota_project_id=None,
417419
client_info=transports.base.DEFAULT_CLIENT_INFO,
420+
always_use_jwt_access=True,
418421
)
419422

420423

@@ -441,6 +444,7 @@ def test_domains_client_client_options_credentials_file(
441444
client_cert_source_for_mtls=None,
442445
quota_project_id=None,
443446
client_info=transports.base.DEFAULT_CLIENT_INFO,
447+
always_use_jwt_access=True,
444448
)
445449

446450

@@ -458,6 +462,7 @@ def test_domains_client_client_options_from_dict():
458462
client_cert_source_for_mtls=None,
459463
quota_project_id=None,
460464
client_info=transports.base.DEFAULT_CLIENT_INFO,
465+
always_use_jwt_access=True,
461466
)
462467

463468

0 commit comments

Comments
 (0)
0