Skip to content

Commit ca1ccbc

Browse files
authored
Merge pull request #8 from Red4Sec/shargon-patch-1
Change to coveralls
2 parents cba6b9f + 8a672ac commit ca1ccbc

File tree

8 files changed

+107
-11
lines changed

8 files changed

+107
-11
lines changed

.travis.yml

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,15 @@ before_install:
1414
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then ulimit -n 2048; fi
1515
install:
1616
- dotnet tool install -g dotnet-format --version 4.0.40103 --add-source https://dotnet.myget.org/F/format/api/v3/index.json
17+
- dotnet tool install -g coveralls.net --version 1.0.0
1718
- export PATH="$PATH:$HOME/.dotnet/tools"
1819
- dotnet-format --version
20+
- csmacnz.Coveralls --version
1921
before_script:
20-
- echo "Checking format ..."
22+
- echo "Extracting author information ..."
23+
- export COMMITTER_EMAIL="$(git log -1 $TRAVIS_COMMIT --pretty="%cE")"
24+
- export AUTHOR_NAME="$(git log -1 $TRAVIS_COMMIT --pretty="%aN")"
25+
- echo "Checking format ..."
2126
- dotnet format --check --dry-run -w src/TuringMachine -v diagnostic
2227
- dotnet format --check --dry-run -w src/TuringMachine.Core -v diagnostic
2328
- dotnet format --check --dry-run -w tests/TuringMachine.Core.Tests -v diagnostic
@@ -28,7 +33,9 @@ script:
2833
- cd tests/TuringMachine.Core.Tests
2934
- dotnet restore
3035
- find * -name *.csproj | xargs -I % dotnet add % package coverlet.msbuild
31-
- dotnet test -v m /p:CollectCoverage=true /p:CoverletOutputFormat=opencover
36+
- dotnet test -v m /p:CollectCoverage=true /p:CoverletOutputFormat=opencover /p:CoverletOutput='../../coverage.xml' /p:Exclude=\"[coverlet.*]*,[*]Coverlet.Core*\"
3237
after_success:
33-
- echo "Test Success - Branch($TRAVIS_BRANCH) Pull Request($TRAVIS_PULL_REQUEST) Tag($TRAVIS_TAG)"
34-
- bash <(curl -s https://codecov.io/bash)
38+
- echo "Test Success - Branch($TRAVIS_BRANCH) Pull Request($TRAVIS_PULL_REQUEST) Tag($TRAVIS_TAG) Author($AUTHOR_NAME) CommitterEmail($COMMITTER_EMAIL)"
39+
# - bash <(curl -s https://codecov.io/bash)
40+
- cd ../../
41+
- csmacnz.Coveralls --opencover -i coverage.xml --repoTokenVariable COVERALLS_REPO_TOKEN --useRelativePaths --commitId $TRAVIS_COMMIT --commitBranch $TRAVIS_BRANCH --jobId $TRAVIS_JOB_ID --commitMessage "$TRAVIS_COMMIT_MESSAGE" --commitAuthor "$AUTHOR_NAME" --commitEmail "$COMMITTER_EMAIL"

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
<a href="https://travis-ci.org/Red4Sec/TuringMachine" target="_blank">
88
<img src="https://travis-ci.org/Red4Sec/TuringMachine.svg?branch=master" alt="Current TravisCI build status.">
99
</a>
10-
<a href="https://codecov.io/gh/Red4Sec/TuringMachine" target="_blank">
11-
<img src="https://codecov.io/github/Red4Sec/TuringMachine/branch/master/graph/badge.svg" alt="Current Coverage Status." />
10+
<a href='https://coveralls.io/github/Red4Sec/TuringMachine?branch=master' target="_blank">
11+
<img src='https://coveralls.io/repos/github/Red4Sec/TuringMachine/badge.svg?branch=master' alt='Coverage Status' />
1212
</a>
1313
<a href="https://github.com/Red4Sec/TuringMachine/blob/master/LICENSE" target="_blank">
1414
<img src="https://img.shields.io/badge/license-MIT-blue.svg" alt="License.">

src/TuringMachine.Core/Extensions/ObjectExtensions.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ public static bool EqualWithNullCheck<T>(this IEquatable<T> a, IEquatable<T> b)
3535
/// <returns>True if are equals</returns>
3636
public static bool SequenceEqualWithNullCheck<T>(this IList<T> a, IList<T> b)
3737
{
38+
if (typeof(T) == typeof(byte[]))
39+
{
40+
return ChunkSequenceEqualWithNullCheck((IList<byte[]>)a, (IList<byte[]>)b);
41+
}
42+
3843
if ((a == null) != (b == null))
3944
{
4045
return false;
@@ -50,7 +55,7 @@ public static bool SequenceEqualWithNullCheck<T>(this IList<T> a, IList<T> b)
5055
/// <param name="a">A</param>
5156
/// <param name="b">B</param>
5257
/// <returns>True if are equals</returns>
53-
public static bool ChunkSequenceEqualWithNullCheck(this IList<byte[]> chunks1, IList<byte[]> chunks2)
58+
private static bool ChunkSequenceEqualWithNullCheck(this IList<byte[]> chunks1, IList<byte[]> chunks2)
5459
{
5560
if ((chunks1 == null) != (chunks2 == null)) return false;
5661
if (chunks1 == null) return true;

src/TuringMachine.Core/Fuzzers/Mutational/MutationalChunk.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public bool Equals(MutationalChunk obj)
9494
if (obj == null) return false;
9595

9696
return obj.Type == Type
97-
&& obj.Allowed.ChunkSequenceEqualWithNullCheck(Allowed);
97+
&& obj.Allowed.SequenceEqualWithNullCheck(Allowed);
9898
}
9999

100100
/// <summary>
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
using NUnit.Framework;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Net;
5+
using TuringMachine.Core.Extensions;
6+
7+
namespace TuringMachine.Core.Tests.Extensions
8+
{
9+
[TestFixture]
10+
public class ObjectExtensionsTest
11+
{
12+
[Test]
13+
public void ClearTest()
14+
{
15+
// IPEndPoint
16+
17+
Assert.IsFalse(ObjectExtensions.EqualWithNullCheck(new IPEndPoint(0, 1), null));
18+
Assert.IsFalse(ObjectExtensions.EqualWithNullCheck(null, new IPEndPoint(0, 1)));
19+
Assert.IsTrue(ObjectExtensions.EqualWithNullCheck(new IPEndPoint(0, 1), new IPEndPoint(0, 1)));
20+
Assert.IsFalse(ObjectExtensions.EqualWithNullCheck(new IPEndPoint(0, 1), new IPEndPoint(0, 2)));
21+
22+
// Byte[]
23+
24+
Assert.IsFalse(ObjectExtensions.SequenceEqualWithNullCheck(new byte[] { 0x00, 0x01 }, null));
25+
Assert.IsFalse(ObjectExtensions.SequenceEqualWithNullCheck(null, new byte[] { 0x00, 0x01 }));
26+
Assert.IsTrue(ObjectExtensions.SequenceEqualWithNullCheck(new byte[] { 0x00, 0x01 }, new byte[] { 0x00, 0x01 }));
27+
Assert.IsFalse(ObjectExtensions.SequenceEqualWithNullCheck(new byte[] { 0x00, 0x01 }, new byte[] { 0x00, 0x02 }));
28+
29+
// IList
30+
31+
Assert.IsFalse(ObjectExtensions.SequenceEqualWithNullCheck(new List<byte>(new byte[] { 0x00, 0x01 }), null));
32+
Assert.IsFalse(ObjectExtensions.SequenceEqualWithNullCheck(null, new List<byte>(new byte[] { 0x00, 0x01 })));
33+
Assert.IsTrue(ObjectExtensions.SequenceEqualWithNullCheck(new List<byte>(new byte[] { 0x00, 0x01 }), new List<byte>(new byte[] { 0x00, 0x01 })));
34+
Assert.IsFalse(ObjectExtensions.SequenceEqualWithNullCheck(new List<byte>(new byte[] { 0x00, 0x01 }), new List<byte>(new byte[] { 0x00, 0x02 })));
35+
36+
// IEquatable
37+
38+
Assert.IsFalse(ObjectExtensions.EqualWithNullCheck((IEquatable<Decimal>)new Decimal(1), null));
39+
Assert.IsFalse(ObjectExtensions.EqualWithNullCheck(null, (IEquatable<Decimal>)new Decimal(1)));
40+
Assert.IsTrue(ObjectExtensions.EqualWithNullCheck((IEquatable<Decimal>)new Decimal(1), (IEquatable<Decimal>)new Decimal(1)));
41+
Assert.IsFalse(ObjectExtensions.EqualWithNullCheck((IEquatable<Decimal>)new Decimal(1), (IEquatable<Decimal>)new Decimal(2)));
42+
43+
// IList<byte[]>
44+
45+
Assert.IsFalse(ObjectExtensions.SequenceEqualWithNullCheck(new List<byte[]>(new byte[][] { new byte[] { 0x00, 0x01 } }), null));
46+
Assert.IsFalse(ObjectExtensions.SequenceEqualWithNullCheck(null, new List<byte[]>(new byte[][] { new byte[] { 0x00, 0x01 } })));
47+
Assert.IsTrue(ObjectExtensions.SequenceEqualWithNullCheck(new List<byte[]>(new byte[][] { new byte[] { 0x00, 0x01 } }), new List<byte[]>(new byte[][] { new byte[] { 0x00, 0x01 } })));
48+
Assert.IsFalse(ObjectExtensions.SequenceEqualWithNullCheck(new List<byte[]>(new byte[][] { new byte[] { 0x00, 0x01 } }), new List<byte[]>(new byte[][] { new byte[] { 0x00, 0x02 } })));
49+
}
50+
}
51+
}

tests/TuringMachine.Core.Tests/FuzzerTest.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ private void Test(FuzzerConnectionBase serverConnection, FuzzerConnectionBase cl
6767
using (var server = new FuzzerServer())
6868
using (var client = new FuzzerClient())
6969
{
70+
// Change name
71+
72+
client.PublicName = "TestClient_" + Guid.NewGuid().ToString();
73+
7074
// Ensure no error
7175

7276
client.SendLog(null);
@@ -143,7 +147,7 @@ private void Test(FuzzerConnectionBase serverConnection, FuzzerConnectionBase cl
143147
Assert.IsTrue(waitInput.WaitOne(TimeSpan.FromSeconds(10)), "Waiting for inputs");
144148

145149
Assert.AreEqual(1, server.Connections.Count);
146-
Assert.IsTrue(!string.IsNullOrEmpty(server.Connections.Values.FirstOrDefault()?.Source.Description));
150+
Assert.IsTrue(server.Connections.Values.FirstOrDefault()?.Source.Description.Contains(client.PublicName));
147151
Assert.AreNotEqual(Guid.Empty, server.Connections.Values.FirstOrDefault()?.Source.Id);
148152
Assert.AreNotEqual(Guid.Empty, server.Connections.Values.FirstOrDefault()?.Id);
149153

tests/TuringMachine.Core.Tests/Fuzzers/Mutational/MutationalTest.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,7 @@ public void MutationalEntryPeerByteTest()
340340
entry.Changes.Add(new MutationalChange()
341341
{
342342
Weight = 5,
343+
Description = "Add A",
343344
Append = new MutationalFromTo((byte)'A'),
344345
RemoveLength = new FromToValue<ushort>(1),
345346
AppendIterations = new FromToValue<ushort>(1)
@@ -348,6 +349,7 @@ public void MutationalEntryPeerByteTest()
348349
{
349350
// Remmove
350351
Weight = 1,
352+
Description = "Remove",
351353
RemoveLength = new FromToValue<ushort>(1),
352354
AppendIterations = new FromToValue<ushort>(1)
353355
});
@@ -407,13 +409,14 @@ public void MutationalEntryPeerByteTest()
407409

408410
// Max changes 2
409411

412+
entry.Changes.RemoveAt(1);
410413
entry.ValidOffset = new FromToValue<long>(0, long.MaxValue);
411414
entry.MaxChanges = new FromToValue<ushort>(2);
412-
413415
input = new ManualFuzzingInput(new byte[100]);
416+
414417
using (var stream = new FuzzingStream(config, input.GetStream()))
415418
{
416-
stream.CopyTo(new MemoryStream(), 100);
419+
stream.CopyTo(new MemoryStream(), 16);
417420

418421
Assert.AreEqual(2, stream.Log.Length);
419422
Assert.AreEqual(0, stream.Log[0].Offset);

tests/TuringMachine.Core.Tests/FuzzingStreamTest.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,32 @@ namespace TuringMachine.Core.Tests
1010
[TestFixture]
1111
public class FuzzingStreamTest
1212
{
13+
class Disposable : IDisposable
14+
{
15+
public int IsDisposed = 0;
16+
17+
public void Dispose()
18+
{
19+
IsDisposed++;
20+
}
21+
}
22+
23+
[Test]
24+
public void DisposeTest()
25+
{
26+
var original = new byte[90];
27+
var disposed = new Disposable();
28+
29+
using (var stream = new FuzzingStream(null, original))
30+
{
31+
stream.Variables.Add(0, disposed);
32+
33+
Assert.AreEqual(0, disposed.IsDisposed);
34+
}
35+
36+
Assert.AreEqual(1, disposed.IsDisposed);
37+
}
38+
1339
[Test]
1440
public void CleanTest()
1541
{

0 commit comments

Comments
 (0)