handler: simplify parsing valid location constraint. (#4040)

Separate out validating v/s parsing logic in
isValidLocationConstraint() into parseLocationConstraint()
and isValidLocation()

Additionally also set `X-Amz-Bucket-Region` as part of the
common headers for the clients to fallback on in-case of any
region related errors.
This commit is contained in:
Harshavardhana
2017-04-03 14:50:09 -07:00
committed by GitHub
parent 4041e5f20d
commit 3fe33e7b15
5 changed files with 35 additions and 31 deletions

View File

@@ -39,7 +39,7 @@ func TestIsValidLocationContraint(t *testing.T) {
Body: ioutil.NopCloser(bytes.NewBuffer([]byte("<>"))),
ContentLength: int64(len("<>")),
}
if err := isValidLocationConstraint(malformedReq); err != ErrMalformedXML {
if _, err := parseLocationConstraint(malformedReq); err != ErrMalformedXML {
t.Fatal("Unexpected error: ", err)
}
@@ -68,8 +68,6 @@ func TestIsValidLocationContraint(t *testing.T) {
// Test case - 2.
// In case of empty request body ErrNone is returned.
{"", globalMinioDefaultRegion, ErrNone},
// Test case - 3.
{"eu-central-1", globalMinioDefaultRegion, ErrInvalidRegion},
}
for i, testCase := range testCases {
inputRequest, e := createExpectedRequest(&http.Request{}, testCase.locationForInputRequest)
@@ -77,7 +75,7 @@ func TestIsValidLocationContraint(t *testing.T) {
t.Fatalf("Test %d: Failed to Marshal bucket configuration", i+1)
}
serverConfig.SetRegion(testCase.serverConfigRegion)
actualCode := isValidLocationConstraint(inputRequest)
_, actualCode := parseLocationConstraint(inputRequest)
if testCase.expectedCode != actualCode {
t.Errorf("Test %d: Expected the APIErrCode to be %d, but instead found %d", i+1, testCase.expectedCode, actualCode)
}