-
Notifications
You must be signed in to change notification settings - Fork 225
RoutingClient: match Client's (host, port, tls=...) signature #1840
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
python/cuopt/cuopt/tests/routing/test_routing_grpc_client_tls.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| """TLS/mTLS coverage for the compiled VRP gRPC client (cuopt.grpc.routing). | ||
|
|
||
| Unlike test_routing_grpc_client.py, these tests do not need | ||
| CUOPT_GRPC_SERVER -- the tls_server_info/mtls_server_info fixtures start | ||
| their own cuopt_grpc_server subprocess (skipped if the test TLS certs are | ||
| not found). | ||
| """ | ||
|
|
||
| import os | ||
|
|
||
| import numpy as np | ||
| import pytest | ||
|
|
||
| from cuopt import routing | ||
| from cuopt.grpc.linear_programming import TlsConfig | ||
|
|
||
| grpc_routing = pytest.importorskip("cuopt.grpc.routing") | ||
|
|
||
|
|
||
| def _small_vrp(): | ||
| dm = routing.DataModel(5, 2) | ||
| cost = np.array( | ||
| [ | ||
| [0, 1, 2, 2, 1], | ||
| [1, 0, 1, 2, 2], | ||
| [2, 1, 0, 1, 2], | ||
| [2, 2, 1, 0, 1], | ||
| [1, 2, 2, 1, 0], | ||
| ], | ||
| dtype=np.float32, | ||
| ) | ||
| dm.add_cost_matrix(cost) | ||
| return dm | ||
|
|
||
|
|
||
| def test_rejects_invalid_tls_argument(): | ||
| with pytest.raises(TypeError): | ||
| grpc_routing.RoutingClient("localhost", 1, tls="bogus") | ||
|
|
||
|
|
||
| @pytest.mark.xdist_group(name="grpc_server") | ||
| @pytest.mark.filterwarnings("ignore::DeprecationWarning") | ||
| class TestRoutingClientTls: | ||
| def test_submit_with_explicit_tls_config(self, tls_server_info): | ||
| cert_dir = tls_server_info["cert_dir"] | ||
| client = grpc_routing.RoutingClient( | ||
| "localhost", | ||
| tls_server_info["port"], | ||
| tls=TlsConfig(os.path.join(cert_dir, "ca.crt")), | ||
| ) | ||
| solution = client.solve(_small_vrp(), {"time_limit": 2.0}) | ||
| assert solution["status"] == 0, solution["status_message"] | ||
|
|
||
| def test_tls_server_rejects_plain_client(self, tls_server_info): | ||
| with pytest.raises(grpc_routing.RoutingSolveError): | ||
| grpc_routing.RoutingClient( | ||
| "localhost", tls_server_info["port"], tls=False | ||
| ) | ||
|
|
||
| def test_submit_with_explicit_mtls_config(self, mtls_server_info): | ||
| cert_dir = mtls_server_info["cert_dir"] | ||
| client = grpc_routing.RoutingClient( | ||
| "localhost", | ||
| mtls_server_info["port"], | ||
| tls=TlsConfig( | ||
| os.path.join(cert_dir, "ca.crt"), | ||
| client_cert=os.path.join(cert_dir, "client.crt"), | ||
| client_key=os.path.join(cert_dir, "client.key"), | ||
| ), | ||
| ) | ||
| solution = client.solve(_small_vrp(), {"time_limit": 2.0}) | ||
| assert solution["status"] == 0, solution["status_message"] | ||
|
|
||
| def test_mtls_server_rejects_missing_client_cert(self, mtls_server_info): | ||
| cert_dir = mtls_server_info["cert_dir"] | ||
| with pytest.raises(grpc_routing.RoutingSolveError): | ||
| grpc_routing.RoutingClient( | ||
| "localhost", | ||
| mtls_server_info["port"], | ||
| tls=TlsConfig(os.path.join(cert_dir, "ca.crt")), | ||
| ) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.