fix(relay): authenticate endpoints and fail closed on missing routes

This commit is contained in:
sagitchu
2026-11-08 23:31:08 +08:00
parent 46bfb86c1b
commit 7f0177491b
50 changed files with 5405 additions and 277 deletions
@@ -37,7 +37,7 @@ type cleanupAgent struct {
commands []cleanupAgentCommand
}
func newCleanupAgent(t *testing.T) *cleanupAgent {
func newCleanupAgent(t *testing.T, setup ...func(*repo.Repository)) *cleanupAgent {
t.Helper()
r, err := repo.Open(filepath.Join(t.TempDir(), "cleanup.db"))
if err != nil {
@@ -48,6 +48,11 @@ func newCleanupAgent(t *testing.T) *cleanupAgent {
if err := r.DB().Create(&model.Node{ID: 1, Name: "relay", Secret: secret, ServerIP: "127.0.0.1", Port: "30000", Status: 1}).Error; err != nil {
t.Fatal(err)
}
// Register test-local database callbacks before WebSocket goroutines can
// execute them. Keep registries immutable until the fixture is closed.
for _, configure := range setup {
configure(r)
}
server := ws.NewServer(r, "test-jwt-secret")
online := make(chan struct{})
server.SetNodeOnlineHook(func(int64) { close(online) })