fix: List buckets response should return UTC modtime (#5004)

master
A. Elleuch 7 years ago committed by Dee Koder
parent 60cc6184d2
commit a4f26aec00
  1. 2
      cmd/api-response.go
  2. 36
      cmd/server_test.go

@ -307,7 +307,7 @@ func generateListBucketsResponse(buckets []BucketInfo) ListBucketsResponse {
for _, bucket := range buckets {
var listbucket = Bucket{}
listbucket.Name = bucket.Name
listbucket.CreationDate = bucket.Created.Format(timeFormatAMZLong)
listbucket.CreationDate = bucket.Created.UTC().Format(timeFormatAMZLong)
listbucket.HealBucketInfo = bucket.HealBucketInfo
listbuckets = append(listbuckets, listbucket)
}

@ -1151,23 +1151,53 @@ func (s *TestSuiteCommon) TestPutObject(c *C) {
// XML response is parsed.
// Its success verifies the format of the response.
func (s *TestSuiteCommon) TestListBuckets(c *C) {
// create HTTP request for listing buckets.
request, err := newTestSignedRequest("GET", getListBucketURL(s.endPoint),
// generate a random bucket name.
bucketName := getRandomBucketName()
// HTTP request to create the bucket.
request, err := newTestSignedRequest("PUT", getMakeBucketURL(s.endPoint, bucketName),
0, nil, s.accessKey, s.secretKey, s.signer)
c.Assert(err, IsNil)
client := http.Client{Transport: s.transport}
// execute the HTTP request to list buckets.
response, err := client.Do(request)
c.Assert(err, IsNil)
c.Assert(response.StatusCode, Equals, http.StatusOK)
// create HTTP request for listing buckets.
request, err = newTestSignedRequest("GET", getListBucketURL(s.endPoint),
0, nil, s.accessKey, s.secretKey, s.signer)
c.Assert(err, IsNil)
client = http.Client{Transport: s.transport}
// execute the HTTP request to list buckets.
response, err = client.Do(request)
c.Assert(err, IsNil)
c.Assert(response.StatusCode, Equals, http.StatusOK)
var results ListBucketsResponse
// parse the list bucket response.
decoder := xml.NewDecoder(response.Body)
err = decoder.Decode(&results)
// validating that the xml-decoding/parsing was successful.
c.Assert(err, IsNil)
// Fetch the bucket created above
var createdBucket Bucket
for _, b := range results.Buckets.Buckets {
if b.Name == bucketName {
createdBucket = b
}
}
c.Assert(createdBucket.Name != "", Equals, true)
// Parse the bucket modtime
creationTime, err := time.Parse(timeFormatAMZLong, createdBucket.CreationDate)
c.Assert(err, IsNil)
// Check if bucket modtime is consistent (not less than current time and not late more than 5 minutes)
timeNow := time.Now().UTC()
c.Assert(creationTime.Before(timeNow), Equals, true)
c.Assert(timeNow.Sub(creationTime) < time.Minute*5, Equals, true)
}
// This tests validate if PUT handler can successfully detect signature mismatch.

Loading…
Cancel
Save