rcourtman
de90519b21
test: Add handleHealth method tests
...
Add 2 tests for health endpoint:
- POST/PUT/DELETE/PATCH return 405 Method Not Allowed
- HEAD is allowed (same as GET)
Coverage: 50% → 83.3%
2025-12-02 02:09:04 +00:00
rcourtman
5ff69a7e35
test: Add adminBypassEnabled tests
...
Add 5 tests to cover all branches:
- Not requested (ALLOW_ADMIN_BYPASS != "1")
- Enabled with PULSE_DEV=true
- Enabled with NODE_ENV=development
- Case-insensitive NODE_ENV check
- Declined when outside dev mode
Coverage: 40% → 100%
2025-12-02 01:53:55 +00:00
rcourtman
7ed8ef2074
test: Add loadTrustedProxyCIDRs tests
...
Cover invalid CIDR, invalid IP, IPv6, and empty entry handling (48% to 100%)
2025-12-02 01:48:41 +00:00
rcourtman
24fbce1281
test: Add LogAuditEvent tests
...
Cover success and failure logging branches (66.7% to 100%)
2025-12-02 01:46:27 +00:00
rcourtman
8f42156781
test: Add SecurityHeadersWithConfig tests
...
Cover all CSP/X-Frame-Options embedding configurations (57.1% to 100%)
2025-12-02 01:44:22 +00:00
rcourtman
07997b3516
test: Add filesystem error tests for SessionStore
...
Cover saveUnsafe (57.9% to 89.5%) and load (55.6% to 74.1%) error paths
2025-12-02 01:40:54 +00:00
rcourtman
21b69607f0
test: Add filesystem error tests for CSRFTokenStore
...
Cover saveUnsafe (57.9% to 89.5%) and load (50.0% to 67.9%) error paths
2025-12-02 01:38:49 +00:00
rcourtman
999f19beed
test: Add filesystem error tests for RecoveryTokenStore.saveUnsafe
...
Cover MkdirAll, WriteFile, and Rename error paths (46.7% to 86.7%)
2025-12-02 01:36:21 +00:00
rcourtman
b3f88d7a8c
test: Add edge case tests for HandleSetupScript
...
Tests method not allowed, missing type parameter, and invalid host
parameter error paths (71.4% to 79.2% coverage).
2025-12-02 01:11:57 +00:00
rcourtman
7d3de1bbcc
test: Add invalid PEM data test for newOIDCHTTPClient
...
Tests the error path when a CA bundle file contains non-PEM data
(81.8% to 86.4% coverage).
2025-12-02 01:00:06 +00:00
rcourtman
1a595b3b2e
test: Add edge cases for UniversalRateLimitMiddleware
...
Cover nil config initialization and static asset bypass paths.
Coverage: UniversalRateLimitMiddleware 87.5% -> 100%
2025-12-02 00:54:37 +00:00
rcourtman
c57c07f827
test: Add edge case for initializeBootstrapToken error path
...
Cover loadOrCreateBootstrapToken failure path.
Coverage: initializeBootstrapToken 92% -> 100%
2025-12-02 00:51:44 +00:00
rcourtman
a5f0482d97
test: Add edge cases for HandleLookup error paths
...
Cover method-not-allowed and missing lookup parameter paths.
Coverage: HandleLookup 88.4% -> 97.7%
2025-12-02 00:49:16 +00:00
rcourtman
6777257a7a
test: Add edge cases for normalizeRequestedScopes
...
- Test blank scope identifier returns error
- Test wildcard-only input returns wildcard scope
Coverage: 89.7% → 96.6% (remaining 3.4% is defensive
unreachable code path)
2025-12-02 00:19:20 +00:00
rcourtman
b5d42f6e2e
test: Add edge case for ensureSettingsWriteScope valid scope
...
Tests the code path when an API token has the settings:write scope,
which allows the operation to proceed.
2025-12-02 00:13:32 +00:00
rcourtman
8597eca010
Fix backup indicator being reset when VMs/Containers are re-polled
...
UpdateVMsForInstance and UpdateContainersForInstance were replacing
guest data without preserving the LastBackup field that was populated
by SyncGuestBackupTimes. This caused backup indicators to always show
"no backup found" since the LastBackup would be wiped every time
guests were polled (which happens more frequently than backup polling).
Now both functions preserve LastBackup from existing data when the
incoming guest data has a zero value.
Related to #762
2025-12-02 00:12:31 +00:00
rcourtman
9baf99d32a
test: Add edge cases for isTrustedProxyIP and GetClientIP
...
Tests empty string, invalid IP, and IP not matching CIDR for
isTrustedProxyIP. Also adds tests for GetClientIP empty RemoteAddr
and X-Real-IP fallback paths.
2025-12-02 00:09:23 +00:00
rcourtman
02419827b6
test: Add tests for hostAgentSearchCandidates parameter variants
...
Tests all code paths: strict mode (both params), platform only,
and no params (generic paths).
2025-12-02 00:03:19 +00:00
rcourtman
7407447bbf
test: Add edge case for handleServerInfo method not allowed
...
Tests that POST requests to /api/server/info return 405.
2025-12-02 00:01:17 +00:00
rcourtman
4751f57187
test: Add edge case for capturePublicURLFromRequest nil inputs
...
Tests the early return paths when router, request, or config are nil.
2025-12-01 23:59:17 +00:00
rcourtman
b9f9077496
test: Add edge case for canCapturePublicURL nil inputs
...
Tests the early return paths when config or request are nil.
2025-12-01 23:56:59 +00:00
rcourtman
f0688db9af
test: Add edge case for recovery token load read error
...
Tests the error logging path when os.ReadFile fails with an error
other than ErrNotExist. Uses a directory in place of the file.
2025-12-01 23:54:42 +00:00
rcourtman
347d6b1cbb
test: Add edge case for writeErrorResponse encode failure
...
Tests the error logging path when json.Encode fails due to a
write error on the ResponseWriter.
2025-12-01 23:52:21 +00:00
rcourtman
90d81f2217
test: Add edge cases for markAutoRegistered empty inputs
...
Tests the early return paths when nodeType or nodeName are empty.
2025-12-01 23:50:10 +00:00
rcourtman
3280fad5ae
test: Add edge case for clearBootstrapToken remove failure
...
Tests the warning log path when os.Remove fails with an error other
than ErrNotExist. Uses a directory with contents to trigger ENOTEMPTY.
2025-12-01 23:47:58 +00:00
rcourtman
678c5aac5f
test: Add edge cases for initializeBootstrapToken
...
- Nil router and nil config handling (no panic)
- OIDC enabled clears bootstrap token
Coverage: 80% to 92%.
2025-12-01 23:40:22 +00:00
rcourtman
8c40c7faa3
test: Add panic recovery test for ErrorHandler
...
Tests that panics in handlers are recovered and return 500.
Coverage: 91.7% to 100%.
2025-12-01 23:37:50 +00:00
rcourtman
d0c2524353
test: Add edge case for handleValidateBootstrapToken invalid JSON
...
Tests invalid JSON body triggers json.Decode error and returns 400.
Coverage: 90.5% to 100%.
2025-12-01 23:35:40 +00:00
rcourtman
890178acb0
test: Add edge case for RequireScope empty scope
...
Empty scope should allow all requests through without checking token.
Coverage: 84.6% to 100%.
2025-12-01 23:33:11 +00:00
rcourtman
0fa717a78a
test: Add edge case for normalizeNodeHost URL parse error
...
Control character (null byte) triggers url.Parse error, covering the
'invalid host format' error branch. Coverage: 96.3% to 100%.
2025-12-01 23:28:32 +00:00
rcourtman
08765c7b59
test: Add edge case for DemoModeMiddleware WebSocket POST upgrade
...
Tests WebSocket upgrade with POST method in demo mode, ensuring the
websocket check branch is exercised after the GET/HEAD/OPTIONS check.
Coverage: 90% to 100%.
2025-12-01 23:24:06 +00:00
rcourtman
a5369ba2cd
test: Add test for ErrorHandler empty URL path normalization
...
Covers the fix for issue #334 where empty path is normalized to '/'.
Coverage: 87.5% to 91.7%.
2025-12-01 23:21:07 +00:00
rcourtman
1fdb15c779
test: Add edge case tests for auth helper functions
...
- respondMissingScope: nil writer handling (80% to 100%)
- attachAPITokenRecord: nil record handling (80% to 100%)
- getAPITokenRecordFromRequest: wrong type and missing value (87.5% to 100%)
2025-12-01 23:15:04 +00:00
rcourtman
c71fb694bb
test: Add edge case test for addQueryParam URL parse error
...
Add test case for URL containing control character (null byte)
which triggers url.Parse error and returns path unchanged.
Coverage improved from 88.9% to 100%.
2025-12-01 23:08:36 +00:00
rcourtman
37cc97952f
test: Add comprehensive test cases for isPrivateIP function
...
Expand test coverage from 5 cases to 26 cases:
- Public IPv4/IPv6 addresses
- All RFC1918 private ranges (10.x, 172.16-31.x, 192.168.x)
- Loopback addresses (127.x.x.x, ::1)
- Link-local addresses (169.254.x.x, fe80::)
- Link-local multicast (224.0.0.x, ff02::)
- Unique local IPv6 (fc00::/7, fd00::)
- Edge cases: empty string, invalid IP, invalid format
- Addresses with port numbers
Coverage unchanged at 93.8% (remaining 6.2% is defensive
error handling for hardcoded valid CIDRs).
2025-12-01 22:54:56 +00:00
rcourtman
ef380df362
test: Add edge case tests for normalizeNodeHost function
...
Add 6 new test cases covering previously untested branches:
- Empty host returns error
- Whitespace-only host returns error
- Unknown node type keeps host without port
- Docker node type keeps host without port
- IPv4 address gets default port
- IPv4 with custom port preserved
Coverage improved from 92.6% to 96.3%.
2025-12-01 22:49:29 +00:00
rcourtman
4019b3006b
test: Add tests for instance lookup and setup token validation
...
- Add TestFindInstanceNameByHost (12 test cases):
- PVE instance lookup by host
- PBS instance lookup by host
- Unknown node types return empty
- Empty config handling
- Add TestValidateSetupToken (8 test cases):
- Empty token returns false
- Valid/expired/used setup codes
- Valid/expired recent setup tokens
- Non-existent token handling
- Precedence of setup codes over recent tokens
Both functions now have 100% coverage of their logic paths.
2025-12-01 22:19:30 +00:00
rcourtman
67a351fbd9
test: Add tests for webhook template generation and bootstrap token functions
...
- Add comprehensive tests for generatePayloadFromTemplateWithService covering:
- Valid JSON template rendering
- Invalid template syntax error handling
- Template execution errors
- ntfy service (plain text, skips JSON validation)
- Various services (discord, telegram, pagerduty) JSON validation
- Template function usage (upper, title)
- Numeric and boolean values in templates
- Special characters and empty template edge cases
- Add tests for bootstrapTokenValid covering:
- Nil router handling
- Empty hash and empty token cases
- Valid token validation
- Invalid token rejection
- Whitespace trimming
- Add tests for clearBootstrapToken covering:
- Nil router safety
- Token file deletion
- Missing file handling
- Empty path handling
2025-12-01 22:07:40 +00:00
rcourtman
3233c48986
test: Add tests for API helper functions
...
- isRecentlyAutoRegistered: expiry logic, cleanup behavior
- clearAutoRegistered: key deletion, empty input handling
- normalizeDockerAgentArch: all arch variants, case handling, trimming
2025-12-01 21:33:45 +00:00
rcourtman
4973eb4c8a
test: Improve coverage for cluster config handler functions
...
- deriveSchemeAndPort: 87.5% → 100%
- Empty/whitespace string handling
- Invalid URL parsing fallback
- Host without port
- ensureHostHasPort: 91.7% → 100%
- Empty port returns host unchanged
- Protocol-relative URL handling (//host)
2025-12-01 14:46:00 +00:00
rcourtman
c6030d1b13
test: Add tests for ResetRateLimitForIP function
...
- Test nil globalRateLimitConfig early return (no panic)
- Test actual rate limit reset clears IP from limiter
- Improves coverage from 80% to 100%
2025-12-01 14:38:26 +00:00
rcourtman
737c02983f
test: Improve coverage for security utility functions
...
- Add fmt.Stringer test cases for isEmptyInterface (80% -> 100%)
- Expand isTrustedNetwork tests with edge cases (80% -> 100%)
- Empty/invalid IP strings
- Invalid CIDR handling
- Whitespace trimming in CIDRs
- Multiple network matching
2025-12-01 14:33:31 +00:00
rcourtman
b863b2473d
test: Add tests for config handler utility functions
...
- TestSanitizeErrorMessage: All operation types and error hiding
- TestFindExistingGuestURL: Node matching and edge cases
- TestMatchInstanceNameByHost: Host normalization and matching
Coverage: api 27.7% → 28.0%
2025-12-01 14:09:35 +00:00
rcourtman
be5a6eb97e
test: Add tests for OIDC handler utility functions
...
- sanitizeOIDCReturnTo: path validation, protocol-relative URL rejection
- addQueryParam: URL building, encoding, fragment preservation
- extractStringClaim: type handling (string, []string, []interface{})
- extractStringSliceClaim: slice extraction with comma/space splitting
- matchesValue: case-insensitive value matching
- matchesDomain: email domain validation with @ handling
- intersects: set intersection with case normalization
- buildRedirectURL: proxy header handling (X-Forwarded-Proto/Host)
Coverage: api 26.7% → 27.7%
2025-12-01 13:56:38 +00:00
rcourtman
c2de40d696
test: Add error path tests for loadOrCreateBootstrapToken
...
Cover all error branches in bootstrap token loading:
- Empty/whitespace dataPath validation
- os.MkdirAll failure (directory creation blocked by file)
- os.WriteFile failure (read-only directory)
- os.ReadFile failure (permission denied on existing file)
- Empty file contents after read
- Whitespace-only file contents
Also adds test for generateBootstrapToken helper function.
2025-12-01 13:00:27 +00:00
rcourtman
72420a616a
ADA changes (auto-committed by cron safety check)
2025-12-01 11:20:57 +00:00
rcourtman
22b429a1c9
test: Add unit tests for validateIPAddress, validatePort, defaultPortForNodeType
...
Cover API validation functions that were previously untested:
- validateIPAddress: IPv4/IPv6 validation with edge cases
- validatePort: Port range validation (1-65535)
- defaultPortForNodeType: Proxmox node type to default port mapping
2025-12-01 11:06:50 +00:00
rcourtman
82c7925895
refactor: Remove dead HandleTestExistingNode function
...
This function was superseded by HandleTestNode which is wired to the
router at /api/config/nodes/{id}/test. The old function was not
registered in the router and served no purpose.
Removes 121 lines of unused code.
2025-12-01 10:21:50 +00:00
rcourtman
5fcd4e9cb9
Add unit tests for extractHostAndPort utility function
...
27 test cases covering URL/host:port parsing for node configuration:
- Scheme stripping (http://, https://)
- Path removal from URLs
- IPv4 addresses with and without ports
- IPv6 addresses (bracketed with port, unbracketed)
- Edge cases (empty string, localhost, port-only)
- Error cases (malformed brackets)
Documents current behavior: bracketed IPv6 without port returns error
(net.SplitHostPort limitation).
2025-12-01 01:19:10 +00:00
rcourtman
a21dd8c3d2
Add unit tests for system_settings.go map utility functions
...
52 test cases covering:
- firstValueForKeys: 18 cases for multi-key lookup with priority ordering
- hasAnyKey: 15 cases for key existence checking
- discoveryConfigMap: 19 cases for nested config extraction with camelCase/snake_case support
Tests verify edge cases including nil maps, empty key slices, type assertion failures,
and priority ordering for field name variants used in configuration parsing.
2025-12-01 01:05:07 +00:00