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>
This commit is contained in:
84
internal/capture/capture_test.go
Normal file
84
internal/capture/capture_test.go
Normal file
@ -0,0 +1,84 @@
|
||||
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")
|
||||
}
|
||||
Reference in New Issue
Block a user