Skip to content

Commit

Permalink
tests:process_exec: more tests for get caps and ns
Browse files Browse the repository at this point in the history
[Upstream main 11a8cb0 ]

Signed-off-by: Djalal Harouni <[email protected]>
  • Loading branch information
tixxdz committed Jul 19, 2024
1 parent 2a1ea78 commit 90e9e1b
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions pkg/sensors/exec/exec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
"github.com/cilium/tetragon/pkg/observer/observertesthelper"
"github.com/cilium/tetragon/pkg/option"
proc "github.com/cilium/tetragon/pkg/process"
"github.com/cilium/tetragon/pkg/reader/caps"
"github.com/cilium/tetragon/pkg/reader/namespace"
"github.com/cilium/tetragon/pkg/sensors"
"github.com/cilium/tetragon/pkg/sensors/base"
Expand Down Expand Up @@ -257,9 +258,14 @@ func TestEventExecve(t *testing.T) {

testNop := testutils.RepoRootPath("contrib/tester-progs/nop")

myCaps := ec.NewCapabilitiesChecker().FromCapabilities(caps.GetCurrentCapabilities())
myNs := ec.NewNamespacesChecker().FromNamespaces(namespace.GetCurrentNamespace())

procChecker := ec.NewProcessChecker().
WithBinary(sm.Full(testNop)).
WithArguments(sm.Full("arg1 arg2 arg3"))
WithArguments(sm.Full("arg1 arg2 arg3")).
WithCap(myCaps).
WithNs(myNs)

execChecker := ec.NewProcessExecChecker("").WithProcess(procChecker)
checker := ec.NewUnorderedEventChecker(execChecker)
Expand Down Expand Up @@ -873,6 +879,9 @@ func TestExecProcessCredentials(t *testing.T) {

testNop := testutils.RepoRootPath("contrib/tester-progs/nop")

myCaps := ec.NewCapabilitiesChecker().FromCapabilities(caps.GetCurrentCapabilities())
myNs := ec.NewNamespacesChecker().FromNamespaces(namespace.GetCurrentNamespace())

if err := exec.Command(testNop).Run(); err != nil {
t.Fatalf("Failed to execute test binary: %s\n", err)
}
Expand All @@ -895,10 +904,14 @@ func TestExecProcessCredentials(t *testing.T) {
WithGid(0).WithEgid(gid).WithSgid(gid).WithFsgid(gid)

procExecChecker := ec.NewProcessChecker().
WithBinary(sm.Full(testNop)).WithProcessCredentials(creds).WithBinaryProperties(nil)
WithBinary(sm.Full(testNop)).WithProcessCredentials(creds).WithBinaryProperties(nil).
WithCap(myCaps).
WithNs(myNs)

procGidExecChecker := ec.NewProcessChecker().
WithBinary(sm.Full(testNop)).WithProcessCredentials(gidCreds).WithBinaryProperties(nil)
WithBinary(sm.Full(testNop)).WithProcessCredentials(gidCreds).WithBinaryProperties(nil).
WithCap(myCaps).
WithNs(myNs)

execChecker := ec.NewProcessExecChecker("exec").WithProcess(procExecChecker)
execGidChecker := ec.NewProcessExecChecker("exec").WithProcess(procGidExecChecker)
Expand Down

0 comments on commit 90e9e1b

Please sign in to comment.