mirror of
https://github.com/minio/minio.git
synced 2024-12-28 08:05:55 -05:00
Merge pull request #427 from harshavardhana/pr_out_parse_response_headers_in_tests
This commit is contained in:
commit
f848c4095f
@ -36,6 +36,14 @@ func (server *minioAPI) listObjectsHandler(w http.ResponseWriter, req *http.Requ
|
|||||||
|
|
||||||
resources := getBucketResources(req.URL.Query())
|
resources := getBucketResources(req.URL.Query())
|
||||||
if resources.Policy == true {
|
if resources.Policy == true {
|
||||||
|
// TODO
|
||||||
|
// ----
|
||||||
|
// This is handled here instead of router, is only because semantically
|
||||||
|
// resource queries are not treated differently by Gorilla mux
|
||||||
|
//
|
||||||
|
// In-fact a request coming in as /bucket/?policy={} and /bucket/object are
|
||||||
|
// treated similarly. A proper fix would be to remove this comment and
|
||||||
|
// find a right regex pattern for individual requests
|
||||||
server.getBucketPolicyHandler(w, req)
|
server.getBucketPolicyHandler(w, req)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -51,13 +51,13 @@ func (server *minioAPI) getObjectHandler(w http.ResponseWriter, req *http.Reques
|
|||||||
setObjectHeaders(w, metadata)
|
setObjectHeaders(w, metadata)
|
||||||
if _, err := server.driver.GetObject(w, bucket, object); err != nil {
|
if _, err := server.driver.GetObject(w, bucket, object); err != nil {
|
||||||
// unable to write headers, we've already printed data. Just close the connection.
|
// unable to write headers, we've already printed data. Just close the connection.
|
||||||
|
log.Error.Println(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case false:
|
case false:
|
||||||
{
|
{
|
||||||
metadata.Size = httpRange.length
|
metadata.Size = httpRange.length
|
||||||
setRangeObjectHeaders(w, metadata, httpRange)
|
setRangeObjectHeaders(w, metadata, httpRange)
|
||||||
// contentRangeValue := "bytes " + strconv.FormatInt(httpRange.start, 10) + "-" + strconv.FormatInt(httpRange.length, 10) + "/" + strconv.FormatInt(httpRange.size, 10)
|
|
||||||
w.WriteHeader(http.StatusPartialContent)
|
w.WriteHeader(http.StatusPartialContent)
|
||||||
_, err := server.driver.GetPartialObject(w, bucket, object, httpRange.start, httpRange.length)
|
_, err := server.driver.GetPartialObject(w, bucket, object, httpRange.start, httpRange.length)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -147,8 +147,14 @@ func (server *minioAPI) putObjectHandler(w http.ResponseWriter, req *http.Reques
|
|||||||
|
|
||||||
resources := getBucketResources(req.URL.Query())
|
resources := getBucketResources(req.URL.Query())
|
||||||
if resources.Policy == true && object == "" {
|
if resources.Policy == true && object == "" {
|
||||||
// TODO figure out if we can hand this off to router instead of embedding here.
|
// TODO
|
||||||
// hand off request to pubBucketPolicyHandler
|
// ----
|
||||||
|
// This is handled here instead of router, is only because semantically
|
||||||
|
// resource queries are not treated differently by Gorilla mux
|
||||||
|
//
|
||||||
|
// In-fact a request coming in as /bucket/?policy={} and /bucket/object are
|
||||||
|
// treated similarly. A proper fix would be to remove this comment and
|
||||||
|
// find a right regex pattern for individual requests
|
||||||
server.putBucketPolicyHandler(w, req)
|
server.putBucketPolicyHandler(w, req)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -54,15 +54,11 @@ func generateBucketsListResult(buckets []drivers.BucketMetadata) BucketListRespo
|
|||||||
return data
|
return data
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// itemKey
|
||||||
type itemKey []*Item
|
type itemKey []*Item
|
||||||
|
|
||||||
// Len
|
func (b itemKey) Len() int { return len(b) }
|
||||||
func (b itemKey) Len() int { return len(b) }
|
func (b itemKey) Swap(i, j int) { b[i], b[j] = b[j], b[i] }
|
||||||
|
|
||||||
// Swap
|
|
||||||
func (b itemKey) Swap(i, j int) { b[i], b[j] = b[j], b[i] }
|
|
||||||
|
|
||||||
// Less
|
|
||||||
func (b itemKey) Less(i, j int) bool { return b[i].Key < b[j].Key }
|
func (b itemKey) Less(i, j int) bool { return b[i].Key < b[j].Key }
|
||||||
|
|
||||||
// takes a set of objects and prepares the objects for serialization
|
// takes a set of objects and prepares the objects for serialization
|
||||||
|
@ -31,6 +31,7 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/clbanning/mxj"
|
||||||
"github.com/minio-io/minio/pkg/api"
|
"github.com/minio-io/minio/pkg/api"
|
||||||
"github.com/minio-io/minio/pkg/drivers"
|
"github.com/minio-io/minio/pkg/drivers"
|
||||||
"github.com/minio-io/minio/pkg/drivers/donut"
|
"github.com/minio-io/minio/pkg/drivers/donut"
|
||||||
@ -121,6 +122,34 @@ func (s *MySuite) TearDownTest(c *C) {
|
|||||||
s.Root = ""
|
s.Root = ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* **** SAMPLE ERROR RESPONSE ****
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<Error>
|
||||||
|
<Code>AccessDenied</Code>
|
||||||
|
<Message>Access Denied</Message>
|
||||||
|
<Resource>/mybucket/myphoto.jpg</Resource>
|
||||||
|
<RequestId>F19772218238A85A</RequestId>
|
||||||
|
<HostId>GuWkjyviSiGHizehqpmsD1ndz5NClSP19DOT+s2mv7gXGQ8/X1lhbDGiIJEXpGFD</HostId>
|
||||||
|
</Error>
|
||||||
|
*/
|
||||||
|
|
||||||
|
type responseMap struct {
|
||||||
|
res *http.Response // response headers
|
||||||
|
resMsg mxj.Map // Keys: Code, Message, Resource, RequestId, HostId
|
||||||
|
}
|
||||||
|
|
||||||
|
// parseResponse returns a new initialized S3.Error structure
|
||||||
|
func parseResponse(res *http.Response) (*responseMap, error) {
|
||||||
|
var err error
|
||||||
|
resp := responseMap{}
|
||||||
|
resp.res = res
|
||||||
|
resp.resMsg, err = mxj.NewMapXmlReader(res.Body)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return &resp, nil
|
||||||
|
}
|
||||||
|
|
||||||
func (s *MySuite) TestNonExistantObject(c *C) {
|
func (s *MySuite) TestNonExistantObject(c *C) {
|
||||||
driver := s.Driver
|
driver := s.Driver
|
||||||
s.MockDriver.On("GetObjectMetadata", "bucket", "object", "").Return(drivers.ObjectMetadata{}, drivers.BucketNotFound{Bucket: "bucket"}).Once()
|
s.MockDriver.On("GetObjectMetadata", "bucket", "object", "").Return(drivers.ObjectMetadata{}, drivers.BucketNotFound{Bucket: "bucket"}).Once()
|
||||||
@ -130,7 +159,6 @@ func (s *MySuite) TestNonExistantObject(c *C) {
|
|||||||
|
|
||||||
response, err := http.Get(testServer.URL + "/bucket/object")
|
response, err := http.Get(testServer.URL + "/bucket/object")
|
||||||
c.Assert(err, IsNil)
|
c.Assert(err, IsNil)
|
||||||
c.Log(response.StatusCode)
|
|
||||||
c.Assert(response.StatusCode, Equals, http.StatusNotFound)
|
c.Assert(response.StatusCode, Equals, http.StatusNotFound)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -217,9 +245,8 @@ func (s *MySuite) TestMultipleObjects(c *C) {
|
|||||||
Key: "object1",
|
Key: "object1",
|
||||||
ContentType: "application/octet-stream",
|
ContentType: "application/octet-stream",
|
||||||
Created: time.Now(),
|
Created: time.Now(),
|
||||||
// TODO correct md5
|
Md5: "5eb63bbbe01eeed093cb22bb8f5acdc3", // TODO correct md5
|
||||||
Md5: "5eb63bbbe01eeed093cb22bb8f5acdc3",
|
Size: 9,
|
||||||
Size: 9,
|
|
||||||
}
|
}
|
||||||
metadata2 := drivers.ObjectMetadata{
|
metadata2 := drivers.ObjectMetadata{
|
||||||
Bucket: "bucket",
|
Bucket: "bucket",
|
||||||
@ -258,8 +285,12 @@ func (s *MySuite) TestMultipleObjects(c *C) {
|
|||||||
typedDriver.On("GetObjectMetadata", "bucket", "object", "").Return(drivers.ObjectMetadata{}, drivers.ObjectNotFound{}).Once()
|
typedDriver.On("GetObjectMetadata", "bucket", "object", "").Return(drivers.ObjectMetadata{}, drivers.ObjectNotFound{}).Once()
|
||||||
response, err := http.Get(testServer.URL + "/bucket/object")
|
response, err := http.Get(testServer.URL + "/bucket/object")
|
||||||
c.Assert(err, IsNil)
|
c.Assert(err, IsNil)
|
||||||
c.Assert(response.StatusCode, Equals, http.StatusNotFound)
|
responseMap, err := parseResponse(response)
|
||||||
// TODO Test Headers
|
c.Assert(err, IsNil)
|
||||||
|
c.Assert(responseMap.res.StatusCode, Equals, http.StatusNotFound)
|
||||||
|
values, err := responseMap.resMsg.ValuesForKey("Code")
|
||||||
|
c.Assert(err, IsNil)
|
||||||
|
c.Assert(values[0], Equals, "NoSuchKey")
|
||||||
|
|
||||||
//// test object 1
|
//// test object 1
|
||||||
|
|
||||||
@ -341,6 +372,7 @@ func (s *MySuite) TestNotImplemented(c *C) {
|
|||||||
response, err := http.Get(testServer.URL + "/bucket/object?acl")
|
response, err := http.Get(testServer.URL + "/bucket/object?acl")
|
||||||
c.Assert(err, IsNil)
|
c.Assert(err, IsNil)
|
||||||
c.Assert(response.StatusCode, Equals, http.StatusNotImplemented)
|
c.Assert(response.StatusCode, Equals, http.StatusNotImplemented)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *MySuite) TestHeader(c *C) {
|
func (s *MySuite) TestHeader(c *C) {
|
||||||
@ -354,7 +386,12 @@ func (s *MySuite) TestHeader(c *C) {
|
|||||||
typedDriver.On("GetObjectMetadata", "bucket", "object", "").Return(drivers.ObjectMetadata{}, drivers.ObjectNotFound{}).Once()
|
typedDriver.On("GetObjectMetadata", "bucket", "object", "").Return(drivers.ObjectMetadata{}, drivers.ObjectNotFound{}).Once()
|
||||||
response, err := http.Get(testServer.URL + "/bucket/object")
|
response, err := http.Get(testServer.URL + "/bucket/object")
|
||||||
c.Assert(err, IsNil)
|
c.Assert(err, IsNil)
|
||||||
c.Assert(response.StatusCode, Equals, http.StatusNotFound)
|
responseMap, err := parseResponse(response)
|
||||||
|
c.Assert(err, IsNil)
|
||||||
|
c.Assert(responseMap.res.StatusCode, Equals, http.StatusNotFound)
|
||||||
|
values, err := responseMap.resMsg.ValuesForKey("Code")
|
||||||
|
c.Assert(err, IsNil)
|
||||||
|
c.Assert(values[0], Equals, "NoSuchKey")
|
||||||
|
|
||||||
buffer := bytes.NewBufferString("hello world")
|
buffer := bytes.NewBufferString("hello world")
|
||||||
typedDriver.On("CreateBucket", "bucket").Return(nil).Once()
|
typedDriver.On("CreateBucket", "bucket").Return(nil).Once()
|
||||||
@ -367,9 +404,8 @@ func (s *MySuite) TestHeader(c *C) {
|
|||||||
Key: "object",
|
Key: "object",
|
||||||
ContentType: "application/octet-stream",
|
ContentType: "application/octet-stream",
|
||||||
Created: time.Now(),
|
Created: time.Now(),
|
||||||
// TODO correct md5
|
Md5: "5eb63bbbe01eeed093cb22bb8f5acdc3", // TODO correct md5
|
||||||
Md5: "5eb63bbbe01eeed093cb22bb8f5acdc3",
|
Size: 11,
|
||||||
Size: 11,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
typedDriver.On("GetObjectMetadata", "bucket", "object", "").Return(objectMetadata, nil).Once()
|
typedDriver.On("GetObjectMetadata", "bucket", "object", "").Return(objectMetadata, nil).Once()
|
||||||
@ -731,9 +767,8 @@ func (s *MySuite) TestPartialContent(c *C) {
|
|||||||
Key: "bar",
|
Key: "bar",
|
||||||
ContentType: "application/octet-stream",
|
ContentType: "application/octet-stream",
|
||||||
Created: time.Now(),
|
Created: time.Now(),
|
||||||
// TODO Determine if md5 of range or full object needed
|
Md5: "e81c4e4f2b7b93b481e13a8553c2ae1b", // TODO Determine if md5 of range or full object needed
|
||||||
Md5: "e81c4e4f2b7b93b481e13a8553c2ae1b",
|
Size: 11,
|
||||||
Size: 11,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
typedDriver.On("CreateBucket", "foo").Return(nil).Once()
|
typedDriver.On("CreateBucket", "foo").Return(nil).Once()
|
||||||
|
@ -88,6 +88,11 @@ func (file *fileDriver) GetObject(w io.Writer, bucket string, object string) (in
|
|||||||
return 0, drivers.BucketNameInvalid{Bucket: bucket}
|
return 0, drivers.BucketNameInvalid{Bucket: bucket}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// check bucket exists
|
||||||
|
if _, err := os.Stat(path.Join(file.root, bucket)); os.IsNotExist(err) {
|
||||||
|
return 0, drivers.BucketNotFound{Bucket: bucket}
|
||||||
|
}
|
||||||
|
|
||||||
// validate object
|
// validate object
|
||||||
if drivers.IsValidObject(object) == false {
|
if drivers.IsValidObject(object) == false {
|
||||||
return 0, drivers.ObjectNameInvalid{Bucket: bucket, Object: object}
|
return 0, drivers.ObjectNameInvalid{Bucket: bucket, Object: object}
|
||||||
|
Loading…
Reference in New Issue
Block a user