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

Function TestNewOperatorListsNETs

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

Source from the content-addressed store, hash-verified

513}
514
515func TestNewOperatorListsNETs(t *testing.T) {
516 t.Log("Test NewOperator() Lists domains_regexp")
517
518 var subOp *Operator
519 var list []Operator
520 listData := `[{"type": "simple", "operand": "user.id", "data": "666", "sensitive": false}, {"type": "lists", "operand": "lists.nets", "data": "testdata/lists/nets/", "sensitive": false}]`
521
522 opLists, err := NewOperator(List, false, OpList, listData, list)
523 if err != nil {
524 t.Error("NewOperator Lists domains_regexp, shouldn't be nil: ", err)
525 t.Fail()
526 }
527 if err := opLists.Compile(); err != nil {
528 t.Error("NewOperator Lists domains_regexp, Compile() error:", err)
529 }
530 opLists.List = *unmarshalListData(opLists.Data, t)
531 for i := 0; i < len(opLists.List); i++ {
532 if err := opLists.List[i].Compile(); err != nil {
533 t.Error("NewOperator Lists domains_regexp, Compile() subitem error:", err)
534 }
535 if opLists.List[i].Type == Lists {
536 subOp = &opLists.List[i]
537 }
538 }
539
540 time.Sleep(time.Second)
541 if opLists.Match(conn, false) == false {
542 t.Error("Test NewOperator() Lists domains_regexp, doesn't match:", conn.DstHost)
543 }
544
545 subOp.Lock()
546 listslen := len(subOp.lists)
547 subOp.Unlock()
548 if listslen != 2 {
549 t.Error("NewOperator Lists domains_regexp, number of domains error:", subOp.lists)
550 }
551
552 //t.Log("checking lists.domains_regexp:", tries, conn.DstHost)
553 if opLists.Match(conn, false) == false {
554 // we don't care about if it matches, we're testing race conditions
555 t.Log("Test NewOperator() Lists domains_regexp, doesn't match:", conn.DstHost)
556 }
557
558 subOp.StopMonitoringLists()
559 time.Sleep(time.Second)
560 subOp.Lock()
561 if len(subOp.lists) != 0 {
562 t.Error("NewOperator Lists number should be 0:", subOp.lists, len(subOp.lists))
563 }
564 subOp.Unlock()
565
566 restoreConnection()
567}
568
569func TestNewOperatorListsComplex(t *testing.T) {
570 t.Log("Test NewOperator() Lists complex")

Callers

nothing calls this directly

Calls 9

CompileMethod · 0.95
MatchMethod · 0.95
StopMonitoringListsMethod · 0.95
unmarshalListDataFunction · 0.85
restoreConnectionFunction · 0.85
LockMethod · 0.80
UnlockMethod · 0.80
NewOperatorFunction · 0.70
LogMethod · 0.65

Tested by

no test coverage detected