Skip to content

Commit 5617814

Browse files
move test to prose test file
1 parent 0a28387 commit 5617814

File tree

2 files changed

+36
-36
lines changed

2 files changed

+36
-36
lines changed

test/integration/mongodb-handshake/mongodb-handshake.prose.test.ts

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { expect } from 'chai';
2+
import * as sinon from 'sinon';
23

3-
import { getFAASEnv, type MongoClient } from '../../mongodb';
4-
4+
import { Connection, getFAASEnv, LEGACY_HELLO_COMMAND, type MongoClient } from '../../mongodb';
55
describe('Handshake Prose Tests', function () {
66
let client: MongoClient;
77

@@ -109,4 +109,38 @@ describe('Handshake Prose Tests', function () {
109109
});
110110
});
111111
}
112+
113+
context(`Test 2: Test that the driver accepts an arbitrary auth mechanism`, function () {
114+
beforeEach(() => {
115+
// Mock the server response in a way that saslSupportedMechs array in the hello command response contains an arbitrary string.
116+
sinon.stub(Connection.prototype, 'command').callsFake(async function (ns, cmd, options) {
117+
// @ts-expect-error: sinon will place wrappedMethod there
118+
const command = Connection.prototype.command.wrappedMethod.bind(this);
119+
if (cmd.hello || cmd[LEGACY_HELLO_COMMAND]) {
120+
return stub();
121+
}
122+
return command(ns, cmd, options);
123+
124+
async function stub() {
125+
const response = await command(ns, cmd, options);
126+
// console.error({ response });
127+
return {
128+
...response,
129+
saslSupportedMechs: [...(response.saslSupportedMechs ?? []), 'random string']
130+
};
131+
}
132+
});
133+
});
134+
135+
afterEach(() => sinon.restore());
136+
137+
it('no error is thrown', { requires: { auth: 'enabled' } }, async function () {
138+
// Create and connect a Connection object that connects to the server that returns the mocked response.
139+
// Assert that no error is raised.
140+
client = this.configuration.newClient();
141+
await client.connect();
142+
await client.db('foo').collection('bar').insertOne({ name: 'john doe' });
143+
await client.close();
144+
});
145+
});
112146
});

test/integration/mongodb-handshake/mongodb-handshake.test.ts

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -131,38 +131,4 @@ describe('MongoDB Handshake', () => {
131131
}
132132
});
133133
});
134-
135-
context(
136-
`when the handshake response includes 'saslSupportedMechs' and the array includes an unknown mechanism`,
137-
function () {
138-
beforeEach(() => {
139-
sinon.stub(Connection.prototype, 'command').callsFake(async function (ns, cmd, options) {
140-
// @ts-expect-error: sinon will place wrappedMethod there
141-
const command = Connection.prototype.command.wrappedMethod.bind(this);
142-
if (cmd.hello || cmd[LEGACY_HELLO_COMMAND]) {
143-
return stub();
144-
}
145-
return command(ns, cmd, options);
146-
147-
async function stub() {
148-
const response = await command(ns, cmd, options);
149-
// console.error({ response });
150-
return {
151-
...response,
152-
saslSupportedMechs: [...(response.saslSupportedMechs ?? []), 'random string']
153-
};
154-
}
155-
});
156-
});
157-
158-
afterEach(() => sinon.restore());
159-
160-
it('no error is thrown', { requires: { auth: 'enabled' } }, async function () {
161-
client = this.configuration.newClient();
162-
await client.connect();
163-
await client.db('foo').collection('bar').insertOne({ name: 'john doe' });
164-
await client.close();
165-
});
166-
}
167-
);
168134
});

0 commit comments

Comments
 (0)