mirror of
https://github.com/projectdiscovery/nuclei.git
synced 2025-12-17 22:55:27 +00:00
* chore: fix non-constant fmt string in call Signed-off-by: Dwi Siswanto <git@dw1.io> * build: bump all direct modules Signed-off-by: Dwi Siswanto <git@dw1.io> * chore(hosterrorscache): update import path Signed-off-by: Dwi Siswanto <git@dw1.io> * fix(charts): break changes Signed-off-by: Dwi Siswanto <git@dw1.io> * build: pinned `github.com/zmap/zcrypto` to v0.0.0-20240512203510-0fef58d9a9db Signed-off-by: Dwi Siswanto <git@dw1.io> * chore: golangci-lint auto fixes Signed-off-by: Dwi Siswanto <git@dw1.io> * chore: satisfy lints Signed-off-by: Dwi Siswanto <git@dw1.io> * build: migrate `github.com/xanzy/go-gitlab` => `gitlab.com/gitlab-org/api/client-go` Signed-off-by: Dwi Siswanto <git@dw1.io> * feat(json): update build constraints Signed-off-by: Dwi Siswanto <git@dw1.io> * chore: dont panicking on close err Signed-off-by: Dwi Siswanto <git@dw1.io> --------- Signed-off-by: Dwi Siswanto <git@dw1.io>
75 lines
2.4 KiB
Go
75 lines
2.4 KiB
Go
package input
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/projectdiscovery/hmap/store/hybrid"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestConvertInputToType(t *testing.T) {
|
|
helper := &Helper{}
|
|
|
|
hm, err := hybrid.New(hybrid.DefaultDiskOptions)
|
|
require.NoError(t, err, "could not create hybrid map")
|
|
helper.InputsHTTP = hm
|
|
defer func() {
|
|
_ = hm.Close()
|
|
}()
|
|
|
|
_ = hm.Set("google.com", []byte("https://google.com"))
|
|
|
|
tests := []struct {
|
|
input string
|
|
inputType inputType
|
|
result string
|
|
defaultPort string
|
|
}{
|
|
// host
|
|
{"google.com", typeHostOnly, "google.com", ""},
|
|
{"google.com:443", typeHostOnly, "google.com", ""},
|
|
{"https://google.com", typeHostOnly, "google.com", ""},
|
|
{"https://google.com:443", typeHostOnly, "google.com", ""},
|
|
|
|
// url
|
|
{"test.com", typeURL, "test.com", ""},
|
|
{"google.com", typeURL, "https://google.com", ""},
|
|
{"https://google.com", typeURL, "https://google.com", ""},
|
|
|
|
// file
|
|
{"google.com:443", typeFilepath, "", ""},
|
|
{"https://google.com:443", typeFilepath, "", ""},
|
|
{"/example/path", typeFilepath, "/example/path", ""},
|
|
{"input_test.go", typeFilepath, "input_test.go", ""},
|
|
{"../input", typeFilepath, "../input", ""},
|
|
{"input_test.*", typeFilepath, "input_test.*", ""},
|
|
|
|
// host-port
|
|
{"google.com", typeHostWithPort, "google.com", ""},
|
|
{"google.com:443", typeHostWithPort, "google.com:443", ""},
|
|
{"https://google.com", typeHostWithPort, "google.com:443", ""},
|
|
{"https://google.com:443", typeHostWithPort, "google.com:443", ""},
|
|
// host-port with default port
|
|
{"google.com", typeHostWithPort, "google.com:443", "443"},
|
|
|
|
// host with optional port
|
|
{"google.com", typeHostWithOptionalPort, "google.com", ""},
|
|
{"google.com:443", typeHostWithOptionalPort, "google.com:443", ""},
|
|
{"https://google.com", typeHostWithOptionalPort, "google.com:443", ""},
|
|
{"https://google.com:443", typeHostWithOptionalPort, "google.com:443", ""},
|
|
// host with optional port and default port
|
|
{"google.com", typeHostWithOptionalPort, "google.com:443", "443"},
|
|
|
|
// websocket
|
|
{"google.com", typeWebsocket, "", ""},
|
|
{"google.com:443", typeWebsocket, "", ""},
|
|
{"https://google.com:443", typeWebsocket, "", ""},
|
|
{"wss://google.com", typeWebsocket, "wss://google.com", ""},
|
|
}
|
|
|
|
for _, test := range tests {
|
|
result := helper.convertInputToType(test.input, test.inputType, test.defaultPort)
|
|
require.Equal(t, test.result, result, "could not get correct result %+v", test)
|
|
}
|
|
}
|