[NoBrainer] Avoid HTTPS redirection warnings in integration test logs

I recently implemented ASP.NET Core integration tests in a project I am working on. I have followed the official documentation, which was extremely helpful.

The system under test (SUT) is an ASP.NET Core Web API (.NET 7) implementing backends for frontends (BFF) pattern. To follow security best practices we enabled HTTPS redirection in all stages (development, test and production) including local development environment by using HTTPS Redirection Middleware.

Program.cs

var builder = WebApplication.CreateBuilder(args);
...
app.UseHttpsRedirection();
...

When executing the integration tests (i.e. in an Azure DevOps YAML pipeline) the following warning appears multiple times and clutters the logs which makes it harder to find failing tests.

warn: Microsoft.AspNetCore.HttpsPolicy.HttpsRedirectionMiddleware[3]
Failed to determine the https port for redirect.

To avoid these warnings, the default value of BaseAddress (http://localhost) in WebApplicationFactoryClientOptions has to be overridden as follows.

new WebApplicationFactoryClientOptions
{
    BaseAddress = new Uri("https://localhost")
}

Now the HttpClient directly calls the HTTPS endpoints of the API and therefore the above mentioned warning is not logged anymore.

Leave a comment

Website Powered by WordPress.com.

Up ↑