Skip to content

Commit

Permalink
add mint test for metadata size restrictions
Browse files Browse the repository at this point in the history
This change adds a test for the metadata size restriction of AWS.
AWS allows user-defined metadata of 2KB and a total HTTP header
size of 8KB.

Fixes minio/mint#119
  • Loading branch information
Andreas Auernhammer committed Sep 19, 2017
1 parent 4e0f567 commit 4ad5494
Showing 1 changed file with 53 additions and 1 deletion.
54 changes: 53 additions & 1 deletion functional_tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ import (
minio "github.com/minio/minio-go"
log "github.com/sirupsen/logrus"

"github.com/dustin/go-humanize"
"github.com/minio/minio-go/pkg/encrypt"
"github.com/minio/minio-go/pkg/policy"
)
Expand Down Expand Up @@ -260,6 +259,59 @@ func testMakeBucketError() {
successLogger(function, args, startTime).Info()
}

func testMetadataSizeLimit() {
startTime := time.Now().Unix()
function := "PutObjectWithMetadata(bucketName, objectName, reader, metadata)"
args := map[string]interface{}{
"bucketName": "",
"objectName": "",
"metadata": "",
}
rand.Seed(startTime)

// Instantiate new minio client object.
c, err := minio.New(
os.Getenv(serverEndpoint),
os.Getenv(accessKey),
os.Getenv(secretKey),
mustParseBool(os.Getenv(enableHTTPS)),
)
if err != nil {
failureLog(function, args, startTime, "", "Minio client creation failed", err).Fatal()
}
c.SetAppInfo("Minio-go-FunctionalTest", "0.1.0")

bucketName := randString(60, rand.NewSource(time.Now().UnixNano()), "minio-go-test")
args["bucketName"] = bucketName

objectName := randString(60, rand.NewSource(time.Now().UnixNano()), "")
args["objectName"] = objectName

err = c.MakeBucket(bucketName, "us-east-1")
if err != nil {
failureLog(function, args, startTime, "", "Make bucket failed", err).Fatal()
}

const HeaderSizeLimit = 8 * 1024
const UserMetadataLimit = 2 * 1024

metadata := make(map[string]string)
metadata["X-Amz-Meta-Mint-Test"] = string(bytes.Repeat([]byte("m"), 1+UserMetadataLimit-len("X-Amz-Meta-Mint-Test")))
args[metadata] = fmt.Sprint(metadata)
_, err := c.PutObjectWithMetadata(bucketName, objectName, bytes.NewReader(nil), metadata, nil)
if err == nil {
failureLog(function, args, startTime, "", "Created object with too much user-defined metadata successfully", nil).Fatal()
}

metadata = make(map[string]string)
metadata["X-Amz-Mint-Test"] = string(bytes.Repeat([]byte("m"), 1+HeaderSizeLimit-len("X-Amz-Mint-Test")))
args[metadata] = fmt.Sprint(metadata)
_, err := c.PutObjectWithMetadata(bucketName, objectName, bytes.NewReader(nil), metadata, nil)
if err == nil {
failureLog(function, args, startTime, "", "Created object with too much metadata successfully", nil).Fatal()
}
}

// Tests various bucket supported formats.
func testMakeBucketRegions() {
region := "eu-central-1"
Expand Down

0 comments on commit 4ad5494

Please sign in to comment.