nuclei/pkg/input/formats/swagger/swagger_test.go
Tryfon Papatriantafyllou c6e5bdd857
Fixing the server URL path for OpenAPI scanning (#5504)
* fix_openAPI_serverURL_path

* Issue #5503
2024-08-16 17:37:02 +05:30

35 lines
783 B
Go

package swagger
import (
"testing"
"github.com/projectdiscovery/nuclei/v3/pkg/input/types"
"github.com/stretchr/testify/require"
)
func TestSwaggerAPIParser(t *testing.T) {
format := New()
proxifyInputFile := "../testdata/swagger.yaml"
var gotMethodsToURLs []string
err := format.Parse(proxifyInputFile, func(request *types.RequestResponse) bool {
gotMethodsToURLs = append(gotMethodsToURLs, request.URL.String())
return false
})
if err != nil {
t.Fatal(err)
}
if len(gotMethodsToURLs) != 2 {
t.Fatalf("invalid number of methods: %d", len(gotMethodsToURLs))
}
expectedURLs := []string{
"https://localhost/v1/users",
"https://localhost/v1/users/1?test=asc",
}
require.ElementsMatch(t, gotMethodsToURLs, expectedURLs, "could not get swagger urls")
}