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

Port latest fixes from TlsHandlerTests to SniHandlerTests #46

Merged
merged 2 commits into from
Oct 5, 2024
Merged
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
29 changes: 11 additions & 18 deletions test/DotNetty.Handlers.Tests/SniHandlerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,8 @@ public async Task TlsRead(int[] frameLengths, bool isClient, IWriteStrategy writ
}

driverStream.Dispose();

if (ch.Finish())
{
var emptyByteBufferOutbound = ch.ReadOutbound<EmptyByteBuffer>();
Assert.NotNull(emptyByteBufferOutbound);
}

await ch.CloseAsync(); //closing channel causes TlsHandler.Flush() to send final empty buffer
var _ = ch.ReadOutbound<EmptyByteBuffer>();
Assert.False(ch.Finish());
}
finally
Expand Down Expand Up @@ -203,13 +198,8 @@ await ReadOutboundAsync(
}

driverStream.Dispose();

if (ch.Finish())
{
var emptyByteBufferOutbound = ch.ReadOutbound<EmptyByteBuffer>();
Assert.NotNull(emptyByteBufferOutbound);
}

await ch.CloseAsync(); //closing channel causes TlsHandler.Flush() to send final empty buffer
var _ = ch.ReadOutbound<EmptyByteBuffer>();
Assert.False(ch.Finish());
}
finally
Expand Down Expand Up @@ -267,15 +257,18 @@ static async Task<Tuple<EmbeddedChannel, SslStream>> SetupStreamAndChannelAsync(
});

var driverStream = new SslStream(mediationStream, true, (_1, _2, _3, _4) => true);
var handshakeTimeout = TimeSpan.FromSeconds(5);
if (isClient)
{
ServerTlsSettings serverTlsSettings = CertificateSelector(targetHost).Result;
await Task.Run(() => driverStream.AuthenticateAsServerAsync(serverTlsSettings.Certificate, false, protocol | serverTlsSettings.EnabledProtocols, false).WithTimeout(TimeSpan.FromSeconds(5)));
await Task.Run(() => driverStream.AuthenticateAsServerAsync(serverTlsSettings.Certificate, false, protocol | serverTlsSettings.EnabledProtocols, false).WithTimeout(handshakeTimeout));
}
else
{
await Task.Run(() => driverStream.AuthenticateAsClientAsync(targetHost, null, protocol, false)).WithTimeout(TimeSpan.FromSeconds(5));
await Task.Run(() => driverStream.AuthenticateAsClientAsync(targetHost, null, protocol, false)).WithTimeout(handshakeTimeout);
}

await ch.Pipeline.Get<TlsHandler>().HandshakeCompletion.WithTimeout(handshakeTimeout);
writeTasks.Clear();

return Tuple.Create(ch, driverStream);
Expand Down Expand Up @@ -312,8 +305,8 @@ static Task ReadOutboundAsync(Func<Task<IByteBuffer>> readFunc, int expectedByte

if (!output.IsReadable())
{
output.Release();
return true;
output.Release(); //received empty message but that's not necessary the end of the data stream
continue;
}

remaining -= output.ReadableBytes;
Expand Down