Skip to content

test(NODE-4264): part 1 of removing connect from tests #3257

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 8 commits into from
Jun 28, 2022
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
12 changes: 6 additions & 6 deletions global.d.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
import { OneOrMore } from './src/mongo_types';
import type { TestConfiguration } from './test/tools/runner/config';

type WithExclusion<T extends string> = `!${T}`;
/** Defined in test/tools/runner/filters/mongodb_topology_filter.js (topologyTypeToString) */
type TopologyTypes = 'single' | 'replicaset' | 'sharded' | 'load-balanced';
type TopologyTypeRequirement = OneOrMore<TopologyTypes> | OneOrMore<WithExclusion<TopologyTypes>>;

declare global {
interface MongoDBMetadataUI {
requires?: {
topology?: TopologyTypeRequirement;
mongodb?: string;
os?: NodeJS.Platform | `!${NodeJS.Platform}`;
apiVersion?: '1';
apiVersion?: '1' | boolean;
clientSideEncryption?: boolean;
serverless?: 'forbid' | 'allow' | 'require';
auth?: 'enabled' | 'disabled';
Expand All @@ -23,6 +18,11 @@ declare global {
};
}

type WithExclusion<T extends string> = `!${T}`;
/** Defined in test/tools/runner/filters/mongodb_topology_filter.js (topologyTypeToString) */
type TopologyTypes = 'single' | 'replicaset' | 'sharded' | 'load-balanced';
type TopologyTypeRequirement = OneOrMore<TopologyTypes> | OneOrMore<WithExclusion<TopologyTypes>>;

interface MetadataAndTest<Fn> {
metadata: MongoDBMetadataUI;
test: Fn;
Expand Down
12 changes: 11 additions & 1 deletion test/integration/auth/auth.prose.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,20 @@ const sinon = require('sinon');
const { expect } = require('chai');
const { Connection } = require('../../../src/cmap/connection');
const { ScramSHA256 } = require('../../../src/cmap/auth/scram');
const { setupDatabase, withClient } = require('../shared');
const { setupDatabase } = require('../shared');
const { LEGACY_HELLO_COMMAND } = require('../../../src/constants');

// TODO(NODE-4338): withClient usage prevented these tests from running
// the import has been removed since the function is being deleted, this is here to keep modifications minimal
// so that the implementer of the fix for these tests can try to reference the original intent
const withClient = () => null;

describe('auth prose tests', () => {
beforeEach(function () {
this.currentTest.skipReason = 'TODO(NODE-4338): correct withClient usage';
this.currentTest.skip();
});

describe('SCRAM-SHA-256 prose test', () => {
describe('SCRAM-SHA-256 prose test Steps 1-3', function () {
const test = {};
Expand Down
49 changes: 20 additions & 29 deletions test/integration/auth/mongodb_aws.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,37 +15,28 @@ describe('MONGODB-AWS', function () {
}
});

it('should not authorize when not authenticated', function (done) {
const config = this.configuration;
const url = removeAuthFromConnectionString(config.url());
const client = config.newClient(url); // strip provided URI of credentials
client.connect(err => {
expect(err).to.not.exist;
this.defer(() => client.close());
it('should not authorize when not authenticated', async function () {
const url = removeAuthFromConnectionString(this.configuration.url());
const client = this.configuration.newClient(url); // strip provided URI of credentials

client.db('aws').command({ count: 'test' }, (err, count) => {
expect(err).to.exist;
expect(count).to.not.exist;
const error = await client
.db('aws')
.command({ ping: 1 })
.catch(error => error);

done();
});
});
expect(error).to.be.instanceOf(MongoAWSError);
});

it('should authorize when successfully authenticated', function (done) {
const config = this.configuration;
const client = config.newClient(process.env.MONGODB_URI); // use the URI built by the test environment
client.connect(err => {
expect(err).to.not.exist;
this.defer(() => client.close());
it('should authorize when successfully authenticated', async function () {
const client = this.configuration.newClient(process.env.MONGODB_URI); // use the URI built by the test environment

client.db('aws').command({ count: 'test' }, (err, count) => {
expect(err).to.not.exist;
expect(count).to.exist;
const result = await client
.db('aws')
.command({ ping: 1 })
.catch(error => error);

done();
});
});
expect(result).to.not.be.instanceOf(MongoAWSError);
expect(result).to.have.property('ok', 1);
});

it('should allow empty string in authMechanismProperties.AWS_SESSION_TOKEN to override AWS_SESSION_TOKEN environment variable', function () {
Expand Down Expand Up @@ -84,10 +75,10 @@ describe('MONGODB-AWS', function () {
client = config.newClient(process.env.MONGODB_URI, { authMechanism: 'MONGODB-AWS' }); // use the URI built by the test environment
const startTime = performance.now();

let caughtError = null;
await client.connect().catch(err => {
caughtError = err;
});
const caughtError = await client
.db()
.command({ ping: 1 })
.catch(error => error);

const endTime = performance.now();
const timeTaken = endTime - startTime;
Expand Down
76 changes: 0 additions & 76 deletions test/integration/auth/scram_sha_1.test.js

This file was deleted.

29 changes: 29 additions & 0 deletions test/integration/auth/scram_sha_1.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { expect } from 'chai';

import type { MongoClient } from '../../../src';

describe('SCRAM-SHA-1', function () {
let client: MongoClient;

beforeEach(async function () {
const onlyScram1AuthMech =
this.configuration.parameters?.authenticationMechanisms.length === 1 &&
this.configuration.parameters?.authenticationMechanisms[0] === 'SCRAM-SHA-1';

if (!onlyScram1AuthMech) {
this.currentTest.skipReason = `MongoDB auth mechanism must only be SCRAM-SHA-1, got ${this.configuration.parameters?.authenticationMechanisms}`;
return this.skip();
}

client = this.configuration.newClient();
});

afterEach(async () => {
await client?.close();
});

it('successfuly authenticates', async () => {
const result = await client.db().admin().command({ ping: 1 });
expect(result).to.have.property('ok', 1);
});
});
12 changes: 11 additions & 1 deletion test/integration/auth/scram_sha_256.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,20 @@ const sinon = require('sinon');
const { expect } = require('chai');
const { Connection } = require('../../../src/cmap/connection');
const { ScramSHA256 } = require('../../../src/cmap/auth/scram');
const { setupDatabase, withClient } = require('../shared');
const { setupDatabase } = require('../shared');
const { LEGACY_HELLO_COMMAND } = require('../../../src/constants');

// TODO(NODE-4338): withClient usage prevented these tests from running
// the import has been removed since the function is being deleted, this is here to keep modifications minimal
// so that the implementer of the fix for these tests can try to reference the original intent
const withClient = () => null;

describe('SCRAM_SHA_256', function () {
beforeEach(function () {
this.currentTest.skipReason = 'TODO(NODE-4338): correct withClient usage';
this.currentTest.skip();
});

const test = {};

// Note: this setup was adapted from the prose test setup
Expand Down
55 changes: 21 additions & 34 deletions test/integration/bson-decimal128/decimal128.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,43 +9,30 @@ describe('Decimal128', function () {
return setupDatabase(this.configuration);
});

it('should correctly insert decimal128 value', {
// Add a tag that our runner can trigger on
// in this case we are setting that node needs to be higher than 0.10.X to run
metadata: {
requires: {
mongodb: '>=3.3.6',
topology: ['single']
}
},
it('should correctly insert decimal128 value', function (done) {
var configuration = this.configuration;
var client = configuration.newClient(configuration.writeConcernMax(), { maxPoolSize: 1 });
var db = client.db(configuration.db);
var object = {
id: 1,
value: Decimal128.fromString('1.28')
};

test: function (done) {
var configuration = this.configuration;
var client = configuration.newClient(configuration.writeConcernMax(), { maxPoolSize: 1 });
client.connect(function (err, client) {
var db = client.db(configuration.db);
var object = {
id: 1,
value: Decimal128.fromString('1')
};
db.collection('decimal128').insertOne(object, function (err) {
expect(err).to.not.exist;

db.collection('decimal128').insertOne(object, function (err) {
db.collection('decimal128').findOne(
{
id: 1
},
function (err, doc) {
expect(err).to.not.exist;
test.ok(doc.value instanceof Decimal128);
test.equal('1.28', doc.value.toString());

db.collection('decimal128').findOne(
{
id: 1
},
function (err, doc) {
expect(err).to.not.exist;
test.ok(doc.value instanceof Decimal128);
test.equal('1', doc.value.toString());

client.close(done);
}
);
});
});
}
client.close(done);
}
);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ describe('Causal Consistency - prose tests', function () {
test.client.on('commandSucceeded', event => {
if (ignoredCommands.indexOf(event.commandName) === -1) test.commands.succeeded.push(event);
});

return test.client.connect();
});

afterEach(() => {
Expand Down
4 changes: 2 additions & 2 deletions test/integration/change-streams/change_stream.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ describe('Change Streams', function () {
context('ChangeStreamCursor options', function () {
let client, db, collection;

beforeEach(async function () {
client = await this.configuration.newClient().connect();
beforeEach(function () {
client = this.configuration.newClient();
db = client.db('db');
collection = db.collection('collection');
});
Expand Down
Loading