Skip to content

Commit d38c513

Browse files
authored
RUST-1664: Introduce OIDC prose tests (#1063)
1 parent cbcd275 commit d38c513

File tree

9 files changed

+1491
-228
lines changed

9 files changed

+1491
-228
lines changed

.evergreen/config.yml

Lines changed: 65 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -292,16 +292,38 @@ buildvariants:
292292
tasks:
293293
- serverless-task-group
294294

295-
- name: oidc
296-
display_name: OIDC
297-
patchable: false
295+
- name: oidc-linux
296+
display_name: "OIDC Linux"
297+
patchable: true
298298
run_on:
299-
- ubuntu2204-small
299+
- ubuntu2204-large
300+
expansions:
301+
AUTH: auth
302+
SSL: ssl
303+
tasks:
304+
- testoidc_task_group
305+
306+
- name: oidc-macos
307+
display_name: "OIDC Macos"
308+
patchable: true
309+
run_on:
310+
- macos-1100
300311
expansions:
301312
AUTH: auth
302313
SSL: ssl
303314
tasks:
304-
- test-oidc
315+
- testoidc_task_group
316+
317+
- name: oidc-windows
318+
display_name: "OIDC Windows"
319+
patchable: true
320+
run_on:
321+
- windows-64-vsMulti-small
322+
expansions:
323+
AUTH: auth
324+
SSL: ssl
325+
tasks:
326+
- testoidc_task_group
305327

306328
- name: in-use-encryption
307329
display_name: "In-Use Encryption"
@@ -588,6 +610,35 @@ task_groups:
588610
tasks:
589611
- test-aws-lambda-deployed
590612

613+
- name: testoidc_task_group
614+
setup_group:
615+
- func: fetch source
616+
- func: create expansions
617+
- func: prepare resources
618+
- func: fix absolute paths
619+
- func: init test-results
620+
- func: make files executable
621+
- func: assume ec2 role
622+
- func: install rust
623+
- func: install junit dependencies
624+
- command: shell.exec
625+
params:
626+
shell: bash
627+
include_expansions_in_env: ["AWS_ACCESS_KEY_ID", "AWS_SECRET_ACCESS_KEY", "AWS_SESSION_TOKEN"]
628+
script: |
629+
${PREPARE_SHELL}
630+
${DRIVERS_TOOLS}/.evergreen/auth_oidc/setup.sh
631+
teardown_task:
632+
- command: subprocess.exec
633+
params:
634+
binary: bash
635+
args:
636+
- ${DRIVERS_TOOLS}/.evergreen/auth_oidc/teardown.sh
637+
setup_group_can_fail_task: true
638+
setup_group_timeout_secs: 1800
639+
tasks:
640+
- oidc-auth-test-latest
641+
591642
#########
592643
# Tasks #
593644
#########
@@ -1052,18 +1103,6 @@ tasks:
10521103
TOPOLOGY: replica_set
10531104
- func: "run sync tests"
10541105

1055-
- name: test-oidc
1056-
commands:
1057-
- func: bootstrap oidc
1058-
- func: bootstrap mongo-orchestration
1059-
vars:
1060-
AUTH: auth
1061-
ORCHESTRATION_FILE: auth-oidc.json
1062-
MONGODB_VERSION: latest
1063-
TOPOLOGY: replica_set
1064-
- func: setup oidc
1065-
- func: run oidc tests
1066-
10671106
- name: test-in-use-encryption-4.2
10681107
tags: [in-use-encryption]
10691108
commands:
@@ -1219,7 +1258,7 @@ tasks:
12191258
LOAD_BALANCER: true
12201259
- func: start load balancer
12211260
- func: run driver test suite
1222-
1261+
12231262
- name: test-aws-lambda-deployed
12241263
commands:
12251264
- command: ec2.assume_role
@@ -1238,6 +1277,10 @@ tasks:
12381277
AWS_REGION: us-east-1
12391278
SAM_BUILD_ARGS: --beta-features --debug
12401279

1280+
- name: "oidc-auth-test-latest"
1281+
commands:
1282+
- func: "run oidc auth test with test credentials"
1283+
12411284
#############
12421285
# Functions #
12431286
#############
@@ -1678,45 +1721,21 @@ functions:
16781721
./test-contents/test-exe on_demand_gcp_credentials --nocapture"
16791722
$DRIVERS_TOOLS/.evergreen/csfle/gcpkms/run-command.sh
16801723
1681-
"bootstrap oidc":
1724+
"assume ec2 role":
16821725
- command: ec2.assume_role
16831726
params:
16841727
role_arn: ${aws_test_secrets_role}
1685-
- command: shell.exec
1686-
params:
1687-
working_dir: src
1688-
shell: bash
1689-
script: |
1690-
${PREPARE_SHELL}
1691-
cd ${DRIVERS_TOOLS}/.evergreen/auth_oidc
1692-
set +o xtrace
1693-
1694-
export OIDC_TOKEN_DIR=/tmp/tokens
1695-
1696-
. ./activate-authoidcvenv.sh
1697-
python oidc_write_orchestration.py
1698-
python oidc_get_tokens.py
1699-
1700-
"setup oidc":
1701-
- command: shell.exec
1702-
params:
1703-
working_dir: src
1704-
shell: bash
1705-
script: |
1706-
${PREPARE_SHELL}
1707-
cd ${DRIVERS_TOOLS}/.evergreen/auth_oidc
1708-
mongosh setup_oidc.js
17091728

1710-
"run oidc tests":
1729+
"run oidc auth test with test credentials":
17111730
- command: shell.exec
17121731
type: test
17131732
params:
17141733
working_dir: src
17151734
shell: bash
1735+
include_expansions_in_env: ["DRIVERS_TOOLS", "AWS_ACCESS_KEY_ID", "AWS_SECRET_ACCESS_KEY", "AWS_SESSION_TOKEN"]
17161736
script: |
17171737
${PREPARE_SHELL}
1718-
export OIDC_TOKEN_DIR=/tmp/tokens
1719-
.evergreen/run-oidc-tests.sh
1738+
.evergreen/run-mongodb-oidc-test.sh
17201739
17211740
"compile only":
17221741
- command: shell.exec

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

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/bin/bash
2+
3+
set +x # Disable debug trace
4+
set -o errexit # Exit the script with error if any of the commands fail
5+
6+
source .evergreen/env.sh
7+
source .evergreen/cargo-test.sh
8+
9+
echo "Running MONGODB-OIDC authentication tests"
10+
11+
OIDC_ENV=${OIDC_ENV:-"test"}
12+
13+
if [ $OIDC_ENV == "test" ]; then
14+
# Make sure DRIVERS_TOOLS is set.
15+
if [ -z "$DRIVERS_TOOLS" ]; then
16+
echo "Must specify DRIVERS_TOOLS"
17+
exit 1
18+
fi
19+
source ${DRIVERS_TOOLS}/.evergreen/auth_oidc/secrets-export.sh
20+
21+
elif [ $OIDC_ENV == "azure" ]; then
22+
source ./env.sh
23+
24+
else
25+
echo "Unrecognized OIDC_ENV $OIDC_ENV"
26+
exit 1
27+
fi
28+
29+
export TEST_AUTH_OIDC=1
30+
export COVERAGE=1
31+
export AUTH="auth"
32+
export OIDC="oidc"
33+
34+
cargo nextest run test::spec::oidc --profile ci
35+
RESULT=$?
36+
cp target/nextest/ci/junit.xml results.xml
37+
exit $RESULT

.evergreen/run-oidc-tests.sh

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

src/client/auth.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ impl AuthMechanism {
258258

259259
/// Constructs the first message to be sent to the server as part of the authentication
260260
/// handshake, which can be used for speculative authentication.
261-
pub(crate) fn build_speculative_client_first(
261+
pub(crate) async fn build_speculative_client_first(
262262
&self,
263263
credential: &Credential,
264264
) -> Result<Option<ClientFirst>> {
@@ -278,9 +278,9 @@ impl AuthMechanism {
278278
x509::build_speculative_client_first(credential),
279279
)))),
280280
Self::Plain => Ok(None),
281-
Self::MongoDbOidc => Ok(Some(ClientFirst::Oidc(Box::new(
282-
oidc::build_speculative_client_first(credential),
283-
)))),
281+
Self::MongoDbOidc => Ok(oidc::build_speculative_client_first(credential)
282+
.await
283+
.map(|comm| ClientFirst::Oidc(Box::new(comm)))),
284284
#[cfg(feature = "aws-auth")]
285285
AuthMechanism::MongoDbAws => Ok(None),
286286
AuthMechanism::MongoDbCr => Err(ErrorKind::Authentication {
@@ -556,6 +556,7 @@ impl Debug for Credential {
556556
}
557557

558558
/// Contains the first client message sent as part of the authentication handshake.
559+
#[derive(Debug)]
559560
pub(crate) enum ClientFirst {
560561
Scram(ScramVersion, scram::ClientFirst),
561562
X509(Box<Command>),

0 commit comments

Comments
 (0)