Skip to content

Commit eb4430e

Browse files
committed
Add integration test for autobuild truststore merging (github/codeql-team#4482)
1 parent fedb946 commit eb4430e

File tree

6 files changed

+70
-8
lines changed

6 files changed

+70
-8
lines changed

java/ql/integration-tests/java/buildless-inherit-trust-store/buildless-fetches.expected renamed to java/ql/integration-tests/java/buildless-inherit-trust-store/buildless-fetches.buildless.expected

File renamed without changes.

java/ql/integration-tests/java/buildless-inherit-trust-store/diagnostics.autobuild.expected

Whitespace-only changes.

java/ql/integration-tests/java/buildless-inherit-trust-store/diagnostics.expected renamed to java/ql/integration-tests/java/buildless-inherit-trust-store/diagnostics.buildless.expected

File renamed without changes.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
diagnostics
2+
| file://:0:0:0:0 | Appending source destination directory target/generated-sources/annotations to sourcepath |
3+
#select
4+
| DepClass |

java/ql/integration-tests/java/buildless-inherit-trust-store/test.expected renamed to java/ql/integration-tests/java/buildless-inherit-trust-store/test.buildless.expected

File renamed without changes.
Lines changed: 66 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,85 @@
1+
"""
2+
Integration tests for truststore inheritance and merging.
3+
4+
Tests that CodeQL can connect to HTTPS servers with custom CA certificates:
5+
1. test_buildless: Buildless mode inherits truststore from MAVEN_OPTS
6+
2. test_autobuild_merge_trust_store: Autobuild merges system truststore with
7+
CODEQL_PROXY_CA_CERTIFICATE (fixes github/codeql-team#4482)
8+
"""
19
import subprocess
210
import os
11+
import pytest
312
import runs_on
13+
from contextlib import contextmanager
414

515

6-
def test(codeql, java, cwd):
7-
# This serves the "repo" directory on https://locahost:4443
16+
@contextmanager
17+
def _https_server(cwd):
18+
"""Start an HTTPS server serving the repo/ directory on https://localhost:4443."""
819
command = ["python3", "../server.py"]
920
if runs_on.github_actions and runs_on.posix:
1021
# On GitHub Actions, we saw the server timing out while running in parallel with other tests
1122
# we work around that by running it with higher permissions
1223
command = ["sudo"] + command
1324
repo_server_process = subprocess.Popen(command, cwd="repo")
14-
certspath = cwd / "jdk8_shipped_cacerts_plus_cert_pem"
15-
# If we override MAVEN_OPTS, we'll break cross-test maven isolation, so we need to append to it instead
16-
maven_opts = os.environ["MAVEN_OPTS"] + f" -Djavax.net.ssl.trustStore={certspath}"
17-
1825
try:
26+
yield
27+
finally:
28+
repo_server_process.kill()
29+
30+
31+
@pytest.mark.ql_test(expected=".buildless.expected")
32+
def test_buildless(codeql, java, cwd, check_diagnostics, check_buildless_fetches):
33+
"""Test that buildless mode inherits truststore from MAVEN_OPTS."""
34+
# Use buildless-specific expected file suffixes
35+
check_diagnostics.expected_suffix = ".buildless.expected"
36+
check_buildless_fetches.expected_suffix = ".buildless.expected"
37+
38+
with _https_server(cwd):
39+
certspath = cwd / "jdk8_shipped_cacerts_plus_cert_pem"
40+
# If we override MAVEN_OPTS, we'll break cross-test maven isolation, so we need to append to it instead
41+
maven_opts = os.environ["MAVEN_OPTS"] + f" -Djavax.net.ssl.trustStore={certspath}"
42+
1943
codeql.database.create(
2044
extractor_option="buildless=true",
2145
_env={
2246
"MAVEN_OPTS": maven_opts,
2347
"CODEQL_JAVA_EXTRACTOR_TRUST_STORE_PATH": str(certspath),
2448
},
2549
)
26-
finally:
27-
repo_server_process.kill()
50+
51+
52+
@pytest.mark.ql_test(expected=".autobuild.expected")
53+
def test_autobuild_merge_trust_store(codeql, java, cwd, check_diagnostics):
54+
"""
55+
Test that autobuild merges system truststore with CODEQL_PROXY_CA_CERTIFICATE.
56+
57+
This tests the fix for github/codeql-team#4482 where autobuild was overriding
58+
JAVA_TOOL_OPTIONS truststore with a new one containing only the proxy CA,
59+
causing PKIX failures when connecting to internal HTTPS servers.
60+
"""
61+
# Use autobuild-specific expected file suffix
62+
check_diagnostics.expected_suffix = ".autobuild.expected"
63+
64+
with _https_server(cwd):
65+
certspath = cwd / "jdk8_shipped_cacerts_plus_cert_pem"
66+
67+
# Read the certificate to use as CODEQL_PROXY_CA_CERTIFICATE
68+
with open(cwd / "cert.pem", "r") as f:
69+
proxy_ca_cert = f.read()
70+
71+
# Set JAVA_TOOL_OPTIONS to use our custom truststore
72+
# This is the key setting that was being overridden before the fix
73+
java_tool_options = f"-Djavax.net.ssl.trustStore={certspath}"
74+
75+
# Run autobuild with the truststore configured
76+
# Before the fix: autobuild would create a new truststore with ONLY the proxy CA,
77+
# losing the custom CA from JAVA_TOOL_OPTIONS, causing PKIX failures
78+
# After the fix: autobuild merges the system truststore + proxy CA
79+
codeql.database.create(
80+
build_mode="autobuild",
81+
_env={
82+
"JAVA_TOOL_OPTIONS": java_tool_options,
83+
"CODEQL_PROXY_CA_CERTIFICATE": proxy_ca_cert,
84+
},
85+
)

0 commit comments

Comments
 (0)