// ExecObjectLayerAPIAnonTest - Helper function to validate object Layer API handler response for anonymous/unsigned HTTP request.
// ExecObjectLayerAPIAnonTest - Helper function to validate object Layer API handler
// response for anonymous/unsigned and unknown signature type HTTP request.
// Here is the brief description of some of the arguments to the function below.
// Here is the brief description of some of the arguments to the function below.
// apiRouter - http.Handler with the relevant API endPoint (API endPoint under test) registered.
// apiRouter - http.Handler with the relevant API endPoint (API endPoint under test) registered.
// anonReq - unsigned *http.Request to invoke the handler's response for anonymous requests.
// anonReq - unsigned *http.Request to invoke the handler's response for anonymous requests.
// policyFunc - function to return bucketPolicy statement which would permit the anonymous request to be served.
// policyFunc - function to return bucketPolicy statement which would permit the anonymous request to be served.
// The test works in 2 steps, here is the description of the steps.
// The test works in 2 steps, here is the description of the steps.
// STEP 1: Call the handler with the unsigned HTTP request (anonReq), assert for the `ErrAccessDenied` error response.
// STEP 1: Call the handler with the unsigned HTTP request (anonReq), assert for the `ErrAccessDenied` error response.
// STEP 2: Set the policy to allow the unsigned request, use the policyFunc to obtain the relevant statement and call the handler again to verify its success.
// STEP 2: Set the policy to allow the unsigned request, use the policyFunc to obtain the relevant statement and call
// compare the HTTP response status code with the expected one.
// compare the HTTP response status code with the expected one.
ifrec.Code!=expectedHTTPStatus{
ifrec.Code!=expectedHTTPStatus{
failTest(fmt.Sprintf("Expected the anonymous HTTP request to be served after the policy changes\n,Expected response HTTP status code to be %d, got %d.",
failTest(anonTestStr,fmt.Sprintf("Expected the anonymous HTTP request to be served after the policy changes\n,Expected response HTTP status code to be %d, got %d.",
expectedHTTPStatus,rec.Code))
expectedHTTPStatus,rec.Code))
}
}
// test for unknown auth case.
anonReq.Body=readerThree
// Setting the `Authorization` header to a random value so that the signature falls into unknown auth case.
anonReq.Header.Set("Authorization","nothingElse")
// initialize new response recorder.
rec=httptest.NewRecorder()
// call the handler using the HTTP Request.
apiRouter.ServeHTTP(rec,anonReq)
// verify the response body for `ErrAccessDenied` message =.
failTest(unknownSignTestStr,"error response content differs from expected value")
}
}
ifrec.Code!=accesDeniedHTTPStatus{
failTest(unknownSignTestStr,fmt.Sprintf("Object API Unknow auth test for \"%s\", expected to fail with %d, but failed with %d.",testName,accesDeniedHTTPStatus,rec.Code))
}
}
}
// ExecObjectLayerAPINilTest - Sets the object layer to `nil`, and calls rhe registered object layer API endpoint, and assert the error response.
// ExecObjectLayerAPINilTest - Sets the object layer to `nil`, and calls rhe registered object layer API endpoint, and assert the error response.