Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
projectdiscovery
GitHub Repository: projectdiscovery/nuclei
Path: blob/dev/pkg/input/transform_test.go
2070 views
1
package input
2
3
import (
4
"testing"
5
6
"github.com/projectdiscovery/hmap/store/hybrid"
7
"github.com/stretchr/testify/require"
8
)
9
10
func TestConvertInputToType(t *testing.T) {
11
helper := &Helper{}
12
13
hm, err := hybrid.New(hybrid.DefaultDiskOptions)
14
require.NoError(t, err, "could not create hybrid map")
15
helper.InputsHTTP = hm
16
defer func() {
17
_ = hm.Close()
18
}()
19
20
_ = hm.Set("google.com", []byte("https://google.com"))
21
22
tests := []struct {
23
input string
24
inputType inputType
25
result string
26
defaultPort string
27
}{
28
// host
29
{"google.com", typeHostOnly, "google.com", ""},
30
{"google.com:443", typeHostOnly, "google.com", ""},
31
{"https://google.com", typeHostOnly, "google.com", ""},
32
{"https://google.com:443", typeHostOnly, "google.com", ""},
33
34
// url
35
{"test.com", typeURL, "test.com", ""},
36
{"google.com", typeURL, "https://google.com", ""},
37
{"https://google.com", typeURL, "https://google.com", ""},
38
39
// file
40
{"google.com:443", typeFilepath, "", ""},
41
{"https://google.com:443", typeFilepath, "", ""},
42
{"/example/path", typeFilepath, "/example/path", ""},
43
{"input_test.go", typeFilepath, "input_test.go", ""},
44
{"../input", typeFilepath, "../input", ""},
45
{"input_test.*", typeFilepath, "input_test.*", ""},
46
47
// host-port
48
{"google.com", typeHostWithPort, "google.com", ""},
49
{"google.com:443", typeHostWithPort, "google.com:443", ""},
50
{"https://google.com", typeHostWithPort, "google.com:443", ""},
51
{"https://google.com:443", typeHostWithPort, "google.com:443", ""},
52
// host-port with default port
53
{"google.com", typeHostWithPort, "google.com:443", "443"},
54
55
// host with optional port
56
{"google.com", typeHostWithOptionalPort, "google.com", ""},
57
{"google.com:443", typeHostWithOptionalPort, "google.com:443", ""},
58
{"https://google.com", typeHostWithOptionalPort, "google.com:443", ""},
59
{"https://google.com:443", typeHostWithOptionalPort, "google.com:443", ""},
60
// host with optional port and default port
61
{"google.com", typeHostWithOptionalPort, "google.com:443", "443"},
62
63
// websocket
64
{"google.com", typeWebsocket, "", ""},
65
{"google.com:443", typeWebsocket, "", ""},
66
{"https://google.com:443", typeWebsocket, "", ""},
67
{"wss://google.com", typeWebsocket, "wss://google.com", ""},
68
}
69
70
for _, test := range tests {
71
result := helper.convertInputToType(test.input, test.inputType, test.defaultPort)
72
require.Equal(t, test.result, result, "could not get correct result %+v", test)
73
}
74
}
75
76