Path: blob/dev/pkg/input/formats/swagger/swagger_test.go
2070 views
package swagger12import (3"os"4"testing"56"github.com/projectdiscovery/nuclei/v3/pkg/input/types"7"github.com/stretchr/testify/require"8)910func TestSwaggerAPIParser(t *testing.T) {11format := New()1213proxifyInputFile := "../testdata/swagger.yaml"1415var gotMethodsToURLs []string1617file, err := os.Open(proxifyInputFile)18require.Nilf(t, err, "error opening proxify input file: %v", err)19defer func() {20_ = file.Close()21}()2223err = format.Parse(file, func(request *types.RequestResponse) bool {24gotMethodsToURLs = append(gotMethodsToURLs, request.URL.String())25return false26}, proxifyInputFile)27if err != nil {28t.Fatal(err)29}3031if len(gotMethodsToURLs) != 2 {32t.Fatalf("invalid number of methods: %d", len(gotMethodsToURLs))33}3435expectedURLs := []string{36"https://localhost/v1/users",37"https://localhost/v1/users/1?test=asc",38}39require.ElementsMatch(t, gotMethodsToURLs, expectedURLs, "could not get swagger urls")40}414243