public async Task TestSslConnectOnPlainTextPortFailureAsync() { Assert.Throws <ArgumentNullException> (() => new FakeClient(null)); using (var client = new FakeClient(new NullProtocolLogger())) { try { await client.ConnectAsync("www.google.com", 80, SecureSocketOptions.SslOnConnect); Assert.Fail("SSL handshake should have failed with www.google.com:80."); } catch (SslHandshakeException ex) { Assert.IsNull(ex.ServerCertificate, "ServerCertificate"); Assert.IsNull(ex.RootCertificateAuthority, "RootCertificateAuthority"); } catch (Exception ex) { Assert.Ignore("SSL handshake failure inconclusive: {0}", ex); } } }
public async Task TestSslCertificateValidationFailureAsync() { Assert.Throws <ArgumentNullException> (() => new FakeClient(null)); using (var client = new FakeClient(new NullProtocolLogger())) { try { await client.ConnectAsync("untrusted-root.badssl.com", 443, SecureSocketOptions.SslOnConnect); Assert.Fail("SSL handshake should have failed with untrusted-root.badssl.com."); } catch (SslHandshakeException ex) { Assert.NotNull(ex.ServerCertificate, "ServerCertificate"); AssertServerCertificate((X509Certificate2)ex.ServerCertificate); // Note: This is null on Mono because Mono provides an empty chain. if (ex.RootCertificateAuthority is X509Certificate2 root) { AssertRootCertificate(root); } } catch (Exception ex) { Assert.Ignore("SSL handshake failure inconclusive: {0}", ex); } } }