2024-03-14 03:08:53 +05:30
|
|
|
package yaml
|
|
|
|
|
|
|
|
|
|
import (
|
2025-02-13 18:46:28 +05:30
|
|
|
"os"
|
2025-06-12 15:44:11 +02:00
|
|
|
"strings"
|
2024-03-14 03:08:53 +05:30
|
|
|
"testing"
|
|
|
|
|
|
2025-06-12 15:03:33 +02:00
|
|
|
"github.com/projectdiscovery/nuclei/v3/pkg/input/formats"
|
2024-03-14 03:08:53 +05:30
|
|
|
"github.com/projectdiscovery/nuclei/v3/pkg/input/types"
|
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func TestYamlFormatterParse(t *testing.T) {
|
|
|
|
|
format := New()
|
|
|
|
|
|
|
|
|
|
proxifyInputFile := "../testdata/ginandjuice.proxify.yaml"
|
|
|
|
|
|
|
|
|
|
expectedUrls := []string{
|
|
|
|
|
"https://ginandjuice.shop/blog/post?postId=3&source=proxify",
|
|
|
|
|
"https://ginandjuice.shop/users/3",
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-13 18:46:28 +05:30
|
|
|
file, err := os.Open(proxifyInputFile)
|
|
|
|
|
require.Nilf(t, err, "error opening proxify input file: %v", err)
|
2025-07-01 00:40:44 +07:00
|
|
|
defer func() {
|
|
|
|
|
_ = file.Close()
|
|
|
|
|
}()
|
2025-02-13 18:46:28 +05:30
|
|
|
|
2024-03-14 03:08:53 +05:30
|
|
|
var urls []string
|
2025-02-13 18:46:28 +05:30
|
|
|
err = format.Parse(file, func(request *types.RequestResponse) bool {
|
2024-03-14 03:08:53 +05:30
|
|
|
urls = append(urls, request.URL.String())
|
|
|
|
|
return false
|
2025-02-13 18:46:28 +05:30
|
|
|
}, proxifyInputFile)
|
2024-03-14 03:08:53 +05:30
|
|
|
require.Nilf(t, err, "error parsing yaml file: %v", err)
|
|
|
|
|
require.Len(t, urls, len(expectedUrls), "invalid number of urls")
|
|
|
|
|
require.ElementsMatch(t, urls, expectedUrls, "invalid urls")
|
|
|
|
|
}
|
2025-06-12 15:03:33 +02:00
|
|
|
|
|
|
|
|
func TestYamlFormatterParseWithVariables(t *testing.T) {
|
|
|
|
|
format := New()
|
2025-07-03 17:05:14 +02:00
|
|
|
proxifyYttFile := "../testdata/ytt/ginandjuice.ytt.yaml"
|
2025-06-12 15:03:33 +02:00
|
|
|
|
|
|
|
|
expectedUrls := []string{
|
|
|
|
|
"https://ginandjuice.shop/users/3",
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
format.SetOptions(formats.InputFormatOptions{
|
|
|
|
|
VarsTextTemplating: true,
|
|
|
|
|
Variables: map[string]interface{}{
|
|
|
|
|
"foo": "catalog",
|
|
|
|
|
"bar": "product",
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
file, err := os.Open(proxifyYttFile)
|
|
|
|
|
require.Nilf(t, err, "error opening proxify ytt input file: %v", err)
|
|
|
|
|
defer file.Close()
|
|
|
|
|
|
|
|
|
|
var urls []string
|
|
|
|
|
err = format.Parse(file, func(request *types.RequestResponse) bool {
|
|
|
|
|
urls = append(urls, request.URL.String())
|
|
|
|
|
expectedRaw := `POST /users/3 HTTP/1.1
|
|
|
|
|
Host: ginandjuice.shop
|
|
|
|
|
Authorization: Bearer 3x4mpl3t0k3n
|
|
|
|
|
Accept-Encoding: gzip
|
|
|
|
|
Content-Type: application/x-www-form-urlencoded
|
|
|
|
|
Connection: close
|
|
|
|
|
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 11_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36
|
|
|
|
|
|
|
|
|
|
foo=catalog&bar=product`
|
2025-06-12 15:44:11 +02:00
|
|
|
normalised := strings.ReplaceAll(request.Request.Raw, "\r\n", "\n")
|
|
|
|
|
require.Equal(t, expectedRaw, strings.TrimSuffix(normalised, "\n"), "request raw does not match expected value")
|
2025-06-12 15:03:33 +02:00
|
|
|
|
|
|
|
|
return false
|
|
|
|
|
}, proxifyYttFile)
|
|
|
|
|
|
|
|
|
|
require.Nilf(t, err, "error parsing yaml file: %v", err)
|
|
|
|
|
require.Len(t, urls, len(expectedUrls), "invalid number of urls")
|
|
|
|
|
require.ElementsMatch(t, urls, expectedUrls, "invalid urls")
|
|
|
|
|
|
|
|
|
|
}
|