Skip to content

Commit

Permalink
Code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
nikouu committed Nov 23, 2024
1 parent 1eea14e commit aa25077
Show file tree
Hide file tree
Showing 15 changed files with 61 additions and 48 deletions.
1 change: 1 addition & 0 deletions devDocs/New API Checklist.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
When adding or updating a new API:

1. Tests
1. Overwrite tests too
1. Update public API check
1. Bump version
1. Code coverage
Expand Down
5 changes: 0 additions & 5 deletions src/ZeroRedact.Benchmark/SimpleRedactionBenchmarks.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
using BenchmarkDotNet.Attributes;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ZeroRedact.Benchmark.Redactors;

namespace ZeroRedact.Benchmark
{
Expand Down
28 changes: 19 additions & 9 deletions src/ZeroRedact.UnitTest/Redactors/CheckForOverwriteTests.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using static System.Net.Mime.MediaTypeNames;

namespace ZeroRedact.UnitTest.Redactors
namespace ZeroRedact.UnitTest.Redactors
{
// Tests to ensure that the redactors aren't manipulating the input data itself
// https://stackoverflow.com/a/10779478
Expand Down Expand Up @@ -786,5 +778,23 @@ public void CheckForOverwrite_String_IgnoreSymbols()
// Assert
Assert.AreEqual(expected, input);
}

[TestMethod]
public void CheckForOverwrite_String_ShowFirstAndLast()
{
// Arrange
var redactor = new Redactor();
var input = "Hello, world!";
var expected = new string(input.ToArray());

// Act
_ = redactor.RedactString(input, new StringRedactorOptions
{
RedactorType = StringRedaction.ShowFirstAndLast
});

// Assert
Assert.AreEqual(expected, input);
}
}
}
9 changes: 5 additions & 4 deletions src/ZeroRedact.UnitTest/Redactors/RedactCreditCardTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ private static IEnumerable<object[]> All_TestData()

yield return new object[] { "2023/06/15", "********" };
yield return new object[] { "[email protected]", "********" };
yield return new object[] { "100.100.100.100", "********"};
yield return new object[] { "100.100.100.100", "********" };
yield return new object[] { "2001:0db8:85a3:0000:0000:8a2e:0370:7334", "********" };
yield return new object[] { "00:1A:2B:FF:FE:3C:4D:5E", "********" };
yield return new object[] { "+1 (555) 123-4567", "********" };
Expand Down Expand Up @@ -79,7 +79,7 @@ private static IEnumerable<object[]> Full_TestData()

yield return new object[] { "2023/06/15", "********" };
yield return new object[] { "[email protected]", "********" };
yield return new object[] { "100.100.100.100", "********"};
yield return new object[] { "100.100.100.100", "********" };
yield return new object[] { "2001:0db8:85a3:0000:0000:8a2e:0370:7334", "********" };
yield return new object[] { "00:1A:2B:FF:FE:3C:4D:5E", "********" };
yield return new object[] { "+1 (555) 123-4567", "********" };
Expand All @@ -106,7 +106,7 @@ private static IEnumerable<object[]> ShowLastFour_TestData()

yield return new object[] { "2023/06/15", "********" };
yield return new object[] { "[email protected]", "********" };
yield return new object[] { "100.100.100.100", "********"};
yield return new object[] { "100.100.100.100", "********" };
yield return new object[] { "2001:0db8:85a3:0000:0000:8a2e:0370:7334", "********" };
yield return new object[] { "00:1A:2B:FF:FE:3C:4D:5E", "********" };
yield return new object[] { "+1 (555) 123-4567", "********" };
Expand Down Expand Up @@ -134,13 +134,14 @@ private static IEnumerable<object[]> ShowFirstSixLastFour_TestData()

yield return new object[] { "2023/06/15", "********" };
yield return new object[] { "[email protected]", "********" };
yield return new object[] { "100.100.100.100", "********"};
yield return new object[] { "100.100.100.100", "********" };
yield return new object[] { "2001:0db8:85a3:0000:0000:8a2e:0370:7334", "********" };
yield return new object[] { "00:1A:2B:FF:FE:3C:4D:5E", "********" };
yield return new object[] { "+1 (555) 123-4567", "********" };
yield return new object[] { "abc123 !@#", "********" };
}


[TestMethod]
[DynamicData(nameof(All_TestData), DynamicDataSourceType.Method)]
public void RedactCreditCard_All_ShouldReturnRedactedCreditCard_String(string input, string expected)
Expand Down
6 changes: 6 additions & 0 deletions src/ZeroRedact.UnitTest/Redactors/RedactDateTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public void Setup()
{
_redactor = new Redactor();
}

private static IEnumerable<object[]> All_TestData()
{
yield return new object[] { null, 2023, 1, 1, "**********" };
Expand All @@ -37,6 +38,7 @@ private static IEnumerable<object[]> All_TestData()
yield return new object[] { "ja-JP", 2023, 11, 1, "**********" };
yield return new object[] { "ja-JP", 2023, 12, 31, "**********" };
}

private static IEnumerable<object[]> FixedLength_TestData()
{
yield return new object[] { null, 2023, 1, 1, "********" };
Expand Down Expand Up @@ -82,6 +84,7 @@ private static IEnumerable<object[]> Full_TestData()
yield return new object[] { "ja-JP", 2023, 11, 1, "****/**/**" };
yield return new object[] { "ja-JP", 2023, 12, 31, "****/**/**" };
}

private static IEnumerable<object[]> Day_TestData()
{
yield return new object[] { null, 2023, 1, 1, "01/**/2023" };
Expand Down Expand Up @@ -127,6 +130,7 @@ private static IEnumerable<object[]> Month_TestData()
yield return new object[] { "ja-JP", 2023, 11, 1, "2023/**/01" };
yield return new object[] { "ja-JP", 2023, 12, 31, "2023/**/31" };
}

private static IEnumerable<object[]> Year_TestData()
{
yield return new object[] { null, 2023, 1, 1, "01/01/****" };
Expand All @@ -149,6 +153,7 @@ private static IEnumerable<object[]> Year_TestData()
yield return new object[] { "ja-JP", 2023, 11, 1, "****/11/01" };
yield return new object[] { "ja-JP", 2023, 12, 31, "****/12/31" };
}

private static IEnumerable<object[]> DayAndMonth_TestData()
{
yield return new object[] { null, 2023, 1, 1, "**/**/2023" };
Expand All @@ -171,6 +176,7 @@ private static IEnumerable<object[]> DayAndMonth_TestData()
yield return new object[] { "ja-JP", 2023, 11, 1, "2023/**/**" };
yield return new object[] { "ja-JP", 2023, 12, 31, "2023/**/**" };
}

private static IEnumerable<object[]> MonthAndYear_TestData()
{
yield return new object[] { null, 2023, 1, 1, "**/01/****" };
Expand Down
17 changes: 9 additions & 8 deletions src/ZeroRedact.UnitTest/Redactors/RedactEmailAddressTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ private static IEnumerable<object[]> All_TestData()

yield return new object[] { "4111 1111 1111 1111", "********" };
yield return new object[] { "2023/06/15", "********" };
yield return new object[] { "100.100.100.100", "********"};
yield return new object[] { "100.100.100.100", "********" };
yield return new object[] { "2001:0db8:85a3:0000:0000:8a2e:0370:7334", "********" };
yield return new object[] { "00:1A:2B:FF:FE:3C:4D:5E", "********" };
yield return new object[] { "+1 (555) 123-4567", "********" };
Expand Down Expand Up @@ -97,7 +97,7 @@ private static IEnumerable<object[]> FixedLength_TestData()

yield return new object[] { "4111 1111 1111 1111", "********" };
yield return new object[] { "2023/06/15", "********" };
yield return new object[] { "100.100.100.100", "********"};
yield return new object[] { "100.100.100.100", "********" };
yield return new object[] { "2001:0db8:85a3:0000:0000:8a2e:0370:7334", "********" };
yield return new object[] { "00:1A:2B:FF:FE:3C:4D:5E", "********" };
yield return new object[] { "+1 (555) 123-4567", "********" };
Expand Down Expand Up @@ -146,7 +146,7 @@ private static IEnumerable<object[]> Full_TestData()

yield return new object[] { "4111 1111 1111 1111", "********" };
yield return new object[] { "2023/06/15", "********" };
yield return new object[] { "100.100.100.100", "********"};
yield return new object[] { "100.100.100.100", "********" };
yield return new object[] { "2001:0db8:85a3:0000:0000:8a2e:0370:7334", "********" };
yield return new object[] { "00:1A:2B:FF:FE:3C:4D:5E", "********" };
yield return new object[] { "+1 (555) 123-4567", "********" };
Expand Down Expand Up @@ -195,7 +195,7 @@ private static IEnumerable<object[]> Username_TestData()

yield return new object[] { "4111 1111 1111 1111", "********" };
yield return new object[] { "2023/06/15", "********" };
yield return new object[] { "100.100.100.100", "********"};
yield return new object[] { "100.100.100.100", "********" };
yield return new object[] { "2001:0db8:85a3:0000:0000:8a2e:0370:7334", "********" };
yield return new object[] { "00:1A:2B:FF:FE:3C:4D:5E", "********" };
yield return new object[] { "+1 (555) 123-4567", "********" };
Expand Down Expand Up @@ -244,7 +244,7 @@ private static IEnumerable<object[]> HalfUsername_TestData()

yield return new object[] { "4111 1111 1111 1111", "********" };
yield return new object[] { "2023/06/15", "********" };
yield return new object[] { "100.100.100.100", "********"};
yield return new object[] { "100.100.100.100", "********" };
yield return new object[] { "2001:0db8:85a3:0000:0000:8a2e:0370:7334", "********" };
yield return new object[] { "00:1A:2B:FF:FE:3C:4D:5E", "********" };
yield return new object[] { "+1 (555) 123-4567", "********" };
Expand Down Expand Up @@ -293,7 +293,7 @@ private static IEnumerable<object[]> Middle_TestData()

yield return new object[] { "4111 1111 1111 1111", "********" };
yield return new object[] { "2023/06/15", "********" };
yield return new object[] { "100.100.100.100", "********"};
yield return new object[] { "100.100.100.100", "********" };
yield return new object[] { "2001:0db8:85a3:0000:0000:8a2e:0370:7334", "********" };
yield return new object[] { "00:1A:2B:FF:FE:3C:4D:5E", "********" };
yield return new object[] { "+1 (555) 123-4567", "********" };
Expand Down Expand Up @@ -342,7 +342,7 @@ private static IEnumerable<object[]> MostUsername_TestData()

yield return new object[] { "4111 1111 1111 1111", "********" };
yield return new object[] { "2023/06/15", "********" };
yield return new object[] { "100.100.100.100", "********"};
yield return new object[] { "100.100.100.100", "********" };
yield return new object[] { "2001:0db8:85a3:0000:0000:8a2e:0370:7334", "********" };
yield return new object[] { "00:1A:2B:FF:FE:3C:4D:5E", "********" };
yield return new object[] { "+1 (555) 123-4567", "********" };
Expand Down Expand Up @@ -391,13 +391,14 @@ private static IEnumerable<object[]> ShowFirstCharacters_TestData()

yield return new object[] { "4111 1111 1111 1111", "********" };
yield return new object[] { "2023/06/15", "********" };
yield return new object[] { "100.100.100.100", "********"};
yield return new object[] { "100.100.100.100", "********" };
yield return new object[] { "2001:0db8:85a3:0000:0000:8a2e:0370:7334", "********" };
yield return new object[] { "00:1A:2B:FF:FE:3C:4D:5E", "********" };
yield return new object[] { "+1 (555) 123-4567", "********" };
yield return new object[] { "abc123 !@#", "********" };
}


[TestMethod]
[DynamicData(nameof(All_TestData), DynamicDataSourceType.Method)]
public void RedactEmailAddressAddress_All_ShouldReturnRedactedEmailAddress_String(string input, string expected)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ private static IEnumerable<object[]> All_TestData()
yield return new object[] { "[email protected]", "********************" };
yield return new object[] { "just”not”[email protected]", "**************************" };
}

private static IEnumerable<object[]> FixedLength_TestData()
{
yield return new object[] { "[email protected]", "********" };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,7 @@ private static IEnumerable<object[]> ShowLastOctet_TestData()
yield return new object[] { "abc123 !@#", "********" };
}


[TestMethod]
[DynamicData(nameof(All_TestData), DynamicDataSourceType.Method)]
public void RedactIpv4_All_ShouldReturnRedactedRedactIPv4_String(string input, string expected)
Expand Down
12 changes: 8 additions & 4 deletions src/ZeroRedact.UnitTest/Redactors/RedactIPv6AddressTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@ private static IEnumerable<object[]> All_TestData()
yield return new object[] { "4111 1111 1111 1111", "********" };
yield return new object[] { "2023/06/15", "********" };
yield return new object[] { "[email protected]", "********" };
yield return new object[] { "100.100.100.100", "********"};
yield return new object[] { "100.100.100.100", "********" };
yield return new object[] { "00:1A:2B:FF:FE:3C:4D:5E", "***********************" };
yield return new object[] { "+1 (555) 123-4567", "********" };
yield return new object[] { "abc123 !@#", "********" };
}


private static IEnumerable<object[]> FixedLength_TestData()
{
yield return new object[] { "", "" };
Expand All @@ -33,12 +34,13 @@ private static IEnumerable<object[]> FixedLength_TestData()
yield return new object[] { "4111 1111 1111 1111", "********" };
yield return new object[] { "2023/06/15", "********" };
yield return new object[] { "[email protected]", "********" };
yield return new object[] { "100.100.100.100", "********"};
yield return new object[] { "100.100.100.100", "********" };
yield return new object[] { "00:1A:2B:FF:FE:3C:4D:5E", "********" };
yield return new object[] { "+1 (555) 123-4567", "********" };
yield return new object[] { "abc123 !@#", "********" };
}


private static IEnumerable<object[]> Full_TestData()
{
yield return new object[] { "", "" };
Expand All @@ -52,12 +54,13 @@ private static IEnumerable<object[]> Full_TestData()
yield return new object[] { "4111 1111 1111 1111", "********" };
yield return new object[] { "2023/06/15", "********" };
yield return new object[] { "[email protected]", "********" };
yield return new object[] { "100.100.100.100", "********"};
yield return new object[] { "100.100.100.100", "********" };
yield return new object[] { "00:1A:2B:FF:FE:3C:4D:5E", "**:**:**:**:**:**:**:**" };
yield return new object[] { "+1 (555) 123-4567", "********" };
yield return new object[] { "abc123 !@#", "********" };
}


private static IEnumerable<object[]> ShowLastQuartet_TestData()
{
yield return new object[] { "", "" };
Expand All @@ -71,12 +74,13 @@ private static IEnumerable<object[]> ShowLastQuartet_TestData()
yield return new object[] { "4111 1111 1111 1111", "********" };
yield return new object[] { "2023/06/15", "********" };
yield return new object[] { "[email protected]", "********" };
yield return new object[] { "100.100.100.100", "********"};
yield return new object[] { "100.100.100.100", "********" };
yield return new object[] { "00:1A:2B:FF:FE:3C:4D:5E", "**:**:**:**:**:**:**:5E" };
yield return new object[] { "+1 (555) 123-4567", "********" };
yield return new object[] { "abc123 !@#", "********" };
}


[TestMethod]
[DynamicData(nameof(All_TestData), DynamicDataSourceType.Method)]
public void RedactIpv6_All_ShouldReturnRedactedRedactIPv6_String(string input, string expected)
Expand Down
8 changes: 4 additions & 4 deletions src/ZeroRedact.UnitTest/Redactors/RedactMACAddressTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ private static IEnumerable<object[]> All_TestData()
yield return new object[] { "4111 1111 1111 1111", "********" };
yield return new object[] { "2023/06/15", "********" };
yield return new object[] { "[email protected]", "********" };
yield return new object[] { "100.100.100.100", "********"};
yield return new object[] { "100.100.100.100", "********" };
yield return new object[] { "2001:0db8:85a3:0000:0000:8a2e:0370:7334", "***************************************" };
yield return new object[] { "+1 (555) 123-4567", "********" };
yield return new object[] { "abc123 !@#", "********" };
Expand All @@ -31,7 +31,7 @@ private static IEnumerable<object[]> FixedLength_TestData()
yield return new object[] { "4111 1111 1111 1111", "********" };
yield return new object[] { "2023/06/15", "********" };
yield return new object[] { "[email protected]", "********" };
yield return new object[] { "100.100.100.100", "********"};
yield return new object[] { "100.100.100.100", "********" };
yield return new object[] { "2001:0db8:85a3:0000:0000:8a2e:0370:7334", "********" };
yield return new object[] { "+1 (555) 123-4567", "********" };
yield return new object[] { "abc123 !@#", "********" };
Expand All @@ -48,7 +48,7 @@ private static IEnumerable<object[]> Full_TestData()
yield return new object[] { "4111 1111 1111 1111", "********" };
yield return new object[] { "2023/06/15", "********" };
yield return new object[] { "[email protected]", "********" };
yield return new object[] { "100.100.100.100", "********"};
yield return new object[] { "100.100.100.100", "********" };
yield return new object[] { "2001:0db8:85a3:0000:0000:8a2e:0370:7334", "****:****:****:****:****:****:****:****" };
yield return new object[] { "+1 (555) 123-4567", "********" };
yield return new object[] { "abc123 !@#", "********" };
Expand All @@ -65,7 +65,7 @@ private static IEnumerable<object[]> ShowLastByte_TestData()
yield return new object[] { "4111 1111 1111 1111", "********" };
yield return new object[] { "2023/06/15", "********" };
yield return new object[] { "[email protected]", "********" };
yield return new object[] { "100.100.100.100", "********"};
yield return new object[] { "100.100.100.100", "********" };
yield return new object[] { "2001:0db8:85a3:0000:0000:8a2e:0370:7334", "****:****:****:****:****:****:****:7334" };
yield return new object[] { "+1 (555) 123-4567", "********" };
yield return new object[] { "abc123 !@#", "********" };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ private static IEnumerable<object[]> FixedLength_TestData()
yield return new object[] { "4111 1111 1111 1111", "********" };
yield return new object[] { "2023/06/15", "********" };
yield return new object[] { "[email protected]", "********" };
yield return new object[] { "100.100.100.100", "********"};
yield return new object[] { "100.100.100.100", "********" };
yield return new object[] { "2001:0db8:85a3:0000:0000:8a2e:0370:7334", "********" };
yield return new object[] { "00:1A:2B:FF:FE:3C:4D:5E", "********" };
yield return new object[] { "abc123 !@#", "********" };
Expand Down
Loading

0 comments on commit aa25077

Please sign in to comment.