2023-01-17 13:01:20 +05:30
|
|
|
package templates
|
2023-01-17 18:20:05 +05:30
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
|
|
"github.com/projectdiscovery/nuclei/v2/pkg/protocols/dns"
|
|
|
|
|
"github.com/projectdiscovery/nuclei/v2/pkg/protocols/http"
|
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func TestClusterTemplates(t *testing.T) {
|
2023-09-13 18:57:48 +02:00
|
|
|
t.Run("http-cluster-get", func(t *testing.T) {
|
|
|
|
|
tp1 := &Template{Path: "first.yaml", RequestsHTTP: []*http.Request{{Path: []string{"{{BaseURL}}"}}}}
|
|
|
|
|
tp2 := &Template{Path: "second.yaml", RequestsHTTP: []*http.Request{{Path: []string{"{{BaseURL}}"}}}}
|
|
|
|
|
tpls := []*Template{tp1, tp2}
|
|
|
|
|
// cluster 0
|
|
|
|
|
expected := []*Template{tp1, tp2}
|
|
|
|
|
got := Cluster(tpls)[0]
|
|
|
|
|
require.ElementsMatchf(t, expected, got, "different %v %v", len(expected), len(got))
|
|
|
|
|
})
|
|
|
|
|
t.Run("no-http-cluster", func(t *testing.T) {
|
|
|
|
|
tp1 := &Template{Path: "first.yaml", RequestsHTTP: []*http.Request{{Path: []string{"{{BaseURL}}/random"}}}}
|
|
|
|
|
tp2 := &Template{Path: "second.yaml", RequestsHTTP: []*http.Request{{Path: []string{"{{BaseURL}}/another"}}}}
|
|
|
|
|
tpls := []*Template{tp1, tp2}
|
|
|
|
|
expected := [][]*Template{{tp1}, {tp2}}
|
|
|
|
|
got := Cluster(tpls)
|
|
|
|
|
require.ElementsMatch(t, expected, got)
|
|
|
|
|
})
|
|
|
|
|
t.Run("dns-cluster", func(t *testing.T) {
|
|
|
|
|
tp1 := &Template{Path: "first.yaml", RequestsDNS: []*dns.Request{{Name: "{{Hostname}}"}}}
|
|
|
|
|
tp2 := &Template{Path: "second.yaml", RequestsDNS: []*dns.Request{{Name: "{{Hostname}}"}}}
|
|
|
|
|
tpls := []*Template{tp1, tp2}
|
|
|
|
|
// cluster 0
|
|
|
|
|
expected := []*Template{tp1, tp2}
|
|
|
|
|
got := Cluster(tpls)[0]
|
|
|
|
|
require.ElementsMatch(t, got, expected)
|
|
|
|
|
})
|
2023-01-17 18:20:05 +05:30
|
|
|
}
|