Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
projectdiscovery
GitHub Repository: projectdiscovery/nuclei
Path: blob/dev/pkg/input/formats/swagger/swagger_test.go
2070 views
1
package swagger
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
func TestSwaggerAPIParser(t *testing.T) {
12
format := New()
13
14
proxifyInputFile := "../testdata/swagger.yaml"
15
16
var gotMethodsToURLs []string
17
18
file, err := os.Open(proxifyInputFile)
19
require.Nilf(t, err, "error opening proxify input file: %v", err)
20
defer func() {
21
_ = file.Close()
22
}()
23
24
err = format.Parse(file, func(request *types.RequestResponse) bool {
25
gotMethodsToURLs = append(gotMethodsToURLs, request.URL.String())
26
return false
27
}, proxifyInputFile)
28
if err != nil {
29
t.Fatal(err)
30
}
31
32
if len(gotMethodsToURLs) != 2 {
33
t.Fatalf("invalid number of methods: %d", len(gotMethodsToURLs))
34
}
35
36
expectedURLs := []string{
37
"https://localhost/v1/users",
38
"https://localhost/v1/users/1?test=asc",
39
}
40
require.ElementsMatch(t, gotMethodsToURLs, expectedURLs, "could not get swagger urls")
41
}
42
43