Path: blob/dev/pkg/input/formats/openapi/openapi_test.go
2070 views
package openapi12import (3"os"4"strings"5"testing"67"github.com/projectdiscovery/nuclei/v3/pkg/input/types"8"github.com/stretchr/testify/require"9)1011const baseURL = "http://hackthebox:5000"1213var methodToURLs = map[string][]string{14"GET": {15"{{baseUrl}}/createdb",16"{{baseUrl}}/",17"{{baseUrl}}/users/v1/John.Doe",18"{{baseUrl}}/users/v1",19"{{baseUrl}}/users/v1/_debug",20"{{baseUrl}}/books/v1",21"{{baseUrl}}/books/v1/bookTitle77",22},23"POST": {24"{{baseUrl}}/users/v1/register",25"{{baseUrl}}/users/v1/login",26"{{baseUrl}}/books/v1",27},28"PUT": {29"{{baseUrl}}/users/v1/name1/email",30"{{baseUrl}}/users/v1/name1/password",31},32"DELETE": {33"{{baseUrl}}/users/v1/name1",34},35}3637func TestOpenAPIParser(t *testing.T) {38format := New()3940proxifyInputFile := "../testdata/openapi.yaml"4142gotMethodsToURLs := make(map[string][]string)4344file, err := os.Open(proxifyInputFile)45require.Nilf(t, err, "error opening proxify input file: %v", err)46defer func() {47_ = file.Close()48}()4950err = format.Parse(file, func(rr *types.RequestResponse) bool {51gotMethodsToURLs[rr.Request.Method] = append(gotMethodsToURLs[rr.Request.Method],52strings.Replace(rr.URL.String(), baseURL, "{{baseUrl}}", 1))53return false54}, proxifyInputFile)55if err != nil {56t.Fatal(err)57}5859if len(gotMethodsToURLs) != len(methodToURLs) {60t.Fatalf("invalid number of methods: %d", len(gotMethodsToURLs))61}6263for method, urls := range gotMethodsToURLs {64if len(urls) != len(methodToURLs[method]) {65t.Fatalf("invalid number of urls for method %s: %d", method, len(urls))66}67require.ElementsMatch(t, urls, methodToURLs[method], "invalid urls for method %s", method)68}69}707172