mirror of
https://github.com/J3vb/OwnCord.git
synced 2026-09-03 03:50:00 +03:00
Applied from a deadcode (RTA from mains, all build tags) sweep with
per-symbol adversarial verification:
Deleted (nothing but their own self-tests used them):
- admin.Handler (deprecated since Phase 6; production mounts NewHandler)
plus its two self-tests
- ws.Hub.broadcastVoiceStateUpdate + wrapper + two self-tests (pre-V2
leftover; the live voice_state path is the hub voice routines)
- ws.VoiceLeaveEvent + methods ('retained as scaffolding', never
constructed in production; MsgTypeVoiceLeaveBC stays — live via the
leave routine)
- ws.parseIdentity (production calls parseParticipantIdentity directly;
ParseIdentityForTest now exercises the real parser)
- telemetry.Float64 (String/Int64 are used; the float case is covered by
the otel-tagged internal test, re-addable when a caller appears)
Moved into export_test.go so they leave the production binary (all
callers are same-package tests): the eight ws test-client constructors
and voice/E2EE setters from ws/client.go, admin.SetBackupBaseDir
(new admin/export_test.go), api.SecurityHeaders (test-only wrapper;
production uses SecurityHeadersWithTLS — docs/api.md updated to the
real name). Client.getVoiceJoinToken/setVoiceChID inlined into their
existing ForTest wrappers; TestSetVoiceChID_* self-tests deleted.
Kept after verification: updater.SetBaseURL (11 cross-package test call
sites) and telemetry.resetAppMetricsForInit (live under -tags otel —
untagged deadcode false positive).
Full gate green: gofmt/vet, 4 build-tag variants, full suite, deadlock,
race.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
53 lines
1.7 KiB
Go
53 lines
1.7 KiB
Go
package api
|
|
|
|
import (
|
|
"context"
|
|
"net/http"
|
|
)
|
|
|
|
// HandleMetricsForTest exposes handleMetrics for use in external tests.
|
|
var HandleMetricsForTest = handleMetrics
|
|
|
|
// HandleLiveKitHealthForTest exposes handleLiveKitHealth for use in external tests.
|
|
func HandleLiveKitHealthForTest(healthCheck func(context.Context) (bool, error)) http.HandlerFunc {
|
|
// Inline the logic since handleLiveKitHealth requires a *ws.Hub.
|
|
return func(w http.ResponseWriter, r *http.Request) {
|
|
ok, err := healthCheck(r.Context())
|
|
if ok {
|
|
writeJSON(w, http.StatusOK, livekitHealthResponse{
|
|
Status: "ok",
|
|
LiveKitReachable: true,
|
|
})
|
|
return
|
|
}
|
|
|
|
errMsg := "unknown"
|
|
if err != nil {
|
|
errMsg = err.Error()
|
|
}
|
|
writeJSON(w, http.StatusServiceUnavailable, livekitHealthResponse{
|
|
Status: "degraded",
|
|
LiveKitReachable: false,
|
|
Error: errMsg,
|
|
})
|
|
}
|
|
}
|
|
|
|
// IsPrivateIPForTest exposes isPrivateIP for use in external tests.
|
|
var IsPrivateIPForTest = isPrivateIP
|
|
|
|
// SetGIFUpstreamForTest points the GIF proxy at a stub upstream and returns a
|
|
// restore func. The production transport uses the SSRF-guarded dialer, which
|
|
// refuses loopback addresses, so tests must supply their own client too.
|
|
func SetGIFUpstreamForTest(baseURL string, client *http.Client) func() {
|
|
prevBase, prevClient := gifAPIBase, gifClient
|
|
gifAPIBase, gifClient = baseURL, client
|
|
return func() { gifAPIBase, gifClient = prevBase, prevClient }
|
|
}
|
|
|
|
// SecurityHeaders is SecurityHeadersWithTLS with TLS disabled (no HSTS).
|
|
// Test-only convenience — production always goes through SecurityHeadersWithTLS.
|
|
func SecurityHeaders(next http.Handler) http.Handler {
|
|
return SecurityHeadersWithTLS("")(next)
|
|
}
|