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

Function TestRaceNewOperatorListsDomainsRegexp

daemon/rule/operator_test.go:670–742  ·  view source on GitHub ↗

Must be launched with -race to test that we don't cause leaks Race occured on operator.go:241 reListCmp().MathString() fixed here: 53419fe

(t *testing.T)

Source from the content-addressed store, hash-verified

668// Race occured on operator.go:241 reListCmp().MathString()
669// fixed here: 53419fe
670func TestRaceNewOperatorListsDomainsRegexp(t *testing.T) {
671 t.Log("Test NewOperator() Lists domains_regexp")
672
673 var subOp *Operator
674 var list []Operator
675 listData := `[{"type": "simple", "operand": "user.id", "data": "666", "sensitive": false}, {"type": "lists", "operand": "lists.domains_regexp", "data": "testdata/lists/regexp/", "sensitive": false}]`
676
677 opLists, err := NewOperator(List, false, OpList, listData, list)
678 if err != nil {
679 t.Error("NewOperator Lists domains_regexp, shouldn't be nil: ", err)
680 t.Fail()
681 }
682 if err := opLists.Compile(); err != nil {
683 t.Error("NewOperator Lists domains_regexp, Compile() error:", err)
684 }
685 opLists.List = *unmarshalListData(opLists.Data, t)
686 for i := 0; i < len(opLists.List); i++ {
687 if err := opLists.List[i].Compile(); err != nil {
688 t.Error("NewOperator Lists domains_regexp, Compile() subitem error:", err)
689 }
690 if opLists.List[i].Type == Lists {
691 subOp = &opLists.List[i]
692 }
693 }
694
695 // touch domains list in background, to force a reload.
696 go func() {
697 touches := 1000
698 for {
699 if touches < 0 {
700 break
701 }
702 core.Exec("/bin/touch", []string{"testdata/lists/regexp/domainsregexp.txt"})
703 touches--
704 time.Sleep(100 * time.Millisecond)
705 //t.Log("touching:", touches)
706 }
707 }()
708
709 time.Sleep(time.Second)
710
711 subOp.Lock()
712 listslen := len(subOp.lists)
713 subOp.Unlock()
714 if listslen != 2 {
715 t.Error("NewOperator Lists domains_regexp, number of domains error:", subOp.lists)
716 }
717
718 tries := 10000
719 for {
720 if tries < 0 {
721 break
722 }
723 //t.Log("checking lists.domains_regexp:", tries, conn.DstHost)
724 if opLists.Match(conn, false) == false {
725 // we don't care about if it matches, we're testing race conditions
726 t.Log("Test NewOperator() Lists domains_regexp, doesn't match:", conn.DstHost)
727 }

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