Skip to content

Commit

Permalink
add basic test
Browse files Browse the repository at this point in the history
  • Loading branch information
paulcacheux committed Dec 19, 2024
1 parent cbb6d45 commit 82f0b18
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions pkg/security/tests/fim_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// Unless explicitly stated otherwise all files in this repository are licensed
// under the Apache License Version 2.0.
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2016-present Datadog, Inc.

//go:build linux && functionaltests

// Package tests holds tests related files
package tests

import (
"os"
"testing"

"github.com/stretchr/testify/assert"

"github.com/DataDog/datadog-agent/pkg/security/secl/model"
"github.com/DataDog/datadog-agent/pkg/security/secl/rules"
)

func TestFIMOpen(t *testing.T) {
SkipIfNotAvailable(t)

ruleDefs := []*rules.RuleDefinition{
{
ID: "test_fim_rule",
Expression: `fim.write.file.path == "{{.Root}}/test-open"`,
},
}

test, err := newTestModule(t, nil, ruleDefs)
if err != nil {
t.Fatal(err)
}
defer test.Close()

testFile, _, err := test.Path("test-open")
if err != nil {
t.Fatal(err)
}
defer os.Remove(testFile)

test.WaitSignal(t, func() error {
f, err := os.Create(testFile)
if err != nil {
return err
}
return f.Close()
}, func(event *model.Event, _ *rules.Rule) {
assert.Equal(t, "open", event.GetType(), "wrong event type")
assertInode(t, event.Open.File.Inode, getInode(t, testFile))
})
}

0 comments on commit 82f0b18

Please sign in to comment.