mirror of
https://github.com/minio/minio.git
synced 2025-04-07 21:25:36 -04:00
fix: List buckets response should return UTC modtime (#5004)
This commit is contained in:
parent
60cc6184d2
commit
a4f26aec00
@ -307,7 +307,7 @@ func generateListBucketsResponse(buckets []BucketInfo) ListBucketsResponse {
|
|||||||
for _, bucket := range buckets {
|
for _, bucket := range buckets {
|
||||||
var listbucket = Bucket{}
|
var listbucket = Bucket{}
|
||||||
listbucket.Name = bucket.Name
|
listbucket.Name = bucket.Name
|
||||||
listbucket.CreationDate = bucket.Created.Format(timeFormatAMZLong)
|
listbucket.CreationDate = bucket.Created.UTC().Format(timeFormatAMZLong)
|
||||||
listbucket.HealBucketInfo = bucket.HealBucketInfo
|
listbucket.HealBucketInfo = bucket.HealBucketInfo
|
||||||
listbuckets = append(listbuckets, listbucket)
|
listbuckets = append(listbuckets, listbucket)
|
||||||
}
|
}
|
||||||
|
@ -1151,23 +1151,53 @@ func (s *TestSuiteCommon) TestPutObject(c *C) {
|
|||||||
// XML response is parsed.
|
// XML response is parsed.
|
||||||
// Its success verifies the format of the response.
|
// Its success verifies the format of the response.
|
||||||
func (s *TestSuiteCommon) TestListBuckets(c *C) {
|
func (s *TestSuiteCommon) TestListBuckets(c *C) {
|
||||||
// create HTTP request for listing buckets.
|
// generate a random bucket name.
|
||||||
request, err := newTestSignedRequest("GET", getListBucketURL(s.endPoint),
|
bucketName := getRandomBucketName()
|
||||||
|
// HTTP request to create the bucket.
|
||||||
|
request, err := newTestSignedRequest("PUT", getMakeBucketURL(s.endPoint, bucketName),
|
||||||
0, nil, s.accessKey, s.secretKey, s.signer)
|
0, nil, s.accessKey, s.secretKey, s.signer)
|
||||||
c.Assert(err, IsNil)
|
c.Assert(err, IsNil)
|
||||||
|
|
||||||
client := http.Client{Transport: s.transport}
|
client := http.Client{Transport: s.transport}
|
||||||
// execute the HTTP request to list buckets.
|
// execute the HTTP request to list buckets.
|
||||||
response, err := client.Do(request)
|
response, err := client.Do(request)
|
||||||
c.Assert(err, IsNil)
|
c.Assert(err, IsNil)
|
||||||
c.Assert(response.StatusCode, Equals, http.StatusOK)
|
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
|
var results ListBucketsResponse
|
||||||
// parse the list bucket response.
|
// parse the list bucket response.
|
||||||
decoder := xml.NewDecoder(response.Body)
|
decoder := xml.NewDecoder(response.Body)
|
||||||
err = decoder.Decode(&results)
|
err = decoder.Decode(&results)
|
||||||
// validating that the xml-decoding/parsing was successful.
|
// validating that the xml-decoding/parsing was successful.
|
||||||
c.Assert(err, IsNil)
|
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.
|
// This tests validate if PUT handler can successfully detect signature mismatch.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user