forked from projectdiscovery/nuclei
-
Notifications
You must be signed in to change notification settings - Fork 2
/
find_test.go
62 lines (54 loc) · 2 KB
/
find_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package offlinehttp
import (
"os"
"path/filepath"
"testing"
"github.com/stretchr/testify/require"
"github.com/projectdiscovery/nuclei/v3/pkg/model"
"github.com/projectdiscovery/nuclei/v3/pkg/model/types/severity"
"github.com/projectdiscovery/nuclei/v3/pkg/operators"
"github.com/projectdiscovery/nuclei/v3/pkg/testutils"
permissionutil "github.com/projectdiscovery/utils/permission"
)
func TestFindResponses(t *testing.T) {
options := testutils.DefaultOptions
testutils.Init(options)
templateID := "testing-offline"
request := &Request{}
executerOpts := testutils.NewMockExecuterOptions(options, &testutils.TemplateInfo{
ID: templateID,
Info: model.Info{SeverityHolder: severity.Holder{Severity: severity.Low}, Name: "test"},
})
executerOpts.Operators = []*operators.Operators{{}}
err := request.Compile(executerOpts)
require.Nil(t, err, "could not compile file request")
tempDir, err := os.MkdirTemp("", "test-*")
require.Nil(t, err, "could not create temporary directory")
defer os.RemoveAll(tempDir)
files := map[string]string{
"test.go": "TEST",
"config.txt": "TEST",
"final.txt": "TEST",
"image_ignored.png": "TEST",
"test.txt": "TEST",
}
for k, v := range files {
err = os.WriteFile(filepath.Join(tempDir, k), []byte(v), permissionutil.TempFilePermission)
require.Nil(t, err, "could not write temporary file")
}
expected := []string{"config.txt", "final.txt", "test.txt"}
got := []string{}
err = request.getInputPaths(tempDir+"/*", func(item string) {
base := filepath.Base(item)
got = append(got, base)
})
require.Nil(t, err, "could not get input paths for glob")
require.ElementsMatch(t, expected, got, "could not get correct file matches for glob")
got = []string{}
err = request.getInputPaths(tempDir, func(item string) {
base := filepath.Base(item)
got = append(got, base)
})
require.Nil(t, err, "could not get input paths for directory")
require.ElementsMatch(t, expected, got, "could not get correct file matches for directory")
}