Skip to content

Commit 8300e06

Browse files
committed
test: prose tests
1 parent b77ed3d commit 8300e06

File tree

6 files changed

+175
-1
lines changed

6 files changed

+175
-1
lines changed

.evergreen/config.in.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -548,6 +548,21 @@ functions:
548548
args:
549549
- .evergreen/prepare-mongodb-aws-ecs-auth.sh
550550

551+
"run aws custom credential providers test":
552+
- command: subprocess.exec
553+
type: test
554+
params:
555+
include_expansions_in_env:
556+
- MONGODB_URI
557+
- DRIVERS_TOOLS
558+
- MONGODB_AWS_SDK
559+
env:
560+
AWS_CREDENTIAL_TYPE: env-creds
561+
working_dir: "src"
562+
binary: bash
563+
args:
564+
- .evergreen/run-aws-custom-credential-providers-test.sh
565+
551566
"run custom csfle tests":
552567
- command: subprocess.exec
553568
type: test

.evergreen/config.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,20 @@ functions:
485485
binary: bash
486486
args:
487487
- .evergreen/prepare-mongodb-aws-ecs-auth.sh
488+
run aws custom credential providers test:
489+
- command: subprocess.exec
490+
type: test
491+
params:
492+
include_expansions_in_env:
493+
- MONGODB_URI
494+
- DRIVERS_TOOLS
495+
- MONGODB_AWS_SDK
496+
env:
497+
AWS_CREDENTIAL_TYPE: env-creds
498+
working_dir: src
499+
binary: bash
500+
args:
501+
- .evergreen/run-aws-custom-credential-providers-test.sh
488502
run custom csfle tests:
489503
- command: subprocess.exec
490504
type: test
@@ -1797,6 +1811,21 @@ tasks:
17971811
- func: bootstrap mongo-orchestration
17981812
- func: assume secrets manager rule
17991813
- func: run aws auth test AssumeRoleWithWebIdentity with AWS_ROLE_SESSION_NAME set
1814+
- name: aws-latest-auth-test-run-aws-custom-credential-providers-test
1815+
commands:
1816+
- command: expansions.update
1817+
type: setup
1818+
params:
1819+
updates:
1820+
- {key: VERSION, value: latest}
1821+
- {key: AUTH, value: auth}
1822+
- {key: ORCHESTRATION_FILE, value: auth-aws.json}
1823+
- {key: TOPOLOGY, value: server}
1824+
- {key: MONGODB_AWS_SDK, value: 'true'}
1825+
- func: install dependencies
1826+
- func: bootstrap mongo-orchestration
1827+
- func: assume secrets manager rule
1828+
- func: run aws custom credential providers test
18001829
- name: aws-latest-auth-test-run-aws-auth-test-with-regular-aws-credentials-no-peer-dependencies
18011830
commands:
18021831
- command: expansions.update
@@ -3688,6 +3717,7 @@ buildvariants:
36883717
- aws-latest-auth-test-run-aws-ECS-auth-test
36893718
- aws-latest-auth-test-run-aws-auth-test-AssumeRoleWithWebIdentity-with-AWS_ROLE_SESSION_NAME-unset
36903719
- aws-latest-auth-test-run-aws-auth-test-AssumeRoleWithWebIdentity-with-AWS_ROLE_SESSION_NAME-set
3720+
- aws-latest-auth-test-run-aws-custom-credential-providers-test
36913721
- aws-latest-auth-test-run-aws-auth-test-with-regular-aws-credentials-no-peer-dependencies
36923722
- aws-latest-auth-test-run-aws-auth-test-with-assume-role-credentials-no-peer-dependencies
36933723
- aws-latest-auth-test-run-aws-auth-test-with-aws-credentials-as-environment-variables-no-peer-dependencies

.evergreen/generate_evergreen_tasks.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,10 @@ for (const VERSION of AWS_AUTH_VERSIONS) {
351351
{
352352
func: 'run aws auth test AssumeRoleWithWebIdentity with AWS_ROLE_SESSION_NAME set',
353353
onlySdk: true
354+
},
355+
{
356+
func: 'run aws custom credential providers test',
357+
onlySdk: true
354358
}
355359
];
356360

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/bin/bash
2+
# set -o xtrace # Write all commands first to stderr
3+
set -o errexit # Exit the script with error if any of the commands fail
4+
5+
MONGODB_URI=${MONGODB_URI:-}
6+
7+
source .evergreen/setup-mongodb-aws-auth-tests.sh
8+
9+
# load node.js environment
10+
source $DRIVERS_TOOLS/.evergreen/init-node-and-npm-env.sh
11+
12+
export TEST_CSFLE=true
13+
14+
npx mocha --config test/mocha_mongodb.js test/integration/client-side-encryption/client_side_encryption.prose.25.custon_aws_credential_providers.test.ts

src/deps.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ export function getZstdLibrary(): ZStandardLib | { kModuleError: MongoMissingDep
8585
export interface AWSCredentials {
8686
accessKeyId: string;
8787
secretAccessKey: string;
88-
sessionToken: string;
88+
sessionToken?: string;
8989
expiration?: Date;
9090
}
9191

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
import { expect } from 'chai';
2+
3+
/* eslint-disable @typescript-eslint/no-restricted-imports */
4+
import { ClientEncryption } from '../../../src/client-side-encryption/client_encryption';
5+
import { AWSTemporaryCredentialProvider, Binary } from '../../mongodb';
6+
7+
const metadata: MongoDBMetadataUI = {
8+
requires: {
9+
clientSideEncryption: true
10+
}
11+
} as const;
12+
13+
const masterKey = {
14+
region: 'us-east-1',
15+
key: 'arn:aws:kms:us-east-1:579766882180:key/89fcc2c4-08b0-4bd9-9f25-e30687b580d0',
16+
endpoint: '127.0.0.1:9002'
17+
};
18+
19+
const isMongoDBAWSAuthEnvironment = (process.env.MONGODB_URI ?? '').includes('MONGODB-AWS');
20+
21+
describe('25. Custom AWS Credential Providers', metadata, () => {
22+
let keyVaultClient;
23+
let credentialProvider;
24+
25+
beforeEach(async function () {
26+
this.currentTest.skipReason = !isMongoDBAWSAuthEnvironment
27+
? 'Test must run in an AWS auth testing environment'
28+
: !AWSTemporaryCredentialProvider.isAWSSDKInstalled
29+
? 'This test must run in an environment where the AWS SDK is installed.'
30+
: undefined;
31+
this.currentTest?.skipReason && this.skip();
32+
33+
keyVaultClient = this.configuration.newClient(process.env.MONGODB_UR);
34+
// @ts-expect-error We intentionally access a protected variable.
35+
credentialProvider = AWSTemporaryCredentialProvider.awsSDK;
36+
});
37+
38+
afterEach(async () => {
39+
await keyVaultClient?.close();
40+
});
41+
42+
context(
43+
'Case 1: Explicit encryption with credentials and custom credential provider',
44+
function () {
45+
it('throws an error', function () {
46+
expect(() => {
47+
new ClientEncryption(keyVaultClient, {
48+
keyVaultNamespace: 'keyvault.datakeys',
49+
kmsProviders: {
50+
aws: {
51+
accessKeyId: process.env.FLE_AWS_KEY,
52+
secretAccessKey: process.env.FLE_AWS_SECRET
53+
}
54+
},
55+
credentialProviders: { aws: credentialProvider.fromNodeProviderChain() }
56+
});
57+
}).to.throw();
58+
});
59+
}
60+
);
61+
62+
context('Case 2: Explicit encryption with custom credential provider', function () {
63+
let clientEncryption;
64+
65+
beforeEach(function () {
66+
clientEncryption = new ClientEncryption(keyVaultClient, {
67+
keyVaultNamespace: 'keyvault.datakeys',
68+
kmsProviders: { aws: {} },
69+
credentialProviders: { aws: credentialProvider.fromNodeProviderChain() }
70+
});
71+
});
72+
73+
it('is successful', async function () {
74+
const dk = await clientEncryption.createDataKey('aws', masterKey);
75+
expect(dk).to.be.instanceOf(Binary);
76+
});
77+
});
78+
79+
context('Case 3: Automatic encryption with different custom providers', function () {
80+
let client;
81+
82+
beforeEach(function () {
83+
client = this.configuration.newClient(process.env.MONGODB_URI, {
84+
authMechanismProperties: {
85+
AWS_CREDENTIAL_PROVIDER: credentialProvider.fromNodeProviderChain()
86+
},
87+
autoEncryption: {
88+
keyVaultNamespace: 'keyvault.datakeys',
89+
kmsProviders: { aws: {} },
90+
credentialProviders: {
91+
aws: async () => {
92+
return {
93+
accessKeyId: process.env.FLE_AWS_KEY,
94+
secretAccessKey: process.env.FLE_AWS_SECRET
95+
};
96+
}
97+
}
98+
}
99+
});
100+
});
101+
102+
afterEach(async function () {
103+
await client?.close();
104+
});
105+
106+
it('is successful', async function () {
107+
const result = await client.db('test').collection('test').insertOne({ n: 1 });
108+
expect(result.ok).to.equal(1);
109+
});
110+
});
111+
});

0 commit comments

Comments
 (0)