Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(Tests) Add unit tests #140

Merged
merged 39 commits into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
c1aed4f
Add equality member
haga-rak Jan 8, 2024
1c74c1c
Add test on Certificate and FluxzySetting
haga-rak Jan 8, 2024
1f0b239
Add ImageResultProducer unit test
Jan 8, 2024
2142b7e
Add ResponseBodySummaryProducer test cases
Jan 8, 2024
b6de60c
Add new unit test for ResponseTextContentProducer
Jan 8, 2024
8eedf32
Add SetCookieProducer unit test and disable auto-redirect
Jan 8, 2024
5a70a4e
Update RequestJsonBodyProducer unit test
Jan 8, 2024
6e9a226
Add ProducersActions tests and update HTTP request handling
Jan 8, 2024
7010746
Add ContentLength assertion in Producers unit test
Jan 8, 2024
ffd72e5
Add unit test for ResponseBodyJsonProducer
Jan 8, 2024
f96c222
Add new test case to ResponseBodyJsonProducer
Jan 8, 2024
6afe625
Add additional assertions in Producers unit tests
Jan 8, 2024
70dab1e
Enhance ProducerContext unit test in Fluxzy.Tests.
Jan 8, 2024
e6d4636
Update SubdomainUtility and add tests
Jan 9, 2024
80817ba
Add unit tests for StringHelper utility class
Jan 9, 2024
79cd40a
Expand FluxzySetting unit tests
Jan 9, 2024
d374360
Add method to register random directories
haga-rak Jan 9, 2024
f6ddfcb
Add unit tests for FxzyImportEngine
haga-rak Jan 9, 2024
8b7beb8
Update null-forgiving post-fix usage in ProxyOrchestrator
haga-rak Jan 9, 2024
4d5cb56
Remove Fluxzy directory from codecov ignore list
haga-rak Jan 9, 2024
81aec04
Add Fluxzy component to codecov.yml
haga-rak Jan 9, 2024
ef7dd7e
Add new test data
haga-rak Jan 9, 2024
3445888
Add unit tests for SearchTextFilter
haga-rak Jan 9, 2024
bd4defb
Add 'with-request-payload.fxzy' to Fluxzy.Tests
haga-rak Jan 9, 2024
dc7bd9e
Remove LegacyPcapWriter class
haga-rak Jan 9, 2024
a33cada
Add NSubstitute package to Fluxzy.Tests.csproj
haga-rak Jan 9, 2024
abfbd5b
Refactor ResponseSuggestedExtension method in HeaderUtility class
haga-rak Jan 9, 2024
7b64b9a
Fix bad GetHashCode that prevents equality
haga-rak Jan 9, 2024
e78a7a3
Add HeaderUtility unit tests
haga-rak Jan 9, 2024
d0472b7
Add equality tests for various classes
haga-rak Jan 9, 2024
a8597be
Merge from main
haga-rak Jan 9, 2024
88e344f
Update codecov.yml to ignore debugging code
haga-rak Jan 9, 2024
9e167c9
Add ArchiveReader unit tests
haga-rak Jan 9, 2024
c4aef80
Add additional assertions in EqualityTesterBase unit tests
haga-rak Jan 9, 2024
dee726b
Add ClientErrorEquality unit test
haga-rak Jan 9, 2024
42ccc7e
Remove BOM
haga-rak Jan 9, 2024
a9dede0
Add ImportEngineProvider unit tests
haga-rak Jan 9, 2024
7186720
Add unit tests for Agent and AuthorityInfo equality
haga-rak Jan 9, 2024
80333f4
Increase timeouts in proxy and OS detection
haga-rak Jan 9, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,18 @@ component_management:
name: Fluxzy.Core
paths:
- src/Fluxzy.Core/**
- component_id: Fluxzy
name: Fluxzy
paths:
- src/Fluxzy/**
ignore:
- "src/Fluxzy.Core.Pcap/**"
- "src/Fluxzy.Core.Pcap.Cli/**"
- "src/Fluxzy.Core.Pcap/**"
- "src/Fluxzy.Extensions/**"
- "src/Fluxzy.Tools.DocGen/**"
- "src/Fluxzy/**"

# Ignore debugging code
- "src/Fluxzy.Core/Clients/H2Logger.cs"
- "src/Fluxzy.Core/Clients/H1Logger.cs"
- "src/Fluxzy.Core/Misc/Streams/DebugFileStream.cs"
201 changes: 0 additions & 201 deletions src/Fluxzy.Core.Pcap/LegacyPcapWriter.cs

This file was deleted.

2 changes: 1 addition & 1 deletion src/Fluxzy.Core/Archiving/Readers/ImportEngineProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public ImportEngineProvider(FxzyDirectoryPackager directoryPackager)

public IReadOnlyCollection<IImportEngine> Engines { get; }

public IImportEngine? GetImportEngine(string fileName)
public IImportEngine? GetImportEngine(string fileName)
{
return Engines.FirstOrDefault(r => r.IsFormat(fileName));
}
Expand Down
2 changes: 1 addition & 1 deletion src/Fluxzy.Core/Core/Proxy/SystemProxySetting.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public override bool Equals(object? obj)

public override int GetHashCode()
{
return HashCode.Combine(BoundHost, ListenPort, ByPassHosts);
return HashCode.Combine(BoundHost, ListenPort);
}
}
}
4 changes: 2 additions & 2 deletions src/Fluxzy.Core/Core/ProxyOrchestrator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -176,10 +176,10 @@ await exchange.Context.BreakPointContext.RequestHeaderCompletion
if (exchange.Context.HasRequestBodySubstitution) {
originalRequestBodyStream = exchange.Request.Body;
exchange.Request.Body = await
exchange.Context.GetSubstitutedRequestBody(exchange.Request.Body, exchange);
exchange.Context.GetSubstitutedRequestBody(exchange.Request.Body!, exchange);
}

exchange.Request.Body = new DispatchStream(exchange.Request.Body,
exchange.Request.Body = new DispatchStream(exchange.Request.Body!,
true,
_archiveWriter.CreateRequestBodyStream(exchange.Id));
}
Expand Down
49 changes: 6 additions & 43 deletions src/Fluxzy.Core/Utils/HeaderUtility.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright 2021 - Haga Rakotoharivelo - https://github.com/haga-rak

using System;
using System.Buffers;
using System.Linq;
using Fluxzy.Clients.H2.Encoder.Utils;

Expand All @@ -16,6 +15,11 @@ public static string GetResponseSuggestedExtension(IExchange exchange)
?.Where(r => r.Name.Span.Equals("content-type", StringComparison.OrdinalIgnoreCase))
.LastOrDefault();

return ResponseSuggestedExtension(contentTypeHeader);
}

internal static string ResponseSuggestedExtension(HeaderFieldInfo? contentTypeHeader)
{
if (contentTypeHeader == null)
return "data";

Expand Down Expand Up @@ -67,48 +71,7 @@ public static string GetRequestSuggestedExtension(IExchange exchange)
?.Where(r => r.Name.Span.Equals("content-type", StringComparison.OrdinalIgnoreCase))
.LastOrDefault();

if (contentTypeHeader == null)
return "data";

if (contentTypeHeader.Value.Span.Contains("json", StringComparison.OrdinalIgnoreCase))
return "json";

if (contentTypeHeader.Value.Span.Contains("html", StringComparison.OrdinalIgnoreCase))
return "html";

if (contentTypeHeader.Value.Span.Contains("css", StringComparison.OrdinalIgnoreCase))
return "css";

if (contentTypeHeader.Value.Span.Contains("xml", StringComparison.OrdinalIgnoreCase))
return "xml";

if (contentTypeHeader.Value.Span.Contains("javascript", StringComparison.OrdinalIgnoreCase))
return "js";

if (contentTypeHeader.Value.Span.Contains("font", StringComparison.OrdinalIgnoreCase))
return "font";

if (contentTypeHeader.Value.Span.Contains("png", StringComparison.OrdinalIgnoreCase))
return "png";

if (contentTypeHeader.Value.Span.Contains("jpeg", StringComparison.OrdinalIgnoreCase)
|| contentTypeHeader.Value.Span.Contains("jpg", StringComparison.OrdinalIgnoreCase)
)
return "jpeg";

if (contentTypeHeader.Value.Span.Contains("gif", StringComparison.OrdinalIgnoreCase))
return "gif";

if (contentTypeHeader.Value.Span.Contains("svg", StringComparison.OrdinalIgnoreCase))
return "svg";

if (contentTypeHeader.Value.Span.Contains("pdf", StringComparison.OrdinalIgnoreCase))
return "pdf";

if (contentTypeHeader.Value.Span.Contains("text", StringComparison.OrdinalIgnoreCase))
return "txt";

return "data";
return ResponseSuggestedExtension(contentTypeHeader);
}

public static string? GetSimplifiedContentType(IExchange exchange)
Expand Down
6 changes: 6 additions & 0 deletions src/Fluxzy.Core/Utils/SubdomainUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ public static bool TryGetSubDomain(string host, out string? subDomain)
return true;
}

if (splittedHost.Length == 2) {
subDomain = host;

return true;
}

subDomain = null;

return false;
Expand Down
10 changes: 10 additions & 0 deletions test/Fluxzy.Tests/Fluxzy.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,18 @@
<ItemGroup>
<None Remove="_Files\Headers\Req001.txt.bin" />
<None Remove="_Files\Headers\Resp001.txt.bin" />
<None Update="_Files\Archives\minimal.saz">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="_Files\Archives\pink-floyd.fxzy">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="_Files\Archives\testarchive.saz">
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
</None>
<None Update="_Files\Archives\with-request-payload.fxzy">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="_Files\Certificates\fluxzytest.txt">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
Expand All @@ -40,6 +49,7 @@
<ItemGroup>
<PackageReference Include="fluxzy.sandbox.models" Version="1.0.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="NSubstitute" Version="5.1.0" />
<PackageReference Include="System.Threading.AccessControl" Version="8.0.0" />
<PackageReference Include="xunit" Version="2.6.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.4">
Expand Down
2 changes: 1 addition & 1 deletion test/Fluxzy.Tests/TimeoutConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public static int Regular {
get
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) {
return 40;
return 60;
}
else {
return 15;
Expand Down
Loading
Loading