Skip to content

Commit a548f7a

Browse files
blink1073NoahStapp
andauthored
PYTHON-5195 Convert OCSP tests to use new test scripts (#2190)
Co-authored-by: Noah Stapp <noah@noahstapp.com>
1 parent 38127f4 commit a548f7a

File tree

8 files changed

+724
-715
lines changed

8 files changed

+724
-715
lines changed

.evergreen/config.yml

Lines changed: 14 additions & 383 deletions
Large diffs are not rendered by default.

.evergreen/generated_configs/tasks.yml

Lines changed: 594 additions & 304 deletions
Large diffs are not rendered by default.

.evergreen/scripts/generate_config.py

Lines changed: 58 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -801,7 +801,7 @@ def create_server_tasks():
801801
AUTH=auth,
802802
SSL=ssl,
803803
)
804-
server_func = FunctionCall(func="run-server", vars=server_vars)
804+
server_func = FunctionCall(func="run server", vars=server_vars)
805805
test_vars = dict(AUTH=auth, SSL=ssl, SYNC=sync)
806806
if sync == "sync":
807807
test_vars["TEST_NAME"] = "default_sync"
@@ -820,7 +820,7 @@ def create_load_balancer_tasks():
820820
server_vars = dict(
821821
TOPOLOGY="sharded_cluster", AUTH=auth, SSL=ssl, TEST_NAME="load_balancer"
822822
)
823-
server_func = FunctionCall(func="run-server", vars=server_vars)
823+
server_func = FunctionCall(func="run server", vars=server_vars)
824824
test_vars = dict(AUTH=auth, SSL=ssl, TEST_NAME="load_balancer")
825825
test_func = FunctionCall(func="run tests", vars=test_vars)
826826
tasks.append(EvgTask(name=name, tags=tags, commands=[server_func, test_func]))
@@ -839,7 +839,7 @@ def create_kms_tasks():
839839
sub_test_name += "-fail"
840840
commands = []
841841
if not success:
842-
commands.append(FunctionCall(func="run-server"))
842+
commands.append(FunctionCall(func="run server"))
843843
test_vars = dict(TEST_NAME="kms", SUB_TEST_NAME=sub_test_name)
844844
test_func = FunctionCall(func="run tests", vars=test_vars)
845845
commands.append(test_func)
@@ -862,7 +862,7 @@ def create_aws_tasks():
862862
base_name = f"test-auth-aws-{version}"
863863
base_tags = ["auth-aws"]
864864
server_vars = dict(AUTH_AWS="1", VERSION=version)
865-
server_func = FunctionCall(func="run-server", vars=server_vars)
865+
server_func = FunctionCall(func="run server", vars=server_vars)
866866
assume_func = FunctionCall(func="assume ec2 role")
867867
for test_type in aws_test_types:
868868
tags = [*base_tags, f"auth-aws-{test_type}"]
@@ -884,6 +884,60 @@ def create_aws_tasks():
884884
return tasks
885885

886886

887+
def _create_ocsp_task(algo, variant, server_type, base_task_name):
888+
file_name = f"{algo}-basic-tls-ocsp-{variant}.json"
889+
890+
vars = dict(TEST_NAME="ocsp", ORCHESTRATION_FILE=file_name)
891+
server_func = FunctionCall(func="run server", vars=vars)
892+
893+
vars = dict(ORCHESTRATION_FILE=file_name, OCSP_SERVER_TYPE=server_type, TEST_NAME="ocsp")
894+
test_func = FunctionCall(func="run tests", vars=vars)
895+
896+
tags = ["ocsp", f"ocsp-{algo}"]
897+
if "disableStapling" not in variant:
898+
tags.append("ocsp-staple")
899+
900+
task_name = f"test-ocsp-{algo}-{base_task_name}"
901+
commands = [server_func, test_func]
902+
return EvgTask(name=task_name, tags=tags, commands=commands)
903+
904+
905+
def create_ocsp_tasks():
906+
tasks = []
907+
tests = [
908+
("disableStapling", "valid", "valid-cert-server-does-not-staple"),
909+
("disableStapling", "revoked", "invalid-cert-server-does-not-staple"),
910+
("disableStapling", "valid-delegate", "delegate-valid-cert-server-does-not-staple"),
911+
("disableStapling", "revoked-delegate", "delegate-invalid-cert-server-does-not-staple"),
912+
("disableStapling", "no-responder", "soft-fail"),
913+
("mustStaple", "valid", "valid-cert-server-staples"),
914+
("mustStaple", "revoked", "invalid-cert-server-staples"),
915+
("mustStaple", "valid-delegate", "delegate-valid-cert-server-staples"),
916+
("mustStaple", "revoked-delegate", "delegate-invalid-cert-server-staples"),
917+
(
918+
"mustStaple-disableStapling",
919+
"revoked",
920+
"malicious-invalid-cert-mustStaple-server-does-not-staple",
921+
),
922+
(
923+
"mustStaple-disableStapling",
924+
"revoked-delegate",
925+
"delegate-malicious-invalid-cert-mustStaple-server-does-not-staple",
926+
),
927+
(
928+
"mustStaple-disableStapling",
929+
"no-responder",
930+
"malicious-no-responder-mustStaple-server-does-not-staple",
931+
),
932+
]
933+
for algo in ["ecdsa", "rsa"]:
934+
for variant, server_type, base_task_name in tests:
935+
task = _create_ocsp_task(algo, variant, server_type, base_task_name)
936+
tasks.append(task)
937+
938+
return tasks
939+
940+
887941
##################
888942
# Generate Config
889943
##################

.evergreen/scripts/run-ocsp-test.sh

Lines changed: 0 additions & 12 deletions
This file was deleted.

.evergreen/scripts/run_server.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,26 @@ def start_server():
3232
elif test_name == "load_balancer":
3333
set_env("LOAD_BALANCER")
3434

35+
elif test_name == "ocsp":
36+
opts.ssl = True
37+
if "ORCHESTRATION_FILE" not in os.environ:
38+
found = False
39+
for opt in extra_opts:
40+
if opt.startswith("--orchestration-file"):
41+
found = True
42+
if not found:
43+
raise ValueError("Please provide an orchestration file")
44+
3545
if not os.environ.get("TEST_CRYPT_SHARED"):
3646
set_env("SKIP_CRYPT_SHARED")
3747

3848
if opts.ssl:
3949
extra_opts.append("--ssl")
40-
certs = ROOT / "test/certificates"
41-
set_env("TLS_CERT_KEY_FILE", certs / "client.pem")
42-
set_env("TLS_PEM_KEY_FILE", certs / "server.pem")
43-
set_env("TLS_CA_FILE", certs / "ca.pem")
50+
if test_name != "ocsp":
51+
certs = ROOT / "test/certificates"
52+
set_env("TLS_CERT_KEY_FILE", certs / "client.pem")
53+
set_env("TLS_PEM_KEY_FILE", certs / "server.pem")
54+
set_env("TLS_CA_FILE", certs / "ca.pem")
4455

4556
cmd = ["bash", f"{DRIVERS_TOOLS}/.evergreen/run-orchestration.sh", *extra_opts]
4657
run_command(cmd, cwd=DRIVERS_TOOLS)

.evergreen/scripts/setup_tests.py

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,30 @@ def handle_test_env() -> None:
239239
cmd = f'bash "{DRIVERS_TOOLS}/.evergreen/run-load-balancer.sh" start'
240240
run_command(cmd)
241241

242+
if test_name == "ocsp":
243+
if sub_test_name:
244+
os.environ["OCSP_SERVER_TYPE"] = sub_test_name
245+
for name in ["OCSP_SERVER_TYPE", "ORCHESTRATION_FILE"]:
246+
if name not in os.environ:
247+
raise ValueError(f"Please set {name}")
248+
249+
server_type = os.environ["OCSP_SERVER_TYPE"]
250+
orch_file = os.environ["ORCHESTRATION_FILE"]
251+
ocsp_algo = orch_file.split("-")[0]
252+
if server_type == "no-responder":
253+
tls_should_succeed = "false" if "mustStaple-disableStapling" in orch_file else "true"
254+
else:
255+
tls_should_succeed = "true" if "valid" in server_type else "false"
256+
257+
write_env("OCSP_TLS_SHOULD_SUCCEED", tls_should_succeed)
258+
write_env("CA_FILE", f"{DRIVERS_TOOLS}/.evergreen/ocsp/{ocsp_algo}/ca.pem")
259+
260+
if server_type != "no-responder":
261+
env = os.environ.copy()
262+
env["SERVER_TYPE"] = server_type
263+
env["OCSP_ALGORITHM"] = ocsp_algo
264+
run_command(f"bash {DRIVERS_TOOLS}/.evergreen/ocsp/setup.sh", env=env)
265+
242266
if SSL != "nossl":
243267
if not DRIVERS_TOOLS:
244268
raise RuntimeError("Missing DRIVERS_TOOLS")
@@ -302,10 +326,6 @@ def handle_test_env() -> None:
302326

303327
setup_kms(sub_test_name)
304328

305-
if test_name == "ocsp":
306-
write_env("CA_FILE", os.environ["CA_FILE"])
307-
write_env("OCSP_TLS_SHOULD_SUCCEED", os.environ["OCSP_TLS_SHOULD_SUCCEED"])
308-
309329
if test_name == "auth_aws" and sub_test_name != "ecs-remote":
310330
auth_aws_dir = f"{DRIVERS_TOOLS}/.evergreen/auth_aws"
311331
if "AWS_ROLE_SESSION_NAME" in os.environ:

.evergreen/scripts/teardown_tests.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@
2424

2525
teardown_kms(SUB_TEST_NAME)
2626

27+
# Tear down ocsp if applicable.
28+
elif TEST_NAME == "ocsp":
29+
run_command(f"bash {DRIVERS_TOOLS}/.evergreen/teardown.sh")
30+
2731
# Tear down auth_aws if applicable.
2832
# We do not run web-identity hosts on macos, because the hosts lack permissions,
2933
# so there is no reason to run the teardown, which would error with a 401.

CONTRIBUTING.md

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -218,12 +218,12 @@ the pages will re-render and the browser will automatically refresh.
218218
### Usage
219219

220220
- Run `just run-server` with optional args to set up the server.
221-
All given flags will be passed to `run-orchestration.sh` in `DRIVERS_TOOLS`.
221+
All given flags will be passed to `run-orchestration.sh` in `$DRIVERS_TOOLS`.
222222
- Run `just setup-tests` with optional args to set up the test environment, secrets, etc.
223223
- Run `just run-tests` to run the tests in an appropriate Python environment.
224224
- When done, run `just teardown-tests` to clean up and `just stop-server` to stop the server.
225225

226-
## Encryption tests
226+
### Encryption tests
227227

228228
- Run `just run-server` to start the server.
229229
- Run `just setup-tests encryption`.
@@ -236,13 +236,13 @@ the pages will re-render and the browser will automatically refresh.
236236
- Set up the test with `just setup-tests load_balancer`.
237237
- Run the tests with `just run-tests`.
238238

239-
## AWS tests
239+
### AWS tests
240240

241241
- Run `just run-server auth_aws` to start the server.
242242
- Run `just setup-tests auth_aws <aws-test-type>` to set up the AWS test.
243243
- Run the tests with `just run-tests`.
244244

245-
## KMS tests
245+
### KMS tests
246246

247247
For KMS tests that are run locally, and expected to fail, in this case using `azure`:
248248

@@ -255,6 +255,17 @@ For KMS tests that run remotely and are expected to pass, in this case using `gc
255255
- Run `just setup-tests kms gcp`.
256256
- Run `just run-tests`.
257257

258+
### OCSP tests
259+
260+
- Export the orchestration file, e.g. `export ORCHESTRATION_FILE=rsa-basic-tls-ocsp-disableStapling.json`.
261+
This corresponds to a config file in `$DRIVERS_TOOLS/.evergreen/orchestration/configs/servers`.
262+
MongoDB servers on MacOS and Windows do not staple OCSP responses and only support RSA.
263+
- Run `just run-server ocsp`.
264+
- Run `just setup-tests ocsp <sub test>` (options are "valid", "revoked", "valid-delegate", "revoked-delegate").
265+
- Run `just run-tests`
266+
267+
If you are running one of the `no-responder` tests, omit the `run-server` step.
268+
258269
## Enable Debug Logs
259270
- Use `-o log_cli_level="DEBUG" -o log_cli=1` with `just test` or `pytest`.
260271
- Add `log_cli_level = "DEBUG` and `log_cli = 1` to the `tool.pytest.ini_options` section in `pyproject.toml` for Evergreen patches or to enable debug logs by default on your machine.

0 commit comments

Comments
 (0)