public void BypassSpawningMongocryptdViaBypassAutoEncryptionTest( [Values(false, true)] bool async) { RequireServer.Check().Supports(Feature.ClientSideEncryption); var extraOptions = new Dictionary <string, object> { { "mongocryptdSpawnArgs", new [] { "--pidfilepath=bypass-spawning-mongocryptd.pid", "--port=27021" } }, }; using (var mongocryptdClient = new DisposableMongoClient(new MongoClient("mongodb://localhost:27021/?serverSelectionTimeoutMS=1000"))) using (var clientEncrypted = ConfigureClientEncrypted( kmsProviderFilter: "local", bypassAutoEncryption: true, extraOptions: extraOptions)) { var coll = GetCollection(clientEncrypted, __collCollectionNamespace); Insert(coll, async, new BsonDocument("unencrypted", "test")); var adminDatabase = mongocryptdClient.GetDatabase(DatabaseNamespace.Admin.DatabaseName); var isMasterCommand = new BsonDocument("ismaster", 1); var exception = Record.Exception(() => adminDatabase.RunCommand <BsonDocument>(isMasterCommand)); exception.Should().BeOfType <TimeoutException>(); exception.Message.Should().Contain("A timeout occured after 1000ms selecting a server"); } }
public void Topology_secondary_discovery_with_directConnection_false_should_work_as_expected([Values(false, true, null)] bool?directConnection) { RequireServer .Check() .Supports(Feature.DirectConnectionSetting) .ClusterTypes(ClusterType.ReplicaSet) .Authentication(false); // we don't use auth connection string in this test var setupClient = DriverTestConfiguration.Client; setupClient.GetDatabase(DriverTestConfiguration.DatabaseNamespace.DatabaseName).RunCommand <BsonDocument>("{ ping : 1 }"); var setupCluster = setupClient.Cluster; SpinWait.SpinUntil(() => setupCluster.Description.State == ClusterState.Connected, TimeSpan.FromSeconds(3)); var clusterDescription = setupCluster.Description; var secondary = clusterDescription.Servers.FirstOrDefault(s => s.State == ServerState.Connected && s.Type == ServerType.ReplicaSetSecondary); if (secondary == null) { throw new Exception("No secondary was found."); } var dnsEndpoint = (DnsEndPoint)secondary.EndPoint; var replicaSetName = secondary.ReplicaSetConfig.Name; using (var client = new DisposableMongoClient(new MongoClient(CreateConnectionString(dnsEndpoint, directConnection, replicaSetName)), CreateLogger <DisposableMongoClient>())) { var database = client.GetDatabase(DriverTestConfiguration.DatabaseNamespace.DatabaseName); var collection = database.GetCollection <BsonDocument>(DriverTestConfiguration.CollectionNamespace.CollectionName); var exception = Record.Exception(() => collection.InsertOne(new BsonDocument())); if (directConnection.GetValueOrDefault()) { exception.Should().BeOfType <MongoNotPrimaryException>(); exception.Message.Should().Contain("Server returned not primary error"); } else { exception.Should().BeNull(); } } }