nuclei/pkg/fuzz/component/path_test.go
Dwi Siswanto 87ed0b2bb9
build: bump all direct modules (#6290)
* 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>
2025-07-01 00:40:44 +07:00

81 lines
1.7 KiB
Go

package component
import (
"net/http"
"testing"
"github.com/projectdiscovery/retryablehttp-go"
"github.com/stretchr/testify/require"
)
func TestURLComponent(t *testing.T) {
req, err := retryablehttp.NewRequest(http.MethodGet, "https://example.com/testpath", nil)
if err != nil {
t.Fatal(err)
}
urlComponent := NewPath()
_, err = urlComponent.Parse(req)
if err != nil {
t.Fatal(err)
}
var keys []string
var values []string
_ = urlComponent.Iterate(func(key string, value interface{}) error {
keys = append(keys, key)
values = append(values, value.(string))
return nil
})
require.Equal(t, []string{"1"}, keys, "unexpected keys")
require.Equal(t, []string{"/testpath"}, values, "unexpected values")
err = urlComponent.SetValue("1", "/newpath")
if err != nil {
t.Fatal(err)
}
rebuilt, err := urlComponent.Rebuild()
if err != nil {
t.Fatal(err)
}
require.Equal(t, "/newpath", rebuilt.Path, "unexpected URL path")
require.Equal(t, "https://example.com/newpath", rebuilt.String(), "unexpected full URL")
}
func TestURLComponent_NestedPaths(t *testing.T) {
path := NewPath()
req, err := retryablehttp.NewRequest(http.MethodGet, "https://example.com/user/753/profile", nil)
if err != nil {
t.Fatal(err)
}
found, err := path.Parse(req)
if err != nil {
t.Fatal(err)
}
if !found {
t.Fatal("expected path to be found")
}
isSet := false
_ = path.Iterate(func(key string, value interface{}) error {
if !isSet && value.(string) == "/user/753" {
isSet = true
if setErr := path.SetValue(key, "/user/753'"); setErr != nil {
t.Fatal(setErr)
}
}
return nil
})
newReq, err := path.Rebuild()
if err != nil {
t.Fatal(err)
}
if newReq.Path != "/user/753'/profile" {
t.Fatal("expected path to be modified")
}
}