MCPcopy
hub / github.com/evilsocket/opensnitch / TestNewOperatorRegexpSensitive

Function TestNewOperatorRegexpSensitive

daemon/rule/operator_test.go:298–342  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

296}
297
298func TestNewOperatorRegexpSensitive(t *testing.T) {
299 t.Log("Test NewOperator() regexp sensitive")
300 var dummyList []Operator
301
302 var sensitive Sensitive
303 sensitive = true
304
305 conn.Process.Path = "/tmp/cUrL"
306
307 opRE, err := NewOperator(Regexp, sensitive, OpProcessPath, "^/tmp/cUrL$", dummyList)
308 if err != nil {
309 t.Error("NewOperator regexp.case-sensitive.err should be nil: ", err)
310 t.Fail()
311 }
312 if err = opRE.Compile(); err != nil {
313 t.Fail()
314 }
315 if opRE.Match(conn, false) == false {
316 t.Error("Test NewOperator() RE sensitive doesn't match:", conn.Process.Path)
317 t.Fail()
318 }
319
320 t.Run("Operator regexp proc.path case-sensitive", func(t *testing.T) {
321 conn.Process.Path = "/tmp/curl"
322 if opRE.Match(conn, false) == true {
323 t.Error("Test NewOperator() RE sensitive match:", conn.Process.Path)
324 t.Fail()
325 }
326 })
327
328 opRE, err = NewOperator(Regexp, !sensitive, OpProcessPath, "^/tmp/cUrL$", dummyList)
329 if err != nil {
330 t.Error("NewOperator regexp.case-insensitive.err should be nil: ", err)
331 t.Fail()
332 }
333 if err = opRE.Compile(); err != nil {
334 t.Fail()
335 }
336 if opRE.Match(conn, false) == false {
337 t.Error("Test NewOperator() RE not sensitive match:", conn.Process.Path)
338 t.Fail()
339 }
340
341 restoreConnection()
342}
343
344func TestNewOperatorList(t *testing.T) {
345 t.Log("Test NewOperator() List")

Callers

nothing calls this directly

Calls 5

CompileMethod · 0.95
MatchMethod · 0.95
restoreConnectionFunction · 0.85
NewOperatorFunction · 0.70
LogMethod · 0.65

Tested by

no test coverage detected