Skip to content

Commit e7175a3

Browse files
authored
CSHARP-4969: Fix failing CSFLE mocked kms tls tests (#1268)
1 parent ec5d5cf commit e7175a3

File tree

1 file changed

+27
-4
lines changed

1 file changed

+27
-4
lines changed

tests/MongoDB.Driver.Tests/Specifications/client-side-encryption/prose-tests/ClientEncryptionProseTests.cs

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1514,7 +1514,7 @@ void AssertException(Exception exception)
15141514
AssertTlsWithoutClientCertOnWindows(exception);
15151515
break;
15161516
case OperatingSystemPlatform.Linux:
1517-
AssertInnerEncryptionException(exception, Type.GetType("Interop+Crypto+OpenSslCryptographicException, System.Net.Security", throwOnError: true), "Authentication failed, see inner exception.", "SSL Handshake failed with OpenSSL error - SSL_ERROR_SSL.");
1517+
AssertTlsWithoutClientCertOnLinux(exception);
15181518
break;
15191519
case OperatingSystemPlatform.MacOS:
15201520
AssertInnerEncryptionException(exception, Type.GetType("Interop+AppleCrypto+SslException, System.Net.Security", throwOnError: true), "Authentication failed, see inner exception.", "handshake failure");
@@ -1554,7 +1554,7 @@ void AssertException(Exception exception)
15541554
AssertTlsWithoutClientCertOnWindows(exception);
15551555
break;
15561556
case OperatingSystemPlatform.Linux:
1557-
AssertInnerEncryptionException(exception, Type.GetType("Interop+Crypto+OpenSslCryptographicException, System.Net.Security", throwOnError: true), "Authentication failed, see inner exception.", "SSL Handshake failed with OpenSSL error - SSL_ERROR_SSL.");
1557+
AssertTlsWithoutClientCertOnLinux(exception);
15581558
break;
15591559
case OperatingSystemPlatform.MacOS:
15601560
AssertInnerEncryptionException(exception, Type.GetType("Interop+AppleCrypto+SslException, System.Net.Security", throwOnError: true), "Authentication failed, see inner exception.", "handshake failure");
@@ -1592,7 +1592,7 @@ void AssertException(Exception exception)
15921592
AssertTlsWithoutClientCertOnWindows(exception);
15931593
break;
15941594
case OperatingSystemPlatform.Linux:
1595-
AssertInnerEncryptionException(exception, Type.GetType("Interop+Crypto+OpenSslCryptographicException, System.Net.Security", throwOnError: true), "Authentication failed, see inner exception.", "SSL Handshake failed with OpenSSL error - SSL_ERROR_SSL.");
1595+
AssertTlsWithoutClientCertOnLinux(exception);
15961596
break;
15971597
case OperatingSystemPlatform.MacOS:
15981598
AssertInnerEncryptionException(exception, Type.GetType("Interop+AppleCrypto+SslException, System.Net.Security", throwOnError: true), "Authentication failed, see inner exception.", "handshake failure");
@@ -1630,7 +1630,7 @@ void AssertException(Exception exception)
16301630
AssertTlsWithoutClientCertOnWindows(exception);
16311631
break;
16321632
case OperatingSystemPlatform.Linux:
1633-
AssertInnerEncryptionException(exception, Type.GetType("Interop+Crypto+OpenSslCryptographicException, System.Net.Security", throwOnError: true), "Authentication failed, see inner exception.", "SSL Handshake failed with OpenSSL error - SSL_ERROR_SSL.");
1633+
AssertTlsWithoutClientCertOnLinux(exception);
16341634
break;
16351635
case OperatingSystemPlatform.MacOS:
16361636
AssertInnerEncryptionException(exception, Type.GetType("Interop+AppleCrypto+SslException, System.Net.Security", throwOnError: true), "Authentication failed, see inner exception.", "handshake failure");
@@ -1665,6 +1665,29 @@ void AssertCertificate(bool? isExpired, bool? invalidHost)
16651665
isInvalidHost.Should().Be(invalidHost);
16661666
}
16671667

1668+
void AssertTlsWithoutClientCertOnLinux(Exception exception)
1669+
{
1670+
try
1671+
{
1672+
AssertInnerEncryptionException(
1673+
exception,
1674+
Type.GetType("Interop+Crypto+OpenSslCryptographicException, System.Net.Security", throwOnError: true),
1675+
"Authentication failed, see inner exception.",
1676+
"SSL Handshake failed with OpenSSL error - SSL_ERROR_SSL.");
1677+
}
1678+
catch (XunitException)
1679+
{
1680+
// With Tls1.3, there is no report of a failed handshake if the client certificate verification fails
1681+
// since the client receives a 'Finished' message from the server before sending its certificate, it assumes
1682+
// authentication and we will not know if there was an error until we next read/write from the server.
1683+
AssertInnerEncryptionException<SocketException>(
1684+
exception,
1685+
async
1686+
? "Unable to read data from the transport connection: Connection reset by peer."
1687+
: "Unable to write data to the transport connection: Connection reset by peer.");
1688+
}
1689+
}
1690+
16681691
void AssertTlsWithoutClientCertOnWindows(Exception exception)
16691692
{
16701693
try

0 commit comments

Comments
 (0)