Skip to content

Commit 0678efc

Browse files
nbbeekenaditi-khare-mongoDB
authored andcommitted
refactor(NODE-5743): use new connection (#3952)
1 parent b60f216 commit 0678efc

38 files changed

+256
-1719
lines changed

.evergreen/config.in.yml

-2
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,6 @@ functions:
200200
type: test
201201
params:
202202
working_dir: "src"
203-
env:
204-
MONGODB_NEW_CONNECTION: ${MONGODB_NEW_CONNECTION|false}
205203
timeout_secs: 300
206204
shell: bash
207205
script: |

.evergreen/config.yml

-38
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,6 @@ functions:
170170
type: test
171171
params:
172172
working_dir: src
173-
env:
174-
MONGODB_NEW_CONNECTION: ${MONGODB_NEW_CONNECTION|false}
175173
timeout_secs: 300
176174
shell: bash
177175
script: |
@@ -4426,42 +4424,6 @@ buildvariants:
44264424
- test-3.6-server-noauth
44274425
- test-3.6-replica_set-noauth
44284426
- test-3.6-sharded_cluster-noauth
4429-
- name: rhel8-new-connection-tests
4430-
display_name: New Connection Tests
4431-
run_on: rhel80-large
4432-
expansions:
4433-
NODE_LTS_VERSION: 20
4434-
CLIENT_ENCRYPTION: true
4435-
MONGODB_NEW_CONNECTION: true
4436-
tasks:
4437-
- test-latest-server
4438-
- test-latest-replica_set
4439-
- test-latest-sharded_cluster
4440-
- test-rapid-server
4441-
- test-rapid-replica_set
4442-
- test-rapid-sharded_cluster
4443-
- test-7.0-server
4444-
- test-7.0-replica_set
4445-
- test-7.0-sharded_cluster
4446-
- test-6.0-server
4447-
- test-6.0-replica_set
4448-
- test-6.0-sharded_cluster
4449-
- test-5.0-server
4450-
- test-5.0-replica_set
4451-
- test-5.0-sharded_cluster
4452-
- test-4.4-server
4453-
- test-4.4-replica_set
4454-
- test-4.4-sharded_cluster
4455-
- test-4.2-server
4456-
- test-4.2-replica_set
4457-
- test-4.2-sharded_cluster
4458-
- test-4.0-server
4459-
- test-4.0-replica_set
4460-
- test-4.0-sharded_cluster
4461-
- test-3.6-server
4462-
- test-3.6-replica_set
4463-
- test-3.6-sharded_cluster
4464-
- test-latest-server-v1-api
44654427
- name: rhel8-test-lambda
44664428
display_name: AWS Lambda handler tests
44674429
run_on: rhel80-large

.evergreen/generate_evergreen_tasks.js

-11
Original file line numberDiff line numberDiff line change
@@ -738,17 +738,6 @@ BUILD_VARIANTS.push({
738738
tasks: AUTH_DISABLED_TASKS.map(({ name }) => name)
739739
});
740740

741-
BUILD_VARIANTS.push({
742-
name: 'rhel8-new-connection-tests',
743-
display_name: 'New Connection Tests',
744-
run_on: DEFAULT_OS,
745-
expansions: {
746-
NODE_LTS_VERSION: LATEST_LTS,
747-
CLIENT_ENCRYPTION: true,
748-
MONGODB_NEW_CONNECTION: true
749-
},
750-
tasks: BASE_TASKS.map(({ name }) => name)
751-
});
752741

753742
BUILD_VARIANTS.push({
754743
name: 'rhel8-test-lambda',

.evergreen/run-tests.sh

-1
Original file line numberDiff line numberDiff line change
@@ -63,5 +63,4 @@ export MONGODB_URI=${MONGODB_URI}
6363
export LOAD_BALANCER=${LOAD_BALANCER}
6464
export TEST_CSFLE=${TEST_CSFLE}
6565
export COMPRESSOR=${COMPRESSOR}
66-
export MONGODB_NEW_CONNECTION=${MONGODB_NEW_CONNECTION}
6766
npm run "${TEST_NPM_SCRIPT}"

src/cmap/auth/gssapi.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ async function externalCommand(
3030
connection: Connection,
3131
command: ReturnType<typeof saslStart> | ReturnType<typeof saslContinue>
3232
): Promise<{ payload: string; conversationId: any }> {
33-
return connection.commandAsync(ns('$external.$cmd'), command, undefined) as Promise<{
33+
return connection.command(ns('$external.$cmd'), command, undefined) as Promise<{
3434
payload: string;
3535
conversationId: any;
3636
}>;

src/cmap/auth/mongo_credentials.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import type { OIDCRefreshFunction, OIDCRequestFunction } from './mongodb_oidc';
1212
import { AUTH_MECHS_AUTH_SRC_EXTERNAL, AuthMechanism } from './providers';
1313

1414
// https://github.com/mongodb/specifications/blob/master/source/auth/auth.rst
15-
function getDefaultAuthMechanism(hello?: Document): AuthMechanism {
15+
function getDefaultAuthMechanism(hello: Document | null): AuthMechanism {
1616
if (hello) {
1717
// If hello contains saslSupportedMechs, use scram-sha-256
1818
// if it is available, else scram-sha-1
@@ -151,7 +151,7 @@ export class MongoCredentials {
151151
*
152152
* @param hello - A hello response from the server
153153
*/
154-
resolveAuthMechanism(hello?: Document): MongoCredentials {
154+
resolveAuthMechanism(hello: Document | null): MongoCredentials {
155155
// If the mechanism is not "default", then it does not need to be resolved
156156
if (this.mechanism.match(/DEFAULT/i)) {
157157
return new MongoCredentials({

src/cmap/auth/mongocr.ts

+2-6
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,7 @@ export class MongoCR extends AuthProvider {
1313

1414
const { username, password, source } = credentials;
1515

16-
const { nonce } = await connection.commandAsync(
17-
ns(`${source}.$cmd`),
18-
{ getnonce: 1 },
19-
undefined
20-
);
16+
const { nonce } = await connection.command(ns(`${source}.$cmd`), { getnonce: 1 }, undefined);
2117

2218
const hashPassword = crypto
2319
.createHash('md5')
@@ -37,6 +33,6 @@ export class MongoCR extends AuthProvider {
3733
key
3834
};
3935

40-
await connection.commandAsync(ns(`${source}.$cmd`), authenticateCommand, undefined);
36+
await connection.command(ns(`${source}.$cmd`), authenticateCommand, undefined);
4137
}
4238
}

src/cmap/auth/mongodb_aws.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ export class MongoDBAWS extends AuthProvider {
109109
payload: BSON.serialize({ r: nonce, p: ASCII_N }, bsonOptions)
110110
};
111111

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

114114
const serverResponse = BSON.deserialize(saslStartResponse.payload.buffer, bsonOptions) as {
115115
s: Binary;
@@ -169,7 +169,7 @@ export class MongoDBAWS extends AuthProvider {
169169
payload: BSON.serialize(payload, bsonOptions)
170170
};
171171

172-
await connection.commandAsync(ns(`${db}.$cmd`), saslContinue, undefined);
172+
await connection.command(ns(`${db}.$cmd`), saslContinue, undefined);
173173
}
174174
}
175175

src/cmap/auth/mongodb_oidc/callback_workflow.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ export class CallbackWorkflow implements Workflow {
163163
if (!reauthenticating && response?.speculativeAuthenticate) {
164164
result = response.speculativeAuthenticate;
165165
} else {
166-
result = await connection.commandAsync(
166+
result = await connection.command(
167167
ns(credentials.source),
168168
startCommandDocument(credentials),
169169
undefined
@@ -181,7 +181,7 @@ export class CallbackWorkflow implements Workflow {
181181
tokenResult: IdPServerResponse,
182182
conversationId?: number
183183
): Promise<Document> {
184-
const result = await connection.commandAsync(
184+
const result = await connection.command(
185185
ns(credentials.source),
186186
finishCommandDocument(tokenResult.accessToken, conversationId),
187187
undefined

src/cmap/auth/mongodb_oidc/service_workflow.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export abstract class ServiceWorkflow implements Workflow {
1818
async execute(connection: Connection, credentials: MongoCredentials): Promise<Document> {
1919
const token = await this.getToken(credentials);
2020
const command = commandDocument(token);
21-
return connection.commandAsync(ns(credentials.source), command, undefined);
21+
return connection.command(ns(credentials.source), command, undefined);
2222
}
2323

2424
/**

src/cmap/auth/plain.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@ export class Plain extends AuthProvider {
2020
autoAuthorize: 1
2121
};
2222

23-
await connection.commandAsync(ns('$external.$cmd'), command, undefined);
23+
await connection.command(ns('$external.$cmd'), command, undefined);
2424
}
2525
}

src/cmap/auth/scram.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ async function executeScram(cryptoMethod: CryptoMethod, authContext: AuthContext
112112
const db = credentials.source;
113113

114114
const saslStartCmd = makeFirstMessage(cryptoMethod, credentials, nonce);
115-
const response = await connection.commandAsync(ns(`${db}.$cmd`), saslStartCmd, undefined);
115+
const response = await connection.command(ns(`${db}.$cmd`), saslStartCmd, undefined);
116116
await continueScramConversation(cryptoMethod, response, authContext);
117117
}
118118

@@ -186,7 +186,7 @@ async function continueScramConversation(
186186
payload: new Binary(Buffer.from(clientFinal))
187187
};
188188

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

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

207-
await connection.commandAsync(ns(`${db}.$cmd`), retrySaslContinueCmd, undefined);
207+
await connection.command(ns(`${db}.$cmd`), retrySaslContinueCmd, undefined);
208208
}
209209

210210
function parsePayload(payload: Binary) {

src/cmap/auth/x509.ts

+1-5
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,7 @@ export class X509 extends AuthProvider {
2929
return;
3030
}
3131

32-
await connection.commandAsync(
33-
ns('$external.$cmd'),
34-
x509AuthenticateCommand(credentials),
35-
undefined
36-
);
32+
await connection.command(ns('$external.$cmd'), x509AuthenticateCommand(credentials), undefined);
3733
}
3834
}
3935

src/cmap/connect.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ async function performInitialHandshake(
131131
}
132132

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

136136
if (!('isWritablePrimary' in response)) {
137137
// Provide hello-style response document.

0 commit comments

Comments
 (0)