|
4 | 4 | "testing" |
5 | 5 |
|
6 | 6 | "github.com/google/cel-go/cel" |
7 | | - "github.com/google/cel-go/ext" |
8 | 7 | "github.com/kubescape/node-agent/pkg/config" |
9 | 8 | "github.com/stretchr/testify/assert" |
10 | 9 | ) |
@@ -97,81 +96,6 @@ func TestParseLibrary(t *testing.T) { |
97 | 96 | } |
98 | 97 | } |
99 | 98 |
|
100 | | -func TestCelBindWithJoinedArgs(t *testing.T) { |
101 | | - env, err := cel.NewEnv( |
102 | | - cel.Variable("event", cel.AnyType), |
103 | | - Parse(config.Config{}), |
104 | | - ext.Strings(), |
105 | | - ext.Bindings(), |
106 | | - ) |
107 | | - if err != nil { |
108 | | - t.Fatalf("failed to create env: %v", err) |
109 | | - } |
110 | | - |
111 | | - tests := []struct { |
112 | | - name string |
113 | | - expr string |
114 | | - args []string |
115 | | - expected bool |
116 | | - }{ |
117 | | - { |
118 | | - name: "cel.bind caches joined args - match", |
119 | | - expr: "cel.bind(joined_args, event.args.join(' '), joined_args.contains('-e') && joined_args.contains('cmd'))", |
120 | | - args: []string{"nc", "-e", "/bin/sh", "cmd"}, |
121 | | - expected: true, |
122 | | - }, |
123 | | - { |
124 | | - name: "cel.bind caches joined args - no match", |
125 | | - expr: "cel.bind(joined_args, event.args.join(' '), joined_args.contains('-e') && joined_args.contains('cmd'))", |
126 | | - args: []string{"ls", "-la"}, |
127 | | - expected: false, |
128 | | - }, |
129 | | - { |
130 | | - name: "cel.bind with multiple contains checks", |
131 | | - expr: "cel.bind(joined_args, event.args.join(' '), joined_args.contains('socket') || joined_args.contains('exec') || joined_args.contains('pty'))", |
132 | | - args: []string{"python", "-c", "import pty; pty.spawn('/bin/sh')"}, |
133 | | - expected: true, |
134 | | - }, |
135 | | - { |
136 | | - name: "cel.bind with empty args", |
137 | | - expr: "cel.bind(joined_args, event.args.join(' '), joined_args.contains('test'))", |
138 | | - args: []string{}, |
139 | | - expected: false, |
140 | | - }, |
141 | | - } |
142 | | - |
143 | | - for _, tt := range tests { |
144 | | - t.Run(tt.name, func(t *testing.T) { |
145 | | - ast, issues := env.Compile(tt.expr) |
146 | | - if issues != nil { |
147 | | - t.Fatalf("failed to compile expression: %v", issues.Err()) |
148 | | - } |
149 | | - |
150 | | - program, err := env.Program(ast) |
151 | | - if err != nil { |
152 | | - t.Fatalf("failed to create program: %v", err) |
153 | | - } |
154 | | - |
155 | | - result, _, err := program.Eval(map[string]interface{}{ |
156 | | - "event": map[string]interface{}{ |
157 | | - "args": tt.args, |
158 | | - "comm": "test", |
159 | | - }, |
160 | | - }) |
161 | | - if err != nil { |
162 | | - t.Fatalf("failed to eval program: %v", err) |
163 | | - } |
164 | | - |
165 | | - actual, ok := result.Value().(bool) |
166 | | - if !ok { |
167 | | - t.Fatalf("expected bool result, got %T", result.Value()) |
168 | | - } |
169 | | - |
170 | | - assert.Equal(t, tt.expected, actual) |
171 | | - }) |
172 | | - } |
173 | | -} |
174 | | - |
175 | 99 | func TestParseLibraryErrorCases(t *testing.T) { |
176 | 100 | env, err := cel.NewEnv( |
177 | 101 | cel.Variable("event", cel.AnyType), |
|
0 commit comments