-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
47 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
test/integration/mongodb-handshake/mongodb-handshake.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { expect } from 'chai'; | ||
import * as sinon from 'sinon'; | ||
|
||
import { Connection, LEGACY_HELLO_COMMAND, MongoServerSelectionError } from '../../mongodb'; | ||
|
||
describe('MongoDB Handshake Node tests', () => { | ||
let client; | ||
|
||
context('when hello is too large', () => { | ||
before(() => { | ||
sinon.stub(Connection.prototype, 'command').callsFake(function (ns, cmd, options, callback) { | ||
// @ts-expect-error: sinon will place wrappedMethod there | ||
const command = Connection.prototype.command.wrappedMethod.bind(this); | ||
|
||
if (cmd.hello || cmd[LEGACY_HELLO_COMMAND]) { | ||
return command( | ||
ns, | ||
{ ...cmd, client: { driver: { name: 'a'.repeat(1000) } } }, | ||
options, | ||
callback | ||
); | ||
} | ||
return command(ns, cmd, options, callback); | ||
}); | ||
}); | ||
|
||
after(() => sinon.restore()); | ||
|
||
it('client fails to connect with an error relating to size', async function () { | ||
client = this.configuration.newClient({ serverSelectionTimeoutMS: 2000 }); | ||
const error = await client.connect().catch(error => error); | ||
expect(error).to.be.instanceOf(MongoServerSelectionError); | ||
expect(error).to.match(/client metadata document must be less/); | ||
}); | ||
}); | ||
}); |