Files
nezha_domains/cmd/dashboard/dashboard_credential_wiring_test.go
T
xvkong233 3ad985f36e fix(nat): scrub dashboard-issued credentials from all accepted token channels
The initial selective strip covered only the Authorization header, but the
dashboard also accepts its JWT via the ?token= query parameter and the
nz-jwt cookie (jwt.go TokenLookup channels). A dashboard credential arriving
through those channels would still reach a NAT backend.

Apply the same classify-then-strip rule to all three channels at NAT
ingress: values verified as dashboard-issued are removed, foreign values
are preserved byte-for-byte. Adds a ServeNAT flow test exercising the live
classifier and a wiring test pinning the gate injection in main().
2026-10-01 11:17:45 +00:00

28 lines
977 B
Go

package main
import (
"testing"
"github.com/nezhahq/nezha/cmd/dashboard/rpc"
)
// TestWireNATDashboardCredentialGate pins the NAT ingress wiring contract:
// main() must connect the real dashboard-credential classifiers
// (controller.IsDashboardCredential / controller.IsDashboardCredentialValue)
// through wireNATDashboardCredentialGate before any listener serves traffic.
// That the wired functions really classify per channel is pinned end to end
// by the controller package's real-classifier NAT flow test.
func TestWireNATDashboardCredentialGate(t *testing.T) {
if rpc.NATDashboardCredentialGateWired() {
t.Fatal("NAT dashboard credential gate already wired before the test")
}
wireNATDashboardCredentialGate()
if !rpc.NATDashboardCredentialGateWired() {
t.Fatal("wireNATDashboardCredentialGate left the NAT dashboard credential gate unwired")
}
// Leave the process in the wired state main() establishes.
t.Cleanup(wireNATDashboardCredentialGate)
}