Skip to content

fix: Provide default JWT secret for CI tests on fork PRs#282

Merged
nbhansen merged 1 commit intoaau-giraf:dev-mainfrom
nbhansen:fix/ci-jwt-secret
Feb 4, 2026
Merged

fix: Provide default JWT secret for CI tests on fork PRs#282
nbhansen merged 1 commit intoaau-giraf:dev-mainfrom
nbhansen:fix/ci-jwt-secret

Conversation

@nbhansen
Copy link
Contributor

@nbhansen nbhansen commented Feb 4, 2026

Summary

GitHub Actions doesn't expose secrets to fork PRs for security reasons. The workflow sets JWT_SECRET from secrets, but for forks it resolves to an empty string (not null). The ?? operator only checks for null, so empty strings were passing through and causing "key length is zero" errors at runtime.

Changes

Program.cs:

  • Remove duplicate ConfigurationBuilder (was inconsistent with builder.Configuration)
  • Handle empty/whitespace strings explicitly with IsNullOrWhiteSpace()

UsersController.cs:

  • Fix GenerateJwt() to handle empty strings the same way
  • This was the actual source of the runtime "key length is zero" error

CustomApplicationFactory.cs:

  • Use static constructor to set JWT_SECRET before any host creation
  • Remove unused JwtSecretConfig class and null check
  • Add AddInMemoryCollection for belt-and-suspenders config injection

Test Plan

  • CI passes on this fork PR
  • All 98 VTA.Tests pass
  • All 25 SyncService.Tests pass

Note

This PR should be merged first before other fork PRs, as it fixes CI for all fork contributions.

GitHub Actions doesn't expose secrets to fork PRs for security reasons.
The workflow sets JWT_SECRET from secrets, but for forks it becomes an
empty string (not null). The ?? operator only checks for null, so empty
strings passed through and caused "key length is zero" errors.

Changes to Program.cs:
- Remove duplicate ConfigurationBuilder, use builder.Configuration
- Handle empty/whitespace strings explicitly with IsNullOrWhiteSpace()

Changes to UsersController.cs:
- Fix GenerateJwt() to handle empty strings the same way
- This was the actual source of the "key length is zero" error

Changes to CustomApplicationFactory.cs:
- Use static constructor to set JWT_SECRET before any host creation
- Remove unused JwtSecretConfig class
- Add AddInMemoryCollection for config-based injection

This allows fork PRs to pass CI without requiring GitHub secrets access.
@nbhansen nbhansen merged commit 7a3730a into aau-giraf:dev-main Feb 4, 2026
2 checks passed
@nbhansen nbhansen deleted the fix/ci-jwt-secret branch February 4, 2026 14:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Development

Successfully merging this pull request may close these issues.

1 participant