MCPcopy Create free account
hub / github.com/rabbitstack/fibratus / TestGetFileInfo

Function TestGetFileInfo

pkg/filter/util_test.go:32–77  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

30)
31
32func TestGetFileInfo(t *testing.T) {
33 path, err := os.Executable()
34 require.NoError(t, err)
35
36 var tests = []struct {
37 e *event.Event
38 f func(*testing.T, *event.Event)
39 fld fields.Field
40 }{
41 {
42 e: &event.Event{
43 Name: "CreateFile",
44 Params: map[string]*event.Param{
45 params.FilePath: {Name: params.FilePath, Type: params.UnicodeString, Value: path},
46 },
47 },
48 f: func(t *testing.T, e *event.Event) {
49 require.True(t, e.Params.MustGetBool(params.FileIsExecutable))
50 },
51 fld: fields.FileIsExecutable,
52 },
53 {
54 e: &event.Event{
55 Name: "CreateFile",
56 Params: map[string]*event.Param{
57 params.FilePath: {Name: params.FilePath, Type: params.UnicodeString, Value: filepath.Join(os.Getenv("SystemRoot"), "System32", "kernel32.dll")},
58 },
59 },
60 f: func(t *testing.T, e *event.Event) {
61 require.True(t, e.Params.MustGetBool(params.FileIsDLL))
62 },
63 fld: fields.ModuleIsDLL,
64 },
65 }
66
67 for _, tt := range tests {
68 t.Run(tt.e.GetParamAsString(params.FilePath), func(t *testing.T) {
69 v, err := getFileInfo(tt.fld, tt.e)
70 require.NotNil(t, v)
71 require.NoError(t, err)
72 if tt.f != nil {
73 tt.f(t, tt.e)
74 }
75 })
76 }
77}

Callers

nothing calls this directly

Calls 4

getFileInfoFunction · 0.85
MustGetBoolMethod · 0.80
GetParamAsStringMethod · 0.80
RunMethod · 0.65

Tested by

no test coverage detected