From 413b1aba02da5b993f69bcb5019b785bd824ad12 Mon Sep 17 00:00:00 2001 From: maxiar Date: Thu, 15 Oct 2026 10:33:13 -0300 Subject: [PATCH] fix(tests): parse appsettings with comments in the CORS configuration tests The ASP.NET configuration loader accepts comments and trailing commas in appsettings files, but CorsConfigurationTests reads them with a strict JsonDocument.Parse. The first project that documents a setting inline (a common thing to do in a scaffolded app) gets a JsonReaderException from a test that has nothing to do with the comment. Parse with the same leniency. Co-Authored-By: Claude Opus 5.5 --- .../Framework.Tests/Web/CorsConfigurationTests.cs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/Tests/Framework.Tests/Web/CorsConfigurationTests.cs b/src/Tests/Framework.Tests/Web/CorsConfigurationTests.cs index 930b28eb84..e3cda6b673 100644 --- a/src/Tests/Framework.Tests/Web/CorsConfigurationTests.cs +++ b/src/Tests/Framework.Tests/Web/CorsConfigurationTests.cs @@ -4,6 +4,14 @@ namespace Framework.Tests.Web; public sealed class CorsConfigurationTests { + // appsettings files are read by the ASP.NET configuration loader, which accepts comments and + // trailing commas, so parse them the same way. + private static readonly JsonDocumentOptions AppSettingsJson = new() + { + CommentHandling = JsonCommentHandling.Skip, + AllowTrailingCommas = true, + }; + [Theory] [InlineData("appsettings.json")] [InlineData("appsettings.Production.json")] @@ -13,7 +21,7 @@ public void AllowedMethods_Should_IncludePatch_When_RestrictedCorsIsConfigured(s string path = Path.Combine(AppContext.BaseDirectory, "HostConfiguration", fileName); // Act - using JsonDocument document = JsonDocument.Parse(File.ReadAllText(path)); + using JsonDocument document = JsonDocument.Parse(File.ReadAllText(path), AppSettingsJson); JsonElement corsOptions = document.RootElement.GetProperty("CorsOptions"); string[] allowedMethods = corsOptions .GetProperty("AllowedMethods") @@ -47,7 +55,7 @@ public void AllowedHeaders_Should_IncludeClientHeader_When_RestrictedCorsIsConfi string path = Path.Combine(AppContext.BaseDirectory, "HostConfiguration", fileName); // Act - using JsonDocument document = JsonDocument.Parse(File.ReadAllText(path)); + using JsonDocument document = JsonDocument.Parse(File.ReadAllText(path), AppSettingsJson); string[] allowedHeaders = document.RootElement .GetProperty("CorsOptions") .GetProperty("AllowedHeaders")