2024-03-14 03:08:53 +05:30
|
|
|
package json
|
|
|
|
|
|
|
|
|
|
import (
|
2025-02-13 18:46:28 +05:30
|
|
|
"os"
|
2024-03-14 03:08:53 +05:30
|
|
|
"testing"
|
|
|
|
|
|
|
|
|
|
"github.com/projectdiscovery/nuclei/v3/pkg/input/types"
|
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
var expectedURLs = []string{
|
|
|
|
|
"https://ginandjuice.shop/",
|
|
|
|
|
"https://ginandjuice.shop/catalog/product?productId=1",
|
|
|
|
|
"https://ginandjuice.shop/resources/js/stockCheck.js",
|
|
|
|
|
"https://ginandjuice.shop/resources/js/xmlStockCheckPayload.js",
|
|
|
|
|
"https://ginandjuice.shop/resources/js/xmlStockCheckPayload.js",
|
|
|
|
|
"https://ginandjuice.shop/resources/js/stockCheck.js",
|
|
|
|
|
"https://ginandjuice.shop/catalog/product/stock",
|
|
|
|
|
"https://ginandjuice.shop/catalog/cart",
|
|
|
|
|
"https://ginandjuice.shop/catalog/product?productId=1",
|
|
|
|
|
"https://ginandjuice.shop/catalog/subscribe",
|
|
|
|
|
"https://ginandjuice.shop/blog",
|
|
|
|
|
"https://ginandjuice.shop/blog/?search=dadad&back=%2Fblog%2F",
|
|
|
|
|
"https://ginandjuice.shop/logger",
|
|
|
|
|
"https://ginandjuice.shop/blog/",
|
|
|
|
|
"https://ginandjuice.shop/blog/post?postId=3",
|
|
|
|
|
"https://ginandjuice.shop/about",
|
|
|
|
|
"https://ginandjuice.shop/my-account",
|
|
|
|
|
"https://ginandjuice.shop/login",
|
|
|
|
|
"https://ginandjuice.shop/login",
|
|
|
|
|
"https://ginandjuice.shop/login",
|
|
|
|
|
"https://ginandjuice.shop/my-account",
|
|
|
|
|
"https://ginandjuice.shop/catalog/cart",
|
|
|
|
|
"https://ginandjuice.shop/my-account",
|
|
|
|
|
"https://ginandjuice.shop/logout",
|
|
|
|
|
"https://ginandjuice.shop/",
|
|
|
|
|
"https://ginandjuice.shop/catalog",
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestJSONFormatterParse(t *testing.T) {
|
|
|
|
|
format := New()
|
|
|
|
|
|
|
|
|
|
proxifyInputFile := "../testdata/ginandjuice.proxify.json"
|
|
|
|
|
|
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
|
|
|
if err != nil {
|
|
|
|
|
t.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if len(urls) != len(expectedURLs) {
|
|
|
|
|
t.Fatalf("invalid number of urls: %d", len(urls))
|
|
|
|
|
}
|
|
|
|
|
require.ElementsMatch(t, urls, expectedURLs)
|
|
|
|
|
}
|