Commit ae2067b6 authored by Brickner_cp's avatar Brickner_cp

Code Coverage 95.52%

parent 3e6b8508
...@@ -39,9 +39,11 @@ namespace PcapDotNet.Core.Test ...@@ -39,9 +39,11 @@ namespace PcapDotNet.Core.Test
break; break;
case "vlan.trailer": case "vlan.trailer":
if ( if (!new[]
!new[] {(EthernetType)1, (EthernetType)5, (EthernetType)17, (EthernetType)30, (EthernetType)43, (EthernetType)50}.Contains( {
vLanTaggedFrameDatagram.EtherType)) (EthernetType)1, (EthernetType)5, (EthernetType)17, (EthernetType)29, (EthernetType)30, (EthernetType)43, (EthernetType)50
}.Contains(
vLanTaggedFrameDatagram.EtherType))
field.AssertValue(vLanTaggedFrameDatagram.TrailerWithFrameCheckSequence); field.AssertValue(vLanTaggedFrameDatagram.TrailerWithFrameCheckSequence);
break; break;
......
...@@ -26,6 +26,7 @@ namespace PcapDotNet.Packets.Test ...@@ -26,6 +26,7 @@ namespace PcapDotNet.Packets.Test
public TestContext TestContext { get; set; } public TestContext TestContext { get; set; }
#region Additional test attributes #region Additional test attributes
// //
// You can use the following additional attributes as you write your tests: // You can use the following additional attributes as you write your tests:
// //
...@@ -45,6 +46,7 @@ namespace PcapDotNet.Packets.Test ...@@ -45,6 +46,7 @@ namespace PcapDotNet.Packets.Test
// [TestCleanup()] // [TestCleanup()]
// public void MyTestCleanup() { } // public void MyTestCleanup() { }
// //
#endregion #endregion
[TestMethod] [TestMethod]
...@@ -132,7 +134,8 @@ namespace PcapDotNet.Packets.Test ...@@ -132,7 +134,8 @@ namespace PcapDotNet.Packets.Test
switch (subOption.OptionType) switch (subOption.OptionType)
{ {
case IpV6AccessNetworkIdentifierSubOptionType.GeoLocation: case IpV6AccessNetworkIdentifierSubOptionType.GeoLocation:
IpV6AccessNetworkIdentifierSubOptionGeoLocation subOptionGeoLocation = (IpV6AccessNetworkIdentifierSubOptionGeoLocation)subOption; IpV6AccessNetworkIdentifierSubOptionGeoLocation subOptionGeoLocation =
(IpV6AccessNetworkIdentifierSubOptionGeoLocation)subOption;
MoreAssert.IsBiggerOrEqual(-90, subOptionGeoLocation.LatitudeDegreesReal); MoreAssert.IsBiggerOrEqual(-90, subOptionGeoLocation.LatitudeDegreesReal);
MoreAssert.IsSmallerOrEqual(90, subOptionGeoLocation.LatitudeDegreesReal); MoreAssert.IsSmallerOrEqual(90, subOptionGeoLocation.LatitudeDegreesReal);
MoreAssert.IsBiggerOrEqual(-180, subOptionGeoLocation.LongitudeDegreesReal); MoreAssert.IsBiggerOrEqual(-180, subOptionGeoLocation.LongitudeDegreesReal);
...@@ -164,7 +167,7 @@ namespace PcapDotNet.Packets.Test ...@@ -164,7 +167,7 @@ namespace PcapDotNet.Packets.Test
Assert.AreEqual(subOptionBindingReference, Assert.AreEqual(subOptionBindingReference,
new IpV6FlowIdentificationSubOptionBindingReference( new IpV6FlowIdentificationSubOptionBindingReference(
subOptionBindingReference.BindingIds.AsEnumerable())); subOptionBindingReference.BindingIds.AsEnumerable()));
break; break;
} }
} }
break; break;
...@@ -224,10 +227,10 @@ namespace PcapDotNet.Packets.Test ...@@ -224,10 +227,10 @@ namespace PcapDotNet.Packets.Test
DateTime.Now, DateTime.Now,
new EthernetLayer(), new EthernetLayer(),
new IpV6Layer new IpV6Layer
{ {
ExtensionHeaders = new IpV6ExtensionHeaders( ExtensionHeaders = new IpV6ExtensionHeaders(
new IpV6ExtensionHeaderDestinationOptions(IpV4Protocol.Skip, new IpV6Options(option))) new IpV6ExtensionHeaderDestinationOptions(IpV4Protocol.Skip, new IpV6Options(option)))
}); });
Assert.IsTrue(packet.IsValid); Assert.IsTrue(packet.IsValid);
Assert.AreEqual(option, ((IpV6ExtensionHeaderDestinationOptions)packet.Ethernet.IpV6.ExtensionHeaders[0]).Options[0]); Assert.AreEqual(option, ((IpV6ExtensionHeaderDestinationOptions)packet.Ethernet.IpV6.ExtensionHeaders[0]).Options[0]);
} }
...@@ -261,14 +264,14 @@ namespace PcapDotNet.Packets.Test ...@@ -261,14 +264,14 @@ namespace PcapDotNet.Packets.Test
DateTime.Now, DateTime.Now,
new EthernetLayer(), new EthernetLayer(),
new IpV6Layer new IpV6Layer
{ {
ExtensionHeaders = new IpV6ExtensionHeaders( ExtensionHeaders = new IpV6ExtensionHeaders(
new IpV6ExtensionHeaderMobilityBindingError( new IpV6ExtensionHeaderMobilityBindingError(
IpV4Protocol.Skip, 0, IpV6BindingErrorStatus.UnrecognizedMhTypeValue, IpV6Address.Zero, IpV4Protocol.Skip, 0, IpV6BindingErrorStatus.UnrecognizedMhTypeValue, IpV6Address.Zero,
new IpV6MobilityOptions( new IpV6MobilityOptions(
new IpV6MobilityOptionAccessNetworkIdentifier( new IpV6MobilityOptionAccessNetworkIdentifier(
new IpV6AccessNetworkIdentifierSubOptions(subOption))))) new IpV6AccessNetworkIdentifierSubOptions(subOption)))))
}); });
Assert.IsTrue(packet.IsValid); Assert.IsTrue(packet.IsValid);
Assert.AreEqual(subOption, Assert.AreEqual(subOption,
((IpV6MobilityOptionAccessNetworkIdentifier) ((IpV6MobilityOptionAccessNetworkIdentifier)
...@@ -284,14 +287,14 @@ namespace PcapDotNet.Packets.Test ...@@ -284,14 +287,14 @@ namespace PcapDotNet.Packets.Test
DateTime.Now, DateTime.Now,
new EthernetLayer(), new EthernetLayer(),
new IpV6Layer new IpV6Layer
{ {
ExtensionHeaders = new IpV6ExtensionHeaders( ExtensionHeaders = new IpV6ExtensionHeaders(
new IpV6ExtensionHeaderMobilityBindingError( new IpV6ExtensionHeaderMobilityBindingError(
IpV4Protocol.Skip, 0, IpV6BindingErrorStatus.UnrecognizedMhTypeValue, IpV6Address.Zero, IpV4Protocol.Skip, 0, IpV6BindingErrorStatus.UnrecognizedMhTypeValue, IpV6Address.Zero,
new IpV6MobilityOptions( new IpV6MobilityOptions(
new IpV6MobilityOptionFlowIdentification(0, 0, IpV6FlowIdentificationStatus.FlowIdentifierNotFound, new IpV6MobilityOptionFlowIdentification(0, 0, IpV6FlowIdentificationStatus.FlowIdentifierNotFound,
new IpV6FlowIdentificationSubOptions(subOption))))) new IpV6FlowIdentificationSubOptions(subOption)))))
}); });
Assert.IsTrue(packet.IsValid); Assert.IsTrue(packet.IsValid);
Assert.AreEqual(subOption, Assert.AreEqual(subOption,
((IpV6MobilityOptionFlowIdentification) ((IpV6MobilityOptionFlowIdentification)
...@@ -485,10 +488,10 @@ namespace PcapDotNet.Packets.Test ...@@ -485,10 +488,10 @@ namespace PcapDotNet.Packets.Test
DateTime.Now, DateTime.Now,
new EthernetLayer(), new EthernetLayer(),
new IpV6Layer new IpV6Layer
{ {
ExtensionHeaders = new IpV6ExtensionHeaders( ExtensionHeaders = new IpV6ExtensionHeaders(
new IpV6ExtensionHeaderDestinationOptions(IpV4Protocol.Skip, IpV6Options.Empty)) new IpV6ExtensionHeaderDestinationOptions(IpV4Protocol.Skip, IpV6Options.Empty))
}); });
Assert.IsTrue(packet.IsValid); Assert.IsTrue(packet.IsValid);
Packet invalidPacket = new Packet(packet.Buffer.Take(packet.Length - 1).ToArray(), DateTime.Now, DataLinkKind.Ethernet); Packet invalidPacket = new Packet(packet.Buffer.Take(packet.Length - 1).ToArray(), DateTime.Now, DataLinkKind.Ethernet);
Assert.IsFalse(invalidPacket.IsValid); Assert.IsFalse(invalidPacket.IsValid);
...@@ -501,10 +504,10 @@ namespace PcapDotNet.Packets.Test ...@@ -501,10 +504,10 @@ namespace PcapDotNet.Packets.Test
DateTime.Now, DateTime.Now,
new EthernetLayer(), new EthernetLayer(),
new IpV6Layer new IpV6Layer
{ {
ExtensionHeaders = new IpV6ExtensionHeaders( ExtensionHeaders = new IpV6ExtensionHeaders(
new IpV6ExtensionHeaderAuthentication(IpV4Protocol.Skip, 0, 0, DataSegment.Empty)) new IpV6ExtensionHeaderAuthentication(IpV4Protocol.Skip, 0, 0, DataSegment.Empty))
}); });
Assert.IsTrue(packet.IsValid); Assert.IsTrue(packet.IsValid);
Packet invalidPacket = new Packet(packet.Buffer.Take(packet.Length - 1).ToArray(), DateTime.Now, DataLinkKind.Ethernet); Packet invalidPacket = new Packet(packet.Buffer.Take(packet.Length - 1).ToArray(), DateTime.Now, DataLinkKind.Ethernet);
Assert.IsFalse(invalidPacket.IsValid); Assert.IsFalse(invalidPacket.IsValid);
...@@ -517,10 +520,10 @@ namespace PcapDotNet.Packets.Test ...@@ -517,10 +520,10 @@ namespace PcapDotNet.Packets.Test
DateTime.Now, DateTime.Now,
new EthernetLayer(), new EthernetLayer(),
new IpV6Layer new IpV6Layer
{ {
ExtensionHeaders = new IpV6ExtensionHeaders( ExtensionHeaders = new IpV6ExtensionHeaders(
new IpV6ExtensionHeaderAuthentication(IpV4Protocol.Skip, 0, 0, new DataSegment(new byte[12]))) new IpV6ExtensionHeaderAuthentication(IpV4Protocol.Skip, 0, 0, new DataSegment(new byte[12])))
}); });
Assert.IsTrue(packet.IsValid); Assert.IsTrue(packet.IsValid);
++packet.Buffer[14 + 40 + 1]; ++packet.Buffer[14 + 40 + 1];
Packet invalidPacket = new Packet(packet.Buffer, DateTime.Now, DataLinkKind.Ethernet); Packet invalidPacket = new Packet(packet.Buffer, DateTime.Now, DataLinkKind.Ethernet);
...@@ -536,9 +539,9 @@ namespace PcapDotNet.Packets.Test ...@@ -536,9 +539,9 @@ namespace PcapDotNet.Packets.Test
DateTime.Now, DateTime.Now,
new EthernetLayer(), new EthernetLayer(),
new IpV6Layer new IpV6Layer
{ {
NextHeader = IpV4Protocol.IpV6Route NextHeader = IpV4Protocol.IpV6Route
}, },
new PayloadLayer {Data = new Datagram(payload)}); new PayloadLayer {Data = new Datagram(payload)});
Assert.IsFalse(packet.IsValid); Assert.IsFalse(packet.IsValid);
} }
...@@ -552,9 +555,9 @@ namespace PcapDotNet.Packets.Test ...@@ -552,9 +555,9 @@ namespace PcapDotNet.Packets.Test
DateTime.Now, DateTime.Now,
new EthernetLayer(), new EthernetLayer(),
new IpV6Layer new IpV6Layer
{ {
ExtensionHeaders = new IpV6ExtensionHeaders(new IpV6ExtensionHeaderEncapsulatingSecurityPayload(0, 0, DataSegment.Empty)) ExtensionHeaders = new IpV6ExtensionHeaders(new IpV6ExtensionHeaderEncapsulatingSecurityPayload(0, 0, DataSegment.Empty))
}, },
new PayloadLayer {Data = new Datagram(new byte[10])})); new PayloadLayer {Data = new Datagram(new byte[10])}));
} }
...@@ -642,5 +645,102 @@ namespace PcapDotNet.Packets.Test ...@@ -642,5 +645,102 @@ namespace PcapDotNet.Packets.Test
new IpV6AccessNetworkIdentifierSubOptionOperatorIdentifier(IpV6AccessNetworkIdentifierOperatorIdentifierType.PrivateEnterpriseNumber, new IpV6AccessNetworkIdentifierSubOptionOperatorIdentifier(IpV6AccessNetworkIdentifierOperatorIdentifierType.PrivateEnterpriseNumber,
new DataSegment(new byte[254]))))); new DataSegment(new byte[254])))));
} }
[TestMethod]
public void IpV6MobilityOptionRedirectCreateInstanceDataShorterThanMinimum()
{
Packet packet = PacketBuilder.Build(
DateTime.Now,
new EthernetLayer(),
new IpV6Layer
{
ExtensionHeaders =
new IpV6ExtensionHeaders(
new IpV6ExtensionHeaderMobilityBindingError(
IpV4Protocol.Skip, 0, IpV6BindingErrorStatus.UnrecognizedMhTypeValue, IpV6Address.Zero,
new IpV6MobilityOptions(new IpV6MobilityOptionRedirect(IpV4Address.Zero))))
});
Assert.IsTrue(packet.IsValid);
packet.Buffer[14 + 40 + 24 + 1] = 1;
Packet invalidPacket = new Packet(packet.Buffer, DateTime.Now, DataLinkKind.Ethernet);
Assert.IsFalse(invalidPacket.IsValid);
}
[TestMethod]
public void IpV6MobilityOptionRedirectCreateInstanceDataTooShortForIpV4()
{
Packet packet = PacketBuilder.Build(
DateTime.Now,
new EthernetLayer(),
new IpV6Layer
{
ExtensionHeaders =
new IpV6ExtensionHeaders(
new IpV6ExtensionHeaderMobilityBindingError(
IpV4Protocol.Skip, 0, IpV6BindingErrorStatus.UnrecognizedMhTypeValue, IpV6Address.Zero,
new IpV6MobilityOptions(new IpV6MobilityOptionRedirect(IpV4Address.Zero))))
});
Assert.IsTrue(packet.IsValid);
packet.Buffer[14 + 40 + 24 + 1] = 3;
Packet invalidPacket = new Packet(packet.Buffer, DateTime.Now, DataLinkKind.Ethernet);
Assert.IsFalse(invalidPacket.IsValid);
}
[TestMethod]
public void IpV6MobilityOptionRedirectCreateInstanceDataTooShortForIpV6()
{
Packet packet = PacketBuilder.Build(
DateTime.Now,
new EthernetLayer(),
new IpV6Layer
{
ExtensionHeaders =
new IpV6ExtensionHeaders(
new IpV6ExtensionHeaderMobilityBindingError(
IpV4Protocol.Skip, 0, IpV6BindingErrorStatus.UnrecognizedMhTypeValue, IpV6Address.Zero,
new IpV6MobilityOptions(new IpV6MobilityOptionRedirect(IpV6Address.Zero))))
});
Assert.IsTrue(packet.IsValid);
packet.Buffer[14 + 40 + 24 + 1] = 15;
Packet invalidPacket = new Packet(packet.Buffer, DateTime.Now, DataLinkKind.Ethernet);
Assert.IsFalse(invalidPacket.IsValid);
}
[TestMethod]
public void IpV6MobilityOptionRedirectCreateInstanceNotIpV6OrIpV4()
{
Packet packet = PacketBuilder.Build(
DateTime.Now,
new EthernetLayer(),
new IpV6Layer
{
ExtensionHeaders =
new IpV6ExtensionHeaders(
new IpV6ExtensionHeaderMobilityBindingError(
IpV4Protocol.Skip, 0, IpV6BindingErrorStatus.UnrecognizedMhTypeValue, IpV6Address.Zero,
new IpV6MobilityOptions(new IpV6MobilityOptionRedirect(IpV4Address.Zero))))
});
Assert.IsTrue(packet.IsValid);
packet.Buffer[14 + 40 + 24 + 2] = 0;
Packet invalidPacket = new Packet(packet.Buffer, DateTime.Now, DataLinkKind.Ethernet);
Assert.IsFalse(invalidPacket.IsValid);
}
[TestMethod]
public void IpV6ExtensionHeaderRoutingRplParseRoutingDataPadSizeMakeNumAddressesNegative()
{
Packet packet = PacketBuilder.Build(
DateTime.Now,
new EthernetLayer(),
new IpV6Layer
{
ExtensionHeaders =
new IpV6ExtensionHeaders(
new IpV6ExtensionHeaderRoutingRpl(IpV4Protocol.Skip, 8, 8, 0))
});
packet.Buffer[14 + 40 + 5] = 0x10;
Packet invalidPacket = new Packet(packet.Buffer, DateTime.Now, DataLinkKind.Ethernet);
Assert.IsFalse(invalidPacket.IsValid);
}
} }
} }
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