Skip to content

Commit

Permalink
Added more SslHandshakeException tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jstedfast committed May 18, 2024
1 parent e8f6b9e commit c543f33
Show file tree
Hide file tree
Showing 4 changed files with 260 additions and 32 deletions.
16 changes: 8 additions & 8 deletions UnitTests/Net/Imap/ImapClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -387,11 +387,11 @@ public void TestSslHandshakeExceptions ()
Assert.Fail ("SSL handshake should have failed with untrusted-root.badssl.com.");
} catch (SslHandshakeException ex) {
Assert.That (ex.ServerCertificate, Is.Not.Null, "ServerCertificate");
SslHandshakeExceptionTests.AssertServerCertificate ((X509Certificate2) ex.ServerCertificate);
SslHandshakeExceptionTests.AssertBadSslUntrustedRootServerCertificate ((X509Certificate2) ex.ServerCertificate);

// Note: This is null on Mono because Mono provides an empty chain.
if (ex.RootCertificateAuthority is X509Certificate2 root)
SslHandshakeExceptionTests.AssertRootCertificate (root);
SslHandshakeExceptionTests.AssertBadSslUntrustedRootCACertificate (root);
} catch (Exception ex) {
Assert.Ignore ($"SSL handshake failure inconclusive: {ex}");
}
Expand All @@ -402,11 +402,11 @@ public void TestSslHandshakeExceptions ()
Assert.Fail ("SSL handshake should have failed with untrusted-root.badssl.com.");
} catch (SslHandshakeException ex) {
Assert.That (ex.ServerCertificate, Is.Not.Null, "ServerCertificate");
SslHandshakeExceptionTests.AssertServerCertificate ((X509Certificate2) ex.ServerCertificate);
SslHandshakeExceptionTests.AssertBadSslUntrustedRootServerCertificate ((X509Certificate2) ex.ServerCertificate);

// Note: This is null on Mono because Mono provides an empty chain.
if (ex.RootCertificateAuthority is X509Certificate2 root)
SslHandshakeExceptionTests.AssertRootCertificate (root);
SslHandshakeExceptionTests.AssertBadSslUntrustedRootCACertificate (root);
} catch (Exception ex) {
Assert.Ignore ($"SSL handshake failure inconclusive: {ex}");
}
Expand All @@ -431,11 +431,11 @@ public async Task TestSslHandshakeExceptionsAsync ()
Assert.Fail ("SSL handshake should have failed with untrusted-root.badssl.com.");
} catch (SslHandshakeException ex) {
Assert.That (ex.ServerCertificate, Is.Not.Null, "ServerCertificate");
SslHandshakeExceptionTests.AssertServerCertificate ((X509Certificate2) ex.ServerCertificate);
SslHandshakeExceptionTests.AssertBadSslUntrustedRootServerCertificate ((X509Certificate2) ex.ServerCertificate);

// Note: This is null on Mono because Mono provides an empty chain.
if (ex.RootCertificateAuthority is X509Certificate2 root)
SslHandshakeExceptionTests.AssertRootCertificate (root);
SslHandshakeExceptionTests.AssertBadSslUntrustedRootCACertificate (root);
} catch (Exception ex) {
Assert.Ignore ($"SSL handshake failure inconclusive: {ex}");
}
Expand All @@ -446,11 +446,11 @@ public async Task TestSslHandshakeExceptionsAsync ()
Assert.Fail ("SSL handshake should have failed with untrusted-root.badssl.com.");
} catch (SslHandshakeException ex) {
Assert.That (ex.ServerCertificate, Is.Not.Null, "ServerCertificate");
SslHandshakeExceptionTests.AssertServerCertificate ((X509Certificate2) ex.ServerCertificate);
SslHandshakeExceptionTests.AssertBadSslUntrustedRootServerCertificate ((X509Certificate2) ex.ServerCertificate);

// Note: This is null on Mono because Mono provides an empty chain.
if (ex.RootCertificateAuthority is X509Certificate2 root)
SslHandshakeExceptionTests.AssertRootCertificate (root);
SslHandshakeExceptionTests.AssertBadSslUntrustedRootCACertificate (root);
} catch (Exception ex) {
Assert.Ignore ($"SSL handshake failure inconclusive: {ex}");
}
Expand Down
16 changes: 8 additions & 8 deletions UnitTests/Net/Pop3/Pop3ClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -229,11 +229,11 @@ public void TestSslHandshakeExceptions ()
Assert.Fail ("SSL handshake should have failed with untrusted-root.badssl.com.");
} catch (SslHandshakeException ex) {
Assert.That (ex.ServerCertificate, Is.Not.Null, "ServerCertificate");
SslHandshakeExceptionTests.AssertServerCertificate ((X509Certificate2) ex.ServerCertificate);
SslHandshakeExceptionTests.AssertBadSslUntrustedRootServerCertificate ((X509Certificate2) ex.ServerCertificate);

// Note: This is null on Mono because Mono provides an empty chain.
if (ex.RootCertificateAuthority is X509Certificate2 root)
SslHandshakeExceptionTests.AssertRootCertificate (root);
SslHandshakeExceptionTests.AssertBadSslUntrustedRootCACertificate (root);
} catch (Exception ex) {
Assert.Ignore ($"SSL handshake failure inconclusive: {ex}");
}
Expand All @@ -244,11 +244,11 @@ public void TestSslHandshakeExceptions ()
Assert.Fail ("SSL handshake should have failed with untrusted-root.badssl.com.");
} catch (SslHandshakeException ex) {
Assert.That (ex.ServerCertificate, Is.Not.Null, "ServerCertificate");
SslHandshakeExceptionTests.AssertServerCertificate ((X509Certificate2) ex.ServerCertificate);
SslHandshakeExceptionTests.AssertBadSslUntrustedRootServerCertificate ((X509Certificate2) ex.ServerCertificate);

// Note: This is null on Mono because Mono provides an empty chain.
if (ex.RootCertificateAuthority is X509Certificate2 root)
SslHandshakeExceptionTests.AssertRootCertificate (root);
SslHandshakeExceptionTests.AssertBadSslUntrustedRootCACertificate (root);
} catch (Exception ex) {
Assert.Ignore ($"SSL handshake failure inconclusive: {ex}");
}
Expand All @@ -273,11 +273,11 @@ public async Task TestSslHandshakeExceptionsAsync ()
Assert.Fail ("SSL handshake should have failed with untrusted-root.badssl.com.");
} catch (SslHandshakeException ex) {
Assert.That (ex.ServerCertificate, Is.Not.Null, "ServerCertificate");
SslHandshakeExceptionTests.AssertServerCertificate ((X509Certificate2) ex.ServerCertificate);
SslHandshakeExceptionTests.AssertBadSslUntrustedRootServerCertificate ((X509Certificate2) ex.ServerCertificate);

// Note: This is null on Mono because Mono provides an empty chain.
if (ex.RootCertificateAuthority is X509Certificate2 root)
SslHandshakeExceptionTests.AssertRootCertificate (root);
SslHandshakeExceptionTests.AssertBadSslUntrustedRootCACertificate (root);
} catch (Exception ex) {
Assert.Ignore ($"SSL handshake failure inconclusive: {ex}");
}
Expand All @@ -288,11 +288,11 @@ public async Task TestSslHandshakeExceptionsAsync ()
Assert.Fail ("SSL handshake should have failed with untrusted-root.badssl.com.");
} catch (SslHandshakeException ex) {
Assert.That (ex.ServerCertificate, Is.Not.Null, "ServerCertificate");
SslHandshakeExceptionTests.AssertServerCertificate ((X509Certificate2) ex.ServerCertificate);
SslHandshakeExceptionTests.AssertBadSslUntrustedRootServerCertificate ((X509Certificate2) ex.ServerCertificate);

// Note: This is null on Mono because Mono provides an empty chain.
if (ex.RootCertificateAuthority is X509Certificate2 root)
SslHandshakeExceptionTests.AssertRootCertificate (root);
SslHandshakeExceptionTests.AssertBadSslUntrustedRootCACertificate (root);
} catch (Exception ex) {
Assert.Ignore ($"SSL handshake failure inconclusive: {ex}");
}
Expand Down
16 changes: 8 additions & 8 deletions UnitTests/Net/Smtp/SmtpClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -336,11 +336,11 @@ public void TestSslHandshakeExceptions ()
Assert.Fail ("SSL handshake should have failed with untrusted-root.badssl.com.");
} catch (SslHandshakeException ex) {
Assert.That (ex.ServerCertificate, Is.Not.Null, "ServerCertificate");
SslHandshakeExceptionTests.AssertServerCertificate ((X509Certificate2) ex.ServerCertificate);
SslHandshakeExceptionTests.AssertBadSslUntrustedRootServerCertificate ((X509Certificate2) ex.ServerCertificate);

// Note: This is null on Mono because Mono provides an empty chain.
if (ex.RootCertificateAuthority is X509Certificate2 root)
SslHandshakeExceptionTests.AssertRootCertificate (root);
SslHandshakeExceptionTests.AssertBadSslUntrustedRootCACertificate (root);
} catch (Exception ex) {
Assert.Ignore ($"SSL handshake failure inconclusive: {ex}");
}
Expand All @@ -351,11 +351,11 @@ public void TestSslHandshakeExceptions ()
Assert.Fail ("SSL handshake should have failed with untrusted-root.badssl.com.");
} catch (SslHandshakeException ex) {
Assert.That (ex.ServerCertificate, Is.Not.Null, "ServerCertificate");
SslHandshakeExceptionTests.AssertServerCertificate ((X509Certificate2) ex.ServerCertificate);
SslHandshakeExceptionTests.AssertBadSslUntrustedRootServerCertificate ((X509Certificate2) ex.ServerCertificate);

// Note: This is null on Mono because Mono provides an empty chain.
if (ex.RootCertificateAuthority is X509Certificate2 root)
SslHandshakeExceptionTests.AssertRootCertificate (root);
SslHandshakeExceptionTests.AssertBadSslUntrustedRootCACertificate (root);
} catch (Exception ex) {
Assert.Ignore ($"SSL handshake failure inconclusive: {ex}");
}
Expand All @@ -380,11 +380,11 @@ public async Task TestSslHandshakeExceptionsAsync ()
Assert.Fail ("SSL handshake should have failed with untrusted-root.badssl.com.");
} catch (SslHandshakeException ex) {
Assert.That (ex.ServerCertificate, Is.Not.Null, "ServerCertificate");
SslHandshakeExceptionTests.AssertServerCertificate ((X509Certificate2) ex.ServerCertificate);
SslHandshakeExceptionTests.AssertBadSslUntrustedRootServerCertificate ((X509Certificate2) ex.ServerCertificate);

// Note: This is null on Mono because Mono provides an empty chain.
if (ex.RootCertificateAuthority is X509Certificate2 root)
SslHandshakeExceptionTests.AssertRootCertificate (root);
SslHandshakeExceptionTests.AssertBadSslUntrustedRootCACertificate (root);
} catch (Exception ex) {
Assert.Ignore ($"SSL handshake failure inconclusive: {ex}");
}
Expand All @@ -395,11 +395,11 @@ public async Task TestSslHandshakeExceptionsAsync ()
Assert.Fail ("SSL handshake should have failed with untrusted-root.badssl.com.");
} catch (SslHandshakeException ex) {
Assert.That (ex.ServerCertificate, Is.Not.Null, "ServerCertificate");
SslHandshakeExceptionTests.AssertServerCertificate ((X509Certificate2) ex.ServerCertificate);
SslHandshakeExceptionTests.AssertBadSslUntrustedRootServerCertificate ((X509Certificate2) ex.ServerCertificate);

// Note: This is null on Mono because Mono provides an empty chain.
if (ex.RootCertificateAuthority is X509Certificate2 root)
SslHandshakeExceptionTests.AssertRootCertificate (root);
SslHandshakeExceptionTests.AssertBadSslUntrustedRootCACertificate (root);
} catch (Exception ex) {
Assert.Ignore ($"SSL handshake failure inconclusive: {ex}");
}
Expand Down
Loading

0 comments on commit c543f33

Please sign in to comment.