Skip to content

Commit

Permalink
pkg/sensors: add a regression test on long args
Browse files Browse the repository at this point in the history
This test make sure that we don't have a regression on the bug fixed in
the previous commit about truncating long args.

Signed-off-by: Mahe Tardy <[email protected]>
  • Loading branch information
mtardy committed Feb 21, 2025
1 parent 4171841 commit 8a8506f
Showing 1 changed file with 59 additions and 0 deletions.
59 changes: 59 additions & 0 deletions pkg/sensors/tracing/kprobe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ import (
"os"
"os/exec"
"os/signal"
"path"
"path/filepath"
"slices"
"strconv"
"strings"
"sync"
Expand Down Expand Up @@ -7211,3 +7213,60 @@ spec:
err = jsonchecker.JsonTestCheck(t, checker)
assert.NoError(t, err)
}

func TestKprobeMatchArgsLongFile(t *testing.T) {
var doneWG, readyWG sync.WaitGroup
defer doneWG.Wait()

ctx, cancel := context.WithTimeout(context.Background(), tus.Conf().CmdWaitTime)
defer cancel()

// depending on temp dir, this should generate a path of ~2000 chars
longDirectory := strings.Repeat("a", 255)
longPathSlices := slices.Repeat([]string{longDirectory}, 8)
longPath := path.Join(t.TempDir(), path.Join(longPathSlices...))

// create a long temporary directory structure
err := os.MkdirAll(longPath, 0644)
require.NoError(t, err)
longPathWithFile := path.Join(longPath, "file")
file, err := os.Create(longPathWithFile)
require.NoError(t, err)
file.Close()

fdinstallHook := `apiVersion: cilium.io/v1alpha1
kind: TracingPolicy
metadata:
name: "fdinstall"
spec:
kprobes:
- call: "fd_install"
syscall: false
args:
- index: 1
type: "file"`

createCrdFile(t, fdinstallHook)

longFileArgChecker := ec.NewProcessKprobeChecker("longFile").
WithFunctionName(sm.Full("fd_install")).
WithArgs(ec.NewKprobeArgumentListMatcher().WithValues(
ec.NewKprobeArgumentChecker().WithFileArg(ec.NewKprobeFileChecker().WithPath(sm.Full(longPathWithFile))),
))

obs, err := observertesthelper.GetDefaultObserverWithFile(t, ctx, testConfigFile, tus.Conf().TetragonLib, observertesthelper.WithMyPid())
if err != nil {
t.Fatalf("GetDefaultObserverWithFile error: %s", err)
}
observertesthelper.LoopEvents(ctx, t, &doneWG, &readyWG, obs)
readyWG.Wait()

// generate an event by opening the file
file, err = os.Open(longPathWithFile)
require.NoError(t, err)
file.Close()

checker := ec.NewUnorderedEventChecker(longFileArgChecker)
err = jsonchecker.JsonTestCheck(t, checker)
assert.NoError(t, err)
}

0 comments on commit 8a8506f

Please sign in to comment.