Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
32 changes: 30 additions & 2 deletions .github/workflows/build-natives.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ jobs:
working-directory: native
steps:
- uses: Cysharp/Actions/.github/actions/checkout@main
with:
submodules: true
- uses: Cysharp/Actions/.github/actions/setup-dotnet@main
- run: cargo build --target x86_64-pc-windows-msvc --profile ${{ env._RUST_BUILD_CONFIG == 'debug' && 'dev' || env._RUST_BUILD_CONFIG }}
- uses: Cysharp/Actions/.github/actions/upload-artifact@main
Expand All @@ -73,6 +75,8 @@ jobs:
working-directory: native
steps:
- uses: Cysharp/Actions/.github/actions/checkout@main
with:
submodules: true
- uses: Cysharp/Actions/.github/actions/setup-dotnet@main
- run: rustup target add aarch64-pc-windows-msvc
- run: |
Expand Down Expand Up @@ -100,6 +104,8 @@ jobs:
working-directory: native
steps:
- uses: Cysharp/Actions/.github/actions/checkout@main
with:
submodules: true
- uses: Cysharp/Actions/.github/actions/setup-dotnet@main
- run: rustup toolchain install nightly-2024-07-10-x86_64-pc-windows-msvc
- run: rustup component add rust-src --toolchain nightly-2024-07-10-x86_64-pc-windows-msvc
Expand Down Expand Up @@ -154,9 +160,9 @@ jobs:
env:
DEBIAN_FRONTEND: noninteractive
- uses: Cysharp/Actions/.github/actions/checkout@main
- uses: Cysharp/Actions/.github/actions/setup-dotnet@main
with:
dotnet-version: 8.0.x
submodules: true
- uses: Cysharp/Actions/.github/actions/setup-dotnet@main
- uses: actions-rust-lang/setup-rust-toolchain@2fcdc490d667999e01ddbbf0f2823181beef6b39 # v1.15.0
- run: cargo build --target x86_64-unknown-linux-gnu --profile ${{ env._RUST_BUILD_CONFIG == 'debug' && 'dev' || env._RUST_BUILD_CONFIG }}
- uses: Cysharp/Actions/.github/actions/upload-artifact@main
Expand All @@ -181,6 +187,8 @@ jobs:
working-directory: native
steps:
- uses: Cysharp/Actions/.github/actions/checkout@main
with:
submodules: true
- uses: Cysharp/Actions/.github/actions/setup-dotnet@main
- run: rustup target add x86_64-apple-darwin
- run: cargo build --target x86_64-apple-darwin --profile ${{ env._RUST_BUILD_CONFIG == 'debug' && 'dev' || env._RUST_BUILD_CONFIG }}
Expand All @@ -206,6 +214,9 @@ jobs:
working-directory: native
steps:
- uses: Cysharp/Actions/.github/actions/checkout@main
with:
submodules: true
- uses: Cysharp/Actions/.github/actions/setup-dotnet@main
- run: rustup target add aarch64-apple-darwin
- run: cargo build --target aarch64-apple-darwin --profile ${{ env._RUST_BUILD_CONFIG == 'debug' && 'dev' || env._RUST_BUILD_CONFIG }}
- uses: Cysharp/Actions/.github/actions/upload-artifact@main
Expand All @@ -228,6 +239,8 @@ jobs:
timeout-minutes: 30
steps:
- uses: Cysharp/Actions/.github/actions/checkout@main
with:
submodules: true
- uses: Cysharp/Actions/.github/actions/download-artifact@main
with:
path: native/artifacts
Expand All @@ -250,6 +263,8 @@ jobs:
working-directory: native
steps:
- uses: Cysharp/Actions/.github/actions/checkout@main
with:
submodules: true
- run: rustup target add x86_64-apple-ios
- run: cargo build --target x86_64-apple-ios --profile ${{ env._RUST_BUILD_CONFIG == 'debug' && 'dev' || env._RUST_BUILD_CONFIG }}
env:
Expand All @@ -272,6 +287,8 @@ jobs:
working-directory: native
steps:
- uses: Cysharp/Actions/.github/actions/checkout@main
with:
submodules: true
- run: rustup target add aarch64-apple-ios
- run: cargo build --target aarch64-apple-ios --profile ${{ env._RUST_BUILD_CONFIG == 'debug' && 'dev' || env._RUST_BUILD_CONFIG }}
env:
Expand All @@ -294,6 +311,8 @@ jobs:
working-directory: native
steps:
- uses: Cysharp/Actions/.github/actions/checkout@main
with:
submodules: true
- run: rustup target add aarch64-apple-ios-sim
- run: cargo build --target aarch64-apple-ios-sim --profile ${{ env._RUST_BUILD_CONFIG == 'debug' && 'dev' || env._RUST_BUILD_CONFIG }}
env:
Expand All @@ -316,6 +335,8 @@ jobs:
working-directory: native
steps:
- uses: Cysharp/Actions/.github/actions/checkout@main
with:
submodules: true
- name: Use latest Android NDK
run: |
echo "ANDROID_NDK=$ANDROID_NDK_LATEST_HOME" >> $GITHUB_ENV
Expand Down Expand Up @@ -343,6 +364,8 @@ jobs:
working-directory: native
steps:
- uses: Cysharp/Actions/.github/actions/checkout@main
with:
submodules: true
- name: Use latest Android NDK
run: |
echo "ANDROID_NDK=$ANDROID_NDK_LATEST_HOME" >> $GITHUB_ENV
Expand Down Expand Up @@ -370,6 +393,8 @@ jobs:
working-directory: native
steps:
- uses: Cysharp/Actions/.github/actions/checkout@main
with:
submodules: true
- name: Use latest Android NDK
run: |
echo "ANDROID_NDK=$ANDROID_NDK_LATEST_HOME" >> $GITHUB_ENV
Expand Down Expand Up @@ -407,6 +432,9 @@ jobs:
timeout-minutes: 30
steps:
- uses: Cysharp/Actions/.github/actions/checkout@main
with:
submodules: true
- uses: Cysharp/Actions/.github/actions/setup-dotnet@main
- uses: Cysharp/Actions/.github/actions/download-artifact@main
with:
path: native/artifacts
Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "external/HttpClientTestServer"]
path = external/HttpClientTestServer
url = https://github.com/Cysharp/HttpClientTestServer.git
6 changes: 5 additions & 1 deletion YetAnotherHttpHandler.slnx
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,12 @@
<File Path=".github/workflows/build-release.yml" />
</Folder>
<Folder Name="/tests/">
<Project Path="test/YetAnotherHttpHandler.StandaloneTestServer/YetAnotherHttpHandler.StandaloneTestServer.csproj" />
<Project Path="test/YetAnotherHttpHandler.Test/YetAnotherHttpHandler.Test.csproj" />
</Folder>
<Folder Name="/tests/external/">
<Project Path="external/HttpClientTestServer/src/HttpClientTestServer.Abstractions/HttpClientTestServer.Abstractions.csproj" />
<Project Path="external/HttpClientTestServer/src/HttpClientTestServer.Launcher.Container/HttpClientTestServer.Launcher.Container.csproj" />
<Project Path="external/HttpClientTestServer/src/HttpClientTestServer/HttpClientTestServer.csproj" />
</Folder>
<Project Path="src/YetAnotherHttpHandler/YetAnotherHttpHandler.csproj" />
</Solution>
1 change: 1 addition & 0 deletions external/HttpClientTestServer
Submodule HttpClientTestServer added at 0f8be7
9 changes: 0 additions & 9 deletions test/YetAnotherHttpHandler.StandaloneTestServer/Program.cs

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

4 changes: 2 additions & 2 deletions test/YetAnotherHttpHandler.Test/BackPressureTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public async Task FlushTest(int size)
{
using var httpHandler = new YetAnotherHttpHandler();
using var client = new HttpClient(httpHandler);
await using var server = await LaunchServerAsync<TestServerForHttp1AndHttp2>(TestWebAppServerListenMode.InsecureHttp1Only);
await using var server = await LaunchServerAsync(TestServerListenMode.InsecureHttp1Only);

var numRequests = Environment.ProcessorCount + 1; // more than the number of tokio worker threads

Expand All @@ -36,4 +36,4 @@ public async Task FlushTest(int size)

foreach (var stream in pendingStreams) await stream.DisposeAsync();
}
}
}
46 changes: 12 additions & 34 deletions test/YetAnotherHttpHandler.Test/ClientCertificateTest.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
using System.Security.Cryptography.X509Certificates;
using System.Security.Cryptography.X509Certificates;
using Cysharp.Net.Http;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Server.Kestrel.Https;
using HttpClientTestServer;

namespace _YetAnotherHttpHandler.Test;

Expand All @@ -12,34 +10,14 @@ public ClientCertificateTest(ITestOutputHelper testOutputHelper) : base(testOutp
{
}

protected Task<TestWebAppServer> LaunchServerAsync<T>(Action<WebApplicationBuilder>? configure = null)
where T : ITestServerBuilder
{
return LaunchServerAsync<T>(TestWebAppServerListenMode.SecureHttp1AndHttp2, builder =>
{
// Use self-signed certificate for testing purpose.
builder.WebHost.ConfigureKestrel(options =>
{
options.ConfigureHttpsDefaults(options =>
{
options.ServerCertificate = new X509Certificate2("Certificates/localhost.pfx");
options.ClientCertificateMode = ClientCertificateMode.RequireCertificate;
options.ClientCertificateValidation = (certificate2, chain, policyError) =>
{
return certificate2.Subject == "CN=client.example.com";
};
});
});

configure?.Invoke(builder);
});
}
protected Task<ITestServer> LaunchServerAsync()
=> LaunchServerAsync(new TestServerOptions(ListenHttpProtocols.Http1AndHttp2, isSecure: true) { EnableClientCertificateValidation = true });

[Fact]
public async Task NotSet()
{
// Arrange
await using var server = await LaunchServerAsync<TestServerForHttp1AndHttp2>();
await using var server = await LaunchServerAsync();
using var httpHandler = new YetAnotherHttpHandler()
{
//ClientAuthCertificates = File.ReadAllText("./Certificates/client.crt"),
Expand All @@ -61,7 +39,7 @@ public async Task NotSet()
public async Task UseClientCertificate()
{
// Arrange
await using var server = await LaunchServerAsync<TestServerForHttp1AndHttp2>();
await using var server = await LaunchServerAsync();
using var httpHandler = new YetAnotherHttpHandler()
{
ClientAuthCertificates = File.ReadAllText("./Certificates/client.crt"),
Expand All @@ -78,12 +56,12 @@ public async Task UseClientCertificate()
// Assert
Assert.Equal("__OK__", result);
}

[Fact]
public async Task Invalid()
{
// Arrange
await using var server = await LaunchServerAsync<TestServerForHttp1AndHttp2>();
await using var server = await LaunchServerAsync();
using var httpHandler = new YetAnotherHttpHandler()
{
ClientAuthCertificates = File.ReadAllText("./Certificates/client_unknown.crt"), // CN=unknown.example.com
Expand All @@ -104,7 +82,7 @@ public async Task Invalid()
public async Task Reference_SocketHttpHandler_NotSet()
{
// Arrange
await using var server = await LaunchServerAsync<TestServerForHttp1AndHttp2>();
await using var server = await LaunchServerAsync();
using var httpHandler = new SocketsHttpHandler();
httpHandler.SslOptions.RemoteCertificateValidationCallback = (sender, certificate, chain, errors) => true;
var httpClient = new HttpClient(httpHandler);
Expand All @@ -121,7 +99,7 @@ public async Task Reference_SocketHttpHandler_NotSet()
public async Task Reference_SocketHttpHandler_UseClientCertificate()
{
// Arrange
await using var server = await LaunchServerAsync<TestServerForHttp1AndHttp2>();
await using var server = await LaunchServerAsync();
using var httpHandler = new SocketsHttpHandler();
httpHandler.SslOptions.RemoteCertificateValidationCallback = (sender, certificate, chain, errors) => true;
httpHandler.SslOptions.ClientCertificates = new X509CertificateCollection()
Expand All @@ -143,7 +121,7 @@ public async Task Reference_SocketHttpHandler_UseClientCertificate()
public async Task Reference_SocketHttpHandler_Invalid()
{
// Arrange
await using var server = await LaunchServerAsync<TestServerForHttp1AndHttp2>();
await using var server = await LaunchServerAsync();
using var httpHandler = new SocketsHttpHandler();
httpHandler.SslOptions.RemoteCertificateValidationCallback = (sender, certificate, chain, errors) => true;
httpHandler.SslOptions.ClientCertificates = new X509CertificateCollection()
Expand All @@ -159,4 +137,4 @@ public async Task Reference_SocketHttpHandler_Invalid()
// Assert
Assert.IsType<HttpRequestException>(ex);
}
}
}
35 changes: 0 additions & 35 deletions test/YetAnotherHttpHandler.Test/Helpers/TestServerHelper.cs

This file was deleted.

Loading
Loading