Skip to content

Commit

Permalink
Added factory default tests. Fixed factory default bugs in IEEE802_1x…
Browse files Browse the repository at this point in the history
… and TCP. Fixed minimum parseable size for IEEE802_1x. Bumped version number.
  • Loading branch information
Noah Potash committed Feb 20, 2016
1 parent 29bd2d8 commit f07503b
Show file tree
Hide file tree
Showing 17 changed files with 281 additions and 4 deletions.
4 changes: 3 additions & 1 deletion src/LibPacketGremlin/PacketFactories/IEEE802_1xFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ public override bool TryParse(byte[] buffer, int index, int count, out IEEE802_1
/// <returns>A Packet with default values</returns>
public IEEE802_1x<T> Default<T>(T payload) where T : class, IPacket
{
return new IEEE802_1x<T> { Payload = payload };
var packet = new IEEE802_1x<T> { Payload = payload };
packet.CorrectFields();
return packet;
}
}
}
5 changes: 4 additions & 1 deletion src/LibPacketGremlin/PacketFactories/TCPFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,14 @@ public override bool TryParse(byte[] buffer, int index, int count, out TCP packe
/// <returns>A Packet with default values</returns>
public TCP<T> Default<T>(T payload) where T : class, IPacket
{
return new TCP<T>
var packet = new TCP<T>
{
OptionsAndPadding = Array.Empty<byte>(),
Payload = payload
};

packet.CorrectFields();
return packet;
}
}
}
2 changes: 1 addition & 1 deletion src/LibPacketGremlin/Packets/IEEE802_1x.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace OutbreakLabs.LibPacketGremlin.Packets
/// </summary>
public abstract class IEEE802_1x : IPacket
{
private const int MinimumParseableBytes = 8;
private const int MinimumParseableBytes = 4;

protected UInt16 _BodyLength;

Expand Down
2 changes: 1 addition & 1 deletion src/LibPacketGremlin/project.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "1.0.0-beta-3",
"version": "1.0.0-beta-4",
"description": "Library for manipulating packets",
"authors": [ "Noah Potash" ],
"tags": [ "packet", "packets" ],
Expand Down
21 changes: 21 additions & 0 deletions test/LibPacketGremlinTests/PacketFactories/ARPFactoryTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using FluentAssertions;
using OutbreakLabs.LibPacketGremlin.Extensions;
using OutbreakLabs.LibPacketGremlin.PacketFactories;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Xunit;

namespace LibPacketGremlinTests.PacketFactories
{
public class ARPFactoryTests
{
[Fact]
public void GeneratesParseableDefault()
{
var defaultPacket = ARPFactory.Instance.Default();
ARPFactory.Instance.ParseAs(defaultPacket.ToArray()).Should().NotBeNull();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using FluentAssertions;
using OutbreakLabs.LibPacketGremlin.Extensions;
using OutbreakLabs.LibPacketGremlin.PacketFactories;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Xunit;

namespace LibPacketGremlinTests.PacketFactories
{
public class EthernetIIFactoryTests
{
[Fact]
public void GeneratesParseableDefault()
{
var defaultPacket = EthernetIIFactory.Instance.Default(GenericFactory.Instance.Default());
EthernetIIFactory.Instance.ParseAs(defaultPacket.ToArray()).Should().NotBeNull();
}
}
}
21 changes: 21 additions & 0 deletions test/LibPacketGremlinTests/PacketFactories/GenericFactoryTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using FluentAssertions;
using OutbreakLabs.LibPacketGremlin.Extensions;
using OutbreakLabs.LibPacketGremlin.PacketFactories;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Xunit;

namespace LibPacketGremlinTests.PacketFactories
{
public class GenericFactoryTests
{
[Fact]
public void GeneratesParseableDefault()
{
var defaultPacket = GenericFactory.Instance.Default();
GenericFactory.Instance.ParseAs(defaultPacket.ToArray()).Should().NotBeNull();
}
}
}
20 changes: 20 additions & 0 deletions test/LibPacketGremlinTests/PacketFactories/ICMPFactoryTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using FluentAssertions;
using OutbreakLabs.LibPacketGremlin.Extensions;
using OutbreakLabs.LibPacketGremlin.PacketFactories;
using System;
using System.Linq;
using System.Threading.Tasks;
using Xunit;

namespace LibPacketGremlinTests.PacketFactories
{
public class ICMPFactoryTests
{
[Fact]
public void GeneratesParseableDefault()
{
var defaultPacket = ICMPFactory.Instance.Default();
ICMPFactory.Instance.ParseAs(defaultPacket.ToArray()).Should().NotBeNull();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using FluentAssertions;
using OutbreakLabs.LibPacketGremlin.Extensions;
using OutbreakLabs.LibPacketGremlin.PacketFactories;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Xunit;

namespace LibPacketGremlinTests.PacketFactories
{
public class IEEE802_1xFactoryTests
{
[Fact]
public void GeneratesParseableDefault()
{
var defaultPacket = IEEE802_1xFactory.Instance.Default(GenericFactory.Instance.Default());
IEEE802_1xFactory.Instance.ParseAs(defaultPacket.ToArray()).Should().NotBeNull();
}
}
}
21 changes: 21 additions & 0 deletions test/LibPacketGremlinTests/PacketFactories/IPv4FactoryTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using FluentAssertions;
using OutbreakLabs.LibPacketGremlin.Extensions;
using OutbreakLabs.LibPacketGremlin.PacketFactories;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Xunit;

namespace LibPacketGremlinTests.PacketFactories
{
public class IPv4FactoryTests
{
[Fact]
public void GeneratesParseableDefault()
{
var defaultPacket = IPv4Factory.Instance.Default(GenericFactory.Instance.Default());
IPv4Factory.Instance.ParseAs(defaultPacket.ToArray()).Should().NotBeNull();
}
}
}
21 changes: 21 additions & 0 deletions test/LibPacketGremlinTests/PacketFactories/LLCFactoryTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using FluentAssertions;
using OutbreakLabs.LibPacketGremlin.Extensions;
using OutbreakLabs.LibPacketGremlin.PacketFactories;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Xunit;

namespace LibPacketGremlinTests.PacketFactories
{
public class LLCFactoryTests
{
[Fact]
public void GeneratesParseableDefault()
{
var defaultPacket = LLCFactory.Instance.Default(GenericFactory.Instance.Default());
LLCFactory.Instance.ParseAs(defaultPacket.ToArray()).Should().NotBeNull();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using FluentAssertions;
using OutbreakLabs.LibPacketGremlin.Extensions;
using OutbreakLabs.LibPacketGremlin.PacketFactories;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Xunit;

namespace LibPacketGremlinTests.PacketFactories
{
public class MSMon802_11FactoryTests
{
[Fact]
public void GeneratesParseableDefault()
{
var defaultPacket = MSMon802_11Factory.Instance.Default(GenericFactory.Instance.Default());
MSMon802_11Factory.Instance.ParseAs(defaultPacket.ToArray()).Should().NotBeNull();
}
}
}
21 changes: 21 additions & 0 deletions test/LibPacketGremlinTests/PacketFactories/RadiotapFactoryTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using FluentAssertions;
using OutbreakLabs.LibPacketGremlin.Extensions;
using OutbreakLabs.LibPacketGremlin.PacketFactories;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Xunit;

namespace LibPacketGremlinTests.PacketFactories
{
public class RadiotapFactoryTests
{
[Fact]
public void GeneratesParseableDefault()
{
var defaultPacket = RadiotapFactory.Instance.Default(GenericFactory.Instance.Default());
RadiotapFactory.Instance.ParseAs(defaultPacket.ToArray()).Should().NotBeNull();
}
}
}
21 changes: 21 additions & 0 deletions test/LibPacketGremlinTests/PacketFactories/SNAPFactoryTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using FluentAssertions;
using OutbreakLabs.LibPacketGremlin.Extensions;
using OutbreakLabs.LibPacketGremlin.PacketFactories;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Xunit;

namespace LibPacketGremlinTests.PacketFactories
{
public class SNAPFactoryTests
{
[Fact]
public void GeneratesParseableDefault()
{
var defaultPacket = SNAPFactory.Instance.Default(GenericFactory.Instance.Default());
SNAPFactory.Instance.ParseAs(defaultPacket.ToArray()).Should().NotBeNull();
}
}
}
21 changes: 21 additions & 0 deletions test/LibPacketGremlinTests/PacketFactories/TCPFactoryTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using FluentAssertions;
using OutbreakLabs.LibPacketGremlin.Extensions;
using OutbreakLabs.LibPacketGremlin.PacketFactories;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Xunit;

namespace LibPacketGremlinTests.PacketFactories
{
public class TCPFactoryTests
{
[Fact]
public void GeneratesParseableDefault()
{
var defaultPacket = TCPFactory.Instance.Default(GenericFactory.Instance.Default());
TCPFactory.Instance.ParseAs(defaultPacket.ToArray()).Should().NotBeNull();
}
}
}
21 changes: 21 additions & 0 deletions test/LibPacketGremlinTests/PacketFactories/UDPFactoryTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using FluentAssertions;
using OutbreakLabs.LibPacketGremlin.Extensions;
using OutbreakLabs.LibPacketGremlin.PacketFactories;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Xunit;

namespace LibPacketGremlinTests.PacketFactories
{
public class UDPFactoryTests
{
[Fact]
public void GeneratesParseableDefault()
{
var defaultPacket = UDPFactory.Instance.Default(GenericFactory.Instance.Default());
UDPFactory.Instance.ParseAs(defaultPacket.ToArray()).Should().NotBeNull();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using FluentAssertions;
using OutbreakLabs.LibPacketGremlin.Extensions;
using OutbreakLabs.LibPacketGremlin.PacketFactories;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Xunit;

namespace LibPacketGremlinTests.PacketFactories
{
public class WakeOnLanFactoryTests
{
[Fact]
public void GeneratesParseableDefault()
{
var defaultPacket = WakeOnLanFactory.Instance.Default();
WakeOnLanFactory.Instance.ParseAs(defaultPacket.ToArray()).Should().NotBeNull();
}
}
}

0 comments on commit f07503b

Please sign in to comment.