public void TestEquals() { RequirePlatform.Check().SkipWhen(SupportedOperatingSystem.MacOS, SupportedTargetFramework.NetStandard15); var settings = new SslSettings(); var clone = settings.Clone(); Assert.Equal(settings, clone); clone = settings.Clone(); clone.CheckCertificateRevocation = !settings.CheckCertificateRevocation; Assert.NotEqual(settings, clone); clone = settings.Clone(); var certificateFileName = GetTestCertificateFileName(); clone.ClientCertificates = new[] { new X509Certificate2(certificateFileName, "password") }; Assert.NotEqual(settings, clone); clone = settings.Clone(); clone.ClientCertificateSelectionCallback = ClientCertificateSelectionCallback; Assert.NotEqual(settings, clone); clone = settings.Clone(); clone.EnabledSslProtocols = SslProtocols.Tls12; Assert.NotEqual(settings, clone); clone = settings.Clone(); clone.ServerCertificateValidationCallback = ServerCertificateValidationCallback; Assert.NotEqual(settings, clone); }
public void Run(JsonDrivenTestCase testCase) { #if DEBUG RequirePlatform .Check() .SkipWhen(SupportedOperatingSystem.Linux) .SkipWhen(SupportedOperatingSystem.MacOS); // Make sure that LB is started. "nginx" is a LB we use for windows testing RequireEnvironment.Check().ProcessStarted("nginx"); Environment.SetEnvironmentVariable("MONGODB_URI", "mongodb://localhost:17017?loadBalanced=true"); Environment.SetEnvironmentVariable("MONGODB_URI_WITH_MULTIPLE_MONGOSES", "mongodb://localhost:17018?loadBalanced=true"); RequireServer .Check() .LoadBalancing(enabled: true, ignorePreviousSetup: true) .Authentication(authentication: false); // auth server requires credentials in connection string #else RequireEnvironment // these env variables are used only on the scripting side .Check() .EnvironmentVariable("SINGLE_MONGOS_LB_URI") .EnvironmentVariable("MULTI_MONGOS_LB_URI"); // EG currently supports LB only for Ubuntu RequirePlatform .Check() .SkipWhen(SupportedOperatingSystem.Windows) .SkipWhen(SupportedOperatingSystem.MacOS); #endif using (var runner = new UnifiedTestRunner()) { runner.Run(testCase); } }
public void Run(JsonDrivenTestCase testCase) { RequirePlatform .Check() .SkipWhen(SupportedOperatingSystem.Linux, SupportedTargetFramework.NetStandard15) .SkipWhen(() => testCase.Name.Contains("gcpKMS.json"), SupportedOperatingSystem.Linux, SupportedTargetFramework.NetStandard20); // gcp is supported starting from netstandard2.1 SetupAndRunTest(testCase); }
public void GetLibraryBasePath_should_get_correct_paths_with_mocking(string rootTestFolder, string expectedRootTestFolder) { var assemblyCodeBase = Path.Combine( RequirePlatform.GetCurrentOperatingSystem() == SupportedOperatingSystem.Windows ? "C:/" : @"\\data", rootTestFolder, GetCommonTestAssemblyFolderEnding(), "MongoDB.Driver.Core.dll"); var testAssemblyCodeBaseUri = new Uri(assemblyCodeBase).ToString(); var subject = new TestRelativeLibraryLocator(mockedAssemblyUri: testAssemblyCodeBaseUri); var result = subject.GetBaseAssemblyDirectory(); var expectedResult = Path.Combine(expectedRootTestFolder, GetCommonTestAssemblyFolderEnding()); result.Should().EndWith(expectedResult); }
public void Run(JsonDrivenTestCase testCase) { if (testCase.Name.Contains("awsTemporary")) { // This test requires setting of some temporary environment variables that can be set by mongo orchestration or manually. // Add this environment variable on your local machine only together with FLE_AWS_TEMP_* variables (note: they will be expired in 12 hours) RequireEnvironment.Check().EnvironmentVariable("FLE_AWS_TEMPORARY_CREDS_ENABLED"); } RequirePlatform .Check() .SkipWhen(SupportedOperatingSystem.Linux, SupportedTargetFramework.NetStandard15) .SkipWhen(() => testCase.Name.Contains("gcpKMS.json"), SupportedOperatingSystem.Linux, SupportedTargetFramework.NetStandard20) // gcp is supported starting from netstandard2.1 .SkipWhen(SupportedOperatingSystem.MacOS, SupportedTargetFramework.NetStandard15) .SkipWhen(() => testCase.Name.Contains("gcpKMS.json"), SupportedOperatingSystem.MacOS, SupportedTargetFramework.NetStandard20); // gcp is supported starting from netstandard2.1 SetupAndRunTest(testCase); }
public void SelectServer_loadbalancing_prose_test([Values(false, true)] bool async) { RequireServer.Check() .Supports(Feature.ShardedTransactions, Feature.FailPointsBlockConnection) .ClusterType(ClusterType.Sharded); RequireMultipleShardRouters(); // temporary disable the test on Win Auth topologies, due to operations timings irregularities if (CoreTestConfiguration.ConnectionString.Tls == true && RequirePlatform.GetCurrentOperatingSystem() == SupportedOperatingSystem.Windows) { throw new SkipException("Win Auth topologies temporary not supported due to timings irregularities."); } const string applicationName = "loadBalancingTest"; const int threadsCount = 10; const int commandsPerThreadCount = 10; const double maxCommandsOnSlowServerRatio = 0.3; // temporary set slow server load to 30% from 25% until find timings are investigated const double operationsCountTolerance = 0.10; var failCommand = BsonDocument.Parse($"{{ configureFailPoint: 'failCommand', mode : {{ times : 10000 }}, data : {{ failCommands : [\"find\"], blockConnection: true, blockTimeMS: 500, appName: '{applicationName}' }} }}"); DropCollection(); var eventCapturer = CreateEventCapturer(); using (var client = CreateDisposableClient(eventCapturer, applicationName)) { var slowServer = client.Cluster.SelectServer(WritableServerSelector.Instance, default); var fastServer = client.Cluster.SelectServer(new DelegateServerSelector((_, servers) => servers.Where(s => s.ServerId != slowServer.ServerId)), default); using var failPoint = FailPoint.Configure(slowServer, NoCoreSession.NewHandle(), failCommand); var database = client.GetDatabase(_databaseName); CreateCollection(); var collection = database.GetCollection <BsonDocument>(_collectionName); // warm up connections var channels = new ConcurrentBag <IChannelHandle>(); ThreadingUtilities.ExecuteOnNewThreads(threadsCount, i => { channels.Add(slowServer.GetChannel(default)); channels.Add(fastServer.GetChannel(default));
public void TestClientCertificates() { RequirePlatform.Check().SkipWhen(SupportedOperatingSystem.MacOS, SupportedTargetFramework.NetStandard15); var settings = new SslSettings(); Assert.Equal(null, settings.ClientCertificates); var certificateFileName = GetTestCertificateFileName(); var clientCertificates = new[] { new X509Certificate2(certificateFileName, "password"), new X509Certificate2(certificateFileName, "password") }; settings.ClientCertificates = clientCertificates; Assert.True(clientCertificates.SequenceEqual(settings.ClientCertificates)); Assert.True(settings.ClientCertificates.Cast <X509Certificate2>().All(cert => cert.HasPrivateKey)); settings.Freeze(); Assert.True(clientCertificates.SequenceEqual(settings.ClientCertificates)); Assert.Throws <InvalidOperationException>(() => { settings.ClientCertificates = clientCertificates; }); }
private void SkipIfNotLoadBalancingMode() { #if DEBUG RequirePlatform.Check().SkipWhen(SupportedOperatingSystem.Linux); RequirePlatform.Check().SkipWhen(SupportedOperatingSystem.MacOS); // Make sure that LB is started. "nginx" is a LB we use for windows testing RequireEnvironment.Check().ProcessStarted("nginx"); Environment.SetEnvironmentVariable("MONGODB_URI", "mongodb://localhost:17017?loadBalanced=true"); Environment.SetEnvironmentVariable("MONGODB_URI_WITH_MULTIPLE_MONGOSES", "mongodb://localhost:17018?loadBalanced=true"); RequireServer .Check() .LoadBalancing(enabled: true, ignorePreviousSetup: true) .Authentication(authentication: false); // auth server requires credentials in connection string #else RequireEnvironment.Check().EnvironmentVariable("SINGLE_MONGOS_LB_URI"); // these env variables are used only on the scripting side RequireEnvironment.Check().EnvironmentVariable("MULTI_MONGOS_LB_URI"); // EG currently supports LB only for Ubuntu RequirePlatform.Check().SkipWhen(SupportedOperatingSystem.Windows); RequirePlatform.Check().SkipWhen(SupportedOperatingSystem.MacOS); RequireServer.Check().ClusterType(ClusterType.LoadBalanced); #endif }