chore(api): fix integration-test Jwt:SecretKey length (>=32 bytes) - #176
Merged
Conversation
WebApplicationFactory<Program> loads config from the Orbit.Api content
root, where appsettings.json carries a 27-byte "REPLACE-IN-DEVELOPMENT-JSON"
placeholder for Jwt:SecretKey. JwtSettings.Validate() requires >=32 bytes,
so every integration test threw at startup
("Jwt:SecretKey must be at least 32 bytes (27 provided)").
The test project's own appsettings.json is never loaded by the factory
(content root resolves to src/Orbit.Api), so its valid key was dead config.
Inject a test-only secret via UseSetting in the factory instead. Production
validator is unchanged.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Correct minimal fix for a pre-existing startup blocker. UseSetting is the right mechanism — it injects a config value that wins over appsettings files regardless of content root, so the 27-byte placeholder in src/Orbit.Api/appsettings.json is overridden cleanly. The injected key is 47 bytes (ASCII), satisfying the JwtSettings.Validate() ≥32-byte guard. Production validator and production secrets are untouched. No contract changes, no CLAUDE.md violations.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Set a test-only
Jwt:SecretKey(>=32 bytes, ASCII) for the integration-test host viaUseSettinginIntegrationTestWebApplicationFactory.Why
This is a pre-existing failure on
mainthat blocks the entiretests/Orbit.IntegrationTestssuite at startup — it is not introduced by any feature branch. Every test threw before reaching any assertion:Root cause
WebApplicationFactory<Program>resolves its content root tosrc/Orbit.Api(per the generatedMvcTestingAppManifest.json), so the host loadssrc/Orbit.Api/appsettings.json, whereJwt:SecretKeyis the placeholder"REPLACE-IN-DEVELOPMENT-JSON"— exactly 27 bytes.JwtSettings.Validate()(called at startup) requires >=32 bytes for HMAC-SHA256 and throws.The test project's own
tests/Orbit.IntegrationTests/appsettings.jsondoes contain a valid 50-byte key, but it is never loaded by the factory (content root is the API project, not the test assembly dir), so it was dead config for this path.Fix
Inject a clearly test-only secret through the web host builder in the factory. This feeds the configuration the host actually reads, independent of content root. The production validator and production secrets are untouched — no weakening of
JwtSettings.Validate().Validation (in worktree)
dotnet build— clean (0 errors).dotnet test tests/Orbit.IntegrationTests --filter "FullyQualifiedName~AuthControllerTests":Jwt:SecretKey must be at least 32 bytes (27 provided).The ConnectionString property has not been initialized), an unrelated env-specific empty-connection-string in this sandbox shell. On an environment whereorbit_testis reachable, the suite boots and connects.Impact
Unblocks the integration suite for in-flight PRs (#81 / #78 / #79).
🤖 Generated with Claude Code