Skip to content

Commit b160a40

Browse files
fix: enable self signed jwt for grpc (#101)
PiperOrigin-RevId: 386504689 Source-Link: googleapis/googleapis@762094a Source-Link: googleapis/googleapis-gen@6bfc480
1 parent 469a9f1 commit b160a40

File tree

2 files changed

+22
-19
lines changed

2 files changed

+22
-19
lines changed

packages/google-cloud-phishing-protection/google/cloud/phishingprotection_v1beta1/services/phishing_protection_service_v1_beta1/client.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,10 @@ def __init__(
338338
client_cert_source_for_mtls=client_cert_source_func,
339339
quota_project_id=client_options.quota_project_id,
340340
client_info=client_info,
341+
always_use_jwt_access=(
342+
Transport == type(self).get_transport_class("grpc")
343+
or Transport == type(self).get_transport_class("grpc_asyncio")
344+
),
341345
)
342346

343347
def report_phishing(

packages/google-cloud-phishing-protection/tests/unit/gapic/phishingprotection_v1beta1/test_phishing_protection_service_v1_beta1.py

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -138,24 +138,6 @@ def test_phishing_protection_service_v1_beta1_client_from_service_account_info(
138138
assert client.transport._host == "phishingprotection.googleapis.com:443"
139139

140140

141-
@pytest.mark.parametrize(
142-
"client_class",
143-
[
144-
PhishingProtectionServiceV1Beta1Client,
145-
PhishingProtectionServiceV1Beta1AsyncClient,
146-
],
147-
)
148-
def test_phishing_protection_service_v1_beta1_client_service_account_always_use_jwt(
149-
client_class,
150-
):
151-
with mock.patch.object(
152-
service_account.Credentials, "with_always_use_jwt_access", create=True
153-
) as use_jwt:
154-
creds = service_account.Credentials(None, None, None)
155-
client = client_class(credentials=creds)
156-
use_jwt.assert_not_called()
157-
158-
159141
@pytest.mark.parametrize(
160142
"transport_class,transport_name",
161143
[
@@ -166,7 +148,7 @@ def test_phishing_protection_service_v1_beta1_client_service_account_always_use_
166148
),
167149
],
168150
)
169-
def test_phishing_protection_service_v1_beta1_client_service_account_always_use_jwt_true(
151+
def test_phishing_protection_service_v1_beta1_client_service_account_always_use_jwt(
170152
transport_class, transport_name
171153
):
172154
with mock.patch.object(
@@ -176,6 +158,13 @@ def test_phishing_protection_service_v1_beta1_client_service_account_always_use_
176158
transport = transport_class(credentials=creds, always_use_jwt_access=True)
177159
use_jwt.assert_called_once_with(True)
178160

161+
with mock.patch.object(
162+
service_account.Credentials, "with_always_use_jwt_access", create=True
163+
) as use_jwt:
164+
creds = service_account.Credentials(None, None, None)
165+
transport = transport_class(credentials=creds, always_use_jwt_access=False)
166+
use_jwt.assert_not_called()
167+
179168

180169
@pytest.mark.parametrize(
181170
"client_class",
@@ -270,6 +259,7 @@ def test_phishing_protection_service_v1_beta1_client_client_options(
270259
client_cert_source_for_mtls=None,
271260
quota_project_id=None,
272261
client_info=transports.base.DEFAULT_CLIENT_INFO,
262+
always_use_jwt_access=True,
273263
)
274264

275265
# Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is
@@ -286,6 +276,7 @@ def test_phishing_protection_service_v1_beta1_client_client_options(
286276
client_cert_source_for_mtls=None,
287277
quota_project_id=None,
288278
client_info=transports.base.DEFAULT_CLIENT_INFO,
279+
always_use_jwt_access=True,
289280
)
290281

291282
# Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is
@@ -302,6 +293,7 @@ def test_phishing_protection_service_v1_beta1_client_client_options(
302293
client_cert_source_for_mtls=None,
303294
quota_project_id=None,
304295
client_info=transports.base.DEFAULT_CLIENT_INFO,
296+
always_use_jwt_access=True,
305297
)
306298

307299
# Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT has
@@ -330,6 +322,7 @@ def test_phishing_protection_service_v1_beta1_client_client_options(
330322
client_cert_source_for_mtls=None,
331323
quota_project_id="octopus",
332324
client_info=transports.base.DEFAULT_CLIENT_INFO,
325+
always_use_jwt_access=True,
333326
)
334327

335328

@@ -406,6 +399,7 @@ def test_phishing_protection_service_v1_beta1_client_mtls_env_auto(
406399
client_cert_source_for_mtls=expected_client_cert_source,
407400
quota_project_id=None,
408401
client_info=transports.base.DEFAULT_CLIENT_INFO,
402+
always_use_jwt_access=True,
409403
)
410404

411405
# Check the case ADC client cert is provided. Whether client cert is used depends on
@@ -439,6 +433,7 @@ def test_phishing_protection_service_v1_beta1_client_mtls_env_auto(
439433
client_cert_source_for_mtls=expected_client_cert_source,
440434
quota_project_id=None,
441435
client_info=transports.base.DEFAULT_CLIENT_INFO,
436+
always_use_jwt_access=True,
442437
)
443438

444439
# Check the case client_cert_source and ADC client cert are not provided.
@@ -460,6 +455,7 @@ def test_phishing_protection_service_v1_beta1_client_mtls_env_auto(
460455
client_cert_source_for_mtls=None,
461456
quota_project_id=None,
462457
client_info=transports.base.DEFAULT_CLIENT_INFO,
458+
always_use_jwt_access=True,
463459
)
464460

465461

@@ -494,6 +490,7 @@ def test_phishing_protection_service_v1_beta1_client_client_options_scopes(
494490
client_cert_source_for_mtls=None,
495491
quota_project_id=None,
496492
client_info=transports.base.DEFAULT_CLIENT_INFO,
493+
always_use_jwt_access=True,
497494
)
498495

499496

@@ -528,6 +525,7 @@ def test_phishing_protection_service_v1_beta1_client_client_options_credentials_
528525
client_cert_source_for_mtls=None,
529526
quota_project_id=None,
530527
client_info=transports.base.DEFAULT_CLIENT_INFO,
528+
always_use_jwt_access=True,
531529
)
532530

533531

@@ -547,6 +545,7 @@ def test_phishing_protection_service_v1_beta1_client_client_options_from_dict():
547545
client_cert_source_for_mtls=None,
548546
quota_project_id=None,
549547
client_info=transports.base.DEFAULT_CLIENT_INFO,
548+
always_use_jwt_access=True,
550549
)
551550

552551

0 commit comments

Comments
 (0)