Commit bfe76f53 authored by Brickner_cp's avatar Brickner_cp

Code coverage 94.86%

parent b9a776fc
...@@ -219,6 +219,15 @@ namespace PcapDotNet.Packets.Test ...@@ -219,6 +219,15 @@ namespace PcapDotNet.Packets.Test
} }
} }
[TestMethod]
public void DnsResourceDataOptionsParseWrongLengthTest()
{
var resourceData = new DnsResourceDataOptions(new DnsOptions(new DnsOptionLongLivedQuery(0, DnsLongLivedQueryOpCode.Setup,
DnsLongLivedQueryErrorCode.Static, 1, 2)));
TestResourceRecordIsNotCreatedWithNewLength(DnsType.Opt, resourceData, 1);
TestResourceRecordIsNotCreatedWithNewLength(DnsType.Opt, resourceData, -1);
}
[TestMethod] [TestMethod]
[ExpectedException(typeof(InvalidOperationException))] [ExpectedException(typeof(InvalidOperationException))]
public void DnsQueryResourceRecordTtlGetTest() public void DnsQueryResourceRecordTtlGetTest()
...@@ -836,6 +845,65 @@ namespace PcapDotNet.Packets.Test ...@@ -836,6 +845,65 @@ namespace PcapDotNet.Packets.Test
TestResourceRecordIsNotCreatedWithNewLength(DnsType.MailExchange, resourceData, -14); TestResourceRecordIsNotCreatedWithNewLength(DnsType.MailExchange, resourceData, -14);
} }
[TestMethod]
[ExpectedException(typeof(ArgumentNullException))]
public void DnsResourceDataDelegationSignerConstructorNullDigestTest()
{
var resourceData = new DnsResourceDataDelegationSigner(1, DnsAlgorithm.PrivateDns, DnsDigestType.Sha1, null);
Assert.IsNull(resourceData);
Assert.Fail();
}
[TestMethod]
public void DnsResourceDataDomainNameParseWrongLengthTest()
{
var resourceData = new DnsResourceDataDomainName(new DnsDomainName("pcapdot.net"));
TestResourceRecordIsNotCreatedWithNewLength(DnsType.Ns, resourceData, 1);
TestResourceRecordIsNotCreatedWithNewLength(DnsType.Ns, resourceData, -1);
}
[TestMethod]
public void DnsResourceDataIsdnParseWrongLengthTest()
{
var resourceData = new DnsResourceDataIsdn(new DataSegment(new byte[5]), new DataSegment(new byte[5]));
TestResourceRecordIsNotCreatedWithNewLength(DnsType.Isdn, resourceData, 1);
TestResourceRecordIsNotCreatedWithNewLength(DnsType.Isdn, resourceData, -1);
}
[TestMethod]
public void DnsResourceDataKeyParseWrongLengthTest()
{
var resourceData = new DnsResourceDataKey(false, true, false, true, false, true, DnsKeyNameType.NonZoneEntity, DnsKeySignatoryAttributes.General,
DnsKeyProtocol.Email, DnsAlgorithm.Indirect, 1, new DataSegment(new byte[5]));
TestResourceRecordIsNotCreatedWithNewLength(DnsType.Key, resourceData, -8);
}
[TestMethod]
[ExpectedException(typeof(ArgumentNullException))]
public void DnsResourceDataNamingAuthorityPointerConstructorNullFlagsTest()
{
var resourceData = new DnsResourceDataNamingAuthorityPointer(1, 2, null, DataSegment.Empty, DataSegment.Empty, DnsDomainName.Root);
Assert.IsNull(resourceData);
Assert.Fail();
}
[TestMethod]
public void DnsResourceDataSignatureParseWrongLengthTest()
{
var resourceData = new DnsResourceDataSignature(DnsType.A, DnsAlgorithm.RsaSha512, 2, 3, 4, 5, 6, new DnsDomainName("pcapdot.net"),
new DataSegment(new byte[5]));
TestResourceRecordIsNotCreatedWithNewLength(DnsType.Signature, resourceData, -6);
TestResourceRecordIsNotCreatedWithNewLength(DnsType.Signature, resourceData, -19);
}
[TestMethod]
public void DnsResourceDataUriParseWrongLengthTest()
{
var resourceData = new DnsResourceDataUri(1, 2, new List<DataSegment> {new DataSegment(new byte[5]), new DataSegment(new byte[5])});
TestResourceRecordIsNotCreatedWithNewLength(DnsType.Uri, resourceData, -1);
TestResourceRecordIsNotCreatedWithNewLength(DnsType.Uri, resourceData, -13);
}
private static void TestDomainNameCompression(int expectedCompressionBenefit, DnsLayer dnsLayer) private static void TestDomainNameCompression(int expectedCompressionBenefit, DnsLayer dnsLayer)
{ {
dnsLayer.DomainNameCompressionMode = DnsDomainNameCompressionMode.Nothing; dnsLayer.DomainNameCompressionMode = DnsDomainNameCompressionMode.Nothing;
......
...@@ -25,6 +25,8 @@ namespace PcapDotNet.Packets.TestUtils ...@@ -25,6 +25,8 @@ namespace PcapDotNet.Packets.TestUtils
dnsLayer.IsRecursionDesired = random.NextBool(); dnsLayer.IsRecursionDesired = random.NextBool();
dnsLayer.IsRecursionAvailable = random.NextBool(); dnsLayer.IsRecursionAvailable = random.NextBool();
dnsLayer.FutureUse = random.NextBool(); dnsLayer.FutureUse = random.NextBool();
dnsLayer.IsAuthenticData = random.NextBool();
dnsLayer.IsCheckingDisabled = random.NextBool();
dnsLayer.ResponseCode = random.NextEnum(DnsResponseCode.BadVersionOrBadSignature, DnsResponseCode.BadKey, DnsResponseCode.BadTime, DnsResponseCode.BadMode, dnsLayer.ResponseCode = random.NextEnum(DnsResponseCode.BadVersionOrBadSignature, DnsResponseCode.BadKey, DnsResponseCode.BadTime, DnsResponseCode.BadMode,
DnsResponseCode.BadName, DnsResponseCode.BadAlgorithm, DnsResponseCode.BadTruncation); DnsResponseCode.BadName, DnsResponseCode.BadAlgorithm, DnsResponseCode.BadTruncation);
dnsLayer.DomainNameCompressionMode = random.NextEnum<DnsDomainNameCompressionMode>(); dnsLayer.DomainNameCompressionMode = random.NextEnum<DnsDomainNameCompressionMode>();
......
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