Skip to content

Commit 0749ee9

Browse files
committed
Merge branch 'master' of github.com:mongodb/mongo-python-driver into PYTHON-5196
2 parents 234ab70 + a548f7a commit 0749ee9

File tree

8 files changed

+723
-715
lines changed

8 files changed

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

892945

.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
@@ -37,15 +37,26 @@ def start_server():
3737
run_command(cmd, cwd=DRIVERS_TOOLS)
3838
return
3939

40+
elif test_name == "ocsp":
41+
opts.ssl = True
42+
if "ORCHESTRATION_FILE" not in os.environ:
43+
found = False
44+
for opt in extra_opts:
45+
if opt.startswith("--orchestration-file"):
46+
found = True
47+
if not found:
48+
raise ValueError("Please provide an orchestration file")
49+
4050
if not os.environ.get("TEST_CRYPT_SHARED"):
4151
set_env("SKIP_CRYPT_SHARED")
4252

4353
if opts.ssl:
4454
extra_opts.append("--ssl")
45-
certs = ROOT / "test/certificates"
46-
set_env("TLS_CERT_KEY_FILE", certs / "client.pem")
47-
set_env("TLS_PEM_KEY_FILE", certs / "server.pem")
48-
set_env("TLS_CA_FILE", certs / "ca.pem")
55+
if test_name != "ocsp":
56+
certs = ROOT / "test/certificates"
57+
set_env("TLS_CERT_KEY_FILE", certs / "client.pem")
58+
set_env("TLS_PEM_KEY_FILE", certs / "server.pem")
59+
set_env("TLS_CA_FILE", certs / "ca.pem")
4960

5061
cmd = ["bash", f"{DRIVERS_TOOLS}/.evergreen/run-orchestration.sh", *extra_opts]
5162
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
@@ -242,6 +242,30 @@ def handle_test_env() -> None:
242242
if test_name == "oidc":
243243
pass
244244

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

306330
setup_kms(sub_test_name)
307331

308-
if test_name == "ocsp":
309-
write_env("CA_FILE", os.environ["CA_FILE"])
310-
write_env("OCSP_TLS_SHOULD_SUCCEED", os.environ["OCSP_TLS_SHOULD_SUCCEED"])
311-
312332
if test_name == "auth_aws" and sub_test_name != "ecs-remote":
313333
auth_aws_dir = f"{DRIVERS_TOOLS}/.evergreen/auth_aws"
314334
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)