Skip to content

fix(tests): parse appsettings with comments in the CORS configuration tests - #1448

Merged
iammukeshm merged 2 commits into
fullstackhero:mainfrom
maxiar:fix/cors-tests-tolerate-appsettings-comments-upstream
Nov 3, 2026
Merged

iammukeshm merged 2 commits into
fullstackhero:mainfrom
maxiar:fix/cors-tests-tolerate-appsettings-comments-upstream

Conversation

@maxiar

@maxiar maxiar commented Oct 15, 2026

Copy link
Copy Markdown
Contributor

CorsConfigurationTests (from #1391) reads appsettings.json / appsettings.Production.json with a strict JsonDocument.Parse. The ASP.NET configuration loader accepts comments and trailing commas in those files, so the test is stricter than the runtime.

It doesn't show up here because the template's appsettings has no comments. It does show up as soon as a scaffolded project documents a setting inline, which is how many teams annotate config. The CORS tests then fail with an error that has nothing to do with CORS:

System.Text.Json.JsonReaderException : '/' is invalid after a value. Expected either ',', '}', or ']'. LineNumber: 67 | BytePositionInLine: 4.

The fix parses the files with JsonCommentHandling.Skip and AllowTrailingCommas, the same leniency as the config loader. The test only changes how it parses the files; its assertions are unchanged.

Verification

dotnet test src/Tests/Framework.Tests --filter CorsConfigurationTests   -> 12/12 pass

The run used -p:NuGetAudit=false, because main currently fails restore on the crypto advisories that #1447 fixes. With a comment added to appsettings.json, the old parser throws and the new one passes.

🤖 Generated with Claude Code

maxiar and others added 2 commits October 15, 2026 11:09
… 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 <noreply@anthropic.com>

@iammukeshm iammukeshm left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense. The test should be no stricter than the config loader it stands in for. Thanks!

@iammukeshm
iammukeshm merged commit 996defe into fullstackhero:main Nov 3, 2026
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants