mirror of
https://github.com/minio/minio.git
synced 2026-02-05 02:10:14 -05:00
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:
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user