Skip to content

test: add tests for azure and GCP CSFLE, fix aws boto3 error #2738

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Feb 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 5 additions & 8 deletions .evergreen/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,7 @@ functions:
if [ -n "${CLIENT_ENCRYPTION}" ]; then
cat <<EOT > prepare_client_encryption.sh
export CLIENT_ENCRYPTION=${CLIENT_ENCRYPTION}
export AWS_ACCESS_KEY_ID="${AWS_ACCESS_KEY_ID}"
export AWS_SECRET_ACCESS_KEY="${AWS_SECRET_ACCESS_KEY}"
export CSFLE_KMS_PROVIDERS='${CSFLE_KMS_PROVIDERS}'
EOT
fi
- command: shell.exec
Expand Down Expand Up @@ -283,6 +282,7 @@ functions:
script: |
${PREPARE_SHELL}
cd ${DRIVERS_TOOLS}/.evergreen/auth_aws
. ./activate_venv.sh
${MONGODB_BINARIES}/mongo aws_e2e_regular_aws.js
- command: shell.exec
type: test
Expand Down Expand Up @@ -311,6 +311,7 @@ functions:
script: |
${PREPARE_SHELL}
cd ${DRIVERS_TOOLS}/.evergreen/auth_aws
. ./activate_venv.sh
${MONGODB_BINARIES}/mongo aws_e2e_assume_role.js
- command: shell.exec
type: test
Expand Down Expand Up @@ -343,6 +344,7 @@ functions:
script: |
${PREPARE_SHELL}
cd ${DRIVERS_TOOLS}/.evergreen/auth_aws
. ./activate_venv.sh
${MONGODB_BINARIES}/mongo aws_e2e_ec2.js
- command: shell.exec
type: test
Expand Down Expand Up @@ -415,6 +417,7 @@ functions:
EOF

cat setup.js
. ./activate_venv.sh
mongo --nodb setup.js aws_e2e_ecs.js
run-ocsp-test:
- command: shell.exec
Expand Down Expand Up @@ -1125,9 +1128,6 @@ tasks:
- func: run aws auth test with regular aws credentials
- func: run aws auth test with assume role credentials
- func: run aws auth test with aws EC2 credentials
- func: run aws auth test with aws credentials as environment variables
- func: run aws auth test with aws credentials and session token as environment variables
- func: run aws ECS auth test
- name: aws-4.4-auth-test
commands:
- func: install dependencies
Expand All @@ -1141,9 +1141,6 @@ tasks:
- func: run aws auth test with regular aws credentials
- func: run aws auth test with assume role credentials
- func: run aws auth test with aws EC2 credentials
- func: run aws auth test with aws credentials as environment variables
- func: run aws auth test with aws credentials and session token as environment variables
- func: run aws ECS auth test
- name: run-checks
tags:
- run-checks
Expand Down
7 changes: 5 additions & 2 deletions .evergreen/config.yml.in
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,7 @@ functions:
if [ -n "${CLIENT_ENCRYPTION}" ]; then
cat <<EOT > prepare_client_encryption.sh
export CLIENT_ENCRYPTION=${CLIENT_ENCRYPTION}
export AWS_ACCESS_KEY_ID="${AWS_ACCESS_KEY_ID}"
export AWS_SECRET_ACCESS_KEY="${AWS_SECRET_ACCESS_KEY}"
export CSFLE_KMS_PROVIDERS='${CSFLE_KMS_PROVIDERS}'
EOT
fi
- command: shell.exec
Expand Down Expand Up @@ -317,6 +316,7 @@ functions:
script: |
${PREPARE_SHELL}
cd ${DRIVERS_TOOLS}/.evergreen/auth_aws
. ./activate_venv.sh
${MONGODB_BINARIES}/mongo aws_e2e_regular_aws.js
- command: shell.exec
type: test
Expand Down Expand Up @@ -346,6 +346,7 @@ functions:
script: |
${PREPARE_SHELL}
cd ${DRIVERS_TOOLS}/.evergreen/auth_aws
. ./activate_venv.sh
${MONGODB_BINARIES}/mongo aws_e2e_assume_role.js
- command: shell.exec
type: test
Expand Down Expand Up @@ -379,6 +380,7 @@ functions:
script: |
${PREPARE_SHELL}
cd ${DRIVERS_TOOLS}/.evergreen/auth_aws
. ./activate_venv.sh
${MONGODB_BINARIES}/mongo aws_e2e_ec2.js
- command: shell.exec
type: test
Expand Down Expand Up @@ -454,6 +456,7 @@ functions:
EOF

cat setup.js
. ./activate_venv.sh
mongo --nodb setup.js aws_e2e_ecs.js

"run-ocsp-test":
Expand Down
7 changes: 4 additions & 3 deletions .evergreen/generate_evergreen_tasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -396,9 +396,10 @@ AWS_AUTH_VERSIONS.forEach(VERSION => {
{ func: 'run aws auth test with regular aws credentials' },
{ func: 'run aws auth test with assume role credentials' },
{ func: 'run aws auth test with aws EC2 credentials' },
{ func: 'run aws auth test with aws credentials as environment variables' },
{ func: 'run aws auth test with aws credentials and session token as environment variables' },
{ func: 'run aws ECS auth test' }
// FIXME: NODE-3113
// { func: 'run aws auth test with aws credentials as environment variables' },
// { func: 'run aws auth test with aws credentials and session token as environment variables' },
// { func: 'run aws ECS auth test' }
]
});
});
Expand Down
2 changes: 1 addition & 1 deletion .evergreen/run-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ if [[ -z "${CLIENT_ENCRYPTION}" ]]; then
unset AWS_ACCESS_KEY_ID;
unset AWS_SECRET_ACCESS_KEY;
else
npm install mongodb-client-encryption
npm install mongodb-client-encryption@">=1.2.1"
fi

MONGODB_UNIFIED_TOPOLOGY=${UNIFIED} MONGODB_URI=${MONGODB_URI} npm run ${TEST_NPM_SCRIPT}
11 changes: 5 additions & 6 deletions src/connection_string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -373,12 +373,11 @@ export function parseOptions(
}

if (mongoOptions.credentials) {
const gssapiOrX509 =
mongoOptions.credentials.mechanism === AuthMechanism.MONGODB_GSSAPI ||
mongoOptions.credentials.mechanism === AuthMechanism.MONGODB_X509;

const isGssapi = mongoOptions.credentials.mechanism === AuthMechanism.MONGODB_GSSAPI;
const isX509 = mongoOptions.credentials.mechanism === AuthMechanism.MONGODB_X509;
const isAws = mongoOptions.credentials.mechanism === AuthMechanism.MONGODB_AWS;
if (
gssapiOrX509 &&
(isGssapi || isX509) &&
allOptions.has('authSource') &&
mongoOptions.credentials.source !== '$external'
) {
Expand All @@ -388,7 +387,7 @@ export function parseOptions(
);
}

if (!gssapiOrX509 && mongoOptions.dbName && !allOptions.has('authSource')) {
if (!(isGssapi || isX509 || isAws) && mongoOptions.dbName && !allOptions.has('authSource')) {
// inherit the dbName unless GSSAPI or X509, then silently ignore dbName
// and there was no specific authSource given
mongoOptions.credentials = MongoCredentials.merge(mongoOptions.credentials, {
Expand Down
48 changes: 33 additions & 15 deletions test/functional/client_side_encryption/corpus.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,21 @@ describe('Client Side Encryption Corpus', function () {
return EJSON.parse(fs.readFileSync(path.resolve(corpusDir, filename)), { relaxed: false });
}

const CSFLE_KMS_PROVIDERS = process.env.CSFLE_KMS_PROVIDERS;
const kmsProviders = CSFLE_KMS_PROVIDERS ? EJSON.parse(CSFLE_KMS_PROVIDERS) : {};
kmsProviders.local = {
key: Buffer.from(
'Mng0NCt4ZHVUYUJCa1kxNkVyNUR1QURhZ2h2UzR2d2RrZzh0cFBwM3R6NmdWMDFBMUN3YkQ5aXRRMkhGRGdQV09wOGVNYUMxT2k3NjZKelhaQmRCZGJkTXVyZG9uSjFk',
'base64'
)
};

// TODO: build this into EJSON
// TODO: make a custom chai assertion for this
function toComparableExtendedJSON(value) {
return JSON.parse(EJSON.stringify({ value }, { relaxed: false }));
}

const localKey = Buffer.from(
'Mng0NCt4ZHVUYUJCa1kxNkVyNUR1QURhZ2h2UzR2d2RrZzh0cFBwM3R6NmdWMDFBMUN3YkQ5aXRRMkhGRGdQV09wOGVNYUMxT2k3NjZKelhaQmRCZGJkTXVyZG9uSjFk',
'base64'
);

// Filters out tests that have to do with dbPointer
// TODO: fix dbpointer and get rid of this.
function filterImportedObject(object) {
Expand All @@ -50,6 +54,8 @@ describe('Client Side Encryption Corpus', function () {
const corpusSchema = loadCorpusData('corpus-schema.json');
const corpusKeyLocal = loadCorpusData('corpus-key-local.json');
const corpusKeyAws = loadCorpusData('corpus-key-aws.json');
const corpusKeyAzure = loadCorpusData('corpus-key-azure.json');
const corpusKeyGcp = loadCorpusData('corpus-key-gcp.json');
const corpusAll = filterImportedObject(loadCorpusData('corpus.json'));
const corpusEncryptedExpectedAll = filterImportedObject(loadCorpusData('corpus-encrypted.json'));

Expand All @@ -66,13 +72,23 @@ describe('Client Side Encryption Corpus', function () {
]);
const identifierMap = new Map([
['local', corpusKeyLocal._id],
['aws', corpusKeyAws._id]
['aws', corpusKeyAws._id],
['azure', corpusKeyAzure._id],
['gcp', corpusKeyGcp._id]
]);
const keyAltNameMap = new Map([
['local', 'local'],
['aws', 'aws']
['aws', 'aws'],
['azure', 'azure'],
['gcp', 'gcp']
]);
const copyOverValues = new Set([
'_id',
'altname_aws',
'altname_local',
'altname_azure',
'altname_gcp'
]);
const copyOverValues = new Set(['_id', 'altname_aws', 'altname_local']);

let client;

Expand All @@ -99,7 +115,7 @@ describe('Client Side Encryption Corpus', function () {
break;
}
default: {
throw new Error('how did you get here?');
throw new Error('Unexpected algorithm: ' + expected.algo);
}
}

Expand All @@ -119,7 +135,7 @@ describe('Client Side Encryption Corpus', function () {
} else if (expected.allowed === false) {
expect(actualJSON).to.deep.equal(expectedJSON);
} else {
throw new Error('how did you get here?');
throw new Error('Unexpected value for allowed: ' + expected.allowed);
}
}

Expand All @@ -136,7 +152,9 @@ describe('Client Side Encryption Corpus', function () {
.then(() => keyDb.dropCollection(keyVaultCollName))
.catch(() => {})
.then(() => keyDb.collection(keyVaultCollName))
.then(keyColl => keyColl.insertMany([corpusKeyLocal, corpusKeyAws]));
.then(keyColl =>
keyColl.insertMany([corpusKeyLocal, corpusKeyAws, corpusKeyAzure, corpusKeyGcp])
);
});
});

Expand Down Expand Up @@ -179,7 +197,7 @@ describe('Client Side Encryption Corpus', function () {
// Configure both objects with ``keyVaultNamespace`` set to ``keyvault.datakeys``.
const autoEncryption = {
keyVaultNamespace,
kmsProviders: this.configuration.kmsProviders(null, localKey)
kmsProviders
};
if (useClientSideSchema) {
autoEncryption.schemaMap = {
Expand All @@ -192,7 +210,7 @@ describe('Client Side Encryption Corpus', function () {
clientEncryption = new mongodbClientEncryption.ClientEncryption(client, {
bson: BSON,
keyVaultNamespace,
kmsProviders: this.configuration.kmsProviders(null, localKey)
kmsProviders
});
});
});
Expand Down Expand Up @@ -257,7 +275,7 @@ describe('Client Side Encryption Corpus', function () {
} else if (field.identifier === 'altname') {
encryptOptions.keyAltName = keyAltNameMap.get(field.kms);
} else {
throw new Error('wtf how did u get here?');
throw new Error('Unexpected identifier: ' + field.identifier);
}

return Promise.resolve()
Expand All @@ -282,7 +300,7 @@ describe('Client Side Encryption Corpus', function () {
);
}

throw new Error('how did u get here?');
throw new Error('Unexpected method: ' + field.method);
});
})
.then(() => {
Expand Down
Loading