justeattakeaway / httpclient-interception

A .NET library for intercepting server-side HTTP requests
https://tech.just-eat.com/2017/10/02/reliably-testing-http-integrations-in-a-dotnet-application/
Apache License 2.0
354 stars 27 forks source link

Test Failures Due to Authorization Issues After Upgrading to .NET 8 and HttpClient-Interception #716

Open dasadhanala opened 7 months ago

dasadhanala commented 7 months ago

We recently upgraded our project to .NET 8 and updated the HttpClient-Interception package to its latest version. Following this upgrade, we are encountering an issue where multiple tests are failing due to authorization failures.

Environment .NET Version: 8.0 HttpClient-Interception Version: 4.1.0 OS: Windows

Issue Description Prior to the upgrade, all our tests were passing consistently. The tests that are failing are specifically those that rely on HttpClient-Interception for mocking HTTP requests and responses. These tests are now failing with an "unauthorized" error, although no changes were made to the test setup or the codebase, apart from the version upgrades.

Steps to Reproduce Upgrade the project to .NET 8. Upgrade HttpClient-Interception to the latest version. Run the existing tests which involve HTTP request mocking.

Expected Behavior Tests that were passing previously should continue to pass after the upgrade, assuming no changes to the test logic or setup.

Actual Behavior Tests involving mocked HTTP requests are failing with an "unauthorized" error.

Additional Information Error logs/output:
Shouldly.ShouldAssertException : response.response.StatusCode should be HttpStatusCode.Created but was HttpStatusCode.Unauthorized

Could you please provide any insights into why this might be happening? Are there any breaking changes in the latest version of HttpClient-Interception that could affect authorization? Also, are there any additional configurations or steps that we need to consider after upgrading to .NET 8 and the latest version of HttpClient-Interception?

Any guidance or suggestions would be greatly appreciated.

Thank you for your help!

martincostello commented 7 months ago

Could you provide a minimal reproducible sample project demonstrating the failure? Otherwise it's hard to guide you on what might be wrong.

There shouldn't be any changes in the library that would break things for .NET 8. I use this library extensively in my personal projects that intercept authorization-related requests to third-party OAuth providers, and they haven't had any issues related to this library.

Two changes I am aware of that have impacted things using this library related to .NET 8 are:

  1. Some of the ASP.NET Core OAuth providers were updated to use newer API versions, causing paths to change. In these cases, the interceptions needed updating - example https://github.com/martincostello/alexa-london-travel-site/commit/be766f127a2bda964f9f8dfd0aa5de53616ccfe7.
  2. Versions of AWS SDKs targeting net8.0 use HttpClient.Send() in some places, which wasn't supported for interception. This support was added by #694 which was part of the 4.1.0 release.