2021-02-03 07:37:24 +00:00
|
|
|
package network
|
|
|
|
|
|
|
|
import (
|
2021-07-16 14:28:13 +00:00
|
|
|
"github.com/projectdiscovery/nuclei/v2/internal/severity"
|
2021-07-12 14:20:01 +00:00
|
|
|
"github.com/projectdiscovery/nuclei/v2/pkg/model"
|
2021-02-03 07:37:24 +00:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/projectdiscovery/nuclei/v2/internal/testutils"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestNetworkCompileMake(t *testing.T) {
|
|
|
|
options := testutils.DefaultOptions
|
|
|
|
|
|
|
|
testutils.Init(options)
|
|
|
|
templateID := "testing-network"
|
|
|
|
request := &Request{
|
|
|
|
ID: templateID,
|
2021-02-23 12:47:24 +00:00
|
|
|
Address: []string{"{{Hostname}}", "{{Hostname}}:8082", "tls://{{Hostname}}:443"},
|
2021-02-03 07:37:24 +00:00
|
|
|
ReadSize: 1024,
|
2021-02-03 12:19:10 +00:00
|
|
|
Inputs: []*Input{{Data: "test-data"}},
|
2021-02-03 07:37:24 +00:00
|
|
|
}
|
|
|
|
executerOpts := testutils.NewMockExecuterOptions(options, &testutils.TemplateInfo{
|
|
|
|
ID: templateID,
|
2021-07-16 14:28:13 +00:00
|
|
|
Info: model.Info{SeverityHolder: severity.SeverityHolder{Severity: severity.Low}, Name: "test"},
|
2021-02-03 07:37:24 +00:00
|
|
|
})
|
|
|
|
err := request.Compile(executerOpts)
|
|
|
|
require.Nil(t, err, "could not compile network request")
|
|
|
|
|
2021-02-23 12:47:24 +00:00
|
|
|
require.Equal(t, 3, len(request.addresses), "could not get correct number of input address")
|
2021-02-03 07:37:24 +00:00
|
|
|
t.Run("check-host", func(t *testing.T) {
|
2021-02-23 12:47:24 +00:00
|
|
|
require.Equal(t, "{{Hostname}}", request.addresses[0].ip, "could not get correct host")
|
2021-02-03 07:37:24 +00:00
|
|
|
})
|
|
|
|
t.Run("check-host-with-port", func(t *testing.T) {
|
2021-02-23 12:47:24 +00:00
|
|
|
require.Equal(t, "{{Hostname}}", request.addresses[1].ip, "could not get correct host with port")
|
|
|
|
require.Equal(t, "8082", request.addresses[1].port, "could not get correct port for host")
|
|
|
|
})
|
|
|
|
t.Run("check-tls-with-port", func(t *testing.T) {
|
|
|
|
require.Equal(t, "{{Hostname}}", request.addresses[2].ip, "could not get correct host with port")
|
|
|
|
require.Equal(t, "443", request.addresses[2].port, "could not get correct port for host")
|
|
|
|
require.True(t, request.addresses[2].tls, "could not get correct port for host")
|
2021-02-03 07:37:24 +00:00
|
|
|
})
|
|
|
|
}
|