tests: Move signature calculation in separate function. (#2160)

Previously newTestRequest() creates request object and returns
signature v4 signed request.  In TestCopyObject(), its required to add
headers later to the request and sign the request.

This patch introduces two new functions
* signRequest(): signs request using given access/secret keys.
* newTestSignedRequest(): returns new request object signed with given
  access/secret keys.

Fixes #2097
This commit is contained in:
Bala FA
2016-07-10 23:40:59 +05:30
committed by Harshavardhana
parent 2a95eabb8a
commit 0793237d94
5 changed files with 252 additions and 214 deletions

View File

@@ -58,6 +58,9 @@ func sumHMAC(key []byte, data []byte) []byte {
return hash.Sum(nil)
}
// Reserved string regexp.
var reservedNames = regexp.MustCompile("^[a-zA-Z0-9-_.~/]+$")
// getURLEncodedName encode the strings from UTF-8 byte representations to HTML hex escape sequences
//
// This is necessary since regular url.Parse() and url.Encode() functions do not support UTF-8
@@ -67,7 +70,6 @@ func sumHMAC(key []byte, data []byte) []byte {
// pretty much every UTF-8 character.
func getURLEncodedName(name string) string {
// if object matches reserved string, no need to encode them
reservedNames := regexp.MustCompile("^[a-zA-Z0-9-_.~/]+$")
if reservedNames.MatchString(name) {
return name
}