Commit 8dbf5714 authored by Brickner_cp's avatar Brickner_cp

Code coverage 94.68%

parent b47f8f31
...@@ -536,6 +536,13 @@ namespace PcapDotNet.Packets.Test ...@@ -536,6 +536,13 @@ namespace PcapDotNet.Packets.Test
Assert.Fail(); Assert.Fail();
} }
[TestMethod]
public void DnsResourceDataLocationInformationParseWrongLengthTest()
{
var resourceData = new DnsResourceDataLocationInformation(0, 1000, 2000, 3000, 100, 200, 300);
TestResourceRecordIsNotCreatedWithNewLength(DnsType.Loc, resourceData, 1);
}
[TestMethod] [TestMethod]
public void DnsResourceDataNextDomainSecureTest() public void DnsResourceDataNextDomainSecureTest()
{ {
...@@ -614,6 +621,18 @@ namespace PcapDotNet.Packets.Test ...@@ -614,6 +621,18 @@ namespace PcapDotNet.Packets.Test
Assert.Fail(); Assert.Fail();
} }
[TestMethod]
public void DnsResourceDataNextDomainSecure3ParseWrongLengthTest()
{
var resourceData = new DnsResourceDataNextDomainSecure3(DnsSecNSec3HashAlgorithm.Sha1, DnsSecNSec3Flags.None, 0, new DataSegment(new byte[5]),
new DataSegment(new byte[5]), new[] {DnsType.A, DnsType.A6,});
TestResourceRecordIsNotCreatedWithNewLength(DnsType.NSec3, resourceData, 1);
TestResourceRecordIsNotCreatedWithNewLength(DnsType.NSec3, resourceData, -8);
TestResourceRecordIsNotCreatedWithNewLength(DnsType.NSec3, resourceData, -13);
TestResourceRecordIsNotCreatedWithNewLength(DnsType.NSec3, resourceData, -14);
TestResourceRecordIsNotCreatedWithNewLength(DnsType.NSec3, resourceData, -19);
}
[TestMethod] [TestMethod]
public void DnsGatewayTest() public void DnsGatewayTest()
{ {
...@@ -730,7 +749,7 @@ namespace PcapDotNet.Packets.Test ...@@ -730,7 +749,7 @@ namespace PcapDotNet.Packets.Test
} }
[TestMethod] [TestMethod]
public void DnsResourceDataGeographicalPositionWrongLengthTest() public void DnsResourceDataGeographicalPositionParseWrongLengthTest()
{ {
var resourceData = new DnsResourceDataGeographicalPosition("5.03", "-44.4", "22.1"); var resourceData = new DnsResourceDataGeographicalPosition("5.03", "-44.4", "22.1");
TestResourceRecordIsNotCreatedWithNewLength(DnsType.GPos, resourceData, 1); TestResourceRecordIsNotCreatedWithNewLength(DnsType.GPos, resourceData, 1);
...@@ -739,6 +758,31 @@ namespace PcapDotNet.Packets.Test ...@@ -739,6 +758,31 @@ namespace PcapDotNet.Packets.Test
TestResourceRecordIsNotCreatedWithNewLength(DnsType.GPos, resourceData, -14); TestResourceRecordIsNotCreatedWithNewLength(DnsType.GPos, resourceData, -14);
} }
[TestMethod]
public void DnsResourceDataX400PointerParseWrongLengthTest()
{
var resourceData = new DnsResourceDataX400Pointer(0, new DnsDomainName("pcapdot.net"), new DnsDomainName("pcapdotnet.codeplex.com"));
TestResourceRecordIsNotCreatedWithNewLength(DnsType.PointerX400, resourceData, 1);
TestResourceRecordIsNotCreatedWithNewLength(DnsType.PointerX400, resourceData, -1);
TestResourceRecordIsNotCreatedWithNewLength(DnsType.PointerX400, resourceData, -26);
TestResourceRecordIsNotCreatedWithNewLength(DnsType.PointerX400, resourceData, -39);
}
[TestMethod]
public void DnsResourceDataIpSecKeyParseWrongLengthTest()
{
var resourceDataIpV4 = new DnsResourceDataIpSecKey(1, new DnsGatewayIpV4(IpV4Address.Zero), DnsPublicKeyAlgorithm.Rsa, new DataSegment(new byte[5]));
TestResourceRecordIsNotCreatedWithNewLength(DnsType.IpSecKey, resourceDataIpV4, -6);
TestResourceRecordIsNotCreatedWithNewLength(DnsType.IpSecKey, resourceDataIpV4, -10);
var resourceDataIpV6 = new DnsResourceDataIpSecKey(1, new DnsGatewayIpV6(IpV6Address.Zero), DnsPublicKeyAlgorithm.Rsa, new DataSegment(new byte[5]));
TestResourceRecordIsNotCreatedWithNewLength(DnsType.IpSecKey, resourceDataIpV6, -6);
var resourceDataDomainName = new DnsResourceDataIpSecKey(1, new DnsGatewayDomainName(new DnsDomainName("pcapdot.net")), DnsPublicKeyAlgorithm.Rsa,
new DataSegment(new byte[5]));
TestResourceRecordIsNotCreatedWithNewLength(DnsType.IpSecKey, resourceDataDomainName, -6);
}
private static void TestDomainNameCompression(int expectedCompressionBenefit, DnsLayer dnsLayer) private static void TestDomainNameCompression(int expectedCompressionBenefit, DnsLayer dnsLayer)
{ {
dnsLayer.DomainNameCompressionMode = DnsDomainNameCompressionMode.Nothing; dnsLayer.DomainNameCompressionMode = DnsDomainNameCompressionMode.Nothing;
......
...@@ -79,6 +79,6 @@ namespace PcapDotNet.Packets.Dns ...@@ -79,6 +79,6 @@ namespace PcapDotNet.Packets.Dns
} }
} }
private static DnsGatewayNone _none = new DnsGatewayNone(); private static readonly DnsGatewayNone _none = new DnsGatewayNone();
} }
} }
\ No newline at end of file
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