-
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.
- Loading branch information
Showing
7 changed files
with
233 additions
and
115 deletions.
There are no files selected for viewing
43 changes: 43 additions & 0 deletions
43
src/Nager.EmailAuthentication.UnitTest/DmarcRecordParserBasicTest.cs
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 |
---|---|---|
@@ -0,0 +1,43 @@ | ||
namespace Nager.EmailAuthentication.UnitTest | ||
{ | ||
[TestClass] | ||
public sealed class DmarcRecordParserBasicTest | ||
{ | ||
[TestMethod] | ||
public void TryParse_InvalidDmarcString1_ReturnsTrueAndPopulatesDmarcRecord() | ||
{ | ||
var isSuccessful = DmarcRecordParser.TryParse("v=DMARC", out var dmarcDataFragment, out var parseErrors); | ||
Assert.IsTrue(isSuccessful); | ||
Assert.IsNotNull(dmarcDataFragment); | ||
Assert.IsNotNull(parseErrors, "ParseErrors is null"); | ||
} | ||
|
||
[TestMethod] | ||
public void TryParse_InvalidDmarcString2_ReturnsTrueAndPopulatesDmarcRecord() | ||
{ | ||
var isSuccessful = DmarcRecordParser.TryParse("v=DMARC1", out var dmarcDataFragment, out var parseErrors); | ||
Assert.IsTrue(isSuccessful); | ||
Assert.IsNotNull(dmarcDataFragment); | ||
Assert.IsNull(parseErrors, "ParseErrors is not null"); | ||
} | ||
|
||
[TestMethod] | ||
public void TryParse_CorruptDmarcString1_ReturnsTrueAndParseErrors() | ||
{ | ||
var isSuccessful = DmarcRecordParser.TryParse("verification=123456789", out var dmarcDataFragment, out var parseErrors); | ||
Assert.IsTrue(isSuccessful); | ||
Assert.IsNotNull(dmarcDataFragment); | ||
Assert.IsNotNull(parseErrors, "ParseErrors is null"); | ||
Assert.IsTrue(parseErrors.Length == 2); | ||
} | ||
|
||
[TestMethod] | ||
public void TryParse_CorruptDmarcString2_ReturnsFalse() | ||
{ | ||
var isSuccessful = DmarcRecordParser.TryParse(" ", out var dmarcDataFragment, out var parseErrors); | ||
Assert.IsFalse(isSuccessful); | ||
Assert.IsNull(dmarcDataFragment); | ||
Assert.IsNull(parseErrors, "ParseErrors is not null"); | ||
} | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
src/Nager.EmailAuthentication.UnitTest/DmarcRecordParserComplexTest.cs
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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
namespace Nager.EmailAuthentication.UnitTest | ||
{ | ||
[TestClass] | ||
public sealed class DmarcRecordParserComplexTest | ||
{ | ||
[TestMethod] | ||
public void TryParse_ValidDmarcString1_ReturnsTrueAndPopulatesDmarcRecord() | ||
{ | ||
var isSuccessful = DmarcRecordParser.TryParse("v=DMARC1; p=reject; rua=mailto:[email protected], mailto:[email protected]; pct=100; adkim=s; aspf=s", out var dmarcDataFragment, out var parseErrors); | ||
Assert.IsTrue(isSuccessful); | ||
Assert.IsNotNull(dmarcDataFragment); | ||
Assert.AreEqual("reject", dmarcDataFragment.DomainPolicy); | ||
Assert.AreEqual("mailto:[email protected], mailto:[email protected]", dmarcDataFragment.AggregateReportUri); | ||
Assert.AreEqual("100", dmarcDataFragment.PolicyPercentage); | ||
Assert.AreEqual("s", dmarcDataFragment.DkimAlignmentMode); | ||
Assert.AreEqual("s", dmarcDataFragment.SpfAlignmentMode); | ||
Assert.IsNull(parseErrors, "ParseErrors is not null"); | ||
} | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
src/Nager.EmailAuthentication.UnitTest/DmarcRecordParserPolicyPercentageTest.cs
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 |
---|---|---|
@@ -0,0 +1,39 @@ | ||
namespace Nager.EmailAuthentication.UnitTest | ||
{ | ||
[TestClass] | ||
public sealed class DmarcRecordParserPolicyPercentageTest | ||
{ | ||
[TestMethod] | ||
public void TryParse_ValidDmarcString1_ReturnsTrueAndPopulatesDmarcRecord() | ||
{ | ||
var isSuccessful = DmarcRecordParser.TryParse("v=DMARC1; p=reject; pct=60;", out var dmarcDataFragment, out var parseErrors); | ||
Assert.IsTrue(isSuccessful); | ||
Assert.IsNotNull(dmarcDataFragment); | ||
Assert.AreEqual("reject", dmarcDataFragment.DomainPolicy); | ||
Assert.AreEqual("60", dmarcDataFragment.PolicyPercentage); | ||
Assert.IsNull(parseErrors, "ParseErrors is not null"); | ||
} | ||
|
||
[TestMethod] | ||
public void TryParse_InvalidDmarcString1_ReturnsTrueWithErrors() | ||
{ | ||
var isSuccessful = DmarcRecordParser.TryParse("v=DMARC1; p=reject; pct=;", out var dmarcDataFragment, out var parseErrors); | ||
Assert.IsTrue(isSuccessful); | ||
Assert.IsNotNull(dmarcDataFragment); | ||
Assert.AreEqual("reject", dmarcDataFragment.DomainPolicy); | ||
Assert.AreEqual("", dmarcDataFragment.PolicyPercentage); | ||
Assert.IsNotNull(parseErrors, "ParseErrors is null"); | ||
} | ||
|
||
[TestMethod] | ||
public void TryParse_InvalidDmarcString2_ReturnsTrueWithErrors() | ||
{ | ||
var isSuccessful = DmarcRecordParser.TryParse("v=DMARC1; p=reject; pct=200;", out var dmarcDataFragment, out var parseErrors); | ||
Assert.IsTrue(isSuccessful); | ||
Assert.IsNotNull(dmarcDataFragment); | ||
Assert.AreEqual("reject", dmarcDataFragment.DomainPolicy); | ||
Assert.AreEqual("200", dmarcDataFragment.PolicyPercentage); | ||
Assert.IsNotNull(parseErrors, "ParseErrors is null"); | ||
} | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
src/Nager.EmailAuthentication.UnitTest/DmarcRecordParserPolicyTest.cs
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 |
---|---|---|
@@ -0,0 +1,49 @@ | ||
namespace Nager.EmailAuthentication.UnitTest | ||
{ | ||
[TestClass] | ||
public sealed class DmarcRecordParserPolicyTest | ||
{ | ||
[TestMethod] | ||
public void TryParse_InvalidDmarcString1_ReturnsTrueAndPopulatesDmarcRecord() | ||
{ | ||
var isSuccessful = DmarcRecordParser.TryParse("v=DMARC1; p=Test", out var dmarcDataFragment, out var parseErrors); | ||
Assert.IsTrue(isSuccessful); | ||
Assert.IsNotNull(dmarcDataFragment); | ||
Assert.AreEqual("Test", dmarcDataFragment.DomainPolicy); | ||
Assert.IsNotNull(parseErrors); | ||
Assert.IsTrue(parseErrors.Length == 1); | ||
} | ||
|
||
[TestMethod] | ||
public void TryParse_InvalidDmarcString2_ReturnsTrueAndPopulatesDmarcRecord() | ||
{ | ||
var isSuccessful = DmarcRecordParser.TryParse("v=DMARC1; p=Test;", out var dmarcDataFragment, out var parseErrors); | ||
Assert.IsTrue(isSuccessful); | ||
Assert.IsNotNull(dmarcDataFragment); | ||
Assert.AreEqual("Test", dmarcDataFragment.DomainPolicy); | ||
Assert.IsNotNull(parseErrors); | ||
Assert.IsTrue(parseErrors.Length == 1); | ||
} | ||
|
||
[TestMethod] | ||
public void TryParse_ValidDmarcString1_ReturnsTrueAndPopulatesDmarcRecord() | ||
{ | ||
var isSuccessful = DmarcRecordParser.TryParse("v=DMARC1; p=reject;", out var dmarcDataFragment, out var parseErrors); | ||
Assert.IsTrue(isSuccessful); | ||
Assert.IsNotNull(dmarcDataFragment); | ||
Assert.AreEqual("reject", dmarcDataFragment.DomainPolicy); | ||
Assert.IsNull(parseErrors, "ParseErrors is not null"); | ||
} | ||
|
||
[TestMethod] | ||
public void TryParse_ValidDmarcString2_ReturnsTrueAndPopulatesDmarcRecord() | ||
{ | ||
var isSuccessful = DmarcRecordParser.TryParse("v=DMARC1; p=reject; sp=none;", out var dmarcDataFragment, out var parseErrors); | ||
Assert.IsTrue(isSuccessful); | ||
Assert.IsNotNull(dmarcDataFragment); | ||
Assert.AreEqual("reject", dmarcDataFragment.DomainPolicy); | ||
Assert.AreEqual("none", dmarcDataFragment.SubdomainPolicy); | ||
Assert.IsNull(parseErrors, "ParseErrors is not null"); | ||
} | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
src/Nager.EmailAuthentication.UnitTest/DmarcRecordParserReportFormatTest.cs
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 |
---|---|---|
@@ -0,0 +1,41 @@ | ||
namespace Nager.EmailAuthentication.UnitTest | ||
{ | ||
[TestClass] | ||
public sealed class DmarcRecordParserReportFormatTest | ||
{ | ||
[TestMethod] | ||
public void TryParse_ValidDmarcString1_ReturnsTrueAndPopulatesDmarcRecord() | ||
{ | ||
var isSuccessful = DmarcRecordParser.TryParse("v=DMARC1; p=reject; rf=afrf", out var dmarcDataFragment, out var parseErrors); | ||
Assert.IsTrue(isSuccessful); | ||
Assert.IsNotNull(dmarcDataFragment); | ||
Assert.AreEqual("reject", dmarcDataFragment.DomainPolicy); | ||
Assert.AreEqual("afrf", dmarcDataFragment.ReportFormat); | ||
Assert.IsNull(parseErrors, "ParseErrors is not null"); ; | ||
} | ||
|
||
[TestMethod] | ||
public void TryParse_InvalidDmarcString1_ReturnsTrueAndPopulatesDmarcRecordWithParseErrors() | ||
{ | ||
var isSuccessful = DmarcRecordParser.TryParse("v=DMARC1; p=reject; rf=afrf1", out var dmarcDataFragment, out var parseErrors); | ||
Assert.IsTrue(isSuccessful); | ||
Assert.IsNotNull(dmarcDataFragment); | ||
Assert.AreEqual("reject", dmarcDataFragment.DomainPolicy); | ||
Assert.AreEqual("afrf1", dmarcDataFragment.ReportFormat); | ||
Assert.IsNotNull(parseErrors, "ParseErrors is null"); | ||
Assert.IsTrue(parseErrors.Length == 1); | ||
} | ||
|
||
[TestMethod] | ||
public void TryParse_InvalidDmarcString2_ReturnsTrueAndPopulatesDmarcRecordWithParseErrors() | ||
{ | ||
var isSuccessful = DmarcRecordParser.TryParse("v=DMARC1; p=reject; rf=", out var dmarcDataFragment, out var parseErrors); | ||
Assert.IsTrue(isSuccessful); | ||
Assert.IsNotNull(dmarcDataFragment); | ||
Assert.AreEqual("reject", dmarcDataFragment.DomainPolicy); | ||
Assert.AreEqual("", dmarcDataFragment.ReportFormat); | ||
Assert.IsNotNull(parseErrors, "ParseErrors is null"); | ||
Assert.IsTrue(parseErrors.Length == 1); | ||
} | ||
} | ||
} |
111 changes: 0 additions & 111 deletions
111
src/Nager.EmailAuthentication.UnitTest/DmarcRecordParserTest.cs
This file was deleted.
Oops, something went wrong.
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