Skip to content

refactor(NODE-5743): use new connection #3952

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 15 commits into from
Dec 20, 2023
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
2 changes: 0 additions & 2 deletions .evergreen/config.in.yml
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,6 @@ functions:
type: test
params:
working_dir: "src"
env:
MONGODB_NEW_CONNECTION: ${MONGODB_NEW_CONNECTION|false}
timeout_secs: 300
shell: bash
script: |
Expand Down
38 changes: 0 additions & 38 deletions .evergreen/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,6 @@ functions:
type: test
params:
working_dir: src
env:
MONGODB_NEW_CONNECTION: ${MONGODB_NEW_CONNECTION|false}
timeout_secs: 300
shell: bash
script: |
Expand Down Expand Up @@ -4426,42 +4424,6 @@ buildvariants:
- test-3.6-server-noauth
- test-3.6-replica_set-noauth
- test-3.6-sharded_cluster-noauth
- name: rhel8-new-connection-tests
display_name: New Connection Tests
run_on: rhel80-large
expansions:
NODE_LTS_VERSION: 20
CLIENT_ENCRYPTION: true
MONGODB_NEW_CONNECTION: true
tasks:
- test-latest-server
- test-latest-replica_set
- test-latest-sharded_cluster
- test-rapid-server
- test-rapid-replica_set
- test-rapid-sharded_cluster
- test-7.0-server
- test-7.0-replica_set
- test-7.0-sharded_cluster
- test-6.0-server
- test-6.0-replica_set
- test-6.0-sharded_cluster
- test-5.0-server
- test-5.0-replica_set
- test-5.0-sharded_cluster
- test-4.4-server
- test-4.4-replica_set
- test-4.4-sharded_cluster
- test-4.2-server
- test-4.2-replica_set
- test-4.2-sharded_cluster
- test-4.0-server
- test-4.0-replica_set
- test-4.0-sharded_cluster
- test-3.6-server
- test-3.6-replica_set
- test-3.6-sharded_cluster
- test-latest-server-v1-api
- name: rhel8-test-lambda
display_name: AWS Lambda handler tests
run_on: rhel80-large
Expand Down
11 changes: 0 additions & 11 deletions .evergreen/generate_evergreen_tasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -738,17 +738,6 @@ BUILD_VARIANTS.push({
tasks: AUTH_DISABLED_TASKS.map(({ name }) => name)
});

BUILD_VARIANTS.push({
name: 'rhel8-new-connection-tests',
display_name: 'New Connection Tests',
run_on: DEFAULT_OS,
expansions: {
NODE_LTS_VERSION: LATEST_LTS,
CLIENT_ENCRYPTION: true,
MONGODB_NEW_CONNECTION: true
},
tasks: BASE_TASKS.map(({ name }) => name)
});

BUILD_VARIANTS.push({
name: 'rhel8-test-lambda',
Expand Down
1 change: 0 additions & 1 deletion .evergreen/run-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,4 @@ export MONGODB_URI=${MONGODB_URI}
export LOAD_BALANCER=${LOAD_BALANCER}
export TEST_CSFLE=${TEST_CSFLE}
export COMPRESSOR=${COMPRESSOR}
export MONGODB_NEW_CONNECTION=${MONGODB_NEW_CONNECTION}
npm run "${TEST_NPM_SCRIPT}"
2 changes: 1 addition & 1 deletion src/cmap/auth/gssapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ async function externalCommand(
connection: Connection,
command: ReturnType<typeof saslStart> | ReturnType<typeof saslContinue>
): Promise<{ payload: string; conversationId: any }> {
return connection.commandAsync(ns('$external.$cmd'), command, undefined) as Promise<{
return connection.command(ns('$external.$cmd'), command, undefined) as Promise<{
payload: string;
conversationId: any;
}>;
Expand Down
4 changes: 2 additions & 2 deletions src/cmap/auth/mongo_credentials.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import type { OIDCRefreshFunction, OIDCRequestFunction } from './mongodb_oidc';
import { AUTH_MECHS_AUTH_SRC_EXTERNAL, AuthMechanism } from './providers';

// https://github.com/mongodb/specifications/blob/master/source/auth/auth.rst
function getDefaultAuthMechanism(hello?: Document): AuthMechanism {
function getDefaultAuthMechanism(hello: Document | null): AuthMechanism {
if (hello) {
// If hello contains saslSupportedMechs, use scram-sha-256
// if it is available, else scram-sha-1
Expand Down Expand Up @@ -151,7 +151,7 @@ export class MongoCredentials {
*
* @param hello - A hello response from the server
*/
resolveAuthMechanism(hello?: Document): MongoCredentials {
resolveAuthMechanism(hello: Document | null): MongoCredentials {
// If the mechanism is not "default", then it does not need to be resolved
if (this.mechanism.match(/DEFAULT/i)) {
return new MongoCredentials({
Expand Down
8 changes: 2 additions & 6 deletions src/cmap/auth/mongocr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,7 @@ export class MongoCR extends AuthProvider {

const { username, password, source } = credentials;

const { nonce } = await connection.commandAsync(
ns(`${source}.$cmd`),
{ getnonce: 1 },
undefined
);
const { nonce } = await connection.command(ns(`${source}.$cmd`), { getnonce: 1 }, undefined);

const hashPassword = crypto
.createHash('md5')
Expand All @@ -37,6 +33,6 @@ export class MongoCR extends AuthProvider {
key
};

await connection.commandAsync(ns(`${source}.$cmd`), authenticateCommand, undefined);
await connection.command(ns(`${source}.$cmd`), authenticateCommand, undefined);
}
}
4 changes: 2 additions & 2 deletions src/cmap/auth/mongodb_aws.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ export class MongoDBAWS extends AuthProvider {
payload: BSON.serialize({ r: nonce, p: ASCII_N }, bsonOptions)
};

const saslStartResponse = await connection.commandAsync(ns(`${db}.$cmd`), saslStart, undefined);
const saslStartResponse = await connection.command(ns(`${db}.$cmd`), saslStart, undefined);

const serverResponse = BSON.deserialize(saslStartResponse.payload.buffer, bsonOptions) as {
s: Binary;
Expand Down Expand Up @@ -169,7 +169,7 @@ export class MongoDBAWS extends AuthProvider {
payload: BSON.serialize(payload, bsonOptions)
};

await connection.commandAsync(ns(`${db}.$cmd`), saslContinue, undefined);
await connection.command(ns(`${db}.$cmd`), saslContinue, undefined);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/cmap/auth/mongodb_oidc/callback_workflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ export class CallbackWorkflow implements Workflow {
if (!reauthenticating && response?.speculativeAuthenticate) {
result = response.speculativeAuthenticate;
} else {
result = await connection.commandAsync(
result = await connection.command(
ns(credentials.source),
startCommandDocument(credentials),
undefined
Expand All @@ -181,7 +181,7 @@ export class CallbackWorkflow implements Workflow {
tokenResult: IdPServerResponse,
conversationId?: number
): Promise<Document> {
const result = await connection.commandAsync(
const result = await connection.command(
ns(credentials.source),
finishCommandDocument(tokenResult.accessToken, conversationId),
undefined
Expand Down
2 changes: 1 addition & 1 deletion src/cmap/auth/mongodb_oidc/service_workflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export abstract class ServiceWorkflow implements Workflow {
async execute(connection: Connection, credentials: MongoCredentials): Promise<Document> {
const token = await this.getToken(credentials);
const command = commandDocument(token);
return connection.commandAsync(ns(credentials.source), command, undefined);
return connection.command(ns(credentials.source), command, undefined);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/cmap/auth/plain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ export class Plain extends AuthProvider {
autoAuthorize: 1
};

await connection.commandAsync(ns('$external.$cmd'), command, undefined);
await connection.command(ns('$external.$cmd'), command, undefined);
}
}
6 changes: 3 additions & 3 deletions src/cmap/auth/scram.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ async function executeScram(cryptoMethod: CryptoMethod, authContext: AuthContext
const db = credentials.source;

const saslStartCmd = makeFirstMessage(cryptoMethod, credentials, nonce);
const response = await connection.commandAsync(ns(`${db}.$cmd`), saslStartCmd, undefined);
const response = await connection.command(ns(`${db}.$cmd`), saslStartCmd, undefined);
await continueScramConversation(cryptoMethod, response, authContext);
}

Expand Down Expand Up @@ -186,7 +186,7 @@ async function continueScramConversation(
payload: new Binary(Buffer.from(clientFinal))
};

const r = await connection.commandAsync(ns(`${db}.$cmd`), saslContinueCmd, undefined);
const r = await connection.command(ns(`${db}.$cmd`), saslContinueCmd, undefined);
const parsedResponse = parsePayload(r.payload);

if (!compareDigest(Buffer.from(parsedResponse.v, 'base64'), serverSignature)) {
Expand All @@ -204,7 +204,7 @@ async function continueScramConversation(
payload: Buffer.alloc(0)
};

await connection.commandAsync(ns(`${db}.$cmd`), retrySaslContinueCmd, undefined);
await connection.command(ns(`${db}.$cmd`), retrySaslContinueCmd, undefined);
}

function parsePayload(payload: Binary) {
Expand Down
6 changes: 1 addition & 5 deletions src/cmap/auth/x509.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,7 @@ export class X509 extends AuthProvider {
return;
}

await connection.commandAsync(
ns('$external.$cmd'),
x509AuthenticateCommand(credentials),
undefined
);
await connection.command(ns('$external.$cmd'), x509AuthenticateCommand(credentials), undefined);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/cmap/connect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ async function performInitialHandshake(
}

const start = new Date().getTime();
const response = await conn.commandAsync(ns('admin.$cmd'), handshakeDoc, handshakeOptions);
const response = await conn.command(ns('admin.$cmd'), handshakeDoc, handshakeOptions);

if (!('isWritablePrimary' in response)) {
// Provide hello-style response document.
Expand Down
Loading