Skip to content

Commit e4dc740

Browse files
committed
Add int test
1 parent 3216d33 commit e4dc740

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed

test/integration/auth/mongodb_aws.test.ts

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,14 @@ import * as sinon from 'sinon';
99
import { refreshKMSCredentials } from '../../../src/client-side-encryption/providers';
1010
import {
1111
AWSTemporaryCredentialProvider,
12+
type CommandOptions,
13+
Connection,
14+
type Document,
1215
MongoAWSError,
1316
type MongoClient,
1417
MongoDBAWS,
18+
type MongoDBNamespace,
19+
type MongoDBResponseConstructor,
1520
MongoMissingCredentialsError,
1621
MongoServerError,
1722
setDifference
@@ -61,6 +66,70 @@ describe('MONGODB-AWS', function () {
6166
expect(result).to.be.a('number');
6267
});
6368

69+
describe('ConversationId', function () {
70+
let commandStub: sinon.SinonStub<
71+
[
72+
ns: MongoDBNamespace,
73+
command: Document,
74+
options?: CommandOptions,
75+
responseType?: MongoDBResponseConstructor
76+
],
77+
Promise<any>
78+
>;
79+
80+
let saslStartResult, saslContinue;
81+
82+
beforeEach(function () {
83+
// spy on connection.command, filter for saslStart and saslContinue commands
84+
commandStub = sinon.stub(Connection.prototype, 'command').callsFake(async function (
85+
ns: MongoDBNamespace,
86+
command: Document,
87+
options: CommandOptions,
88+
responseType?: MongoDBResponseConstructor
89+
) {
90+
if (command.saslStart != null || command.saslContinue != null) {
91+
console.log(command);
92+
}
93+
94+
const result = await commandStub.wrappedMethod.call(
95+
this,
96+
ns,
97+
command,
98+
options,
99+
responseType
100+
);
101+
102+
if (command.saslStart != null) {
103+
// Modify the result to check if the saslContinue uses it
104+
result.conversationId = 999;
105+
saslStartResult = { ...result };
106+
}
107+
if (command.saslContinue != null) {
108+
saslContinue = { ...command };
109+
}
110+
111+
return result;
112+
});
113+
});
114+
115+
afterEach(function () {
116+
sinon.restore();
117+
});
118+
119+
it.only('should use conversationId returned by saslStart in saslContinue', async function () {
120+
client = this.configuration.newClient(process.env.MONGODB_URI); // use the URI built by the test environment
121+
122+
await client.db('aws').collection('aws_test').estimatedDocumentCount();
123+
124+
expect(saslStartResult).to.not.be.undefined;
125+
expect(saslContinue).to.not.be.undefined;
126+
127+
expect(saslStartResult).to.have.property('conversationId', 999);
128+
129+
expect(saslContinue).to.have.property('conversationId').equal(saslStartResult.conversationId);
130+
});
131+
});
132+
64133
it('should allow empty string in authMechanismProperties.AWS_SESSION_TOKEN to override AWS_SESSION_TOKEN environment variable', function () {
65134
client = this.configuration.newClient(this.configuration.url(), {
66135
authMechanismProperties: { AWS_SESSION_TOKEN: '' }

0 commit comments

Comments
 (0)