diff --git a/UnitTests/Net/Imap/ImapClientTests.cs b/UnitTests/Net/Imap/ImapClientTests.cs index cb0263acf3..3b28be8206 100644 --- a/UnitTests/Net/Imap/ImapClientTests.cs +++ b/UnitTests/Net/Imap/ImapClientTests.cs @@ -332,7 +332,7 @@ static Socket Connect (string host, int port) [Test] public void TestSslHandshakeExceptions () { - using (var client = new ImapClient () { TagPrefix = 'A' }) { + using (var client = new ImapClient ()) { Socket socket; // 1. Test connecting to a non-SSL port fails with an SslHandshakeException. @@ -376,7 +376,7 @@ public void TestSslHandshakeExceptions () [Test] public async Task TestSslHandshakeExceptionsAsync () { - using (var client = new ImapClient () { TagPrefix = 'A' }) { + using (var client = new ImapClient ()) { Socket socket; // 1. Test connecting to a non-SSL port fails with an SslHandshakeException. @@ -417,6 +417,21 @@ public async Task TestSslHandshakeExceptionsAsync () } } + [Test] + public void TestStartTlsNotSupported () + { + var commands = new List { + new ImapReplayCommand ("", "common.basic-greeting.txt"), + new ImapReplayCommand ("A00000000 CAPABILITY\r\n", "common.capability.txt"), + }; + + using (var client = new ImapClient () { TagPrefix = 'A' }) + Assert.Throws (() => client.Connect (new ImapReplayStream (commands, false), "localhost", 143, SecureSocketOptions.StartTls), "STARTTLS"); + + using (var client = new ImapClient () { TagPrefix = 'A' }) + Assert.ThrowsAsync (() => client.ConnectAsync (new ImapReplayStream (commands, true), "localhost", 143, SecureSocketOptions.StartTls), "STARTTLS Async"); + } + [Test] public void TestProtocolLoggerExceptions () { diff --git a/UnitTests/Net/Imap/Resources/common/basic-greeting.txt b/UnitTests/Net/Imap/Resources/common/basic-greeting.txt new file mode 100644 index 0000000000..646f85c067 --- /dev/null +++ b/UnitTests/Net/Imap/Resources/common/basic-greeting.txt @@ -0,0 +1 @@ +* OK IMAP4 server ready. diff --git a/UnitTests/Net/Pop3/Pop3ClientTests.cs b/UnitTests/Net/Pop3/Pop3ClientTests.cs index 8db6a099f3..3ad70697cf 100644 --- a/UnitTests/Net/Pop3/Pop3ClientTests.cs +++ b/UnitTests/Net/Pop3/Pop3ClientTests.cs @@ -571,6 +571,21 @@ public async Task TestInvalidStateExceptionsAsync () } } + [Test] + public void TestStartTlsNotSupported () + { + var commands = new List { + new Pop3ReplayCommand ("", "comcast.greeting.txt"), + new Pop3ReplayCommand ("CAPA\r\n", "comcast.err.txt") + }; + + using (var client = new Pop3Client ()) + Assert.Throws (() => client.Connect (new Pop3ReplayStream (commands, false), "localhost", 110, SecureSocketOptions.StartTls), "STLS"); + + using (var client = new Pop3Client ()) + Assert.ThrowsAsync (() => client.ConnectAsync (new Pop3ReplayStream (commands, true), "localhost", 110, SecureSocketOptions.StartTls), "STLS Async"); + } + [Test] public void TestProtocolLoggerExceptions () { @@ -1671,6 +1686,7 @@ public void TestProbedUidlSupportError () Assert.AreEqual (1800662, client.Size, "Expected 1800662 octets"); Assert.Throws (() => client.GetMessageUids ()); + Assert.Throws (() => client.GetMessageUid (0)); try { client.Disconnect (true); @@ -1723,6 +1739,7 @@ public async Task TestProbedUidlSupportErrorAsync () Assert.AreEqual (1800662, client.Size, "Expected 1800662 octets"); Assert.ThrowsAsync (() => client.GetMessageUidsAsync ()); + Assert.ThrowsAsync (() => client.GetMessageUidAsync (0)); try { await client.DisconnectAsync (true); diff --git a/UnitTests/Net/Smtp/SmtpClientTests.cs b/UnitTests/Net/Smtp/SmtpClientTests.cs index 610824d70f..3a9bd6b6b8 100644 --- a/UnitTests/Net/Smtp/SmtpClientTests.cs +++ b/UnitTests/Net/Smtp/SmtpClientTests.cs @@ -659,6 +659,22 @@ public async Task TestInvalidStateExceptionsAsync () } } + [Test] + public void TestStartTlsNotSupported () + { + var commands = new List { + new SmtpReplayCommand ("", "comcast-greeting.txt"), + new SmtpReplayCommand ("EHLO unit-tests.mimekit.org\r\n", "ehlo-failed.txt"), + new SmtpReplayCommand ("HELO unit-tests.mimekit.org\r\n", "helo.txt"), + }; + + using (var client = new SmtpClient () { LocalDomain = "unit-tests.mimekit.org" }) + Assert.Throws (() => client.Connect (new SmtpReplayStream (commands, false), "localhost", 25, SecureSocketOptions.StartTls), "STARTTLS"); + + using (var client = new SmtpClient () { LocalDomain = "unit-tests.mimekit.org" }) + Assert.ThrowsAsync (() => client.ConnectAsync (new SmtpReplayStream (commands, true), "localhost", 25, SecureSocketOptions.StartTls), "STARTTLS Async"); + } + [Test] public void TestServiceNotReady () { diff --git a/UnitTests/UnitTests.csproj b/UnitTests/UnitTests.csproj index 0cc32f0d6c..aea94cb88b 100644 --- a/UnitTests/UnitTests.csproj +++ b/UnitTests/UnitTests.csproj @@ -146,6 +146,7 @@ +