Files
ja4sentinel/internal/capture/capture_test.go
Jacquin Antoine 87d47324fb feat: Ajouter le module de capture réseau avec filtres BPF et tests associés
Co-authored-by: aider (openrouter/qwen/qwen3-coder-plus) <aider@aider.chat>
2026-02-25 04:14:51 +01:00

85 lines
1.6 KiB
Go

package capture
import (
"testing"
"time"
"ja4sentinel/internal/api"
)
func TestBuildBPFForPorts(t *testing.T) {
tests := []struct {
name string
ports []uint16
want string
}{
{
name: "single port",
ports: []uint16{443},
want: "(tcp port 443)",
},
{
name: "multiple ports",
ports: []uint16{443, 8443},
want: "(tcp port 443) or (tcp port 8443)",
},
{
name: "no ports",
ports: []uint16{},
want: "tcp",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := buildBPFForPorts(tt.ports)
if got != tt.want {
t.Errorf("buildBPFForPorts() = %v, want %v", got, tt.want)
}
})
}
}
func TestJoinString(t *testing.T) {
tests := []struct {
name string
parts []string
sep string
want string
}{
{
name: "empty slices",
parts: []string{},
sep: ", ",
want: "",
},
{
name: "single element",
parts: []string{"hello"},
sep: ", ",
want: "hello",
},
{
name: "multiple elements",
parts: []string{"hello", "world", "test"},
sep: ", ",
want: "hello, world, test",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := joinString(tt.parts, tt.sep)
if got != tt.want {
t.Errorf("joinString() = %v, want %v", got, tt.want)
}
})
}
}
// Tests d'intégration nécessitant une interface valide seront à faire dans des environnements de test appropriés
// car la capture réseau nécessite des permissions élevées
func TestCaptureIntegration(t *testing.T) {
t.Skip("Skipping integration test requiring network access and elevated privileges")
}