Skip to content

Commit 34628a4

Browse files
author
Oleksandr Poliakov
committed
wip
1 parent 901d38f commit 34628a4

File tree

5 files changed

+127
-4
lines changed

5 files changed

+127
-4
lines changed

build.cake

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,18 @@ Task("TestGssapiNetStandard20").IsDependentOn("TestGssapi");
257257
Task("TestGssapiNetStandard21").IsDependentOn("TestGssapi");
258258
Task("TestGssapiNet60").IsDependentOn("TestGssapi");
259259

260+
Task("TestMongoDbOidc")
261+
.IsDependentOn("Build")
262+
.DoesForEach(
263+
items: GetFiles("./**/MongoDB.Driver.Tests.csproj"),
264+
action: (BuildConfig buildConfig, Path testProject) =>
265+
RunTests(buildConfig, testProject, filter: "Category=\"MongoDbOidc\""));
266+
267+
Task("TestMongoDbOidcNet472").IsDependentOn("TestMongoDbOidc");
268+
Task("TestMongoDbOidcNetStandard20").IsDependentOn("TestMongoDbOidc");
269+
Task("TestMongoDbOidcNetStandard21").IsDependentOn("TestMongoDbOidc");
270+
Task("TestMongoDbOidcNet60").IsDependentOn("TestMongoDbOidc");
271+
260272
Task("TestServerless")
261273
.IsDependentOn("Build")
262274
.DoesForEach(
@@ -692,7 +704,7 @@ public class BuildConfig
692704
string[] CreateLoggers(string projectName)
693705
{
694706
var testResultsFile = outputDirectory.Combine("test-results").Combine($"TEST-{projectName}-{target.ToLowerInvariant()}-{DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()}.xml");
695-
707+
696708
// Evergreen CI server requires JUnit output format to display test results
697709
var junitLogger = $"junit;LogFilePath={testResultsFile};FailureBodyFormat=Verbose";
698710
var consoleLogger = "console;verbosity=detailed";

evergreen/evergreen.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,11 @@ functions:
451451
params:
452452
file: mongo-csharp-driver/benchmarks/MongoDB.Driver.Benchmarks/Benchmark.Artifacts/results/evergreen-results.json
453453

454+
assume-ec2-role:
455+
- command: ec2.assume_role
456+
params:
457+
role_arn: ${aws_test_secrets_role}
458+
454459
add-aws-auth-variables-to-file:
455460
- command: ec2.assume_role
456461
params:
@@ -706,6 +711,26 @@ functions:
706711
-v \
707712
--fault revoked
708713
714+
run-mongodb-oidc-tests:
715+
- command: subprocess.exec
716+
type: test
717+
params:
718+
working_dir: mongo-csharp-driver
719+
binary: bash
720+
include_expansions_in_env:
721+
- "DRIVERS_TOOLS"
722+
- "AWS_ACCESS_KEY_ID"
723+
- "AWS_SECRET_ACCESS_KEY"
724+
- "AWS_SESSION_TOKEN"
725+
- "OS"
726+
- "FRAMEWORK"
727+
env:
728+
ADMIN_USER: ${OIDC_ALTAS_USER}
729+
ADMIN_PASSWORD: ${OIDC_ATLAS_PASSWORD}
730+
MONGODB_URI: ${OIDC_ATLAS_URI_SINGLE}
731+
args:
732+
- evergreen/run-mongodb-oidc-test.sh
733+
709734
run-serverless-tests:
710735
- command: shell.exec
711736
type: test
@@ -1237,6 +1262,11 @@ tasks:
12371262
commands:
12381263
- func: run-atlas-search-index-helpers-test
12391264

1265+
- name: test-oidc-auth-aws
1266+
commands:
1267+
- func: assume-ec2-role
1268+
- func: run-mongodb-oidc-tests
1269+
12401270
- name: test-serverless
12411271
exec_timeout_secs: 2700 # 45 minutes: 15 for setup + 30 for tests
12421272
commands:

evergreen/run-mongodb-oidc-tests.sh

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
#!/usr/bin/env bash
2+
3+
# Don't trace since the URI contains a password that shouldn't show up in the logs
4+
set -o errexit # Exit the script with error if any of the commands fail
5+
6+
# Supported/used environment variables:
7+
# FRAMEWORK Used in build.cake task, must be set
8+
# OS Operating system, must be set
9+
# ADMIN_USER Admin user, must be set
10+
# ADMIN_PASSWORD Admin password, must be set
11+
# MONGODB_URI Single atlas proxy serverless uri, must be set
12+
# OIDC_TOKEN_DIR Directory to store aws credentials
13+
# Modified/exported environment variables:
14+
# MONGODB_URI MONGODB_URI with embedded admin credentials
15+
# AWS_WEB_IDENTITY_TOKEN_FILE Path to the aws credentials file
16+
# OIDC_TESTS_ENABLED Flag to run Oidc tests
17+
# OIDC_PROVIDER_NAME OIDC provider name to be used in tests
18+
19+
############################################
20+
# Main Program #
21+
############################################
22+
23+
if [ -z "$FRAMEWORK" ]; then
24+
echo "FRAMEWORK should be specified"
25+
exit 1
26+
fi
27+
28+
if [ -z "$ADMIN_USER" ]; then
29+
echo "ADMIN_USER should be specified"
30+
exit 1
31+
fi
32+
33+
if [ -z "$ADMIN_PASSWORD" ]; then
34+
echo "ADMIN_PASSWORD should be specified"
35+
exit 1
36+
fi
37+
38+
if [ -z "$MONGODB_URI" ]; then
39+
echo "MONGODB_URI should be specified"
40+
exit 1
41+
fi
42+
43+
if [ -z "$OIDC_TOKEN_DIR" ]; then
44+
echo "OIDC_TOKEN_DIR should be specified"
45+
exit 1
46+
fi
47+
48+
if [ "$OS" = "Windows_NT" ]; then
49+
for var in TMP TEMP NUGET_PACKAGES NUGET_HTTP_CACHE_PATH APPDATA; do
50+
setx $var z:\\data\\tmp
51+
export $var=z:\\data\\tmp
52+
done
53+
else
54+
for var in TMP TEMP NUGET_PACKAGES NUGET_HTTP_CACHE_PATH APPDATA; do
55+
export $var=/data/tmp;
56+
done
57+
fi
58+
59+
# Make sure DRIVERS_TOOLS is set.
60+
if [ -z "$DRIVERS_TOOLS" ]; then
61+
echo "Must specify DRIVERS_TOOLS"
62+
exit 1
63+
fi
64+
65+
# Make the OIDC tokens.
66+
set -x
67+
pushd ${DRIVERS_TOOLS}/.evergreen/auth_oidc
68+
. ./oidc_get_tokens.sh
69+
popd
70+
71+
# Assume "mongodb+srv" protocol
72+
export MONGODB_URI="mongodb+srv://${ADMIN_USER}:${ADMIN_PASSWORD}@${MONGODB_URI}?authSource=admin"
73+
export AWS_WEB_IDENTITY_TOKEN_FILE="$OIDC_TOKEN_DIR/test_user1"
74+
export OIDC_PROVIDER_NAME="aws"
75+
export OIDC_TESTS_ENABLED="true"
76+
77+
if [ "Windows_NT" = "$OS" ]; then
78+
powershell.exe .\\build.ps1 --target "TestMongoDbOidc${FRAMEWORK}"
79+
else
80+
./build.sh --target="TestServerless${FRAMEWORK}"
81+
fi

tests/MongoDB.Driver.Tests/Specifications/UnifiedTestSpecRunner.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public UnifiedTestSpecRunner(ITestOutputHelper testOutputHelper)
3737
{
3838
}
3939

40-
[Category("Authentication", "MONGODB-OIDC")]
40+
[Category("Authentication", "MongoDbOidc")]
4141
[UnifiedTestsTheory("auth.tests.unified")]
4242
public void Auth(JsonDrivenTestCase testCase) => Run(testCase);
4343

tests/MongoDB.Driver.Tests/Specifications/auth/OidcAuthenticationProseTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636

3737
namespace MongoDB.Driver.Tests.Specifications.auth
3838
{
39-
[Category("Authentication", "OidcMechanism")]
39+
[Category("Authentication", "MongoDbOidc")]
4040
public class OidcAuthenticationProseTests : LoggableTestClass
4141
{
4242
// some auth configuration may support only this name
@@ -89,7 +89,7 @@ await ThreadingUtilities.ExecuteTasksOnNewThreads(10, async t =>
8989
? await collection.FindAsync(Builders<BsonDocument>.Filter.Empty)
9090
: collection.FindSync(Builders<BsonDocument>.Filter.Empty);
9191
}
92-
});
92+
}, (int)TimeSpan.FromSeconds(20).TotalMilliseconds);
9393

9494
VerifyCallbackUsage(callbackMock, async, Times.Once());
9595
}

0 commit comments

Comments
 (0)