Skip to content

Commit ee8b1c8

Browse files
committed
update tests
1 parent 03ac316 commit ee8b1c8

3 files changed

Lines changed: 40 additions & 33 deletions

File tree

packages/gapic-generator/noxfile.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -478,12 +478,17 @@ def showcase_mtls(
478478

479479
# TODO(Phase 3): Remove showcase_pqc once grpcio >= 1.83.0 is enforced by default in google-api-core.
480480
@nox.session(python=NEWEST_PYTHON)
481-
def showcase_pqc(session):
482-
"""Run the Showcase PQC verification test suite against grpcio 1.83+."""
483-
with showcase_library(session):
481+
def showcase_pqc(
482+
session,
483+
templates="DEFAULT",
484+
other_opts: typing.Iterable[str] = (),
485+
env: typing.Optional[typing.Dict[str, str]] = {},
486+
):
487+
"""Run the Showcase PQC verification test suite against grpcio 1.83+ over standard TLS."""
488+
with showcase_library(session, templates=templates, other_opts=other_opts):
484489
session.install("pytest", "pytest-asyncio", "pyopenssl")
485490
session.install("--pre", "--upgrade", "grpcio>=1.83.0rc0", "grpcio-status>=1.83.0rc0")
486-
session.run("py.test", "--quiet", "--mtls", "-s", *(session.posargs or ["tests/system/test_pqc.py"]))
491+
session.run("py.test", "--quiet", "--tls", "-s", *(session.posargs or ["tests/system/test_pqc.py"]), env=env)
487492

488493

489494
def run_showcase_unit_tests(session, fail_under=100, rest_async_io_enabled=False):

packages/gapic-generator/tests/system/conftest.py

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -116,14 +116,17 @@ def async_identity(use_mtls, request, event_loop):
116116

117117

118118
base_dir = os.path.dirname(__file__)
119-
with open(os.path.join(base_dir, "../cert/mtls.crt"), "rb") as fh:
119+
CERT_PATH = os.path.join(base_dir, "../cert/mtls.crt")
120+
KEY_PATH = os.path.join(base_dir, "../cert/mtls.key")
121+
with open(CERT_PATH, "rb") as fh:
120122
cert = fh.read()
121-
with open(os.path.join(base_dir, "../cert/mtls.key"), "rb") as fh:
123+
with open(KEY_PATH, "rb") as fh:
122124
key = fh.read()
123125

124126
ssl_credentials = grpc.ssl_channel_credentials(
125127
root_certificates=cert, certificate_chain=cert, private_key=key
126128
)
129+
tls_credentials = grpc.ssl_channel_credentials(root_certificates=cert)
127130

128131

129132
def callback():
@@ -138,6 +141,9 @@ def pytest_addoption(parser):
138141
parser.addoption(
139142
"--mtls", action="store_true", help="Run system test with mutual TLS channel"
140143
)
144+
parser.addoption(
145+
"--tls", action="store_true", help="Run system test with standard one-way TLS channel"
146+
)
141147

142148

143149
# TODO: Need to test without passing in a transport class
@@ -191,6 +197,11 @@ def use_mtls(request):
191197
return request.config.getoption("--mtls")
192198

193199

200+
@pytest.fixture
201+
def use_tls(request):
202+
return request.config.getoption("--tls")
203+
204+
194205
@pytest.fixture
195206
def parametrized_echo(
196207
use_mtls,
@@ -414,7 +425,7 @@ async def intercept_stream_stream(
414425

415426

416427
@pytest.fixture
417-
def intercepted_echo_grpc(use_mtls):
428+
def intercepted_echo_grpc(use_mtls, use_tls):
418429
# The interceptor adds 'showcase-trailer' client metadata. Showcase server
419430
# echoes any metadata with key 'showcase-trailer', so the same metadata
420431
# should appear as trailing metadata in the response.
@@ -423,11 +434,12 @@ def intercepted_echo_grpc(use_mtls):
423434
"intercepted",
424435
)
425436
host = "localhost:7469"
426-
channel = (
427-
grpc.secure_channel(host, ssl_credentials)
428-
if use_mtls
429-
else grpc.insecure_channel(host)
430-
)
437+
if use_mtls:
438+
channel = grpc.secure_channel(host, ssl_credentials)
439+
elif use_tls:
440+
channel = grpc.secure_channel(host, tls_credentials)
441+
else:
442+
channel = grpc.insecure_channel(host)
431443
intercept_channel = grpc.intercept_channel(channel, interceptor)
432444
transport = EchoClient.get_transport_class("grpc")(
433445
credentials=ga_credentials.AnonymousCredentials(),
@@ -468,51 +480,41 @@ def init_poolmanager(self, connections, maxsize, block=False, **pool_kwargs):
468480

469481

470482
@pytest.fixture
471-
def intercepted_echo_rest(use_mtls):
483+
def intercepted_echo_rest(use_mtls, use_tls):
472484
transport_name = "rest"
473485
transport_cls = EchoClient.get_transport_class(transport_name)
474486
interceptor = EchoMetadataClientRestInterceptor()
475487

476-
url_scheme = "https" if use_mtls else "http"
488+
url_scheme = "https" if (use_mtls or use_tls) else "http"
477489
transport = transport_cls(
478490
credentials=ga_credentials.AnonymousCredentials(),
479491
host="localhost:7469",
480492
url_scheme=url_scheme,
481493
interceptor=interceptor,
482494
)
483-
if use_mtls:
484-
base_dir = os.path.dirname(__file__)
485-
cert_path = os.path.join(base_dir, "../cert/mtls.crt")
486-
key_path = os.path.join(base_dir, "../cert/mtls.key")
487-
transport._session.verify = cert_path
488-
transport._session.cert = (cert_path, key_path)
495+
if use_mtls or use_tls:
496+
transport._session.verify = CERT_PATH
489497
transport._session.mount("https://", HostNameIgnoringAdapter())
498+
if use_mtls:
499+
transport._session.cert = (CERT_PATH, KEY_PATH)
490500

491501
return EchoClient(transport=transport), interceptor
492502

493503

494504
@pytest.fixture
495-
def intercepted_echo_rest_async(use_mtls):
505+
def intercepted_echo_rest_async():
496506
if not HAS_ASYNC_REST_ECHO_TRANSPORT:
497507
pytest.skip("Skipping test with async rest.")
498508

499509
transport_name = "rest_asyncio"
500510
transport_cls = EchoAsyncClient.get_transport_class(transport_name)
501511
interceptor = EchoMetadataClientRestAsyncInterceptor()
502512

503-
url_scheme = "https" if use_mtls else "http"
504513
transport = transport_cls(
505514
credentials=async_anonymous_credentials(),
506515
host="localhost:7469",
507-
url_scheme=url_scheme,
516+
url_scheme="http",
508517
interceptor=interceptor,
509518
)
510-
if use_mtls:
511-
base_dir = os.path.dirname(__file__)
512-
cert_path = os.path.join(base_dir, "../cert/mtls.crt")
513-
key_path = os.path.join(base_dir, "../cert/mtls.key")
514-
transport._session.verify = cert_path
515-
transport._session.cert = (cert_path, key_path)
516-
transport._session.mount("https://", HostNameIgnoringAdapter())
517519

518520
return EchoAsyncClient(transport=transport), interceptor

packages/gapic-generator/tests/system/test_pqc.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919

2020

2121
@pytest.fixture
22-
def run_pqc_test(use_mtls):
23-
if not use_mtls:
24-
pytest.skip("PQC integration test requires mTLS (--mtls flag) to be enabled.")
22+
def run_pqc_test(use_tls):
23+
if not use_tls:
24+
pytest.skip("PQC integration test requires TLS (--tls or --mtls flag) to be enabled.")
2525

2626

2727
def _verify_pqc_negotiated_group(client, interceptor, transport_name):

0 commit comments

Comments
 (0)