|
1 | 1 | const assert = require('assert'); |
2 | 2 | const async = require('async'); |
| 3 | +const { promisify } = require('util'); |
3 | 4 |
|
4 | 5 | const withV4 = require('../support/withV4'); |
5 | 6 | const BucketUtility = require('../../lib/utility/bucket-util'); |
@@ -956,6 +957,71 @@ describe('PUT object with x-scal-s3-version-id header', () => { |
956 | 957 | }, |
957 | 958 | ], done); |
958 | 959 | }); |
| 960 | + |
| 961 | + it('should set restore originOp and drop restore-attempt metadata', done => { |
| 962 | + const params = { Bucket: bucketName, Key: objectName }; |
| 963 | + |
| 964 | + async.series([ |
| 965 | + next => s3.send(new PutObjectCommand({ |
| 966 | + ...params, |
| 967 | + Metadata: { |
| 968 | + 'custom-md': 'preserved-value', |
| 969 | + }, |
| 970 | + })).then(() => next()).catch(next), |
| 971 | + next => fakeMetadataArchive(bucketName, objectName, undefined, archive, next), |
| 972 | + next => getMetadata(bucketName, objectName, undefined, (err, objMD) => { |
| 973 | + if (err) { |
| 974 | + return next(err); |
| 975 | + } |
| 976 | + /* eslint-disable no-param-reassign */ |
| 977 | + objMD['x-amz-meta-scal-s3-restore-attempt'] = '3'; |
| 978 | + /* eslint-enable no-param-reassign */ |
| 979 | + return metadata.putObjectMD(bucketName, objectName, objMD, undefined, log, next); |
| 980 | + }), |
| 981 | + next => putObjectVersion(s3, params, '', next), |
| 982 | + next => getMetadata(bucketName, objectName, undefined, (err, objMD) => { |
| 983 | + if (err) { |
| 984 | + return next(err); |
| 985 | + } |
| 986 | + assert.strictEqual(objMD.originOp, 's3:ObjectRestore:Completed'); |
| 987 | + assert.strictEqual(objMD['x-amz-meta-custom-md'], 'preserved-value'); |
| 988 | + assert.strictEqual(objMD['x-amz-meta-scal-s3-restore-attempt'], undefined); |
| 989 | + return next(); |
| 990 | + }), |
| 991 | + ], done); |
| 992 | + }); |
| 993 | + |
| 994 | + it('should keep x-amz-meta-scal-version-id when restoring on ingestion bucket', async () => { |
| 995 | + const ingestionBucketName = `ingestion-restore-${Date.now()}`; |
| 996 | + const params = { Bucket: ingestionBucketName, Key: objectName }; |
| 997 | + let putVersionId; |
| 998 | + const fakeMetadataArchivePromise = promisify(fakeMetadataArchive); |
| 999 | + const putObjectVersionPromise = promisify(putObjectVersion); |
| 1000 | + const getMetadataPromise = promisify(getMetadata); |
| 1001 | + try { |
| 1002 | + await s3.send(new CreateBucketCommand({ |
| 1003 | + Bucket: ingestionBucketName, |
| 1004 | + CreateBucketConfiguration: { |
| 1005 | + LocationConstraint: 'us-east-2:ingest', |
| 1006 | + }, |
| 1007 | + })); |
| 1008 | + |
| 1009 | + const putRes = await s3.send(new PutObjectCommand(params)); |
| 1010 | + putVersionId = putRes.VersionId; |
| 1011 | + |
| 1012 | + await fakeMetadataArchivePromise(ingestionBucketName, objectName, putVersionId, archive); |
| 1013 | + |
| 1014 | + await putObjectVersionPromise(s3, params, putVersionId); |
| 1015 | + |
| 1016 | + const restoredObjMD = await getMetadataPromise( |
| 1017 | + ingestionBucketName, objectName, putVersionId); |
| 1018 | + |
| 1019 | + assert.strictEqual(restoredObjMD['x-amz-meta-scal-version-id'], putVersionId); |
| 1020 | + } finally { |
| 1021 | + await bucketUtil.emptyMany([ingestionBucketName]).catch(() => {}); |
| 1022 | + await bucketUtil.deleteMany([ingestionBucketName]).catch(() => {}); |
| 1023 | + } |
| 1024 | + }); |
959 | 1025 | }); |
960 | 1026 | }); |
961 | 1027 | }); |
0 commit comments