Skip to content

Commit

Permalink
Test simplifications
Browse files Browse the repository at this point in the history
  • Loading branch information
pepone committed Oct 6, 2023
1 parent 9971d55 commit bf18636
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
namespace IceRpc.Tests.Transports;

/// <summary>Test Ssl authentication with Quic transport.</summary>
public class QuicTransportSslAuthenticationConformanceTests
public class QuicTransportSslAuthenticationTests
{
[OneTimeSetUp]
public void FixtureSetUp()
Expand All @@ -24,7 +24,7 @@ public void FixtureSetUp()
}

[Test]
public async Task Ssl_client_connection_connect_fails_when_server_provides_untrusted_certificate()
public async Task Quic_client_connection_connect_fails_when_server_provides_untrusted_certificate()
{
// Arrange
await using ServiceProvider provider = CreateServiceCollection()
Expand Down Expand Up @@ -59,7 +59,7 @@ public async Task Ssl_client_connection_connect_fails_when_server_provides_untru
"CA5359:Do Not Disable Certificate Validation",
Justification = "The client doesn't need to validate the server certificate for this test")]
[Test]
public async Task Ssl_server_connection_connect_fails_when_client_provides_untrusted_certificate()
public async Task Quic_server_connection_connect_fails_when_client_provides_untrusted_certificate()
{
// Arrange
await using ServiceProvider provider = CreateServiceCollection()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ namespace IceRpc.Tests.Transports.Slic;

/// <summary>Test Ssl authentication with Slic transport.</summary>
[Parallelizable(ParallelScope.All)]
public class SlicTransportSslAuthenticationConformanceTests
public class SlicTransportSslAuthenticationTests
{
[Test]
public async Task Ssl_client_connection_connect_fails_when_server_provides_untrusted_certificate()
public async Task Slic_over_ssl_client_connection_connect_fails_when_server_provides_untrusted_certificate()
{
// Arrange
await using ServiceProvider provider = CreateServiceCollection()
Expand All @@ -39,27 +39,18 @@ public async Task Ssl_client_connection_connect_fails_when_server_provides_untru
// Start the TLS handshake.
Task clientConnectTask = sut.Client.ConnectAsync(default);
(IMultiplexedConnection serverConnection, _) = await listener.AcceptAsync(default);
var serverConnectTask = serverConnection.ConnectAsync(default);
_ = serverConnection.ConnectAsync(default);

// Act/Assert
Assert.That(async () => await clientConnectTask, Throws.TypeOf<AuthenticationException>());

// The client will typically close the transport connection after receiving AuthenticationException
await sut.Client.DisposeAsync();
var exception = Assert.ThrowsAsync<IceRpcException>(async () => await serverConnectTask!);
Assert.That(
exception?.IceRpcError,
Is.EqualTo(IceRpcError.ConnectionAborted).Or.EqualTo(IceRpcError.IceRpcError),
$"The test failed with an unexpected IceRpcError {exception}");
await serverConnection.DisposeAsync();
}

[System.Diagnostics.CodeAnalysis.SuppressMessage(
"Security",
"CA5359:Do Not Disable Certificate Validation",
Justification = "The client doesn't need to validate the server certificate for this test")]
[Test]
public async Task Ssl_server_connection_connect_fails_when_client_provides_untrusted_certificate()
public async Task Slic_over_ssl_server_connection_connect_fails_when_client_provides_untrusted_certificate()
{
// Arrange
await using ServiceProvider provider = CreateServiceCollection()
Expand All @@ -85,28 +76,13 @@ public async Task Ssl_server_connection_connect_fails_when_client_provides_untru
var listener = provider.GetRequiredService<IListener<IMultiplexedConnection>>();

// Start the TLS handshake.
var clientConnectTask = sut.Client.ConnectAsync(default);
_ = sut.Client.ConnectAsync(default);

// Act/Assert
IMultiplexedConnection? serverConnection = null;
(IMultiplexedConnection? serverConnection, _) = await listener.AcceptAsync(default);
Assert.That(
async () =>
{
(serverConnection, _) = await listener.AcceptAsync(default);
await serverConnection.ConnectAsync(default);
},
async () => await serverConnection.ConnectAsync(default),
Throws.TypeOf<AuthenticationException>());

Assert.That(
async () =>
{
if (serverConnection is not null)
{
await serverConnection.DisposeAsync();
}
await clientConnectTask;
},
Throws.TypeOf<AuthenticationException>().Or.TypeOf<IceRpcException>());
}

private static IServiceCollection CreateServiceCollection() =>
Expand Down

0 comments on commit bf18636

Please sign in to comment.