Commit b9a776fc authored by Brickner_cp's avatar Brickner_cp

Code coverage 94.77%

parent 8dbf5714
...@@ -576,6 +576,22 @@ namespace PcapDotNet.Packets.Test ...@@ -576,6 +576,22 @@ namespace PcapDotNet.Packets.Test
Assert.AreEqual(1, resourceData.AuthorityAndFormatIdentifier); Assert.AreEqual(1, resourceData.AuthorityAndFormatIdentifier);
} }
[TestMethod]
[ExpectedException(typeof(ArgumentNullException))]
public void DnsResourceDataNetworkServiceAccessPointConstructorNullAreaAddressTest()
{
var resourceData = new DnsResourceDataNetworkServiceAccessPoint(null, 0, 0);
Assert.IsNull(resourceData);
Assert.Fail();
}
[TestMethod]
public void DnsResourceDataNetworkServiceAccessPointParseWrongLengthTest()
{
var resourceData = new DnsResourceDataNetworkServiceAccessPoint(new DataSegment(new byte[5]), 0, 0);
TestResourceRecordIsNotCreatedWithNewLength(DnsType.NetworkServiceAccessPoint, resourceData, -5);
}
[TestMethod] [TestMethod]
[ExpectedException(typeof(ArgumentOutOfRangeException))] [ExpectedException(typeof(ArgumentOutOfRangeException))]
public void DnsAddressPrefixAddressFamilyDependentPartTooBigTest() public void DnsAddressPrefixAddressFamilyDependentPartTooBigTest()
...@@ -783,6 +799,43 @@ namespace PcapDotNet.Packets.Test ...@@ -783,6 +799,43 @@ namespace PcapDotNet.Packets.Test
TestResourceRecordIsNotCreatedWithNewLength(DnsType.IpSecKey, resourceDataDomainName, -6); TestResourceRecordIsNotCreatedWithNewLength(DnsType.IpSecKey, resourceDataDomainName, -6);
} }
[TestMethod]
public void DnsResourceDataServerSelectionParseWrongLengthTest()
{
var resourceData = new DnsResourceDataServerSelection(0, 0, 0, new DnsDomainName("pcapdot.net"));
TestResourceRecordIsNotCreatedWithNewLength(DnsType.ServerSelection, resourceData, 1);
TestResourceRecordIsNotCreatedWithNewLength(DnsType.ServerSelection, resourceData, -1);
TestResourceRecordIsNotCreatedWithNewLength(DnsType.ServerSelection, resourceData, -14);
}
[TestMethod]
public void DnsResourceDataStartOfAuthorityParseWrongLengthTest()
{
var resourceData = new DnsResourceDataStartOfAuthority(new DnsDomainName("pcapdot.net"), new DnsDomainName("pcapdotnet.codeplex.com"), 1, 2, 3, 4, 5);
TestResourceRecordIsNotCreatedWithNewLength(DnsType.StartOfAuthority, resourceData, 1);
TestResourceRecordIsNotCreatedWithNewLength(DnsType.StartOfAuthority, resourceData, -21);
TestResourceRecordIsNotCreatedWithNewLength(DnsType.StartOfAuthority, resourceData, -46);
}
[TestMethod]
public void DnsResourceDataTrustAnchorLinkParseWrongLengthTest()
{
var resourceData = new DnsResourceDataTrustAnchorLink(new DnsDomainName("pcapdot.net"), new DnsDomainName("pcapdotnet.codeplex.com"));
TestResourceRecordIsNotCreatedWithNewLength(DnsType.TrustAnchorLink, resourceData, 1);
TestResourceRecordIsNotCreatedWithNewLength(DnsType.TrustAnchorLink, resourceData, -1);
TestResourceRecordIsNotCreatedWithNewLength(DnsType.TrustAnchorLink, resourceData, -25);
TestResourceRecordIsNotCreatedWithNewLength(DnsType.TrustAnchorLink, resourceData, -37);
}
[TestMethod]
public void DnsResourceDataMailExchangeParseWrongLengthTest()
{
var resourceData = new DnsResourceDataMailExchange(1, new DnsDomainName("pcapdot.net"));
TestResourceRecordIsNotCreatedWithNewLength(DnsType.MailExchange, resourceData, 1);
TestResourceRecordIsNotCreatedWithNewLength(DnsType.MailExchange, resourceData, -1);
TestResourceRecordIsNotCreatedWithNewLength(DnsType.MailExchange, resourceData, -14);
}
private static void TestDomainNameCompression(int expectedCompressionBenefit, DnsLayer dnsLayer) private static void TestDomainNameCompression(int expectedCompressionBenefit, DnsLayer dnsLayer)
{ {
dnsLayer.DomainNameCompressionMode = DnsDomainNameCompressionMode.Nothing; dnsLayer.DomainNameCompressionMode = DnsDomainNameCompressionMode.Nothing;
......
...@@ -101,6 +101,9 @@ namespace PcapDotNet.Packets.Dns ...@@ -101,6 +101,9 @@ namespace PcapDotNet.Packets.Dns
if (!DnsDomainName.TryParse(dns, offsetInDns, length, out next, out nextLength)) if (!DnsDomainName.TryParse(dns, offsetInDns, length, out next, out nextLength))
return null; return null;
if (length != nextLength)
return null;
return new DnsResourceDataTrustAnchorLink(previous, next); return new DnsResourceDataTrustAnchorLink(previous, next);
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment