mirror of
https://github.com/projectdiscovery/nuclei.git
synced 2025-12-17 20:45:25 +00:00
* chore: fix non-constant fmt string in call Signed-off-by: Dwi Siswanto <git@dw1.io> * build: bump all direct modules Signed-off-by: Dwi Siswanto <git@dw1.io> * chore(hosterrorscache): update import path Signed-off-by: Dwi Siswanto <git@dw1.io> * fix(charts): break changes Signed-off-by: Dwi Siswanto <git@dw1.io> * build: pinned `github.com/zmap/zcrypto` to v0.0.0-20240512203510-0fef58d9a9db Signed-off-by: Dwi Siswanto <git@dw1.io> * chore: golangci-lint auto fixes Signed-off-by: Dwi Siswanto <git@dw1.io> * chore: satisfy lints Signed-off-by: Dwi Siswanto <git@dw1.io> * build: migrate `github.com/xanzy/go-gitlab` => `gitlab.com/gitlab-org/api/client-go` Signed-off-by: Dwi Siswanto <git@dw1.io> * feat(json): update build constraints Signed-off-by: Dwi Siswanto <git@dw1.io> * chore: dont panicking on close err Signed-off-by: Dwi Siswanto <git@dw1.io> --------- Signed-off-by: Dwi Siswanto <git@dw1.io>
71 lines
1.6 KiB
Go
71 lines
1.6 KiB
Go
package openapi
|
|
|
|
import (
|
|
"os"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/projectdiscovery/nuclei/v3/pkg/input/types"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
const baseURL = "http://hackthebox:5000"
|
|
|
|
var methodToURLs = map[string][]string{
|
|
"GET": {
|
|
"{{baseUrl}}/createdb",
|
|
"{{baseUrl}}/",
|
|
"{{baseUrl}}/users/v1/John.Doe",
|
|
"{{baseUrl}}/users/v1",
|
|
"{{baseUrl}}/users/v1/_debug",
|
|
"{{baseUrl}}/books/v1",
|
|
"{{baseUrl}}/books/v1/bookTitle77",
|
|
},
|
|
"POST": {
|
|
"{{baseUrl}}/users/v1/register",
|
|
"{{baseUrl}}/users/v1/login",
|
|
"{{baseUrl}}/books/v1",
|
|
},
|
|
"PUT": {
|
|
"{{baseUrl}}/users/v1/name1/email",
|
|
"{{baseUrl}}/users/v1/name1/password",
|
|
},
|
|
"DELETE": {
|
|
"{{baseUrl}}/users/v1/name1",
|
|
},
|
|
}
|
|
|
|
func TestOpenAPIParser(t *testing.T) {
|
|
format := New()
|
|
|
|
proxifyInputFile := "../testdata/openapi.yaml"
|
|
|
|
gotMethodsToURLs := make(map[string][]string)
|
|
|
|
file, err := os.Open(proxifyInputFile)
|
|
require.Nilf(t, err, "error opening proxify input file: %v", err)
|
|
defer func() {
|
|
_ = file.Close()
|
|
}()
|
|
|
|
err = format.Parse(file, func(rr *types.RequestResponse) bool {
|
|
gotMethodsToURLs[rr.Request.Method] = append(gotMethodsToURLs[rr.Request.Method],
|
|
strings.Replace(rr.URL.String(), baseURL, "{{baseUrl}}", 1))
|
|
return false
|
|
}, proxifyInputFile)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
if len(gotMethodsToURLs) != len(methodToURLs) {
|
|
t.Fatalf("invalid number of methods: %d", len(gotMethodsToURLs))
|
|
}
|
|
|
|
for method, urls := range gotMethodsToURLs {
|
|
if len(urls) != len(methodToURLs[method]) {
|
|
t.Fatalf("invalid number of urls for method %s: %d", method, len(urls))
|
|
}
|
|
require.ElementsMatch(t, urls, methodToURLs[method], "invalid urls for method %s", method)
|
|
}
|
|
}
|