-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(repeater): support unsafe headers violated RFC
closes #85
- Loading branch information
Showing
9 changed files
with
519 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace SecTester.Repeater.Extensions; | ||
|
||
internal static class EnumerableExtensions | ||
{ | ||
public static void ForEach<T>(this IEnumerable<T> source, Action<T> action) | ||
{ | ||
if (source == null) | ||
{ | ||
throw new ArgumentNullException(nameof(source)); | ||
} | ||
|
||
if (action == null) | ||
{ | ||
throw new ArgumentNullException(nameof(action)); | ||
} | ||
|
||
foreach (var item in source) | ||
{ | ||
action(item); | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace SecTester.Repeater.Extensions; | ||
|
||
internal static class ListExtensions | ||
{ | ||
public static int Replace<T>(this List<T> source, T newValue, Predicate<T> predicate) | ||
{ | ||
if (source == null) throw new ArgumentNullException(nameof(source)); | ||
if (predicate == null) throw new ArgumentNullException(nameof(predicate)); | ||
|
||
var contentLenghtIdx = source.FindIndex(predicate); | ||
|
||
if (contentLenghtIdx != -1) | ||
{ | ||
source[contentLenghtIdx] = newValue; | ||
} | ||
|
||
return contentLenghtIdx; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using System; | ||
using System.Text; | ||
|
||
namespace SecTester.Repeater.Runners; | ||
|
||
internal sealed class TruncatedBody | ||
{ | ||
public TruncatedBody(byte[] body, string? charSet = default) | ||
{ | ||
Body = body; | ||
Encoding = string.IsNullOrEmpty(charSet) ? Encoding.Default : Encoding.GetEncoding(charSet); | ||
} | ||
|
||
private Encoding Encoding { get; } | ||
private byte[] Body { get; } | ||
public int Length => Buffer.ByteLength(Body); | ||
|
||
public override string ToString() | ||
{ | ||
return Encoding.GetString(Body); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
test/SecTester.Repeater.Tests/Extensions/EnumerableExtensionsTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
namespace SecTester.Repeater.Tests.Extensions; | ||
|
||
public class EnumerableExtensionsTests | ||
{ | ||
private readonly Action<int> _action = Substitute.For<Action<int>>(); | ||
|
||
[Fact] | ||
public void ForEach_SourceIsNotDefined_ThrowsError() | ||
{ | ||
// act | ||
var act = () => ((null as IEnumerable<int>)!).ForEach(_action); | ||
|
||
// assert | ||
act.Should().Throw<ArgumentNullException>().WithMessage("*source*"); | ||
} | ||
|
||
[Fact] | ||
public void ForEach_ActionIsNotDefined_ThrowsError() | ||
{ | ||
// arrange | ||
IEnumerable<int> list = new List<int> | ||
{ | ||
1, 2, 3 | ||
}; | ||
|
||
// act | ||
var act = () => list.ForEach(null!); | ||
|
||
// assert | ||
act.Should().Throw<ArgumentNullException>().WithMessage("*action*"); | ||
} | ||
|
||
[Fact] | ||
public void ForEach_IterateOverAllElements() | ||
{ | ||
// arrange | ||
IEnumerable<int> list = new List<int> | ||
{ | ||
1, 2, 3 | ||
}; | ||
|
||
// act | ||
list.ForEach(_action); | ||
|
||
// assert | ||
_action.Received(3)(Arg.Any<int>()); | ||
} | ||
|
||
[Fact] | ||
public void ForEach_ExecutesActionInCorrectOrder() | ||
{ | ||
// arrange | ||
var source = Enumerable.Range(1, 10); | ||
var items = new List<int>(); | ||
|
||
// act | ||
source.ForEach(x => items.Add(x)); | ||
|
||
// assert | ||
items.Should().ContainInOrder(source); | ||
} | ||
|
||
[Fact] | ||
public void ForEach_DoesNothingOnEmptyEnumerable() | ||
{ | ||
// arrange | ||
IEnumerable<int> list = new List<int>(); | ||
|
||
// act | ||
list.ForEach(_action); | ||
|
||
// assert | ||
_action.DidNotReceive()(Arg.Any<int>()); | ||
} | ||
} |
Oops, something went wrong.