@@ -30,10 +30,12 @@ import spock.lang.IgnoreIf
30
30
31
31
import java.util.concurrent.TimeUnit
32
32
33
+ import static com.mongodb.ClusterFixture.isAuthenticated
33
34
import static com.mongodb.ClusterFixture.isStandalone
34
35
import static com.mongodb.ClusterFixture.serverVersionAtLeast
35
36
import static com.mongodb.Fixture.getDefaultDatabaseName
36
37
import static com.mongodb.Fixture.getMongoClientURI
38
+ import static com.mongodb.MongoCredential.createCredential
37
39
38
40
class MongoClientSessionSpecification extends FunctionalSpecification {
39
41
@@ -235,7 +237,7 @@ class MongoClientSessionSpecification extends FunctionalSpecification {
235
237
def commandListener = new TestCommandListener ()
236
238
def optionsBuilder = MongoClientOptions . builder()
237
239
.addCommandListener(commandListener)
238
- def client = new MongoClient (getMongoClientURI(optionsBuilder))
240
+ def client = new MongoClient (Fixture . getMongoClientURI(optionsBuilder))
239
241
// TODO: Remove this once SPEC-944 is resolved
240
242
client. getDatabase(' admin' ). runCommand(new BsonDocument (' ping' , new BsonInt32 (1 )))
241
243
@@ -307,4 +309,33 @@ class MongoClientSessionSpecification extends FunctionalSpecification {
307
309
where :
308
310
readConcern << [ReadConcern . DEFAULT , ReadConcern . LOCAL , ReadConcern . MAJORITY ]
309
311
}
312
+
313
+ @IgnoreIf ({ !serverVersionAtLeast(3 , 5 ) || !isAuthenticated() })
314
+ @SuppressWarnings (' deprecation' )
315
+ def ' should not use a default session when there is more than one authenticated user' () {
316
+ given :
317
+ def sessionTestUserName = ' sessionTestUser'
318
+ def sessionTestPassword = ' sessionTestPassword'
319
+ Fixture . getMongoClient(). getDB(' admin' ). addUser(sessionTestUserName, sessionTestPassword. toCharArray())
320
+
321
+ def commandListener = new TestCommandListener ()
322
+ def optionsBuilder = MongoClientOptions . builder()
323
+ .addCommandListener(commandListener)
324
+ def mongoClientURI = getMongoClientURI(optionsBuilder)
325
+ def credentials = [mongoClientURI. getCredentials(),
326
+ createCredential(sessionTestUserName, ' admin' , sessionTestPassword. toCharArray())]
327
+ def client = new MongoClient (mongoClientURI. getHosts(). collect { new ServerAddress (it) },
328
+ credentials, mongoClientURI. getOptions())
329
+
330
+ when :
331
+ client. getDatabase(' admin' ). runCommand(new BsonDocument (' ping' , new BsonInt32 (1 )))
332
+
333
+ then :
334
+ def pingCommandStartedEvent = commandListener. events. get(0 )
335
+ ! (pingCommandStartedEvent as CommandStartedEvent ). command. containsKey(' lsid' )
336
+
337
+ cleanup :
338
+ Fixture . getMongoClient(). getDB(' admin' ). removeUser(sessionTestUserName)
339
+ client?. close()
340
+ }
310
341
}
0 commit comments