Esempio n. 1
0
func TestFindGoTestProcess(t *testing.T) {
	var (
		r Runner
		s search
	)
	r.Parameters = *newParameters()
	s.Names = append(s.Names, "go-build")
	s.Bytes = append(s.Bytes, "7465737420736561726368206c6f6f6b696e6720666f722073656c66")
	s.Contents = append(s.Contents, "test search looking for self")
	s.Options.MatchAll = true
	s.Options.Offset = 0.0
	s.Options.MaxLength = 10000000
	s.Options.LogFailures = true
	r.Parameters.Searches["testsearch"] = s
	msg, err := modules.MakeMessage(modules.MsgClassParameters, r.Parameters)
	if err != nil {
		t.Fatal(err)
	}
	out := r.Run(bytes.NewBuffer(msg))
	if len(out) == 0 {
		t.Fatal("run failed")
	}
	t.Log(out)
	err = json.Unmarshal([]byte(out), &r.Results)
	if err != nil {
		t.Fatal(err)
	}
	if !r.Results.Success {
		t.Fatal("failed to run memory search")
	}
	if !r.Results.FoundAnything {
		t.Fatal("should have found own go test process but didn't")
	}
	prints, err := r.PrintResults(r.Results, false)
	if err != nil {
		t.Fatal(err)
	}
	if len(prints) < 2 {
		t.Fatal("not enough results printed")
	}
	prints, err = r.PrintResults(r.Results, true)
	if err != nil {
		t.Fatal(err)
	}
	if len(prints) != 1 {
		t.Fatal("wrong number of results, should be one")
	}
}
Esempio n. 2
0
func TestSearches(t *testing.T) {
	var parameters = []testParams{
		{true, `{"searches":{"s1":{"names":["go"]}}}`},
		{false, `{"searches":{"s1":{"libraries":["^caribou.so$"]}}}`},
		{true, `{"searches":{"s1":{"contents":["memory_test"], "names": ["go"]}}}`},
		{false, `{"searches":{"s1":{"names":["1983yrotewdshhhoiufhes7fd29"],"bytes":["ffffffffaaaabbbbcccceeee"],"options":{"matchall": true}}}}`},
	}
	for _, tp := range parameters {
		var r Runner
		r.Parameters = *newParameters()
		err := json.Unmarshal([]byte(tp.params), &r.Parameters)
		if err != nil {
			t.Fatal(err)
		}
		msg, err := modules.MakeMessage(modules.MsgClassParameters, r.Parameters)
		if err != nil {
			t.Fatal(err)
		}
		out := r.Run(bytes.NewBuffer(msg))
		if len(out) == 0 {
			t.Fatal("run failed")
		}
		t.Log(out)
		err = json.Unmarshal([]byte(out), &r.Results)
		if err != nil {
			t.Fatal(err)
		}
		if !r.Results.Success {
			t.Fatal("failed to run memory search")
		}
		if r.Results.FoundAnything && !tp.expect {
			t.Fatalf("found something for search '%s' and shouldn't have", tp.params)
		} else if !r.Results.FoundAnything && tp.expect {
			t.Fatalf("found nothing for search '%s' and should have", tp.params)
		}
	}
}