Skip to content

Commit

Permalink
Add failing test
Browse files Browse the repository at this point in the history
  • Loading branch information
rzikm committed May 23, 2024
1 parent fabb9a3 commit 5f30d11
Showing 1 changed file with 19 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System.IO;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Net.Test.Common;
using System.Security.Authentication;
Expand Down Expand Up @@ -115,11 +116,19 @@ public async Task SslStream_RequireClientCert_IsMutuallyAuthenticated_ReturnsTru
}
}
}
public static IEnumerable<object[]> SslProtocolsAndBoolData()
{
foreach (object[] protocol in new SslProtocolSupport.SupportedSslProtocolsTestData())
{
yield return new object[] { protocol[0], true };
yield return new object[] { protocol[0], false };
}
}

[ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsNotWindows7))]
[ClassData(typeof(SslProtocolSupport.SupportedSslProtocolsTestData))]
[MemberData(nameof(SslProtocolsAndBoolData))]
public async Task SslStream_CachedCredentials_IsMutuallyAuthenticatedCorrect(
SslProtocols protocol)
SslProtocols protocol, bool startWithMtls)
{
var clientOptions = new SslClientAuthenticationOptions
{
Expand All @@ -129,18 +138,20 @@ public async Task SslStream_CachedCredentials_IsMutuallyAuthenticatedCorrect(
TargetHost = Guid.NewGuid().ToString("N")
};

SslStreamCertificateContext context = SslStreamCertificateContext.Create(_serverCertificate, null);

for (int i = 0; i < 5; i++)
{
(SslStream client, SslStream server) = TestHelper.GetConnectedSslStreams();
using (client)
using (server)
{
bool expectMutualAuthentication = (i % 2) == 0;
bool expectMutualAuthentication = (i % 2) == (startWithMtls ? 0 : 1);

var serverOptions = new SslServerAuthenticationOptions
{
ClientCertificateRequired = expectMutualAuthentication,
ServerCertificate = expectMutualAuthentication ? _serverCertificate : _selfSignedCertificate,
ServerCertificateContext = context,
RemoteCertificateValidationCallback = delegate { return true; },
EnabledSslProtocols = protocol
};
Expand Down Expand Up @@ -193,7 +204,6 @@ public async Task SslStream_NegotiateClientCertificate_IsMutuallyAuthenticatedCo
ServerCertificateContext = context,
ClientCertificateRequired = false,
EnabledSslProtocols = SslProtocols.Tls12,

});

await TestConfiguration.WhenAllOrAnyFailedWithTimeout(t1, t2);
Expand Down Expand Up @@ -266,7 +276,7 @@ await TestConfiguration.WhenAllOrAnyFailedWithTimeout(
}
else
{
Assert.Null(server.RemoteCertificate);
Assert.Null(server.RemoteCertificate);
}
};
}
Expand Down Expand Up @@ -320,7 +330,7 @@ await TestConfiguration.WhenAllOrAnyFailedWithTimeout(
}
else
{
Assert.Null(server.RemoteCertificate);
Assert.Null(server.RemoteCertificate);
}
};
}
Expand Down Expand Up @@ -357,7 +367,7 @@ public async Task SslStream_ResumedSessionsCallbackMaybeSet_IsMutuallyAuthentica

if (expectMutualAuthentication)
{
clientOptions.LocalCertificateSelectionCallback = (s, t, l, r, a) => _clientCertificate;
clientOptions.LocalCertificateSelectionCallback = (s, t, l, r, a) => _clientCertificate;
}
else
{
Expand All @@ -378,7 +388,7 @@ await TestConfiguration.WhenAllOrAnyFailedWithTimeout(
}
else
{
Assert.Null(server.RemoteCertificate);
Assert.Null(server.RemoteCertificate);
}
};
}
Expand Down

0 comments on commit 5f30d11

Please sign in to comment.