api: postPolicy cleanup. Simplify the code and re-use. (#3890)
This change is cleanup of the postPolicyHandler code primarily to address the flow and also converting certain critical parts into self contained functions.
This commit is contained in:
@@ -22,6 +22,7 @@ import (
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"reflect"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
@@ -83,6 +84,44 @@ func TestIsValidLocationContraint(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// Test validate form field size.
|
||||
func TestValidateFormFieldSize(t *testing.T) {
|
||||
testCases := []struct {
|
||||
header http.Header
|
||||
err error
|
||||
}{
|
||||
// Empty header returns error as nil,
|
||||
{
|
||||
header: nil,
|
||||
err: nil,
|
||||
},
|
||||
// Valid header returns error as nil.
|
||||
{
|
||||
header: http.Header{
|
||||
"Content-Type": []string{"image/png"},
|
||||
},
|
||||
err: nil,
|
||||
},
|
||||
// Invalid header value > maxFormFieldSize+1
|
||||
{
|
||||
header: http.Header{
|
||||
"Garbage": []string{strings.Repeat("a", int(maxFormFieldSize)+1)},
|
||||
},
|
||||
err: errSizeUnexpected,
|
||||
},
|
||||
}
|
||||
|
||||
// Run validate form field size check under all test cases.
|
||||
for i, testCase := range testCases {
|
||||
err := validateFormFieldSize(testCase.header)
|
||||
if err != nil {
|
||||
if errorCause(err).Error() != testCase.err.Error() {
|
||||
t.Errorf("Test %d: Expected error %s, got %s", i+1, testCase.err, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Tests validate metadata extraction from http headers.
|
||||
func TestExtractMetadataHeaders(t *testing.T) {
|
||||
testCases := []struct {
|
||||
@@ -115,6 +154,11 @@ func TestExtractMetadataHeaders(t *testing.T) {
|
||||
"X-Amz-Meta-Appid": "amz-meta",
|
||||
"X-Minio-Meta-Appid": "minio-meta"},
|
||||
},
|
||||
// Empty header input returns empty metadata.
|
||||
{
|
||||
header: nil,
|
||||
metadata: nil,
|
||||
},
|
||||
}
|
||||
|
||||
// Validate if the extracting headers.
|
||||
|
||||
Reference in New Issue
Block a user