Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
projectdiscovery
GitHub Repository: projectdiscovery/nuclei
Path: blob/dev/pkg/input/formats/json/json_test.go
2070 views
1
package json
2
3
import (
4
"os"
5
"testing"
6
7
"github.com/projectdiscovery/nuclei/v3/pkg/input/types"
8
"github.com/stretchr/testify/require"
9
)
10
11
var expectedURLs = []string{
12
"https://ginandjuice.shop/",
13
"https://ginandjuice.shop/catalog/product?productId=1",
14
"https://ginandjuice.shop/resources/js/stockCheck.js",
15
"https://ginandjuice.shop/resources/js/xmlStockCheckPayload.js",
16
"https://ginandjuice.shop/resources/js/xmlStockCheckPayload.js",
17
"https://ginandjuice.shop/resources/js/stockCheck.js",
18
"https://ginandjuice.shop/catalog/product/stock",
19
"https://ginandjuice.shop/catalog/cart",
20
"https://ginandjuice.shop/catalog/product?productId=1",
21
"https://ginandjuice.shop/catalog/subscribe",
22
"https://ginandjuice.shop/blog",
23
"https://ginandjuice.shop/blog/?search=dadad&back=%2Fblog%2F",
24
"https://ginandjuice.shop/logger",
25
"https://ginandjuice.shop/blog/",
26
"https://ginandjuice.shop/blog/post?postId=3",
27
"https://ginandjuice.shop/about",
28
"https://ginandjuice.shop/my-account",
29
"https://ginandjuice.shop/login",
30
"https://ginandjuice.shop/login",
31
"https://ginandjuice.shop/login",
32
"https://ginandjuice.shop/my-account",
33
"https://ginandjuice.shop/catalog/cart",
34
"https://ginandjuice.shop/my-account",
35
"https://ginandjuice.shop/logout",
36
"https://ginandjuice.shop/",
37
"https://ginandjuice.shop/catalog",
38
}
39
40
func TestJSONFormatterParse(t *testing.T) {
41
format := New()
42
43
proxifyInputFile := "../testdata/ginandjuice.proxify.json"
44
45
file, err := os.Open(proxifyInputFile)
46
require.Nilf(t, err, "error opening proxify input file: %v", err)
47
defer func() {
48
_ = file.Close()
49
}()
50
51
var urls []string
52
err = format.Parse(file, func(request *types.RequestResponse) bool {
53
urls = append(urls, request.URL.String())
54
return false
55
}, proxifyInputFile)
56
if err != nil {
57
t.Fatal(err)
58
}
59
60
if len(urls) != len(expectedURLs) {
61
t.Fatalf("invalid number of urls: %d", len(urls))
62
}
63
require.ElementsMatch(t, urls, expectedURLs)
64
}
65
66