Skip to content

TLS Support to OpenSSL workload - users/vdeepar/tls update #550

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

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/VirtualClient/TestResources/Results-OpenSSL-server.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Using default temp DH parameters
ACCEPT
13 changes: 13 additions & 0 deletions src/VirtualClient/TestResources/Results-OpenSSL-stime.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Collecting connection statistics for 5 seconds
*****************

17 connections in 1.54s; 11.04 connections/user sec, bytes read 9126806252
17 connections in 6 real seconds, 536870956 bytes read per connection


Now timing with session id reuse.
starting
rrrrrrrrrrrrrrrrr

17 connections in 1.54s; 11.04 connections/user sec, bytes read 9126806252
17 connections in 6 real seconds, 536870956 bytes read per connection
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

namespace VirtualClient.Actions
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Moq;
using NUnit.Framework;
using VirtualClient.Common;
using VirtualClient.Contracts;

[TestFixture]
[Category("Functional")]
public class TlsOpenSslClientProfileTests
{
private DependencyFixture mockFixture;

[SetUp]
public void SetupFixture()
{
this.mockFixture = new DependencyFixture();
this.mockFixture
.Setup(PlatformID.Unix, Architecture.X64, "Client01")
.SetupLayout(
new ClientInstance("Client01", "1.2.3.4", "Client"),
new ClientInstance("Server01", "1.2.3.5", "Server"));

ComponentTypeCache.Instance.LoadComponentTypes(TestDependencies.TestDirectory);
}

[Test]
[TestCase("Compete-OPENSSL-TLS.json")]
public async Task TlsOpenSslClientCreatesExpectedStateAndExecutesWorkload(string profile)
{
List<string> expectedCommands = new List<string>();

// Setup the expectations for the workload
// - Workload package is installed and exists.
// - Workload binaries/executables exist on the file system.
// - Expected processes are executed.
IPAddress.TryParse("1.2.3.4", out IPAddress ipAddress);
IApiClient apiClient = this.mockFixture.ApiClientManager.GetOrCreateApiClient("1.2.3.4", ipAddress);

State state = new State();

await apiClient.CreateStateAsync(nameof(State), state, CancellationToken.None);

this.mockFixture.ProcessManager.OnCreateProcess = (command, arguments, workingDir) =>
{
IProcessProxy process = this.mockFixture.CreateProcess(command, arguments, workingDir);
if (arguments?.Contains("s_time") == true)
{
return process;
}

return process;
};

using (ProfileExecutor executor = TestDependencies.CreateProfileExecutor(profile, this.mockFixture.Dependencies, dependenciesOnly: true))
{
await executor.ExecuteAsync(ProfileTiming.OneIteration(), CancellationToken.None);
WorkloadAssert.WorkloadPackageInstalled(this.mockFixture, "openssl");
WorkloadAssert.CommandsExecuted(this.mockFixture, expectedCommands.ToArray());
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

namespace VirtualClient.Actions
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using AutoFixture;
using Moq;
using NUnit.Framework;
using VirtualClient.Common;
using VirtualClient.Contracts;

[TestFixture]
[Category("Functional")]
public class TlsOpenSslServerProfileTests
{
private DependencyFixture mockFixture;

[SetUp]
public void SetupFixture()
{
this.mockFixture = new DependencyFixture();
this.mockFixture
.Setup(PlatformID.Unix, Architecture.X64, "Server01")
.SetupLayout(
new ClientInstance("Client01", "1.2.3.4", "Client"),
new ClientInstance("Server01", "1.2.3.5", "Server"));

ComponentTypeCache.Instance.LoadComponentTypes(TestDependencies.TestDirectory);
}

[Test]
[TestCase("Compete-OPENSSL-TLS.json")]
public async Task TlsOpenSslServerWorkloadProfileInstallsTheExpectedDependenciesOnUnixPlatform(string profile)
{
// Setup the expectations for the workload
// - Workload package is installed and exists.
IPAddress.TryParse("1.2.3.5", out IPAddress ipAddress);
IApiClient apiClient = this.mockFixture.ApiClientManager.GetOrCreateApiClient("1.2.3.5", ipAddress);

State state = new State();

await apiClient.CreateStateAsync(nameof(State), state, CancellationToken.None);

using (ProfileExecutor executor = TestDependencies.CreateProfileExecutor(profile, this.mockFixture.Dependencies, dependenciesOnly: true))
{
await executor.ExecuteAsync(ProfileTiming.OneIteration(), CancellationToken.None).ConfigureAwait(false);

// Workload dependency package expectations
// The workload dependency package should have been installed at this point.
WorkloadAssert.WorkloadPackageInstalled(this.mockFixture, "openssl");
}
}

[Test]
[TestCase("Compete-OPENSSL-TLS.json")]
public void TlsOpenSslServerWorkloadProfileActionsWillNotBeExecutedIfTheWorkloadPackageDoesNotExist(string profile)
{
// We ensure the workload package does not exist.
this.mockFixture.PackageManager.Clear();

using (ProfileExecutor executor = TestDependencies.CreateProfileExecutor(profile, this.mockFixture.Dependencies))
{
executor.ExecuteDependencies = false;

DependencyException error = Assert.ThrowsAsync<DependencyException>(() => executor.ExecuteAsync(ProfileTiming.OneIteration(), CancellationToken.None));
Assert.AreEqual(ErrorReason.WorkloadDependencyMissing, error.Reason);
Assert.IsFalse(this.mockFixture.ProcessManager.Commands.Contains("openssl s_server"));
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

namespace VirtualClient.Actions
{
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Runtime.InteropServices;
using System.Threading;
using System.Threading.Tasks;
using VirtualClient.Common;
using Moq;
using NUnit.Framework;
using VirtualClient.Actions.Properties;
using VirtualClient.Common.Telemetry;
using VirtualClient.Contracts;

[TestFixture]
[Category("Unit")]
public class TlsOpenSslClientExecutorTests
{
private DependencyFixture fixture;
private DependencyPath mockPackage;

[Test]
[TestCase(PlatformID.Unix, Architecture.X64, "linux-x64/bin/openssl")]
[TestCase(PlatformID.Unix, Architecture.Arm64, "linux-arm64/bin/openssl")]
public async Task Constructor_InitializesDependenciesAndPolicies(PlatformID platform, Architecture architecture, string binaryPath)
{
SetupEnvironment(platform, architecture);
using (TestOpenSslClientExecutor executor = new TestOpenSslClientExecutor(this.fixture, this.fixture.Parameters))
{

Assert.IsNotNull(executor);
Assert.IsNull(executor.ExecutablePath);

await executor.InitializeAsync(EventContext.None, CancellationToken.None)
.ConfigureAwait(false);

DependencyPath expectedWorkloadPackage = this.fixture.PlatformSpecifics.ToPlatformSpecificPath(this.mockPackage, platform, architecture);
Assert.IsTrue(expectedWorkloadPackage.Equals(executor.Package));


string expectedWorkloadExecutablePath = Path.Combine(this.mockPackage.Path, binaryPath);
Assert.IsTrue(PlatformAgnosticPathComparer.Instance.Equals(expectedWorkloadExecutablePath, executor.ExecutablePath));
}
}

[Test]
[TestCase(PlatformID.Unix, Architecture.X64)]
[TestCase(PlatformID.Unix, Architecture.Arm64)]
public void Properties_ReturnExpectedValues(PlatformID platform, Architecture architecture)
{
SetupEnvironment(platform, architecture);
var executor = new TlsOpenSslClientExecutor(this.fixture.Dependencies, this.fixture.Parameters);

Assert.IsNotNull(executor);
Assert.AreEqual(2, executor.ClientInstances);
Assert.AreEqual(443, executor.ServerPort);
Assert.IsTrue(executor.WarmUp);
Assert.IsNotNull(executor.Parameters);
}


[Test]
public void CaptureMetrics_LogsMetricsOnSuccess()
{
SetupEnvironment(PlatformID.Unix, Architecture.X64);
var executor = new TlsOpenSslClientExecutor(this.fixture.Dependencies, this.fixture.Parameters);
Assert.IsNotNull(executor);
var process = this.fixture.CreateProcess("openssl", "s_time ...", "/tmp");
process.ExitCode = 0;
process.StandardOutput.Append(TestResources.Results_OpenSSL_stime);

var method = typeof(TlsOpenSslClientExecutor).GetMethod("CaptureMetrics", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);

// Should not throw
Assert.DoesNotThrow(() =>
{
method.Invoke(executor, new object[] { process, "s_time ...", EventContext.None, CancellationToken.None });
});
}

private void SetupEnvironment(PlatformID platform = PlatformID.Unix, Architecture architecture = Architecture.X64)
{
// Setup the default behaviors given all expected dependencies are in place such that the
// workload can be executed successfully.
this.fixture = new DependencyFixture();
this.fixture.Setup(platform, architecture);
this.fixture
.Setup(platform, architecture, "Client01")
.SetupLayout(
new ClientInstance("Client01", "1.2.3.4", "Client"),
new ClientInstance("Server01", "1.2.3.5", "Server"));

// ComponentTypeCache.Instance.LoadComponentTypes(TestDependencies.TestDirectory);

this.fixture.SetupPackage(
"OpenSSL",
expectedFiles: $"{PlatformSpecifics.GetPlatformArchitectureName(platform, architecture)}/bin/openssl");

this.mockPackage = this.fixture.PackageManager.First(pkg => pkg.Name == "OpenSSL");

this.fixture.Parameters = new Dictionary<string, IConvertible>
{
{ "ClientInstances", 2 },
{ "ServerPort", 443 },
{ "WarmUp", true },
{ "CommandArguments", "s_time -connect :443 -www /test_1k.html -time 30 -ciphersuites TLS_AES_256_GCM_SHA384 -tls1_3" },
{ "Scenario", "OpenSSL_TLS_Client_AES_256_GCM_SHA384_1k" },
{ "MetricScenario", "tls_client_aes-256-gcm-sha384-1k" },
{ "PackageName", "OpenSSL" },
{ "Tags", "CPU,OpenSSL,Cryptography" },
{ "Role", "Client" }
};
this.fixture.ProcessManager.OnProcessCreated = (process) =>
{
// When we start the OpenSSL process we want to register a successful
// result.
if (process.IsMatch("openssl s_time"))
{
process.StandardOutput.Append(TestResources.Results_OpenSSL_stime);
}
};
}
private class TestOpenSslClientExecutor : TlsOpenSslClientExecutor
{
public TestOpenSslClientExecutor(DependencyFixture mockFixture, IDictionary<string, IConvertible> parameters)
: base(mockFixture.Dependencies, parameters)
{
}

public new DependencyPath Package
{
get
{
return base.Package;
}
}

public new Task ExecuteAsync(EventContext telemetryContext, CancellationToken cancellationToken)
{
return base.ExecuteAsync(telemetryContext, cancellationToken);
}

public new Task InitializeAsync(EventContext telemetryContext, CancellationToken cancellationToken)
{
return base.InitializeAsync(telemetryContext, cancellationToken);
}
public IApiClient MockApiClient
{
get
{
return base.ApiClient;
}
}
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,9 @@
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<data name="Results_OpenSSL_stime" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\Results-OpenSSL-stime.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8</value>
</data>
<data name="Results_DiskSpd_Text" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\Results_DiskSpd_Text.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252</value>
</data>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Collecting connection statistics for 5 seconds
*****************

17 connections in 1.54s; 11.04 connections/user sec, bytes read 9126806252
17 connections in 6 real seconds, 536870956 bytes read per connection


Now timing with session id reuse.
starting
rrrrrrrrrrrrrrrrr

17 connections in 1.54s; 11.04 connections/user sec, bytes read 9126806252
17 connections in 6 real seconds, 536870956 bytes read per connection
Loading
Loading