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

Commit aaaec29

Browse files
1 parent cb627c5 commit aaaec29

File tree

6 files changed

+66
-39
lines changed

6 files changed

+66
-39
lines changed

google/cloud/websecurityscanner_v1/services/web_security_scanner/client.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,10 @@ def __init__(
364364
client_cert_source_for_mtls=client_cert_source_func,
365365
quota_project_id=client_options.quota_project_id,
366366
client_info=client_info,
367+
always_use_jwt_access=(
368+
Transport == type(self).get_transport_class("grpc")
369+
or Transport == type(self).get_transport_class("grpc_asyncio")
370+
),
367371
)
368372

369373
def create_scan_config(

google/cloud/websecurityscanner_v1alpha/services/web_security_scanner/client.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,10 @@ def __init__(
395395
client_cert_source_for_mtls=client_cert_source_func,
396396
quota_project_id=client_options.quota_project_id,
397397
client_info=client_info,
398+
always_use_jwt_access=(
399+
Transport == type(self).get_transport_class("grpc")
400+
or Transport == type(self).get_transport_class("grpc_asyncio")
401+
),
398402
)
399403

400404
def create_scan_config(

google/cloud/websecurityscanner_v1beta/services/web_security_scanner/client.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,10 @@ def __init__(
397397
client_cert_source_for_mtls=client_cert_source_func,
398398
quota_project_id=client_options.quota_project_id,
399399
client_info=client_info,
400+
always_use_jwt_access=(
401+
Transport == type(self).get_transport_class("grpc")
402+
or Transport == type(self).get_transport_class("grpc_asyncio")
403+
),
400404
)
401405

402406
def create_scan_config(

tests/unit/gapic/websecurityscanner_v1/test_web_security_scanner.py

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -133,26 +133,14 @@ def test_web_security_scanner_client_from_service_account_info(client_class):
133133
assert client.transport._host == "websecurityscanner.googleapis.com:443"
134134

135135

136-
@pytest.mark.parametrize(
137-
"client_class", [WebSecurityScannerClient, WebSecurityScannerAsyncClient,]
138-
)
139-
def test_web_security_scanner_client_service_account_always_use_jwt(client_class):
140-
with mock.patch.object(
141-
service_account.Credentials, "with_always_use_jwt_access", create=True
142-
) as use_jwt:
143-
creds = service_account.Credentials(None, None, None)
144-
client = client_class(credentials=creds)
145-
use_jwt.assert_not_called()
146-
147-
148136
@pytest.mark.parametrize(
149137
"transport_class,transport_name",
150138
[
151139
(transports.WebSecurityScannerGrpcTransport, "grpc"),
152140
(transports.WebSecurityScannerGrpcAsyncIOTransport, "grpc_asyncio"),
153141
],
154142
)
155-
def test_web_security_scanner_client_service_account_always_use_jwt_true(
143+
def test_web_security_scanner_client_service_account_always_use_jwt(
156144
transport_class, transport_name
157145
):
158146
with mock.patch.object(
@@ -162,6 +150,13 @@ def test_web_security_scanner_client_service_account_always_use_jwt_true(
162150
transport = transport_class(credentials=creds, always_use_jwt_access=True)
163151
use_jwt.assert_called_once_with(True)
164152

153+
with mock.patch.object(
154+
service_account.Credentials, "with_always_use_jwt_access", create=True
155+
) as use_jwt:
156+
creds = service_account.Credentials(None, None, None)
157+
transport = transport_class(credentials=creds, always_use_jwt_access=False)
158+
use_jwt.assert_not_called()
159+
165160

166161
@pytest.mark.parametrize(
167162
"client_class", [WebSecurityScannerClient, WebSecurityScannerAsyncClient,]
@@ -242,6 +237,7 @@ def test_web_security_scanner_client_client_options(
242237
client_cert_source_for_mtls=None,
243238
quota_project_id=None,
244239
client_info=transports.base.DEFAULT_CLIENT_INFO,
240+
always_use_jwt_access=True,
245241
)
246242

247243
# Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is
@@ -258,6 +254,7 @@ def test_web_security_scanner_client_client_options(
258254
client_cert_source_for_mtls=None,
259255
quota_project_id=None,
260256
client_info=transports.base.DEFAULT_CLIENT_INFO,
257+
always_use_jwt_access=True,
261258
)
262259

263260
# Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is
@@ -274,6 +271,7 @@ def test_web_security_scanner_client_client_options(
274271
client_cert_source_for_mtls=None,
275272
quota_project_id=None,
276273
client_info=transports.base.DEFAULT_CLIENT_INFO,
274+
always_use_jwt_access=True,
277275
)
278276

279277
# Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT has
@@ -302,6 +300,7 @@ def test_web_security_scanner_client_client_options(
302300
client_cert_source_for_mtls=None,
303301
quota_project_id="octopus",
304302
client_info=transports.base.DEFAULT_CLIENT_INFO,
303+
always_use_jwt_access=True,
305304
)
306305

307306

@@ -378,6 +377,7 @@ def test_web_security_scanner_client_mtls_env_auto(
378377
client_cert_source_for_mtls=expected_client_cert_source,
379378
quota_project_id=None,
380379
client_info=transports.base.DEFAULT_CLIENT_INFO,
380+
always_use_jwt_access=True,
381381
)
382382

383383
# Check the case ADC client cert is provided. Whether client cert is used depends on
@@ -411,6 +411,7 @@ def test_web_security_scanner_client_mtls_env_auto(
411411
client_cert_source_for_mtls=expected_client_cert_source,
412412
quota_project_id=None,
413413
client_info=transports.base.DEFAULT_CLIENT_INFO,
414+
always_use_jwt_access=True,
414415
)
415416

416417
# Check the case client_cert_source and ADC client cert are not provided.
@@ -432,6 +433,7 @@ def test_web_security_scanner_client_mtls_env_auto(
432433
client_cert_source_for_mtls=None,
433434
quota_project_id=None,
434435
client_info=transports.base.DEFAULT_CLIENT_INFO,
436+
always_use_jwt_access=True,
435437
)
436438

437439

@@ -462,6 +464,7 @@ def test_web_security_scanner_client_client_options_scopes(
462464
client_cert_source_for_mtls=None,
463465
quota_project_id=None,
464466
client_info=transports.base.DEFAULT_CLIENT_INFO,
467+
always_use_jwt_access=True,
465468
)
466469

467470

@@ -492,6 +495,7 @@ def test_web_security_scanner_client_client_options_credentials_file(
492495
client_cert_source_for_mtls=None,
493496
quota_project_id=None,
494497
client_info=transports.base.DEFAULT_CLIENT_INFO,
498+
always_use_jwt_access=True,
495499
)
496500

497501

@@ -511,6 +515,7 @@ def test_web_security_scanner_client_client_options_from_dict():
511515
client_cert_source_for_mtls=None,
512516
quota_project_id=None,
513517
client_info=transports.base.DEFAULT_CLIENT_INFO,
518+
always_use_jwt_access=True,
514519
)
515520

516521

tests/unit/gapic/websecurityscanner_v1alpha/test_web_security_scanner.py

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -134,26 +134,14 @@ def test_web_security_scanner_client_from_service_account_info(client_class):
134134
assert client.transport._host == "websecurityscanner.googleapis.com:443"
135135

136136

137-
@pytest.mark.parametrize(
138-
"client_class", [WebSecurityScannerClient, WebSecurityScannerAsyncClient,]
139-
)
140-
def test_web_security_scanner_client_service_account_always_use_jwt(client_class):
141-
with mock.patch.object(
142-
service_account.Credentials, "with_always_use_jwt_access", create=True
143-
) as use_jwt:
144-
creds = service_account.Credentials(None, None, None)
145-
client = client_class(credentials=creds)
146-
use_jwt.assert_not_called()
147-
148-
149137
@pytest.mark.parametrize(
150138
"transport_class,transport_name",
151139
[
152140
(transports.WebSecurityScannerGrpcTransport, "grpc"),
153141
(transports.WebSecurityScannerGrpcAsyncIOTransport, "grpc_asyncio"),
154142
],
155143
)
156-
def test_web_security_scanner_client_service_account_always_use_jwt_true(
144+
def test_web_security_scanner_client_service_account_always_use_jwt(
157145
transport_class, transport_name
158146
):
159147
with mock.patch.object(
@@ -163,6 +151,13 @@ def test_web_security_scanner_client_service_account_always_use_jwt_true(
163151
transport = transport_class(credentials=creds, always_use_jwt_access=True)
164152
use_jwt.assert_called_once_with(True)
165153

154+
with mock.patch.object(
155+
service_account.Credentials, "with_always_use_jwt_access", create=True
156+
) as use_jwt:
157+
creds = service_account.Credentials(None, None, None)
158+
transport = transport_class(credentials=creds, always_use_jwt_access=False)
159+
use_jwt.assert_not_called()
160+
166161

167162
@pytest.mark.parametrize(
168163
"client_class", [WebSecurityScannerClient, WebSecurityScannerAsyncClient,]
@@ -243,6 +238,7 @@ def test_web_security_scanner_client_client_options(
243238
client_cert_source_for_mtls=None,
244239
quota_project_id=None,
245240
client_info=transports.base.DEFAULT_CLIENT_INFO,
241+
always_use_jwt_access=True,
246242
)
247243

248244
# Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is
@@ -259,6 +255,7 @@ def test_web_security_scanner_client_client_options(
259255
client_cert_source_for_mtls=None,
260256
quota_project_id=None,
261257
client_info=transports.base.DEFAULT_CLIENT_INFO,
258+
always_use_jwt_access=True,
262259
)
263260

264261
# Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is
@@ -275,6 +272,7 @@ def test_web_security_scanner_client_client_options(
275272
client_cert_source_for_mtls=None,
276273
quota_project_id=None,
277274
client_info=transports.base.DEFAULT_CLIENT_INFO,
275+
always_use_jwt_access=True,
278276
)
279277

280278
# Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT has
@@ -303,6 +301,7 @@ def test_web_security_scanner_client_client_options(
303301
client_cert_source_for_mtls=None,
304302
quota_project_id="octopus",
305303
client_info=transports.base.DEFAULT_CLIENT_INFO,
304+
always_use_jwt_access=True,
306305
)
307306

308307

@@ -379,6 +378,7 @@ def test_web_security_scanner_client_mtls_env_auto(
379378
client_cert_source_for_mtls=expected_client_cert_source,
380379
quota_project_id=None,
381380
client_info=transports.base.DEFAULT_CLIENT_INFO,
381+
always_use_jwt_access=True,
382382
)
383383

384384
# Check the case ADC client cert is provided. Whether client cert is used depends on
@@ -412,6 +412,7 @@ def test_web_security_scanner_client_mtls_env_auto(
412412
client_cert_source_for_mtls=expected_client_cert_source,
413413
quota_project_id=None,
414414
client_info=transports.base.DEFAULT_CLIENT_INFO,
415+
always_use_jwt_access=True,
415416
)
416417

417418
# Check the case client_cert_source and ADC client cert are not provided.
@@ -433,6 +434,7 @@ def test_web_security_scanner_client_mtls_env_auto(
433434
client_cert_source_for_mtls=None,
434435
quota_project_id=None,
435436
client_info=transports.base.DEFAULT_CLIENT_INFO,
437+
always_use_jwt_access=True,
436438
)
437439

438440

@@ -463,6 +465,7 @@ def test_web_security_scanner_client_client_options_scopes(
463465
client_cert_source_for_mtls=None,
464466
quota_project_id=None,
465467
client_info=transports.base.DEFAULT_CLIENT_INFO,
468+
always_use_jwt_access=True,
466469
)
467470

468471

@@ -493,6 +496,7 @@ def test_web_security_scanner_client_client_options_credentials_file(
493496
client_cert_source_for_mtls=None,
494497
quota_project_id=None,
495498
client_info=transports.base.DEFAULT_CLIENT_INFO,
499+
always_use_jwt_access=True,
496500
)
497501

498502

@@ -512,6 +516,7 @@ def test_web_security_scanner_client_client_options_from_dict():
512516
client_cert_source_for_mtls=None,
513517
quota_project_id=None,
514518
client_info=transports.base.DEFAULT_CLIENT_INFO,
519+
always_use_jwt_access=True,
515520
)
516521

517522

tests/unit/gapic/websecurityscanner_v1beta/test_web_security_scanner.py

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -137,26 +137,14 @@ def test_web_security_scanner_client_from_service_account_info(client_class):
137137
assert client.transport._host == "websecurityscanner.googleapis.com:443"
138138

139139

140-
@pytest.mark.parametrize(
141-
"client_class", [WebSecurityScannerClient, WebSecurityScannerAsyncClient,]
142-
)
143-
def test_web_security_scanner_client_service_account_always_use_jwt(client_class):
144-
with mock.patch.object(
145-
service_account.Credentials, "with_always_use_jwt_access", create=True
146-
) as use_jwt:
147-
creds = service_account.Credentials(None, None, None)
148-
client = client_class(credentials=creds)
149-
use_jwt.assert_not_called()
150-
151-
152140
@pytest.mark.parametrize(
153141
"transport_class,transport_name",
154142
[
155143
(transports.WebSecurityScannerGrpcTransport, "grpc"),
156144
(transports.WebSecurityScannerGrpcAsyncIOTransport, "grpc_asyncio"),
157145
],
158146
)
159-
def test_web_security_scanner_client_service_account_always_use_jwt_true(
147+
def test_web_security_scanner_client_service_account_always_use_jwt(
160148
transport_class, transport_name
161149
):
162150
with mock.patch.object(
@@ -166,6 +154,13 @@ def test_web_security_scanner_client_service_account_always_use_jwt_true(
166154
transport = transport_class(credentials=creds, always_use_jwt_access=True)
167155
use_jwt.assert_called_once_with(True)
168156

157+
with mock.patch.object(
158+
service_account.Credentials, "with_always_use_jwt_access", create=True
159+
) as use_jwt:
160+
creds = service_account.Credentials(None, None, None)
161+
transport = transport_class(credentials=creds, always_use_jwt_access=False)
162+
use_jwt.assert_not_called()
163+
169164

170165
@pytest.mark.parametrize(
171166
"client_class", [WebSecurityScannerClient, WebSecurityScannerAsyncClient,]
@@ -246,6 +241,7 @@ def test_web_security_scanner_client_client_options(
246241
client_cert_source_for_mtls=None,
247242
quota_project_id=None,
248243
client_info=transports.base.DEFAULT_CLIENT_INFO,
244+
always_use_jwt_access=True,
249245
)
250246

251247
# Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is
@@ -262,6 +258,7 @@ def test_web_security_scanner_client_client_options(
262258
client_cert_source_for_mtls=None,
263259
quota_project_id=None,
264260
client_info=transports.base.DEFAULT_CLIENT_INFO,
261+
always_use_jwt_access=True,
265262
)
266263

267264
# Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is
@@ -278,6 +275,7 @@ def test_web_security_scanner_client_client_options(
278275
client_cert_source_for_mtls=None,
279276
quota_project_id=None,
280277
client_info=transports.base.DEFAULT_CLIENT_INFO,
278+
always_use_jwt_access=True,
281279
)
282280

283281
# Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT has
@@ -306,6 +304,7 @@ def test_web_security_scanner_client_client_options(
306304
client_cert_source_for_mtls=None,
307305
quota_project_id="octopus",
308306
client_info=transports.base.DEFAULT_CLIENT_INFO,
307+
always_use_jwt_access=True,
309308
)
310309

311310

@@ -382,6 +381,7 @@ def test_web_security_scanner_client_mtls_env_auto(
382381
client_cert_source_for_mtls=expected_client_cert_source,
383382
quota_project_id=None,
384383
client_info=transports.base.DEFAULT_CLIENT_INFO,
384+
always_use_jwt_access=True,
385385
)
386386

387387
# Check the case ADC client cert is provided. Whether client cert is used depends on
@@ -415,6 +415,7 @@ def test_web_security_scanner_client_mtls_env_auto(
415415
client_cert_source_for_mtls=expected_client_cert_source,
416416
quota_project_id=None,
417417
client_info=transports.base.DEFAULT_CLIENT_INFO,
418+
always_use_jwt_access=True,
418419
)
419420

420421
# Check the case client_cert_source and ADC client cert are not provided.
@@ -436,6 +437,7 @@ def test_web_security_scanner_client_mtls_env_auto(
436437
client_cert_source_for_mtls=None,
437438
quota_project_id=None,
438439
client_info=transports.base.DEFAULT_CLIENT_INFO,
440+
always_use_jwt_access=True,
439441
)
440442

441443

@@ -466,6 +468,7 @@ def test_web_security_scanner_client_client_options_scopes(
466468
client_cert_source_for_mtls=None,
467469
quota_project_id=None,
468470
client_info=transports.base.DEFAULT_CLIENT_INFO,
471+
always_use_jwt_access=True,
469472
)
470473

471474

@@ -496,6 +499,7 @@ def test_web_security_scanner_client_client_options_credentials_file(
496499
client_cert_source_for_mtls=None,
497500
quota_project_id=None,
498501
client_info=transports.base.DEFAULT_CLIENT_INFO,
502+
always_use_jwt_access=True,
499503
)
500504

501505

@@ -515,6 +519,7 @@ def test_web_security_scanner_client_client_options_from_dict():
515519
client_cert_source_for_mtls=None,
516520
quota_project_id=None,
517521
client_info=transports.base.DEFAULT_CLIENT_INFO,
522+
always_use_jwt_access=True,
518523
)
519524

520525

0 commit comments

Comments
 (0)