Skip to content

Commit

Permalink
Merge pull request #97 from Cysharp/feature/AddHttp1FixTest
Browse files Browse the repository at this point in the history
Add unit test for #96
  • Loading branch information
mayuki authored Sep 24, 2024
2 parents dbe2765 + 0f63dbf commit 34f25ff
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions test/YetAnotherHttpHandler.Test/Http1Test.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using Microsoft.AspNetCore.Hosting;
using System.IO.Pipelines;
using System.Net;
using System.Security.Cryptography.X509Certificates;
using Xunit.Abstractions;

namespace _YetAnotherHttpHandler.Test;
Expand Down Expand Up @@ -153,4 +155,37 @@ public async Task Post_Timeout()
// NOTE: .NET's HttpClient will unwrap OperationCanceledException if an HttpRequestException containing OperationCanceledException is thrown.
Assert.IsAssignableFrom<OperationCanceledException>(ex);
}

[Fact]
public async Task Secure_Get_Ok()
{
// Arrange
using var httpHandler = new Cysharp.Net.Http.YetAnotherHttpHandler()
{
// We need to verify server certificate.
SkipCertificateVerification = false,
RootCertificates = File.ReadAllText("./Certificates/localhost.crt")
};
var httpClient = new HttpClient(httpHandler);
await using var server = await LaunchServerAsync<TestServerForHttp1AndHttp2>(TestWebAppServerListenMode.SecureHttp1Only, builder =>
{
// Use self-signed certificate for testing purpose.
builder.WebHost.ConfigureKestrel(options =>
{
options.ConfigureHttpsDefaults(options =>
{
options.ServerCertificate = new X509Certificate2("Certificates/localhost.pfx");
});
});
});

// Act
var response = await httpClient.GetAsync($"{server.BaseUri}/");
var responseBody = await response.Content.ReadAsStringAsync();

// Assert
Assert.Equal(HttpVersion.Version11, response.Version);
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
Assert.Equal("__OK__", responseBody);
}
}

0 comments on commit 34f25ff

Please sign in to comment.