Skip to content

Commit e6fa610

Browse files
committed
wip
1 parent 3bbd5f2 commit e6fa610

File tree

6 files changed

+53
-43
lines changed

6 files changed

+53
-43
lines changed

.evergreen/run-mongodb-oidc-test.sh

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,9 @@
33
set +x # Disable debug trace
44
set -eu
55

6-
echo "Running MONGODB-OIDC authentication tests"
6+
echo "Running MONGODB-OIDC authentication tests on ${OIDC_ENV}..."
77

8-
if [ $OIDC_ENV == "azure" ]; then
9-
source ./env.sh
10-
11-
elif [ $OIDC_ENV == "gcp" ]; then
12-
source ./secrets-export.sh
13-
14-
elif [ $OIDC_ENV == "k8s" ]; then
15-
echo "Running oidc on k8s"
16-
17-
else
18-
echo "Unrecognized OIDC_ENV $OIDC_ENV"
19-
exit 1
20-
fi
21-
22-
bash ./.evergreen/just.sh setup-tests auth_oidc remote
8+
bash ./.evergreen/just.sh setup-tests auth_oidc ${OIDC_ENV}-remote
239
bash ./.evergreen/just.sh run-tests "${@:1}"
10+
11+
echo "Running MONGODB-OIDC authentication tests on ${OIDC_ENV}... done."

.evergreen/run-tests.sh

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,6 @@ else
2424
exit 1
2525
fi
2626

27-
# Source the local secrets export file if available.
28-
if [ -f "./secrets-export.sh" ]; then
29-
. "./secrets-export.sh"
30-
fi
31-
3227
# List the packages.
3328
PIP_QUIET=0 uv run ${UV_ARGS} --with pip pip list
3429

.evergreen/scripts/oidc_tester.py

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,43 +2,65 @@
22

33
import os
44

5-
from utils import (
6-
DRIVERS_TOOLS,
7-
TMP_DRIVER_FILE,
8-
run_command,
9-
)
5+
from utils import DRIVERS_TOOLS, TMP_DRIVER_FILE, create_archive, read_env, run_command, write_env
106

117
K8S_NAMES = ["aks", "gke", "eks"]
8+
K8S_REMOTE_NAMES = [f"{n}-remote" for n in K8S_NAMES]
129

1310

1411
def _get_target_dir(sub_test_name: str) -> str:
1512
if sub_test_name == "test":
1613
target_dir = "auth_oidc"
17-
elif sub_test_name == "azure":
14+
elif sub_test_name.startswith("azure"):
1815
target_dir = "auth_oidc/azure"
19-
elif sub_test_name == "gcp":
16+
elif sub_test_name.startswith("gcp"):
2017
target_dir = "auth_oidc/gcp"
21-
elif sub_test_name in K8S_NAMES:
18+
elif sub_test_name in K8S_NAMES + K8S_REMOTE_NAMES:
2219
target_dir = "auth_oidc/k8s"
2320
else:
2421
raise ValueError(f"Invalid sub test name '{sub_test_name}'")
2522
return f"{DRIVERS_TOOLS}/.evergreen/{target_dir}"
2623

2724

28-
def setup_oidc(sub_test_name: str) -> None:
25+
def setup_oidc(sub_test_name: str) -> dict[str, str] | None:
2926
target_dir = _get_target_dir(sub_test_name)
3027
env = os.environ.copy()
3128
if sub_test_name == "azure":
3229
env["AZUREOIDC_VMNAME_PREFIX"] = "PYTHON_DRIVER"
33-
run_command(f"bash {target_dir}/setup.sh", env=env)
30+
elif "-remote" not in sub_test_name:
31+
run_command(f"bash {target_dir}/setup.sh", env=env)
3432
if sub_test_name in K8S_NAMES:
35-
run_command(f"bash {target_dir}/setup-pod.sh")
33+
run_command(f"bash {target_dir}/setup-pod.sh {sub_test_name}")
3634
run_command(f"bash {target_dir}/run-self-test.sh")
35+
return None
36+
37+
source_file = None
38+
if sub_test_name == "test":
39+
source_file = f"{target_dir}/secrets-export.sh"
40+
elif sub_test_name == "azure-remote":
41+
source_file = "./env.sh"
42+
elif sub_test_name == "gcp-remote":
43+
source_file = "./secrets-export.sh"
44+
if sub_test_name in K8S_REMOTE_NAMES:
45+
return os.environ.copy()
46+
if source_file is None:
47+
return None
48+
49+
config = read_env(source_file)
50+
write_env("MONGODB_URI_SINGLE", config["MONGODB_URI_SINGLE"])
51+
write_env("MONGODB_URI", config["MONGODB_URI"])
52+
write_env("DB_IP", config["MONGODB_URI"])
53+
54+
if sub_test_name == "test":
55+
write_env("OIDC_TOKEN_FILE", config["OIDC_TOKEN_FILE"])
56+
write_env("OIDC_TOKEN_DIR", config["OIDC_TOKEN_DIR"])
57+
return config
3758

3859

3960
def test_oidc_remote(sub_test_name: str) -> None:
4061
env = os.environ.copy()
4162
target_dir = _get_target_dir(sub_test_name)
63+
create_archive()
4264
if sub_test_name in ["azure", "gcp"]:
4365
upper_name = sub_test_name.upper()
4466
env[f"{upper_name}OIDC_DRIVERS_TAR_FILE"] = TMP_DRIVER_FILE
@@ -48,8 +70,7 @@ def test_oidc_remote(sub_test_name: str) -> None:
4870
elif sub_test_name in K8S_NAMES:
4971
env["K8S_DRIVERS_TAR_FILE"] = TMP_DRIVER_FILE
5072
env["K8S_TEST_CMD"] = "OIDC_ENV=k8s ./.evergreen/run-mongodb-oidc-test.sh"
51-
52-
run_command(f"bash {target_dir}/run-driver-test.sh")
73+
run_command(f"bash {target_dir}/run-driver-test.sh", env=env)
5374

5475

5576
def teardown_oidc(sub_test_name: str) -> None:

.evergreen/scripts/setup_tests.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,13 @@ def handle_test_env() -> None:
161161
if group := GROUP_MAP.get(test_name, ""):
162162
UV_ARGS.append(f"--group {group}")
163163

164+
if test_name == "auth_oidc":
165+
from oidc_tester import setup_oidc
166+
167+
config = setup_oidc(sub_test_name)
168+
if not config:
169+
AUTH = "noauth"
170+
164171
if AUTH != "noauth":
165172
if test_name == "data_lake":
166173
config = read_env(f"{DRIVERS_TOOLS}/.evergreen/atlas_data_lake/secrets-export.sh")
@@ -174,9 +181,8 @@ def handle_test_env() -> None:
174181
write_env("SINGLE_MONGOS_LB_URI", config["SERVERLESS_URI"])
175182
write_env("MULTI_MONGOS_LB_URI", config["SERVERLESS_URI"])
176183
elif test_name == "auth_oidc":
177-
DB_USER = os.environ["OIDC_ADMIN_USER"]
178-
DB_PASSWORD = os.environ["OIDC_ADMIN_PWD"]
179-
write_env("DB_IP", os.environ["MONGODB_URI"])
184+
DB_USER = config["OIDC_ADMIN_USER"]
185+
DB_PASSWORD = config["OIDC_ADMIN_PWD"]
180186
elif test_name == "index_management":
181187
config = read_env(f"{DRIVERS_TOOLS}/.evergreen/atlas/secrets-export.sh")
182188
DB_USER = config["DRIVERS_ATLAS_LAMBDA_USER"]
@@ -239,11 +245,6 @@ def handle_test_env() -> None:
239245
cmd = f'bash "{DRIVERS_TOOLS}/.evergreen/run-load-balancer.sh" start'
240246
run_command(cmd)
241247

242-
if test_name == "auth_oidc":
243-
from oidc_helper import setup_oidc
244-
245-
setup_oidc(sub_test_name)
246-
247248
if test_name == "ocsp":
248249
if sub_test_name:
249250
os.environ["OCSP_SERVER_TYPE"] = sub_test_name

.evergreen/scripts/teardown_tests.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
teardown_kms(SUB_TEST_NAME)
2626

2727
# Tear down OIDC if applicable.
28-
elif TEST_NAME == "oidc":
28+
elif TEST_NAME == "auth_oidc":
2929
from oidc_tester import teardown_oidc
3030

3131
teardown_oidc(SUB_TEST_NAME)

test/auth_oidc/test_auth_oidc.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,11 @@ def setUpClass(cls):
7070
cls.uri_single = os.environ["MONGODB_URI_SINGLE"]
7171
cls.uri_multiple = os.environ.get("MONGODB_URI_MULTI")
7272
cls.uri_admin = os.environ["MONGODB_URI"]
73+
if ENVIRON == "test":
74+
if not TOKEN_DIR:
75+
raise ValueError("Please set OIDC_TOKEN_DIR")
76+
if not TOKEN_FILE:
77+
raise ValueError("Please set OIDC_TOKEN_FILE")
7378

7479
def setUp(self):
7580
self.request_called = 0

0 commit comments

Comments
 (0)