mirror of
https://github.com/minio/minio.git
synced 2025-03-30 17:23:42 -04:00
tests: use url.QueryEscape() when dealing with url query params. (#3974)
This is to keep the portability and also avoid errors that might occur using the functions written for URL resource name Since query param values have different escaping requirements.
This commit is contained in:
parent
a4ecd8bca2
commit
565ac4c861
@ -845,39 +845,6 @@ func newTestStreamingSignedRequest(method, urlStr string, contentLength, chunkSi
|
|||||||
return req, err
|
return req, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Replaces any occurring '/' in string, into its encoded
|
|
||||||
// representation.
|
|
||||||
func percentEncodeSlash(s string) string {
|
|
||||||
return strings.Replace(s, "/", "%2F", -1)
|
|
||||||
}
|
|
||||||
|
|
||||||
// queryEncode - encodes query values in their URL encoded form. In
|
|
||||||
// addition to the percent encoding performed by getURLEncodedName()
|
|
||||||
// used here, it also percent encodes '/' (forward slash)
|
|
||||||
func queryEncode(v url.Values) string {
|
|
||||||
if v == nil {
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
var buf bytes.Buffer
|
|
||||||
keys := make([]string, 0, len(v))
|
|
||||||
for k := range v {
|
|
||||||
keys = append(keys, k)
|
|
||||||
}
|
|
||||||
sort.Strings(keys)
|
|
||||||
for _, k := range keys {
|
|
||||||
vs := v[k]
|
|
||||||
prefix := percentEncodeSlash(getURLEncodedName(k)) + "="
|
|
||||||
for _, v := range vs {
|
|
||||||
if buf.Len() > 0 {
|
|
||||||
buf.WriteByte('&')
|
|
||||||
}
|
|
||||||
buf.WriteString(prefix)
|
|
||||||
buf.WriteString(percentEncodeSlash(getURLEncodedName(v)))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return buf.String()
|
|
||||||
}
|
|
||||||
|
|
||||||
// preSignV4 presign the request, in accordance with
|
// preSignV4 presign the request, in accordance with
|
||||||
// http://docs.aws.amazon.com/AmazonS3/latest/API/sigv4-query-string-auth.html.
|
// http://docs.aws.amazon.com/AmazonS3/latest/API/sigv4-query-string-auth.html.
|
||||||
func preSignV4(req *http.Request, accessKeyID, secretAccessKey string, expires int64) error {
|
func preSignV4(req *http.Request, accessKeyID, secretAccessKey string, expires int64) error {
|
||||||
@ -912,7 +879,7 @@ func preSignV4(req *http.Request, accessKeyID, secretAccessKey string, expires i
|
|||||||
req.URL.RawQuery = query.Encode()
|
req.URL.RawQuery = query.Encode()
|
||||||
|
|
||||||
// Add signature header to RawQuery.
|
// Add signature header to RawQuery.
|
||||||
req.URL.RawQuery += "&X-Amz-Signature=" + signature
|
req.URL.RawQuery += "&X-Amz-Signature=" + url.QueryEscape(signature)
|
||||||
|
|
||||||
// Construct the final presigned URL.
|
// Construct the final presigned URL.
|
||||||
return nil
|
return nil
|
||||||
@ -963,10 +930,10 @@ func preSignV2(req *http.Request, accessKeyID, secretAccessKey string, expires i
|
|||||||
query.Set("Expires", strconv.FormatInt(epochExpires, 10))
|
query.Set("Expires", strconv.FormatInt(epochExpires, 10))
|
||||||
|
|
||||||
// Encode query and save.
|
// Encode query and save.
|
||||||
req.URL.RawQuery = queryEncode(query)
|
req.URL.RawQuery = query.Encode()
|
||||||
|
|
||||||
// Save signature finally.
|
// Save signature finally.
|
||||||
req.URL.RawQuery += "&Signature=" + getURLEncodedName(signature)
|
req.URL.RawQuery += "&Signature=" + url.QueryEscape(signature)
|
||||||
|
|
||||||
// Success.
|
// Success.
|
||||||
return nil
|
return nil
|
||||||
@ -1398,7 +1365,7 @@ func makeTestTargetURL(endPoint, bucketName, objectName string, queryValues url.
|
|||||||
urlStr = urlStr + getURLEncodedName(objectName)
|
urlStr = urlStr + getURLEncodedName(objectName)
|
||||||
}
|
}
|
||||||
if len(queryValues) > 0 {
|
if len(queryValues) > 0 {
|
||||||
urlStr = urlStr + "?" + queryEncode(queryValues)
|
urlStr = urlStr + "?" + queryValues.Encode()
|
||||||
}
|
}
|
||||||
return urlStr
|
return urlStr
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user