From 402c92beda931f587039451be4603984e163d80b Mon Sep 17 00:00:00 2001 From: Krishnan Parthasarathi Date: Tue, 4 Oct 2016 20:27:35 +0530 Subject: [PATCH] Add listObjectParts test w/ unknown request signature type (#2847) --- cmd/object-handlers_test.go | 56 +++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/cmd/object-handlers_test.go b/cmd/object-handlers_test.go index 1446f706e..5ad2f388f 100644 --- a/cmd/object-handlers_test.go +++ b/cmd/object-handlers_test.go @@ -1610,6 +1610,62 @@ func TestListObjectPartsHandlerV2(t *testing.T) { ExecObjectLayerAPITest(t, testAPIListObjectPartsHandlerV2, []string{"PutObjectPart", "NewMultipart", "ListObjectParts"}) } +func testAPIListObjectPartsHandlerUnknown(obj ObjectLayer, instanceType, bucketName string, apiRouter http.Handler, + credentials credential, t TestErrHandler) { + testObject := "testobject" + rec := httptest.NewRecorder() + req, err := newTestSignedRequestV4("POST", getNewMultipartURL("", bucketName, testObject), + 0, nil, credentials.AccessKeyID, credentials.SecretAccessKey) + if err != nil { + t.Fatalf("[%s] - Failed to create a signed request to initiate multipart upload for %s/%s: %v", + instanceType, bucketName, testObject, err) + } + apiRouter.ServeHTTP(rec, req) + + // Get uploadID of the mulitpart upload initiated. + var mpartResp InitiateMultipartUploadResponse + mpartRespBytes, err := ioutil.ReadAll(rec.Result().Body) + if err != nil { + t.Fatalf("[%s] Failed to read NewMultipartUpload response %v", instanceType, err) + + } + err = xml.Unmarshal(mpartRespBytes, &mpartResp) + if err != nil { + t.Fatalf("[%s] Failed to unmarshal NewMultipartUpload response %v", instanceType, err) + } + accessDeniedErr := getAPIError(ErrAccessDenied) + unKnownRec := httptest.NewRecorder() + unKnownReq, aErr := newTestRequest("GET", + getListMultipartURLWithParams("", bucketName, testObject, mpartResp.UploadID, "", "", ""), + 0, nil) + if aErr != nil { + t.Fatalf("Test %d %s Failed to create an unKnownymous request to list multipart of an upload for %s/%s: %v", + 1, instanceType, bucketName, testObject, aErr) + } + unKnownReq.Header.Set("Authorization", "nothingElse") + apiRouter.ServeHTTP(unKnownRec, unKnownReq) + unKnownErrBytes, err := ioutil.ReadAll(unKnownRec.Result().Body) + if err != nil { + t.Fatalf("Test %d %s Failed to read error response from list object parts request %s/%s: %v", + 1, instanceType, bucketName, testObject, err) + } + var unKnownErrXML APIErrorResponse + err = xml.Unmarshal(unKnownErrBytes, &unKnownErrXML) + if err != nil { + t.Fatalf("Test %d %s Failed to unmarshal error response from list object parts request %s/%s: %v", + 1, instanceType, bucketName, testObject, err) + } + if accessDeniedErr.Code != unKnownErrXML.Code { + t.Errorf("Test %d %s expected to fail with error %s, but received %s", 1, instanceType, + accessDeniedErr.Code, unKnownErrXML.Code) + } +} + +func TestAPIListObjectPartsHandlerUnknown(t *testing.T) { + ExecObjectLayerAPITest(t, testAPIListObjectPartsHandlerUnknown, + []string{"PutObjectPart", "NewMultipart", "ListObjectParts"}) +} + func testAPIListObjectPartsHandlerAnon(obj ObjectLayer, instanceType, bucketName string, apiRouter http.Handler, credentials credential, t TestErrHandler) { // Initialize bucket policies for anonymous request test