fix: sécuriser shutdown, config par défaut et reconnexion socket
Co-authored-by: aider (openrouter/openai/gpt-5.3-codex) <aider@aider.chat>
This commit is contained in:
@ -2,6 +2,7 @@ package config
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
@ -211,3 +212,51 @@ func TestToJSON(t *testing.T) {
|
||||
t.Error("ToJSON() result doesn't contain 'eth0'")
|
||||
}
|
||||
}
|
||||
|
||||
func TestLoad_DefaultConfigFileAbsent_DoesNotFail(t *testing.T) {
|
||||
t.Setenv("JA4SENTINEL_INTERFACE", "")
|
||||
t.Setenv("JA4SENTINEL_PORTS", "")
|
||||
t.Setenv("JA4SENTINEL_BPF_FILTER", "")
|
||||
t.Setenv("JA4SENTINEL_FLOW_TIMEOUT", "")
|
||||
|
||||
tempDir := t.TempDir()
|
||||
oldWD, err := os.Getwd()
|
||||
if err != nil {
|
||||
t.Fatalf("Getwd() error = %v", err)
|
||||
}
|
||||
defer func() {
|
||||
_ = os.Chdir(oldWD)
|
||||
}()
|
||||
|
||||
if err := os.Chdir(tempDir); err != nil {
|
||||
t.Fatalf("Chdir() error = %v", err)
|
||||
}
|
||||
|
||||
_ = os.Remove(filepath.Join(tempDir, "config.yml"))
|
||||
|
||||
loader := NewLoader("")
|
||||
cfg, err := loader.Load()
|
||||
if err != nil {
|
||||
t.Fatalf("Load() error = %v", err)
|
||||
}
|
||||
|
||||
if cfg.Core.Interface != api.DefaultInterface {
|
||||
t.Errorf("Interface = %q, want %q", cfg.Core.Interface, api.DefaultInterface)
|
||||
}
|
||||
if len(cfg.Core.ListenPorts) == 0 || cfg.Core.ListenPorts[0] != api.DefaultPort {
|
||||
t.Errorf("ListenPorts = %v, want first port %d", cfg.Core.ListenPorts, api.DefaultPort)
|
||||
}
|
||||
}
|
||||
|
||||
func TestLoad_ExplicitMissingConfig_Fails(t *testing.T) {
|
||||
t.Setenv("JA4SENTINEL_INTERFACE", "")
|
||||
t.Setenv("JA4SENTINEL_PORTS", "")
|
||||
t.Setenv("JA4SENTINEL_BPF_FILTER", "")
|
||||
t.Setenv("JA4SENTINEL_FLOW_TIMEOUT", "")
|
||||
|
||||
loader := NewLoader("/tmp/definitely-missing-ja4sentinel.yml")
|
||||
_, err := loader.Load()
|
||||
if err == nil {
|
||||
t.Fatal("Load() should fail with explicit missing config path")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user