|
12 | 12 | # See the License for the specific language governing permissions and |
13 | 13 | # limitations under the License. |
14 | 14 |
|
| 15 | +import os |
15 | 16 | import pytest |
| 17 | +import requests |
16 | 18 | from google import showcase |
17 | 19 |
|
18 | 20 | @pytest.fixture |
@@ -50,3 +52,46 @@ def test_pqc_negotiated_group(run_pqc_test, request, transport_fixture): |
50 | 52 | # Enforce PQC compliance (this will fail if not using MLKEM/Kyber) |
51 | 53 | assert "MLKEM" in negotiated_group or "Kyber" in negotiated_group, \ |
52 | 54 | f"Failed: {transport_fixture} Connection is NOT PQC-compliant! Negotiated: {negotiated_group}" |
| 55 | + |
| 56 | + |
| 57 | +def test_google_auth_transport_pqc(run_pqc_test): |
| 58 | + """Verifies that the google-auth HTTP transport adapter negotiates PQC with the Showcase server.""" |
| 59 | + import google.auth.transport.requests |
| 60 | + from conftest import HostNameIgnoringAdapter |
| 61 | + |
| 62 | + # 1. Initialize a standard requests Session with mTLS certs |
| 63 | + session = requests.Session() |
| 64 | + cert_path = "/usr/local/google/home/omairn/git/googleapis/google-cloud-python-dev2/packages/gapic-generator/tests/cert/mtls.crt" |
| 65 | + key_path = "/usr/local/google/home/omairn/git/googleapis/google-cloud-python-dev2/packages/gapic-generator/tests/cert/mtls.key" |
| 66 | + |
| 67 | + session.verify = cert_path |
| 68 | + session.cert = (cert_path, key_path) |
| 69 | + |
| 70 | + # Bypass localhost hostname mismatch |
| 71 | + session.mount("https://", HostNameIgnoringAdapter()) |
| 72 | + |
| 73 | + # 2. Wrap it in google-auth's Transport Request adapter |
| 74 | + # This is the exact object google-auth uses to execute its own HTTP/REST requests. |
| 75 | + auth_transport = google.auth.transport.requests.Request(session=session) |
| 76 | + |
| 77 | + # 3. Make secure call using the google-auth transport adapter |
| 78 | + url = "https://localhost:7469/v1beta1/echo:echo" |
| 79 | + method = "POST" |
| 80 | + headers = {"Content-Type": "application/json"} |
| 81 | + body = b'{"content": "Verify google-auth transport PQC connection."}' |
| 82 | + |
| 83 | + # Execute the request through google-auth's transport layer |
| 84 | + response = auth_transport(url=url, method=method, body=body, headers=headers) |
| 85 | + assert response.status == 200 |
| 86 | + |
| 87 | + # 4. Extract TLS group from response headers returned by Showcase |
| 88 | + negotiated_group = response.headers.get("x-showcase-tls-group") |
| 89 | + supported_groups = response.headers.get("x-showcase-tls-client-supported-groups") |
| 90 | + |
| 91 | + assert negotiated_group is not None, "Failed: Showcase server did not return negotiated TLS group header." |
| 92 | + print(f"\n[google-auth Transport PQC] Negotiated TLS Group: {negotiated_group}") |
| 93 | + print(f"[google-auth Transport PQC] Client Advertised Supported Groups: {supported_groups}") |
| 94 | + |
| 95 | + # Assert PQC compliance |
| 96 | + assert "MLKEM" in negotiated_group or "Kyber" in negotiated_group, \ |
| 97 | + f"Failed: google-auth Transport is NOT PQC-compliant! Negotiated: {negotiated_group}" |
0 commit comments