@@ -9,9 +9,14 @@ import * as sinon from 'sinon';
9
9
import { refreshKMSCredentials } from '../../../src/client-side-encryption/providers' ;
10
10
import {
11
11
AWSTemporaryCredentialProvider ,
12
+ type CommandOptions ,
13
+ Connection ,
14
+ type Document ,
12
15
MongoAWSError ,
13
16
type MongoClient ,
14
17
MongoDBAWS ,
18
+ type MongoDBNamespace ,
19
+ type MongoDBResponseConstructor ,
15
20
MongoMissingCredentialsError ,
16
21
MongoServerError ,
17
22
setDifference
@@ -61,6 +66,70 @@ describe('MONGODB-AWS', function () {
61
66
expect ( result ) . to . be . a ( 'number' ) ;
62
67
} ) ;
63
68
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
+
64
133
it ( 'should allow empty string in authMechanismProperties.AWS_SESSION_TOKEN to override AWS_SESSION_TOKEN environment variable' , function ( ) {
65
134
client = this . configuration . newClient ( this . configuration . url ( ) , {
66
135
authMechanismProperties : { AWS_SESSION_TOKEN : '' }
0 commit comments