Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add mint test for metadata size restrictions #816

Merged
merged 1 commit into from
Sep 24, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
59 changes: 58 additions & 1 deletion functional_tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ import (
"strings"
"time"

humanize "github.com/dustin/go-humanize"
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 @@ -262,6 +262,63 @@ func testMakeBucketError() {
successLogger(function, args, startTime).Info()
}

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

// 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

// Meta-data greater than the 2 KB limit of AWS - PUT calls with this meta-data should fail
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.PutObject(bucketName, objectName, bytes.NewReader(nil), 0, &minio.PutObjectOptions{UserMetadata: metadata})
if err == nil {
failureLog(function, args, startTime, "", "Created object with user-defined metadata exceeding metadata size limits", nil).Fatal()
}

// Meta-data (headers) greater than the 8 KB limit of AWS - PUT calls with this meta-data should fail
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.PutObject(bucketName, objectName, bytes.NewReader(nil), 0, &minio.PutObjectOptions{UserMetadata: metadata})
if err == nil {
failureLog(function, args, startTime, "", "Created object with headers exceeding header size limits", nil).Fatal()
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you pls call successLogger() as well when the test passes? Otherwise looks good.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, thanks.

successLogger(function, args, startTime).Info()
}

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