mirror of
https://github.com/minio/minio.git
synced 2025-01-27 06:33:18 -05:00
Implement x-amz-acl tests
This commit is contained in:
parent
107e077ec0
commit
2c1455af1b
@ -453,6 +453,7 @@ func (s *MySuite) TestPutBucket(c *C) {
|
|||||||
typedDriver.On("CreateBucket", "bucket").Return(nil).Once()
|
typedDriver.On("CreateBucket", "bucket").Return(nil).Once()
|
||||||
request, err := http.NewRequest("PUT", testServer.URL+"/bucket", bytes.NewBufferString(""))
|
request, err := http.NewRequest("PUT", testServer.URL+"/bucket", bytes.NewBufferString(""))
|
||||||
c.Assert(err, IsNil)
|
c.Assert(err, IsNil)
|
||||||
|
request.Header.Add("x-amz-acl", "private")
|
||||||
|
|
||||||
client := http.Client{}
|
client := http.Client{}
|
||||||
response, err := client.Do(request)
|
response, err := client.Do(request)
|
||||||
@ -499,6 +500,7 @@ func (s *MySuite) TestPutObject(c *C) {
|
|||||||
typedDriver.On("CreateBucket", "bucket").Return(nil).Once()
|
typedDriver.On("CreateBucket", "bucket").Return(nil).Once()
|
||||||
request, err := http.NewRequest("PUT", testServer.URL+"/bucket", bytes.NewBufferString(""))
|
request, err := http.NewRequest("PUT", testServer.URL+"/bucket", bytes.NewBufferString(""))
|
||||||
c.Assert(err, IsNil)
|
c.Assert(err, IsNil)
|
||||||
|
request.Header.Add("x-amz-acl", "private")
|
||||||
|
|
||||||
client := http.Client{}
|
client := http.Client{}
|
||||||
response, err := client.Do(request)
|
response, err := client.Do(request)
|
||||||
@ -970,6 +972,8 @@ func (s *MySuite) TestPutBucketErrors(c *C) {
|
|||||||
typedDriver.On("CreateBucket", "foo").Return(drivers.BucketNameInvalid{}).Once()
|
typedDriver.On("CreateBucket", "foo").Return(drivers.BucketNameInvalid{}).Once()
|
||||||
request, err := http.NewRequest("PUT", testServer.URL+"/foo", bytes.NewBufferString(""))
|
request, err := http.NewRequest("PUT", testServer.URL+"/foo", bytes.NewBufferString(""))
|
||||||
c.Assert(err, IsNil)
|
c.Assert(err, IsNil)
|
||||||
|
request.Header.Add("x-amz-acl", "private")
|
||||||
|
|
||||||
response, err := client.Do(request)
|
response, err := client.Do(request)
|
||||||
c.Assert(err, IsNil)
|
c.Assert(err, IsNil)
|
||||||
verifyError(c, response, "InvalidBucketName", "The specified bucket is not valid.", http.StatusBadRequest)
|
verifyError(c, response, "InvalidBucketName", "The specified bucket is not valid.", http.StatusBadRequest)
|
||||||
@ -977,6 +981,8 @@ func (s *MySuite) TestPutBucketErrors(c *C) {
|
|||||||
typedDriver.On("CreateBucket", "foo").Return(drivers.BucketExists{}).Once()
|
typedDriver.On("CreateBucket", "foo").Return(drivers.BucketExists{}).Once()
|
||||||
request, err = http.NewRequest("PUT", testServer.URL+"/foo", bytes.NewBufferString(""))
|
request, err = http.NewRequest("PUT", testServer.URL+"/foo", bytes.NewBufferString(""))
|
||||||
c.Assert(err, IsNil)
|
c.Assert(err, IsNil)
|
||||||
|
request.Header.Add("x-amz-acl", "private")
|
||||||
|
|
||||||
response, err = client.Do(request)
|
response, err = client.Do(request)
|
||||||
c.Assert(err, IsNil)
|
c.Assert(err, IsNil)
|
||||||
verifyError(c, response, "BucketAlreadyExists", "The requested bucket name is not available.", http.StatusConflict)
|
verifyError(c, response, "BucketAlreadyExists", "The requested bucket name is not available.", http.StatusConflict)
|
||||||
@ -984,9 +990,20 @@ func (s *MySuite) TestPutBucketErrors(c *C) {
|
|||||||
typedDriver.On("CreateBucket", "foo").Return(drivers.BackendCorrupted{}).Once()
|
typedDriver.On("CreateBucket", "foo").Return(drivers.BackendCorrupted{}).Once()
|
||||||
request, err = http.NewRequest("PUT", testServer.URL+"/foo", bytes.NewBufferString(""))
|
request, err = http.NewRequest("PUT", testServer.URL+"/foo", bytes.NewBufferString(""))
|
||||||
c.Assert(err, IsNil)
|
c.Assert(err, IsNil)
|
||||||
|
request.Header.Add("x-amz-acl", "private")
|
||||||
|
|
||||||
response, err = client.Do(request)
|
response, err = client.Do(request)
|
||||||
c.Assert(err, IsNil)
|
c.Assert(err, IsNil)
|
||||||
verifyError(c, response, "InternalError", "We encountered an internal error, please try again.", http.StatusInternalServerError)
|
verifyError(c, response, "InternalError", "We encountered an internal error, please try again.", http.StatusInternalServerError)
|
||||||
|
|
||||||
|
typedDriver.On("CreateBucket", "foo").Return(nil).Once()
|
||||||
|
request, err = http.NewRequest("PUT", testServer.URL+"/foo", bytes.NewBufferString(""))
|
||||||
|
c.Assert(err, IsNil)
|
||||||
|
request.Header.Add("x-amz-acl", "unknown")
|
||||||
|
|
||||||
|
response, err = client.Do(request)
|
||||||
|
c.Assert(err, IsNil)
|
||||||
|
verifyError(c, response, "NotImplemented", "A header you provided implies functionality that is not implemented.", http.StatusNotImplemented)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *MySuite) TestGetObjectErrors(c *C) {
|
func (s *MySuite) TestGetObjectErrors(c *C) {
|
||||||
|
@ -16,10 +16,7 @@
|
|||||||
|
|
||||||
package api
|
package api
|
||||||
|
|
||||||
import (
|
import "net/http"
|
||||||
"net/http"
|
|
||||||
"strings"
|
|
||||||
)
|
|
||||||
|
|
||||||
type contentType int
|
type contentType int
|
||||||
|
|
||||||
@ -32,14 +29,17 @@ const (
|
|||||||
// Get content type requested from 'Accept' header
|
// Get content type requested from 'Accept' header
|
||||||
func getContentType(req *http.Request) contentType {
|
func getContentType(req *http.Request) contentType {
|
||||||
acceptHeader := req.Header.Get("Accept")
|
acceptHeader := req.Header.Get("Accept")
|
||||||
switch {
|
if acceptHeader != "" {
|
||||||
case strings.HasPrefix(acceptHeader, "application/json"):
|
switch {
|
||||||
return jsonContentType
|
case acceptHeader == "application/json":
|
||||||
case strings.HasPrefix(acceptHeader, "application/xml"):
|
return jsonContentType
|
||||||
return xmlContentType
|
case acceptHeader == "application/xml":
|
||||||
default:
|
return xmlContentType
|
||||||
return unknownContentType
|
default:
|
||||||
|
return unknownContentType
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
return xmlContentType
|
||||||
}
|
}
|
||||||
|
|
||||||
// Content type to human readable string
|
// Content type to human readable string
|
||||||
|
Loading…
x
Reference in New Issue
Block a user