From e605787e651ceb86b770277b6d845e09396137db Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Thu, 16 Jul 2015 14:08:33 -0700 Subject: [PATCH] Method not allowed is right response for DELETE() operations and add tests --- pkg/server/api/object-handlers.go | 4 ++-- pkg/server/api_donut_cache_test.go | 19 +++++++++++++++++++ pkg/server/api_donut_test.go | 19 +++++++++++++++++++ pkg/server/api_signature_v4_test.go | 19 +++++++++++++++++++ 4 files changed, 59 insertions(+), 2 deletions(-) diff --git a/pkg/server/api/object-handlers.go b/pkg/server/api/object-handlers.go index d8a2b6a9c..f1a5d73d5 100644 --- a/pkg/server/api/object-handlers.go +++ b/pkg/server/api/object-handlers.go @@ -580,12 +580,12 @@ func (api Minio) CompleteMultipartUploadHandler(w http.ResponseWriter, req *http // DeleteBucketHandler - Delete bucket func (api Minio) DeleteBucketHandler(w http.ResponseWriter, req *http.Request) { - error := getErrorCode(NotImplemented) + error := getErrorCode(MethodNotAllowed) w.WriteHeader(error.HTTPStatusCode) } // DeleteObjectHandler - Delete object func (api Minio) DeleteObjectHandler(w http.ResponseWriter, req *http.Request) { - error := getErrorCode(NotImplemented) + error := getErrorCode(MethodNotAllowed) w.WriteHeader(error.HTTPStatusCode) } diff --git a/pkg/server/api_donut_cache_test.go b/pkg/server/api_donut_cache_test.go index 6e3cb04cf..a0afb142d 100644 --- a/pkg/server/api_donut_cache_test.go +++ b/pkg/server/api_donut_cache_test.go @@ -65,6 +65,25 @@ func (s *MyAPIDonutCacheSuite) TearDownSuite(c *C) { testAPIDonutCacheServer.Close() } +func (s *MyAPIDonutCacheSuite) TestDeleteBucket(c *C) { + request, err := http.NewRequest("DELETE", testAPIDonutCacheServer.URL+"/mybucket", nil) + c.Assert(err, IsNil) + + client := &http.Client{} + response, err := client.Do(request) + c.Assert(err, IsNil) + c.Assert(response.StatusCode, Equals, http.StatusMethodNotAllowed) +} + +func (s *MyAPIDonutCacheSuite) TestDeleteObject(c *C) { + request, err := http.NewRequest("DELETE", testAPIDonutCacheServer.URL+"/mybucket/myobject", nil) + c.Assert(err, IsNil) + client := &http.Client{} + response, err := client.Do(request) + c.Assert(err, IsNil) + c.Assert(response.StatusCode, Equals, http.StatusMethodNotAllowed) +} + func (s *MyAPIDonutCacheSuite) TestNonExistantBucket(c *C) { request, err := http.NewRequest("HEAD", testAPIDonutCacheServer.URL+"/nonexistantbucket", nil) c.Assert(err, IsNil) diff --git a/pkg/server/api_donut_test.go b/pkg/server/api_donut_test.go index d16abe89c..23b370c19 100644 --- a/pkg/server/api_donut_test.go +++ b/pkg/server/api_donut_test.go @@ -84,6 +84,25 @@ func (s *MyAPIDonutSuite) TearDownSuite(c *C) { testAPIDonutServer.Close() } +func (s *MyAPIDonutSuite) TestDeleteBucket(c *C) { + request, err := http.NewRequest("DELETE", testAPIDonutServer.URL+"/mybucket", nil) + c.Assert(err, IsNil) + + client := &http.Client{} + response, err := client.Do(request) + c.Assert(err, IsNil) + c.Assert(response.StatusCode, Equals, http.StatusMethodNotAllowed) +} + +func (s *MyAPIDonutSuite) TestDeleteObject(c *C) { + request, err := http.NewRequest("DELETE", testAPIDonutServer.URL+"/mybucket/myobject", nil) + c.Assert(err, IsNil) + client := &http.Client{} + response, err := client.Do(request) + c.Assert(err, IsNil) + c.Assert(response.StatusCode, Equals, http.StatusMethodNotAllowed) +} + func (s *MyAPIDonutSuite) TestNonExistantBucket(c *C) { request, err := http.NewRequest("HEAD", testAPIDonutServer.URL+"/nonexistantbucket", nil) c.Assert(err, IsNil) diff --git a/pkg/server/api_signature_v4_test.go b/pkg/server/api_signature_v4_test.go index 889ac4a7d..8c7b4463e 100644 --- a/pkg/server/api_signature_v4_test.go +++ b/pkg/server/api_signature_v4_test.go @@ -92,6 +92,25 @@ func (s *MyAPISignatureV4Suite) TearDownSuite(c *C) { testSignatureV4Server.Close() } +func (s *MyAPISignatureV4Suite) TestDeleteBucket(c *C) { + request, err := http.NewRequest("DELETE", testSignatureV4Server.URL+"/mybucket", nil) + c.Assert(err, IsNil) + + client := &http.Client{} + response, err := client.Do(request) + c.Assert(err, IsNil) + c.Assert(response.StatusCode, Equals, http.StatusMethodNotAllowed) +} + +func (s *MyAPISignatureV4Suite) TestDeleteObject(c *C) { + request, err := http.NewRequest("DELETE", testSignatureV4Server.URL+"/mybucket/myobject", nil) + c.Assert(err, IsNil) + client := &http.Client{} + response, err := client.Do(request) + c.Assert(err, IsNil) + c.Assert(response.StatusCode, Equals, http.StatusMethodNotAllowed) +} + func (s *MyAPISignatureV4Suite) TestNonExistantBucket(c *C) { request, err := s.newRequest("HEAD", testSignatureV4Server.URL+"/nonexistantbucket", 0, nil) c.Assert(err, IsNil)