-
Notifications
You must be signed in to change notification settings - Fork 1.3k
CSHARP-4386: Test mongocryptd is not spawned when shared library is loaded. #965
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
1e018a1
380c8bd
e9fa33a
aa6e2cf
4c2c981
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,7 @@ | |
using System; | ||
using System.Collections.Generic; | ||
using System.Collections.ObjectModel; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Net; | ||
using System.Net.Http; | ||
|
@@ -34,7 +35,6 @@ | |
using MongoDB.Driver.Core.Authentication.External; | ||
using MongoDB.Driver.Core.Bindings; | ||
using MongoDB.Driver.Core.Clusters; | ||
using MongoDB.Driver.Core.Configuration; | ||
using MongoDB.Driver.Core.Events; | ||
using MongoDB.Driver.Core.Misc; | ||
using MongoDB.Driver.Core.Operations; | ||
|
@@ -271,36 +271,28 @@ public void BypassSpawningMongocryptdViaMongocryptdBypassSpawnTest( | |
kmsProviderFilter: "local", | ||
extraOptions: extraOptions)) | ||
{ | ||
var datakeys = GetCollection(client, __keyVaultCollectionNamespace); | ||
var externalKey = JsonFileReader.Instance.Documents["external.external-key.json"]; | ||
Insert(datakeys, async, externalKey); | ||
|
||
var coll = GetCollection(clientEncrypted, __collCollectionNamespace); | ||
var exception = Record.Exception(() => Insert(coll, async, new BsonDocument("encrypted", "test"))); | ||
|
||
AssertInnerEncryptionException<TimeoutException>(exception, "A timeout occurred after 10000ms selecting a server"); | ||
} | ||
} | ||
|
||
public enum BypassSpawningMongocryptd | ||
{ | ||
BypassAutoEncryption, | ||
BypassQueryAnalysis, | ||
SharedLibrary | ||
} | ||
|
||
[SkippableTheory] | ||
[ParameterAttributeData] | ||
public void BypassSpawningMongocryptdTest( | ||
[Values(false, true)] bool bypassAutoEncryption, // true - BypassAutoEncryption, false - BypassQueryAnalysis | ||
[Values(BypassSpawningMongocryptd.BypassQueryAnalysis, BypassSpawningMongocryptd.BypassAutoEncryption, BypassSpawningMongocryptd.SharedLibrary)] BypassSpawningMongocryptd bypassSpawning, | ||
[Values(false, true)] bool async) | ||
{ | ||
RequireServer.Check().Supports(Feature.ClientSideEncryption); | ||
RequireEnvironment.Check().EnvironmentVariable("CRYPT_SHARED_LIB_PATH", isDefined: false); | ||
|
||
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=10000"), CreateLogger<DisposableMongoClient>())) | ||
using (var clientEncrypted = ConfigureClientEncrypted( | ||
kmsProviderFilter: "local", | ||
bypassAutoEncryption: bypassAutoEncryption, // bypass options are mutually exclusive for this test | ||
bypassQueryAnalysis: !bypassAutoEncryption, | ||
extraOptions: extraOptions)) | ||
using (var clientEncrypted = EnsureEnvironmentAndConfigureTestClientEncrypted()) | ||
using (var mongocryptdClient = new DisposableMongoClient(new MongoClient("mongodb://localhost:27021/?serverSelectionTimeoutMS=1000"), CreateLogger<DisposableMongoClient>())) | ||
{ | ||
var coll = GetCollection(clientEncrypted, __collCollectionNamespace); | ||
Insert(coll, async, new BsonDocument("unencrypted", "test")); | ||
|
@@ -310,7 +302,43 @@ public void BypassSpawningMongocryptdTest( | |
var exception = Record.Exception(() => adminDatabase.RunCommand<BsonDocument>(legacyHelloCommand)); | ||
|
||
exception.Should().BeOfType<TimeoutException>(); | ||
exception.Message.Should().Contain("A timeout occurred after 10000ms selecting a server"); | ||
exception.Message.Should().Contain("A timeout occurred after 1000ms selecting a server").And.Contain("localhost:27021"); | ||
} | ||
|
||
DisposableMongoClient EnsureEnvironmentAndConfigureTestClientEncrypted() | ||
{ | ||
var extraOptions = new Dictionary<string, object> | ||
{ | ||
{ "mongocryptdSpawnArgs", new [] { "--pidfilepath=bypass-spawning-mongocryptd.pid", "--port=27021" } }, | ||
}; | ||
var kmsProvider = "local"; | ||
switch (bypassSpawning) | ||
{ | ||
case BypassSpawningMongocryptd.BypassAutoEncryption: | ||
RequireServer.Check().Supports(Feature.ClientSideEncryption); | ||
RequireEnvironment.Check().EnvironmentVariable("CRYPT_SHARED_LIB_PATH", isDefined: false); | ||
return ConfigureClientEncrypted(kmsProviderFilter: kmsProvider, bypassAutoEncryption: true, extraOptions: extraOptions); | ||
case BypassSpawningMongocryptd.BypassQueryAnalysis: | ||
RequireServer.Check().Supports(Feature.ClientSideEncryption); | ||
RequireEnvironment.Check().EnvironmentVariable("CRYPT_SHARED_LIB_PATH", isDefined: false); | ||
return ConfigureClientEncrypted(kmsProviderFilter: kmsProvider, bypassQueryAnalysis: true, extraOptions: extraOptions); | ||
case BypassSpawningMongocryptd.SharedLibrary: | ||
{ | ||
RequireServer.Check().Supports(Feature.Csfle2).ClusterTypes(ClusterType.ReplicaSet, ClusterType.Sharded, ClusterType.LoadBalanced); | ||
RequireEnvironment.Check().EnvironmentVariable("CRYPT_SHARED_LIB_PATH", isDefined: true, allowEmpty: false); | ||
var clientEncryptedSchema = new BsonDocument("db.coll", JsonFileReader.Instance.Documents["external.external-schema.json"]); | ||
var cryptSharedPath = CoreTestConfiguration.GetCryptSharedLibPath(); | ||
Ensure.That(File.Exists(cryptSharedPath), $"Shared library path {cryptSharedPath} is not valid."); | ||
var effectiveExtraOptions = new Dictionary<string, object>(extraOptions) | ||
{ | ||
{ "mongocryptdURI", "mongodb://localhost:27021/db?serverSelectionTimeoutMS=1000" }, | ||
{ "cryptSharedLibPath", cryptSharedPath }, | ||
{ "cryptSharedRequired", true } | ||
}; | ||
return ConfigureClientEncrypted(kmsProviderFilter: kmsProvider, schemaMap: clientEncryptedSchema, extraOptions: effectiveExtraOptions); | ||
} | ||
default: throw new Exception($"Invalid bypass mongocryptd {bypassSpawning} option."); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In this file, we use |
||
} | ||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where
effectiveExtraOptions
is used?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good point, fixed. The test actually behaves almost the same even without this configuration because a shared library is configured by default, but it's definitely better to have it configured explicitly.