nuclei/pkg/input/transform_test.go
Mohammed Diaa ff23949bb0
Apply input transformation to multi-protocol templates (#5426)
* Apply input transformation to multi-protocol template execution

* Remove ad hoc input transoformation from DNS protocol

* Add SSL protocol input transformer

* Remove ad hoc input transoformation from SSL protocol

* Remove unused function extractDomain from the DNS protocol engine

* transform in flow as well

* bug fix + update test

* bug fix multi proto
:

* bug fix multi proto input

* bug fixes in input transform

---------

Co-authored-by: Tarun Koyalwar <tarun@projectdiscovery.io>
2024-08-01 20:43:47 +05:30

73 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 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)
}
}