Skip to content
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

More TLS tests #622

Draft
wants to merge 2 commits into
base: sast/alix/dont-specify-tls
Choose a base branch
from
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
<PackageReference Include="Serilog.Sinks.NUnit" Version="1.0.3" />
<PackageReference Include="System.Diagnostics.PerformanceCounter" Version="6.0.1" />
<PackageReference Include="TeamCity.VSTest.TestAdapter" Version="1.0.36" />
<PackageReference Include="Serilog" Version="2.12.0" />
<PackageReference Include="Serilog" Version="4.1.0" />
<PackageReference Include="Serilog.Sinks.ColoredConsole" Version="3.0.1" />
<PackageReference Include="Octopus.Shellfish" Version="0.2.1180" />
</ItemGroup>
Expand Down
3 changes: 2 additions & 1 deletion source/Halibut.Tests/Halibut.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,11 @@
<PackageReference Include="NUnit3TestAdapter" Version="4.4.2" />
<PackageReference Include="Serilog.Extensions.Logging" Version="7.0.0" />
<PackageReference Include="Serilog.Sinks.NUnit" Version="1.0.3" />
<PackageReference Include="Serilog.Sinks.TextWriter" Version="3.0.0" />
<PackageReference Include="System.Diagnostics.PerformanceCounter" Version="6.0.1" />
<PackageReference Include="System.Interactive.Async" Version="6.0.1" />
<PackageReference Include="TeamCity.VSTest.TestAdapter" Version="1.0.36" />
<PackageReference Include="Serilog" Version="2.12.0" />
<PackageReference Include="Serilog" Version="4.1.0" />
<PackageReference Include="Serilog.Sinks.ColoredConsole" Version="3.0.1" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
using System;
using System.Collections.Concurrent;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using Halibut.Diagnostics;
using Halibut.Diagnostics.LogCreators;
using Halibut.Logging;
using Halibut.TestProxy;
using Halibut.Tests.Support.Logging;
using Halibut.Transport.Proxy;
using Octopus.TestPortForwarder;
using Serilog;
using ILog = Halibut.Diagnostics.ILog;

namespace Halibut.Tests.Support.BackwardsCompatibility
{
Expand All @@ -21,6 +26,7 @@ public class LatestClientAndPreviousServiceVersionBuilder : IClientAndServiceBui
ProxyFactory? proxyFactory;
Reference<HttpProxyService>? proxyServiceReference;
LogLevel halibutLogLevel = LogLevel.Trace;
StringWriter? loggerStringWriter;
readonly OldServiceAvailableServices availableServices = new(false, false);

LatestClientAndPreviousServiceVersionBuilder(ServiceConnectionType serviceConnectionType, CertAndThumbprint serviceCertAndThumbprint)
Expand Down Expand Up @@ -59,6 +65,12 @@ public static LatestClientAndPreviousServiceVersionBuilder ForServiceConnectionT
}
}

public LatestClientAndPreviousServiceVersionBuilder RecordingLogs(out StringWriter stringWriter)
{
loggerStringWriter = stringWriter = new();
return this;
}

public LatestClientAndPreviousServiceVersionBuilder WithServiceVersion(Version? version)
{
this.version = version;
Expand Down Expand Up @@ -149,7 +161,11 @@ async Task<IClientAndService> IClientAndServiceBuilder.Build(CancellationToken c

public async Task<ClientAndService> Build(CancellationToken cancellationToken)
{
var logger = new SerilogLoggerBuilder().Build().ForContext<LatestClientAndPreviousServiceVersionBuilder>();
var logger = loggerStringWriter == null
? new SerilogLoggerBuilder()
.Build().ForContext<LatestClientAndPreviousServiceVersionBuilder>()
: new LoggerConfiguration().WriteTo.TextWriter(loggerStringWriter).CreateLogger();

CancellationTokenSource cancellationTokenSource = new();
if (version == null)
{
Expand Down
22 changes: 22 additions & 0 deletions source/Halibut.Tests/TlsFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
using FluentAssertions;
using Halibut.Exceptions;
using Halibut.Tests.Support;
using Halibut.Tests.Support.BackwardsCompatibility;
using Halibut.Tests.Support.TestAttributes;
using Halibut.Tests.Support.TestCases;
using Halibut.Tests.TestServices.Async;
Expand Down Expand Up @@ -62,5 +63,26 @@ public async Task LatestClientAndServiceUseBestAvailableSslProtocol(ClientAndSer
.Should().Contain(logEvent => logEvent.FormattedMessage.Contains($"using protocol {expectedSslProtocol}"));
}
}

[Test]
// [PreviousClientAndLatestServiceVersionsTestCases(testNetworkConditions: false)]
[LatestClientAndPreviousServiceVersionsTestCases(testNetworkConditions: false)]
public async Task PreviousClientXorServiceUsageMakeSslProtocolFallBackOnTls12(ClientAndServiceTestCase clientAndServiceTestCase)
{
await using (var clientAndService = await ((LatestClientAndPreviousServiceVersionBuilder)(clientAndServiceTestCase.CreateTestCaseBuilder()
.WithStandardServices()))
.RecordingLogs(out var stringWriter)
.Build(CancellationToken))
{
var echo = clientAndService.CreateAsyncClient<IEchoService, IAsyncClientEchoService>();
await echo.SayHelloAsync("World");
const SslProtocols expectedProtocol = SslProtocols.Tls12;
var expectedLogFragment = clientAndServiceTestCase.ServiceConnectionType == ServiceConnectionType.Listening
? $"client connected with {expectedProtocol}"
: $"using protocol {expectedProtocol}";
var logs = stringWriter.ToString();
logs.Should().Contain(expectedLogFragment);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Serilog" Version="2.12.0" />
<PackageReference Include="Serilog" Version="4.1.0" />
</ItemGroup>

<PropertyGroup Condition=" '$(TargetFramework)' == 'net48' ">
Expand Down