feat(go): port socket detectors
This commit is contained in:
parent
fc9b5f0448
commit
c6f7219de8
23 changed files with 693 additions and 28 deletions
|
|
@ -6,6 +6,8 @@ import (
|
|||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"codeberg.org/anassaeneroi/enodia-sentinal/go-agent/internal/model"
|
||||
)
|
||||
|
||||
func TestCaptureUsesInjectableProcRoot(t *testing.T) {
|
||||
|
|
@ -37,7 +39,10 @@ func TestCaptureUsesInjectableProcRoot(t *testing.T) {
|
|||
if err := os.WriteFile(preload, []byte("/tmp/global.so\n"), 0o600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
state, err := CaptureWithPaths(Paths{ProcRoot: root, LDPreloadPath: preload})
|
||||
state, err := CaptureWithPaths(Paths{
|
||||
ProcRoot: root, LDPreloadPath: preload,
|
||||
SocketSource: func() []model.Socket { return []model.Socket{} },
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
|
@ -55,3 +60,18 @@ func TestCaptureUsesInjectableProcRoot(t *testing.T) {
|
|||
t.Fatalf("unexpected global preload: %q", state.LDPreload)
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseSSMatchesPythonShapes(t *testing.T) {
|
||||
text := "tcp ESTAB 0 0 10.0.0.2:5555 8.8.8.8:443 users:((\"bash\",pid=42,fd=3)) ino:999\n"
|
||||
sockets := parseSS(text, "tcp")
|
||||
if len(sockets) != 1 {
|
||||
t.Fatalf("unexpected sockets: %#v", sockets)
|
||||
}
|
||||
got := sockets[0]
|
||||
if got.State != "ESTAB" || got.Local != "10.0.0.2:5555" || got.Peer != "8.8.8.8:443" {
|
||||
t.Fatalf("unexpected endpoints: %#v", got)
|
||||
}
|
||||
if got.Inode == nil || *got.Inode != 999 || got.PID == nil || *got.PID != 42 || got.Comm != "bash" {
|
||||
t.Fatalf("unexpected ownership: %#v", got)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue