Path: blob/dev/pkg/input/formats/yaml/multidoc_test.go
2852 views
package yaml12import (3"os"4"strings"5"testing"67"github.com/projectdiscovery/nuclei/v3/pkg/input/formats"8"github.com/projectdiscovery/nuclei/v3/pkg/input/types"9"github.com/stretchr/testify/require"10)1112func TestYamlFormatterParse(t *testing.T) {13format := New()1415proxifyInputFile := "../testdata/ginandjuice.proxify.yaml"1617expectedUrls := []string{18"https://ginandjuice.shop/blog/post?postId=3&source=proxify",19"https://ginandjuice.shop/users/3",20}2122file, err := os.Open(proxifyInputFile)23require.Nilf(t, err, "error opening proxify input file: %v", err)24defer func() {25_ = file.Close()26}()2728var urls []string29err = format.Parse(file, func(request *types.RequestResponse) bool {30urls = append(urls, request.URL.String())31return false32}, proxifyInputFile)33require.Nilf(t, err, "error parsing yaml file: %v", err)34require.Len(t, urls, len(expectedUrls), "invalid number of urls")35require.ElementsMatch(t, urls, expectedUrls, "invalid urls")36}3738func TestYamlFormatterParseWithVariables(t *testing.T) {39format := New()40proxifyYttFile := "../testdata/ytt/ginandjuice.ytt.yaml"4142expectedUrls := []string{43"https://ginandjuice.shop/users/3",44}4546format.SetOptions(formats.InputFormatOptions{47VarsTextTemplating: true,48Variables: map[string]interface{}{49"foo": "catalog",50"bar": "product",51},52})53file, err := os.Open(proxifyYttFile)54require.Nilf(t, err, "error opening proxify ytt input file: %v", err)55defer func() {56_ = file.Close()57}()5859var urls []string60err = format.Parse(file, func(request *types.RequestResponse) bool {61urls = append(urls, request.URL.String())62expectedRaw := `POST /users/3 HTTP/1.163Host: ginandjuice.shop64Authorization: Bearer 3x4mpl3t0k3n65Accept-Encoding: gzip66Content-Type: application/x-www-form-urlencoded67Connection: close68User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 11_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.366970foo="catalog"&bar=product&debug=false`71normalised := strings.ReplaceAll(request.Request.Raw, "\r\n", "\n")72require.Equal(t, expectedRaw, strings.TrimSuffix(normalised, "\n"), "request raw does not match expected value")7374return false75}, proxifyYttFile)7677require.Nilf(t, err, "error parsing yaml file: %v", err)78require.Len(t, urls, len(expectedUrls), "invalid number of urls")79require.ElementsMatch(t, urls, expectedUrls, "invalid urls")8081}828384