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 copyObject test changing metadata and preserving etag #944

Merged
merged 1 commit into from
Mar 12, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 59 additions & 6 deletions functional_tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -2685,6 +2685,10 @@ func testCopyObject() {
return
}

// Close all the get readers before proceeding with CopyObject operations.
r.Close()
readerCopy.Close()

// CopyObject again but with wrong conditions
src = minio.NewSourceInfo(bucketName, objectName, nil)
err = src.SetUnmodifiedSinceCond(time.Date(2014, time.April, 0, 0, 0, 0, 0, time.UTC))
Expand All @@ -2705,6 +2709,37 @@ func testCopyObject() {
return
}

// Perform the Copy which should update only metadata.
src = minio.NewSourceInfo(bucketName, objectName, nil)
dst, err = minio.NewDestinationInfo(bucketName, objectName, nil, map[string]string{
"Copy": "should be same",
})
args["dst"] = dst
args["src"] = src
if err != nil {
logError(testName, function, args, startTime, "", "NewDestinationInfo failed", err)
return
}

err = c.CopyObject(dst, src)
if err != nil {
logError(testName, function, args, startTime, "", "CopyObject shouldn't fail", err)
return
}

stOpts := minio.StatObjectOptions{}
stOpts.SetMatchETag(objInfo.ETag)
objInfo, err = c.StatObject(bucketName, objectName, stOpts)
if err != nil {
logError(testName, function, args, startTime, "", "CopyObject ETag should match and not fail", err)
return
}

if objInfo.Metadata.Get("x-amz-meta-copy") != "should be same" {
logError(testName, function, args, startTime, "", "CopyObject modified metadata should match", err)
return
}

// Delete all objects and buckets
if err = cleanupBucket(bucketName, c); err != nil {
logError(testName, function, args, startTime, "", "Cleanup failed", err)
Expand Down Expand Up @@ -2807,6 +2842,7 @@ func testEncryptedGetObjectReadSeekFunctional() {
logError(testName, function, args, startTime, "", "GetObject failed", err)
return
}
defer r.Close()

st, err := r.Stat()
if err != nil {
Expand Down Expand Up @@ -2905,6 +2941,7 @@ func testEncryptedGetObjectReadSeekFunctional() {
cmpData(r, testCase.start, testCase.end)
}
}

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

Expand Down Expand Up @@ -2990,6 +3027,8 @@ func testEncryptedGetObjectReadAtFunctional() {
logError(testName, function, args, startTime, "", "PutObject failed", err)
return
}
defer r.Close()

offset := int64(2048)

// read directly
Expand Down Expand Up @@ -3928,6 +3967,7 @@ func testFunctional() {
logError(testName, function, args, startTime, "", "GetObject bytes mismatch", err)
return
}
newReader.Close()

function = "FGetObject(bucketName, objectName, fileName)"
functionAll += ", " + function
Expand Down Expand Up @@ -4398,6 +4438,7 @@ func testPutObjectUploadSeekedObject() {
logError(testName, function, args, startTime, "", "GetObject failed", err)
return
}
defer obj.Close()

n, err = obj.Seek(int64(offset), 0)
if err != nil {
Expand Down Expand Up @@ -4986,6 +5027,7 @@ func testGetObjectReadSeekFunctionalV2() {
logError(testName, function, args, startTime, "", "GetObject failed", err)
return
}
defer r.Close()

st, err := r.Stat()
if err != nil {
Expand Down Expand Up @@ -5149,6 +5191,7 @@ func testGetObjectReadAtFunctionalV2() {
logError(testName, function, args, startTime, "", "GetObject failed", err)
return
}
defer r.Close()

st, err := r.Stat()
if err != nil {
Expand Down Expand Up @@ -5321,6 +5364,7 @@ func testCopyObjectV2() {
logError(testName, function, args, startTime, "", "Stat failed", err)
return
}
r.Close()

// Copy Source
src := minio.NewSourceInfo(bucketName, objectName, nil)
Expand Down Expand Up @@ -5403,6 +5447,10 @@ func testCopyObjectV2() {
return
}

// Close all the readers.
r.Close()
readerCopy.Close()

// CopyObject again but with wrong conditions
src = minio.NewSourceInfo(bucketName, objectName, nil)
err = src.SetUnmodifiedSinceCond(time.Date(2014, time.April, 0, 0, 0, 0, 0, time.UTC))
Expand Down Expand Up @@ -5793,13 +5841,11 @@ func testEncryptedCopyObjectWrapper(c *minio.Client) {
for k, v := range key2.GetSSEHeaders() {
opts.Set(k, v)
}
coreClient := minio.Core{c}
reader, _, err := coreClient.GetObject(bucketName, "dstObject", opts)
reader, err := c.GetObject(bucketName, "dstObject", opts)
if err != nil {
logError(testName, function, args, startTime, "", "GetObject failed", err)
return
}
defer reader.Close()

decBytes, err := ioutil.ReadAll(reader)
if err != nil {
Expand All @@ -5810,6 +5856,7 @@ func testEncryptedCopyObjectWrapper(c *minio.Client) {
logError(testName, function, args, startTime, "", "Downloaded object mismatched for encrypted object", err)
return
}
reader.Close()

// Test key rotation for source object in-place.
dst, err = minio.NewDestinationInfo(bucketName, "srcObject", &key2, nil)
Expand All @@ -5830,12 +5877,11 @@ func testEncryptedCopyObjectWrapper(c *minio.Client) {
for k, v := range key2.GetSSEHeaders() {
opts.Set(k, v)
}
reader, _, err = coreClient.GetObject(bucketName, "srcObject", opts)
reader, err = c.GetObject(bucketName, "srcObject", opts)
if err != nil {
logError(testName, function, args, startTime, "", "GetObject failed", err)
return
}
defer reader.Close()

decBytes, err = ioutil.ReadAll(reader)
if err != nil {
Expand All @@ -5846,6 +5892,7 @@ func testEncryptedCopyObjectWrapper(c *minio.Client) {
logError(testName, function, args, startTime, "", "Downloaded object mismatched for encrypted object", err)
return
}
reader.Close()

// Test in-place decryption.
dst, err = minio.NewDestinationInfo(bucketName, "srcObject", nil, nil)
Expand All @@ -5865,7 +5912,7 @@ func testEncryptedCopyObjectWrapper(c *minio.Client) {

// Get copied decrypted object and check if content is equal
opts = minio.GetObjectOptions{}
reader, _, err = coreClient.GetObject(bucketName, "srcObject", opts)
reader, err = c.GetObject(bucketName, "srcObject", opts)
if err != nil {
logError(testName, function, args, startTime, "", "GetObject failed", err)
return
Expand Down Expand Up @@ -5935,6 +5982,7 @@ func testEncryptedCopyObjectV2() {
return
}

// c.TraceOn(os.Stderr)
testEncryptedCopyObjectWrapper(c)
}

Expand Down Expand Up @@ -6863,6 +6911,7 @@ func testFunctionalV2() {
logError(testName, function, args, startTime, "", "ReadAll failed", err)
return
}
newReader.Close()

if !bytes.Equal(newReadBytes, buf) {
logError(testName, function, args, startTime, "", "Bytes mismatch", err)
Expand Down Expand Up @@ -7031,6 +7080,7 @@ func testFunctionalV2() {
logError(testName, function, args, startTime, "", "ReadAll failed", err)
return
}
newReader.Close()

if !bytes.Equal(newReadBytes, buf) {
logError(testName, function, args, startTime, "", "Bytes mismatch", err)
Expand Down Expand Up @@ -7119,10 +7169,12 @@ func testGetObjectWithContext() {
logError(testName, function, args, startTime, "", "GetObjectWithContext failed unexpectedly", err)
return
}

if _, err = r.Stat(); err == nil {
logError(testName, function, args, startTime, "", "GetObjectWithContext should fail on short timeout", err)
return
}
r.Close()

ctx, cancel = context.WithTimeout(context.Background(), 1*time.Hour)
args["ctx"] = ctx
Expand Down Expand Up @@ -7401,6 +7453,7 @@ func testGetObjectWithContextV2() {
logError(testName, function, args, startTime, "", "GetObjectWithContext should fail on short timeout", err)
return
}
r.Close()

ctx, cancel = context.WithTimeout(context.Background(), 1*time.Hour)
defer cancel()
Expand Down