@@ -234,6 +234,67 @@ public void BsonSizeLimitAndBatchSizeSplittingTest(
234
234
}
235
235
}
236
236
237
+ [ SkippableTheory ]
238
+ [ ParameterAttributeData ]
239
+ public void BypassSpawningMongocryptdViaMongocryptdBypassSpawnTest(
240
+ [ Values ( false , true ) ] bool async)
241
+ {
242
+ RequireServer . Check ( ) . Supports ( Feature . ClientSideEncryption ) ;
243
+
244
+ var extraOptions = new Dictionary < string , object >
245
+ {
246
+ { "mongocryptdBypassSpawn" , true } ,
247
+ { "mongocryptdURI" , "mongodb://localhost:27021/db?serverSelectionTimeoutMS=1000" } ,
248
+ { "mongocryptdSpawnArgs" , new [ ] { "--pidfilepath=bypass-spawning-mongocryptd.pid" , "--port=27021" } } ,
249
+ } ;
250
+ var clientEncryptedSchema = new BsonDocument ( "db.coll" , JsonFileReader . Instance . Documents [ "external.external-schema.json" ] ) ;
251
+ using ( var client = ConfigureClient ( ) )
252
+ using ( var clientEncrypted = ConfigureClientEncrypted (
253
+ schemaMap : clientEncryptedSchema ,
254
+ kmsProviderFilter : "local" ,
255
+ extraOptions : extraOptions ) )
256
+ {
257
+ var datakeys = GetCollection ( client , __keyVaultCollectionNamespace ) ;
258
+ var externalKey = JsonFileReader . Instance . Documents [ "external.external-key.json" ] ;
259
+ Insert ( datakeys , async , externalKey ) ;
260
+
261
+ var coll = GetCollection ( clientEncrypted , __collCollectionNamespace ) ;
262
+ var exception = Record . Exception ( ( ) => Insert ( coll , async , new BsonDocument ( "encrypted", "test") ) ) ;
263
+
264
+ exception . Should ( ) . BeOfType < MongoEncryptionException > ( ) ;
265
+ exception . Message . Should ( ) . Contain ( "A timeout occured after 1000ms selecting a server" ) ;
266
+ }
267
+ }
268
+
269
+ [ SkippableTheory ]
270
+ [ ParameterAttributeData ]
271
+ public void BypassSpawningMongocryptdViaBypassAutoEncryptionTest(
272
+ [ Values ( false , true ) ] bool async)
273
+ {
274
+ RequireServer . Check ( ) . Supports ( Feature . ClientSideEncryption ) ;
275
+
276
+ var extraOptions = new Dictionary < string , object >
277
+ {
278
+ { "mongocryptdSpawnArgs" , new [ ] { "--pidfilepath=bypass-spawning-mongocryptd.pid" , "--port=27021" } } ,
279
+ } ;
280
+ using ( var mongocryptdClient = new DisposableMongoClient ( new MongoClient ( "mongodb://localhost:27021/?serverSelectionTimeoutMS=1000" ) ) )
281
+ using ( var clientEncrypted = ConfigureClientEncrypted (
282
+ kmsProviderFilter : "local" ,
283
+ bypassAutoEncryption : true ,
284
+ extraOptions : extraOptions ) )
285
+ {
286
+ var coll = GetCollection( clientEncrypted , __collCollectionNamespace ) ;
287
+ Insert ( coll , async , new BsonDocument ( "unencrypted", "test") ) ;
288
+
289
+ var adminDatabase = mongocryptdClient . GetDatabase ( DatabaseNamespace . Admin . DatabaseName ) ;
290
+ var isMasterCommand = new BsonDocument ( "ismaster" , 1 ) ;
291
+ var exception = Record . Exception ( ( ) => adminDatabase . RunCommand < BsonDocument > ( isMasterCommand ) ) ;
292
+
293
+ exception. Should ( ) . BeOfType < TimeoutException > ( ) ;
294
+ exception. Message . Should ( ) . Contain ( "A timeout occured after 1000ms selecting a server" ) ;
295
+ }
296
+ }
297
+
237
298
[ SkippableTheory ]
238
299
[ ParameterAttributeData ]
239
300
public void CorpusTest(
@@ -641,7 +702,9 @@ private DisposableMongoClient ConfigureClientEncrypted(
641
702
BsonDocument schemaMap = null ,
642
703
bool withExternalKeyVault = false ,
643
704
string kmsProviderFilter = null ,
644
- EventCapturer eventCapturer = null )
705
+ EventCapturer eventCapturer = null ,
706
+ Dictionary < string , object > extraOptions = null ,
707
+ bool bypassAutoEncryption = false )
645
708
{
646
709
var kmsProviders = GetKmsProviders ( ) ;
647
710
@@ -659,7 +722,9 @@ private DisposableMongoClient ConfigureClientEncrypted(
659
722
clusterConfigurator :
660
723
eventCapturer != null
661
724
? c => c . Subscribe ( eventCapturer )
662
- : ( Action < ClusterBuilder > ) null ) ;
725
+ : ( Action < ClusterBuilder > ) null ,
726
+ extraOptions : extraOptions ,
727
+ bypassAutoEncryption : bypassAutoEncryption ) ;
663
728
return clientEncrypted ;
664
729
}
665
730
@@ -730,7 +795,9 @@ private DisposableMongoClient CreateMongoClient(
730
795
BsonDocument schemaMapDocument = null ,
731
796
IReadOnlyDictionary < string , IReadOnlyDictionary < string , object > > kmsProviders = null ,
732
797
bool withExternalKeyVault = false,
733
- Action < ClusterBuilder > clusterConfigurator = null )
798
+ Action < ClusterBuilder > clusterConfigurator = null ,
799
+ Dictionary < string , object > extraOptions = null ,
800
+ bool bypassAutoEncryption = false)
734
801
{
735
802
var mongoClientSettings = DriverTestConfiguration. GetClientSettings ( ) . Clone ( ) ;
736
803
#pragma warning disable 618
@@ -743,10 +810,13 @@ private DisposableMongoClient CreateMongoClient(
743
810
744
811
if ( keyVaultNamespace != null || schemaMapDocument != null || kmsProviders != null || withExternalKeyVault )
745
812
{
746
- var extraOptions = new Dictionary < string , object > ( )
813
+ if ( extraOptions == null )
747
814
{
748
- { "mongocryptdSpawnPath" , Environment . GetEnvironmentVariable ( "MONGODB_BINARIES" ) ?? string . Empty }
749
- } ;
815
+ extraOptions = new Dictionary < string , object > ( )
816
+ {
817
+ { "mongocryptdSpawnPath" , Environment . GetEnvironmentVariable ( "MONGODB_BINARIES" ) ?? string . Empty }
818
+ } ;
819
+ }
750
820
751
821
var schemaMap = GetSchemaMapIfNotNull ( schemaMapDocument ) ;
752
822
@@ -759,7 +829,8 @@ private DisposableMongoClient CreateMongoClient(
759
829
keyVaultNamespace : keyVaultNamespace ,
760
830
kmsProviders : kmsProviders ,
761
831
schemaMap : schemaMap ,
762
- extraOptions : extraOptions ) ;
832
+ extraOptions : extraOptions ,
833
+ bypassAutoEncryption : bypassAutoEncryption ) ;
763
834
764
835
if ( withExternalKeyVault )
765
836
{
0 commit comments