Skip to content

Commit

Permalink
asdf
Browse files Browse the repository at this point in the history
  • Loading branch information
baileympearson committed Feb 13, 2025
1 parent d4b8084 commit c919fcc
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 97 deletions.
1 change: 1 addition & 0 deletions .evergreen/run-alpine-fle-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@

source secrets-export.sh

export ALPINE=true
npm run check:csfle
10 changes: 8 additions & 2 deletions etc/docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ docker buildx create --name builder --bootstrap --use
RUN_WITH_MONGOCRYPTD=true bash .evergreen/setup-fle.sh

./mongodb/bin/mongocryptd --fork --port 3000 --pidfilepath $(pwd)/pid.file --logpath $(pwd)/logpath
MONGOCRYPTD_URI='mongodb://localhost:3000'

BASE_TAG=$LINUX_ARCH-alpine-base-node-$NODE_VERSION
docker --debug buildx build --load --progress=plain \
Expand All @@ -87,5 +88,10 @@ docker --debug buildx build --load --progress=plain \
-f ./.evergreen/docker/Dockerfile.musl -t test-tag-1 \
.

docker --debug run --platform linux/$LINUX_ARCH -e MONGODB_URI=${MONGODB_URI} --network host --entrypoint bash test-tag-1 '.evergreen/run-alpine-fle-tests.sh'
# docker --debug run --network host --platform linux/$LINUX_ARCH -e MONGODB_URI=$MONGODB_URI --entrypoint bash -ti test-tag-1
docker --debug run \
--platform linux/$LINUX_ARCH \
-e MONGODB_URI=${MONGODB_URI} -e MONGOCRYPTD_URI=${MONGOCRYPTD_URI} \
--network host \
--entrypoint bash \
test-tag-1 \
'.evergreen/run-alpine-fle-tests.sh'
47 changes: 0 additions & 47 deletions start-cluster.sh

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import * as path from 'path';
// eslint-disable-next-line @typescript-eslint/no-restricted-imports
import { ClientEncryption } from '../../../src/client-side-encryption/client_encryption';
import { type CommandStartedEvent, MongoClient, type MongoClientOptions } from '../../mongodb';
import { getEncryptExtraOptions } from '../../tools/utils';
import { dropCollection } from '../shared';
import { TestConfiguration } from '../../tools/runner/config';

/* REFERENCE: (note commit hash) */
/* https://github.com/mongodb/specifications/blob/b3beada 72ae1c992294ae6a8eea572003a274c35/source/client-side-encryption/tests/README.rst#deadlock-tests */
Expand All @@ -30,20 +30,24 @@ const $jsonSchema = BSON.EJSON.parse(
)
);

class CapturingMongoClient extends MongoClient {
commandStartedEvents: Array<CommandStartedEvent> = [];
clientsCreated = 0;
constructor(url: string, options: MongoClientOptions = {}) {
options = { ...options, monitorCommands: true, __skipPingOnConnect: true };
if (process.env.MONGODB_API_VERSION) {
options.serverApi = process.env.MONGODB_API_VERSION as MongoClientOptions['serverApi'];
}
function makeClient(configuration: TestConfiguration, options: MongoClientOptions = {}): MongoClient &
{
commandStartedEvents: Array<CommandStartedEvent>,
clientsCreated: number
} {
options = { ...options, monitorCommands: true, __skipPingOnConnect: true };
if (process.env.MONGODB_API_VERSION) {
options.serverApi = process.env.MONGODB_API_VERSION as MongoClientOptions['serverApi'];
}

super(url, options);
const client = configuration.newClient(undefined, options) as ReturnType<typeof makeClient>;

this.on('commandStarted', ev => this.commandStartedEvents.push(ev));
this.on('topologyOpening', () => this.clientsCreated++);
}
client.commandStartedEvents = [];
client.clientsCreated = 0;
client.on('commandStarted', ev => client.commandStartedEvents.push(ev));
client.on('topologyOpening', () => client.clientsCreated++);

return client;
}

function deadlockTest(
Expand All @@ -55,7 +59,6 @@ function deadlockTest(
assertions
) {
return async function () {
const url = this.configuration.url();
const clientTest = this.clientTest;
const ciphertext = this.ciphertext;

Expand All @@ -64,17 +67,12 @@ function deadlockTest(
keyVaultNamespace: 'keyvault.datakeys',
kmsProviders: { local: { key: LOCAL_KEY } },
bypassAutoEncryption,
keyVaultClient: useKeyVaultClient ? this.clientKeyVault : undefined,
extraOptions: {
// ...getEncryptExtraOptions(),
mongocryptdBypassSpawn: true,
mongocryptdURI: 'mongodb://localhost:3000'
}
keyVaultClient: useKeyVaultClient ? this.clientKeyVault : undefined
},
maxPoolSize
};

const clientEncrypted = new CapturingMongoClient(url, clientEncryptedOpts);
const clientEncrypted = makeClient(this.configuration, clientEncryptedOpts);

await clientEncrypted.connect();

Expand All @@ -99,30 +97,19 @@ function deadlockTest(
};
}

const metadata = {
const metadata: MongoDBMetadataUI = {
requires: {
clientSideEncryption: true,
mongodb: '>=4.2.0',
topology: '!load-balanced'
}
};
describe('Connection Pool Deadlock Prevention', function () {
describe.only('Connection Pool Deadlock Prevention', function () {
beforeEach(async function () {
const url: string = this.configuration.url();

const options = process.env.ALPINE ? {
autoEncryption: {
extraOptions: {
mongocryptdBypassSpawn: true,
mongocryptdURI: 'mongodb://localhost:3000'
}
}
} : {};
this.clientTest = new CapturingMongoClient(url, options);
this.clientKeyVault = new CapturingMongoClient(url, {
this.clientTest = makeClient(this.configuration);
this.clientKeyVault = makeClient(this.configuration, {
monitorCommands: true,
maxPoolSize: 1,
...options
});

this.clientEncryption = undefined;
Expand Down Expand Up @@ -155,7 +142,7 @@ describe('Connection Pool Deadlock Prevention', function () {
});

afterEach(function () {
return Promise.all([this.clientKeyVault.close(), this.clientTest.close()]).then(() => {
return Promise.all([this.clientKeyVault?.close(), this.clientTest?.close()]).then(() => {
this.clientKeyVault = undefined;
this.clientTest = undefined;
this.clientEncryption = undefined;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const {
ClientSideEncryptionFilter
} = require('../../tools/runner/filters/client_encryption_filter');
const { getCSFLEKMSProviders } = require('../../csfle-kms-providers');
const { AlpineTestConfiguration } = require('../../tools/runner/config');

const getKmsProviders = (localKey, kmipEndpoint, azureEndpoint, gcpEndpoint) => {
const result = getCSFLEKMSProviders();
Expand Down Expand Up @@ -1113,7 +1114,7 @@ describe('Client Side Encryption Prose Tests', metadata, function () {
// configure with `client_encrypted` to use the schema `external/external-schema.json` for
// `db.coll` by setting a schema map like `{"db.coll": <contents of external-schema.json }`
beforeEach(async function () {
if (process.env.ALPINE) {
if (this.configuration instanceof AlpineTestConfiguration) {
this.currentTest.skipReason =
'alpine tests cannot spawn mongocryptds or use the crypt_shared.';
this.skip();
Expand Down
25 changes: 18 additions & 7 deletions test/tools/runner/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -287,13 +287,6 @@ export class TestConfiguration {
delete urlOptions.query?.auth;
}

if (serverOptions.autoEncryption) {
serverOptions.autoEncryption.extraOptions = {
mongocryptdBypassSpawn: true,
mongocryptdURI: 'mongodb://localhost:3000'
}
}

const connectionString = url.format(urlOptions);

return new MongoClient(connectionString, serverOptions);
Expand Down Expand Up @@ -467,3 +460,21 @@ export class AstrolabeTestConfiguration extends TestConfiguration {
return process.env.DRIVERS_ATLAS_TESTING_URI!;
}
}

export class AlpineTestConfiguration extends TestConfiguration {
override newClient(urlOrQueryOptions?: string | Record<string, any>, serverOptions?: MongoClientOptions): MongoClient {
const options = serverOptions ?? {};

if (options.autoEncryption) {
const extraOptions: MongoClientOptions['autoEncryption']['extraOptions'] = {
...options.autoEncryption.extraOptions,
mongocryptdBypassSpawn: true,
mongocryptdURI: 'mongodb://localhost:3000'
// mongocryptdURI: process.env.MONGOCRYPTD_URI
}
options.autoEncryption.extraOptions = extraOptions;
}

return super.newClient(urlOrQueryOptions, options);
}
}
9 changes: 6 additions & 3 deletions test/tools/runner/hooks/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require('source-map-support').install({
});

import { MongoClient } from '../../../mongodb';
import { AstrolabeTestConfiguration, TestConfiguration } from '../config';
import { AlpineTestConfiguration, AstrolabeTestConfiguration, TestConfiguration } from '../config';
import { getEnvironmentalOptions } from '../../utils';
import * as mock from '../../mongodb-mock/index';
import { inspect } from 'util';
Expand Down Expand Up @@ -153,7 +153,8 @@ const testConfigBeforeHook = async function () {
.command({ getParameter: '*' })
.catch(error => ({ noReply: error }));

this.configuration = new TestConfiguration(
const Config: typeof TestConfiguration = process.env.ALPINE ? AlpineTestConfiguration : TestConfiguration;
this.configuration = new Config(
loadBalanced ? SINGLE_MONGOS_LB_URI : MONGODB_URI,
context
);
Expand All @@ -169,6 +170,8 @@ const testConfigBeforeHook = async function () {
version: this.configuration.buildInfo.version,
node: process.version,
os: process.platform,
alpineLinux: Boolean(process.env.ALPINE),
cryptdUri: process.env.MONGOCRYPTD_URI,
pid: process.pid,
serverless: process.env.SERVERLESS === '1',
auth: process.env.AUTH === 'auth',
Expand All @@ -186,7 +189,7 @@ const testConfigBeforeHook = async function () {
adl: this.configuration.buildInfo.dataLake
? this.configuration.buildInfo.dataLake.version
: false,
kerberos: process.env.KRB5_PRINCIPAL != null,
kerberos: process.env.PRINCIPAL != null,
ldap: MONGODB_URI.includes('authMechanism=PLAIN'),
socks5: MONGODB_URI.includes('proxyHost='),
compressor: process.env.COMPRESSOR,
Expand Down

0 comments on commit c919fcc

Please sign in to comment.