forked from hmailserver/hmailserver
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SmtpClientSimulator should throw on error rather than returning true/…
…false
- Loading branch information
1 parent
f44689d
commit e372130
Showing
35 changed files
with
336 additions
and
301 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -440,8 +440,8 @@ public void TestReinitialize() | |
"WhatTest\r\n"; | ||
|
||
Account account = SingletonProvider<TestSetup>.Instance.AddAccount(_domain, "[email protected]", "test"); | ||
Assert.IsTrue(SMTPClientSimulator.StaticSend(account.Address, account.Address, "First message", | ||
"Test message")); | ||
SMTPClientSimulator.StaticSend(account.Address, account.Address, "First message", | ||
"Test message"); | ||
POP3ClientSimulator.AssertMessageCount(account.Address, "test", 1); | ||
|
||
// Create another message on disk and import it. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -86,7 +86,7 @@ public void TestHeloSpamTest() | |
// Send a messages to this account. | ||
var oSMTP = new SMTPClientSimulator(); | ||
|
||
Assert.IsFalse(oSMTP.Send("[email protected]", "[email protected]", "SURBL-Match", "Test")); | ||
CustomAsserts.Throws<DeliveryFailedException>(() => oSMTP.Send("[email protected]", "[email protected]", "SURBL-Match", "Test")); | ||
} | ||
|
||
[Test] | ||
|
@@ -104,25 +104,23 @@ public void TestIncorrectLineEndings() | |
// Send a messages to this account. | ||
|
||
var oSMTP = new SMTPClientSimulator(); | ||
if ( | ||
!oSMTP.Send("[email protected]", "[email protected]", "INBOX", | ||
"This is a test message\r\n consisting of correct lines")) | ||
throw new Exception("ERROR - Was not able to send correct email."); | ||
oSMTP.Send("[email protected]", "[email protected]", "INBOX", | ||
"This is a test message\r\n consisting of correct lines"); | ||
|
||
CustomAsserts.Throws<DeliveryFailedException>(() => oSMTP.Send("[email protected]", | ||
"[email protected]", "INBOX", | ||
"This is a test message\r consisting of incorrect lines")); | ||
|
||
if (oSMTP.Send("[email protected]", "[email protected]", "INBOX", | ||
"This is a test message\r consisting of incorrect lines")) | ||
throw new Exception("ERROR - Was able to send incorrect email."); | ||
|
||
|
||
if (oSMTP.Send("[email protected]", "[email protected]", "INBOX", | ||
"This is a test message\n consisting of incorrect lines")) | ||
throw new Exception("ERROR - Was able to send incorrect email."); | ||
CustomAsserts.Throws<DeliveryFailedException>( | ||
() => oSMTP.Send("[email protected]", "SpamProtectionLineEndings@test.com", "INBOX", | ||
"This is a test message\n consisting of incorrect lines")); | ||
|
||
|
||
if (oSMTP.Send("[email protected]", "[email protected]", "INBOX", | ||
"This is a test message\n\r consisting of incorrect lines")) | ||
throw new Exception("ERROR - Was able to send incorrect email."); | ||
CustomAsserts.Throws<DeliveryFailedException>(() => oSMTP.Send("[email protected]", | ||
"SpamProtectionLineEndings@test.com", "INBOX", | ||
"This is a test message\n\r consisting of incorrect lines")); | ||
|
||
POP3ClientSimulator.AssertMessageCount(oAccount1.Address, "test", 1); | ||
} | ||
|
@@ -161,9 +159,9 @@ public void TestMaxSizeLimit() | |
"1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890\r\n"); | ||
} | ||
|
||
Assert.IsTrue(oSMTP.Send("[email protected]", "[email protected]", "SURBL-No-Match", | ||
oSMTP.Send("[email protected]", "[email protected]", "SURBL-No-Match", | ||
"This is a test message with a SURBL url: -> http://surbl-org-permanent-test-point.com/ <-\r\n" + | ||
sb)); | ||
sb); | ||
|
||
string sMessageContents = POP3ClientSimulator.AssertGetFirstMessageText(oAccount1.Address, "test"); | ||
if (sMessageContents.Contains("X-hMailServer-Spam") || | ||
|
@@ -210,9 +208,9 @@ public void TestMaxSizeNoLimit() | |
"1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890\r\n"); | ||
} | ||
|
||
Assert.IsTrue(oSMTP.Send("[email protected]", "[email protected]", "SURBL-No-Match", | ||
oSMTP.Send("[email protected]", "[email protected]", "SURBL-No-Match", | ||
"This is a test message with a SURBL url: -> http://surbl-org-permanent-test-point.com/ <-\r\n" + | ||
sb)); | ||
sb); | ||
|
||
string sMessageContents = POP3ClientSimulator.AssertGetFirstMessageText(oAccount1.Address, "test"); | ||
if (!sMessageContents.Contains("X-hMailServer-Spam") || | ||
|
@@ -244,12 +242,11 @@ public void TestMissingMXRecord() | |
// Send a messages to this account. | ||
var oSMTP = new SMTPClientSimulator(); | ||
|
||
if (!oSMTP.Send("[email protected]", "[email protected]", "INBOX", "This is a test message.")) | ||
throw new Exception("ERROR - Was not able to send correct email."); | ||
oSMTP.Send("[email protected]", "[email protected]", "INBOX", "This is a test message."); | ||
|
||
if (oSMTP.Send("test@domain_without_mx_records421dfsam430sasd.com", oAccount1.Address, "INBOX", | ||
"This is a test message.")) | ||
throw new Exception("ERROR - Was not able to send incorrect email."); | ||
CustomAsserts.Throws<DeliveryFailedException>( | ||
() => oSMTP.Send("test@domain_without_mx_records421dfsam430sasd.com", oAccount1.Address, "INBOX", | ||
"This is a test message.")); | ||
|
||
_antiSpam.UseMXChecks = false; | ||
|
||
|
@@ -499,8 +496,8 @@ public void TestSURBLCorrectNegative() | |
oSURBLServer.Save(); | ||
|
||
// Send a messages to this account. | ||
Assert.IsTrue(SMTPClientSimulator.StaticSend("[email protected]", "[email protected]", "SURBL-Match", | ||
"This is a test message without a SURBL url: -> http://www.youtube.com/ <-")); | ||
SMTPClientSimulator.StaticSend("[email protected]", "[email protected]", "SURBL-Match", | ||
"This is a test message without a SURBL url: -> http://www.youtube.com/ <-"); | ||
|
||
string sMessageContents = POP3ClientSimulator.AssertGetFirstMessageText(oAccount1.Address, "test"); | ||
if (sMessageContents.Contains("X-hMailServer-Spam")) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
// Copyright (c) 2010 Martin Knafve / hMailServer.com. | ||
// http://www.hmailserver.com | ||
|
||
using System; | ||
using NUnit.Framework; | ||
using RegressionTests.Infrastructure; | ||
using RegressionTests.Shared; | ||
|
@@ -54,8 +55,8 @@ public void TestDeleteThresholdLowerThanMarkThreshold() | |
|
||
// Should not be possible to send this email since it's results in a spam | ||
// score over the delete threshold. | ||
Assert.IsTrue(oSMTP.Send("[email protected]", oAccount1.Address, "INBOX", | ||
"Test http://surbl-org-permanent-test-point.com/ Test 2")); | ||
oSMTP.Send("[email protected]", oAccount1.Address, "INBOX", | ||
"Test http://surbl-org-permanent-test-point.com/ Test 2"); | ||
|
||
string message = POP3ClientSimulator.AssertGetFirstMessageText(oAccount1.Address, "test"); | ||
|
||
|
@@ -92,8 +93,8 @@ public void TestOneFailOnePass() | |
|
||
// Should not be possible to send this email since it's results in a spam | ||
// score over the delete threshold. | ||
Assert.IsTrue(oSMTP.Send("test@domain_without_mx_records421dfsam430sasd.com", oAccount1.Address, "INBOX", | ||
"This is a test message.")); | ||
oSMTP.Send("test@domain_without_mx_records421dfsam430sasd.com", oAccount1.Address, "INBOX", | ||
"This is a test message."); | ||
|
||
string message = POP3ClientSimulator.AssertGetFirstMessageText(oAccount1.Address, "test"); | ||
|
||
|
@@ -144,7 +145,7 @@ public void TestSpamMultipleHits() | |
|
||
// Should not be possible to send this email since it's results in a spam | ||
// score over the delete threshold. | ||
Assert.IsFalse(oSMTP.Send("test@domain_without_mx_records421dfsam430sasd.com", oAccount1.Address, "INBOX", | ||
CustomAsserts.Throws<DeliveryFailedException>(() => oSMTP.Send("test@domain_without_mx_records421dfsam430sasd.com", oAccount1.Address, "INBOX", | ||
"This is a test message. It contains incorrect MX records and a SURBL string: http://surbl-org-permanent-test-point.com/ SpamAssassinString: XJS*C4JDBQADN1.NSBN3*2IDNEN*GTUBE-STANDARD-ANTI-UBE-TEST-EMAIL*C.34X")); | ||
|
||
liveLog = _settings.Logging.LiveLog; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -64,7 +64,7 @@ private string SendMessage(string body) | |
var smtp = new SMTPClientSimulator(); | ||
var recipients = new List<string>(); | ||
recipients.Add("[email protected]"); | ||
Assert.IsTrue(smtp.Send("[email protected]", recipients, "Test", body)); | ||
smtp.Send("[email protected]", recipients, "Test", body); | ||
|
||
// Wait for the client to disconnect. | ||
server.WaitForCompletion(); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
// Copyright (c) 2010 Martin Knafve / hMailServer.com. | ||
// http://www.hmailserver.com | ||
|
||
using System; | ||
using NUnit.Framework; | ||
using RegressionTests.Infrastructure; | ||
using RegressionTests.Shared; | ||
using hMailServer; | ||
|
||
|
@@ -59,7 +61,7 @@ public void TestInvalidBodyHash() | |
"" + "\r\n"; | ||
|
||
Account account1 = SingletonProvider<TestSetup>.Instance.AddAccount(_domain, "[email protected]", "test"); | ||
Assert.IsFalse(SMTPClientSimulator.StaticSendRaw(account1.Address, account1.Address, messageText)); | ||
CustomAsserts.Throws<DeliveryFailedException>(() => SMTPClientSimulator.StaticSendRaw(account1.Address, account1.Address, messageText)); | ||
} | ||
|
||
[Test] | ||
|
@@ -99,7 +101,7 @@ public void TestInvalidBodyHashMark() | |
"" + "\r\n"; | ||
|
||
Account account1 = SingletonProvider<TestSetup>.Instance.AddAccount(_domain, "[email protected]", "test"); | ||
Assert.IsTrue(SMTPClientSimulator.StaticSendRaw(account1.Address, account1.Address, messageText)); | ||
SMTPClientSimulator.StaticSendRaw(account1.Address, account1.Address, messageText); | ||
string text = POP3ClientSimulator.AssertGetFirstMessageText(account1.Address, "test"); | ||
|
||
Assert.IsTrue(text.Contains("Rejected by DKIM. - (Score: 6)")); | ||
|
@@ -140,7 +142,7 @@ public void TestInvalidSignature() | |
"" + "\r\n"; | ||
|
||
Account account1 = SingletonProvider<TestSetup>.Instance.AddAccount(_domain, "[email protected]", "test"); | ||
Assert.IsFalse(SMTPClientSimulator.StaticSendRaw(account1.Address, account1.Address, messageText)); | ||
CustomAsserts.Throws<DeliveryFailedException>(() => SMTPClientSimulator.StaticSendRaw(account1.Address, account1.Address, messageText)); | ||
} | ||
|
||
[Test] | ||
|
@@ -178,7 +180,7 @@ public void TestValidSignatureSHA1() | |
"" + "\r\n"; | ||
|
||
Account account1 = SingletonProvider<TestSetup>.Instance.AddAccount(_domain, "[email protected]", "test"); | ||
Assert.IsTrue(SMTPClientSimulator.StaticSendRaw(account1.Address, account1.Address, messageText)); | ||
SMTPClientSimulator.StaticSendRaw(account1.Address, account1.Address, messageText); | ||
string text = POP3ClientSimulator.AssertGetFirstMessageText(account1.Address, "test"); | ||
} | ||
|
||
|
@@ -217,7 +219,7 @@ public void TestValidSignatureSHA256() | |
"The quick brown fox jumped over the lazy dog." + "\r\n"; | ||
|
||
Account account1 = SingletonProvider<TestSetup>.Instance.AddAccount(_domain, "[email protected]", "test"); | ||
Assert.IsTrue(SMTPClientSimulator.StaticSendRaw(account1.Address, account1.Address, messageText)); | ||
SMTPClientSimulator.StaticSendRaw(account1.Address, account1.Address, messageText); | ||
string text = POP3ClientSimulator.AssertGetFirstMessageText(account1.Address, "test"); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
// Copyright (c) 2010 Martin Knafve / hMailServer.com. | ||
// http://www.hmailserver.com | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using NUnit.Framework; | ||
using RegressionTests.Infrastructure; | ||
using RegressionTests.Shared; | ||
using hMailServer; | ||
|
||
|
@@ -31,13 +33,14 @@ public void ItShouldBePossibleToBypassGreylistingOnMessagesArrivingFromMXorA() | |
|
||
_antiSpam.GreyListingEnabled = true; | ||
|
||
Assert.IsFalse(SMTPClientSimulator.StaticSend("[email protected]", oAccount1.Address, "Test", | ||
"Body")); | ||
CustomAsserts.Throws<DeliveryFailedException>( | ||
() => SMTPClientSimulator.StaticSend("[email protected]", oAccount1.Address, "Test", | ||
"Body")); | ||
|
||
_antiSpam.BypassGreylistingOnMailFromMX = true; | ||
|
||
Assert.IsTrue(SMTPClientSimulator.StaticSend("[email protected]", oAccount1.Address, "Test", | ||
"Body")); | ||
SMTPClientSimulator.StaticSend("[email protected]", oAccount1.Address, "Test", | ||
"Body"); | ||
|
||
POP3ClientSimulator.AssertGetFirstMessageText(oAccount1.Address, "test"); | ||
} | ||
|
@@ -52,19 +55,19 @@ public void TestGreyListing() | |
var smtp = new SMTPClientSimulator(); | ||
var recipients = new List<string>(); | ||
recipients.Add(oAccount1.Address); | ||
bool result = smtp.Send("[email protected]", recipients, "Test", "Body"); | ||
Assert.IsTrue(result); | ||
smtp.Send("[email protected]", recipients, "Test", "Body"); | ||
|
||
POP3ClientSimulator.AssertGetFirstMessageText(oAccount1.Address, "test"); | ||
|
||
_antiSpam.GreyListingEnabled = true; | ||
|
||
result = smtp.Send("[email protected]", recipients, "Test", "Body"); | ||
Assert.IsFalse(result); | ||
CustomAsserts.Throws<DeliveryFailedException>(() => smtp.Send("[email protected]", recipients, "Test", "Body")); | ||
|
||
|
||
_antiSpam.GreyListingEnabled = false; | ||
|
||
result = smtp.Send("[email protected]", recipients, "Test", "Body"); | ||
Assert.IsTrue(result); | ||
smtp.Send("[email protected]", recipients, "Test", "Body"); | ||
|
||
POP3ClientSimulator.AssertGetFirstMessageText(oAccount1.Address, "test"); | ||
} | ||
|
||
|
@@ -80,12 +83,12 @@ public void TestGreyListingWhiteListWildcard() | |
whiteAddress.IPAddress = "127.0.0.5"; | ||
whiteAddress.Save(); | ||
|
||
Assert.IsFalse(SMTPClientSimulator.StaticSend("[email protected]", account.Address, "Test", "Test")); | ||
CustomAsserts.Throws<DeliveryFailedException>(() => SMTPClientSimulator.StaticSend("[email protected]", account.Address, "Test", "Test")); | ||
|
||
whiteAddress.IPAddress = "*"; | ||
whiteAddress.Save(); | ||
|
||
Assert.IsTrue(SMTPClientSimulator.StaticSend("[email protected]", account.Address, "Test", "Test")); | ||
SMTPClientSimulator.StaticSend("[email protected]", account.Address, "Test", "Test"); | ||
|
||
POP3ClientSimulator.AssertGetFirstMessageText(account.Address, "test"); | ||
} | ||
|
@@ -100,20 +103,20 @@ public void TestGreyListingWithDomainAliases() | |
var smtp = new SMTPClientSimulator(); | ||
var recipients = new List<string>(); | ||
recipients.Add(oAccount1.Address); | ||
bool result = smtp.Send("[email protected]", recipients, "Test", "Body"); | ||
Assert.IsTrue(result); | ||
smtp.Send("[email protected]", recipients, "Test", "Body"); | ||
|
||
POP3ClientSimulator.AssertGetFirstMessageText(oAccount1.Address, "test"); | ||
|
||
_antiSpam.GreyListingEnabled = true; | ||
|
||
result = smtp.Send("[email protected]", recipients, "Test", "Body"); | ||
Assert.IsFalse(result); | ||
CustomAsserts.Throws<DeliveryFailedException>(() => smtp.Send("[email protected]", recipients, "Test", "Body")); | ||
|
||
|
||
_domain.AntiSpamEnableGreylisting = false; | ||
_domain.Save(); | ||
|
||
result = smtp.Send("[email protected]", recipients, "Test", "Body"); | ||
Assert.IsTrue(result); | ||
smtp.Send("[email protected]", recipients, "Test", "Body"); | ||
|
||
POP3ClientSimulator.AssertGetFirstMessageText(oAccount1.Address, "test"); | ||
|
||
DomainAlias da = _domain.DomainAliases.Add(); | ||
|
@@ -123,15 +126,13 @@ public void TestGreyListingWithDomainAliases() | |
recipients = new List<string>(); | ||
recipients.Add("[email protected]"); | ||
|
||
result = smtp.Send("[email protected]", recipients, "Test", "Body"); | ||
Assert.IsTrue(result); | ||
smtp.Send("[email protected]", recipients, "Test", "Body"); | ||
POP3ClientSimulator.AssertGetFirstMessageText(oAccount1.Address, "test"); | ||
|
||
_domain.AntiSpamEnableGreylisting = true; | ||
_domain.Save(); | ||
|
||
result = smtp.Send("[email protected]", recipients, "Test", "Body"); | ||
Assert.IsFalse(result); | ||
CustomAsserts.Throws<DeliveryFailedException>(() => smtp.Send("[email protected]", recipients, "Test", "Body")); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.