Path: blob/dev/pkg/input/formats/json/json_test.go
2070 views
package json12import (3"os"4"testing"56"github.com/projectdiscovery/nuclei/v3/pkg/input/types"7"github.com/stretchr/testify/require"8)910var expectedURLs = []string{11"https://ginandjuice.shop/",12"https://ginandjuice.shop/catalog/product?productId=1",13"https://ginandjuice.shop/resources/js/stockCheck.js",14"https://ginandjuice.shop/resources/js/xmlStockCheckPayload.js",15"https://ginandjuice.shop/resources/js/xmlStockCheckPayload.js",16"https://ginandjuice.shop/resources/js/stockCheck.js",17"https://ginandjuice.shop/catalog/product/stock",18"https://ginandjuice.shop/catalog/cart",19"https://ginandjuice.shop/catalog/product?productId=1",20"https://ginandjuice.shop/catalog/subscribe",21"https://ginandjuice.shop/blog",22"https://ginandjuice.shop/blog/?search=dadad&back=%2Fblog%2F",23"https://ginandjuice.shop/logger",24"https://ginandjuice.shop/blog/",25"https://ginandjuice.shop/blog/post?postId=3",26"https://ginandjuice.shop/about",27"https://ginandjuice.shop/my-account",28"https://ginandjuice.shop/login",29"https://ginandjuice.shop/login",30"https://ginandjuice.shop/login",31"https://ginandjuice.shop/my-account",32"https://ginandjuice.shop/catalog/cart",33"https://ginandjuice.shop/my-account",34"https://ginandjuice.shop/logout",35"https://ginandjuice.shop/",36"https://ginandjuice.shop/catalog",37}3839func TestJSONFormatterParse(t *testing.T) {40format := New()4142proxifyInputFile := "../testdata/ginandjuice.proxify.json"4344file, err := os.Open(proxifyInputFile)45require.Nilf(t, err, "error opening proxify input file: %v", err)46defer func() {47_ = file.Close()48}()4950var urls []string51err = format.Parse(file, func(request *types.RequestResponse) bool {52urls = append(urls, request.URL.String())53return false54}, proxifyInputFile)55if err != nil {56t.Fatal(err)57}5859if len(urls) != len(expectedURLs) {60t.Fatalf("invalid number of urls: %d", len(urls))61}62require.ElementsMatch(t, urls, expectedURLs)63}646566