|
1 | | -import { S3Client, PutObjectCommand, DeleteObjectCommand, GetObjectAttributesCommandOutput } from '@aws-sdk/client-s3'; |
| 1 | +import { S3Client, PutObjectCommand, DeleteObjectCommand } from '@aws-sdk/client-s3'; |
2 | 2 | import { createTestClient, testConfig } from './testSetup'; |
3 | 3 | import { describeForMongoBackend } from './testHelpers'; |
4 | 4 | import assert from 'assert'; |
|
7 | 7 | GetObjectAttributesExtendedOutput, |
8 | 8 | ListObjectsExtendedCommand, |
9 | 9 | ListObjectsV2ExtendedCommand, |
| 10 | + ListObjectsV2ExtendedOutput, |
10 | 11 | ListObjectVersionsExtendedCommand, |
11 | 12 | } from '../src/clients/s3Extended'; |
12 | 13 |
|
@@ -139,6 +140,112 @@ describeForMongoBackend('S3 Extended API Tests', () => { |
139 | 140 | }); |
140 | 141 | }); |
141 | 142 |
|
| 143 | + describe.skip('ListObjectsV2 with ObjectAttributes', () => { |
| 144 | + const metaKey1 = `${testConfig.objectKey}-listv2-meta1`; |
| 145 | + const metaKey2 = `${testConfig.objectKey}-listv2-meta2`; |
| 146 | + |
| 147 | + beforeAll(async () => { |
| 148 | + await s3client.send(new PutObjectCommand({ |
| 149 | + Bucket: testConfig.bucketName, |
| 150 | + Key: metaKey1, |
| 151 | + Body: 'data1', |
| 152 | + Metadata: { foo: 'bar', baz: 'qux' }, |
| 153 | + })); |
| 154 | + await s3client.send(new PutObjectCommand({ |
| 155 | + Bucket: testConfig.bucketName, |
| 156 | + Key: metaKey2, |
| 157 | + Body: 'data2', |
| 158 | + Metadata: { foo: 'hello' }, |
| 159 | + })); |
| 160 | + }); |
| 161 | + |
| 162 | + it('should list objects with a single user metadata key', async () => { |
| 163 | + const result = await s3client.send(new ListObjectsV2ExtendedCommand({ |
| 164 | + Bucket: testConfig.bucketName, |
| 165 | + ObjectAttributes: ['x-amz-meta-foo'], |
| 166 | + })) as ListObjectsV2ExtendedOutput; |
| 167 | + |
| 168 | + const obj1 = result.Contents!.find(content => content.Key === metaKey1)!; |
| 169 | + const obj2 = result.Contents!.find(ccontent => ccontent.Key === metaKey2)!; |
| 170 | + |
| 171 | + assert.strictEqual(result.$metadata.httpStatusCode, 200); |
| 172 | + assert.strictEqual(result.Contents?.length, 2); |
| 173 | + assert.strictEqual(obj1['x-amz-meta-foo'], 'bar'); |
| 174 | + assert.strictEqual(obj2['x-amz-meta-foo'], 'hello'); |
| 175 | + }); |
| 176 | + |
| 177 | + it('should list objects with multiple user metadata keys', async () => { |
| 178 | + const result = await s3client.send(new ListObjectsV2ExtendedCommand({ |
| 179 | + Bucket: testConfig.bucketName, |
| 180 | + ObjectAttributes: ['x-amz-meta-foo', 'x-amz-meta-baz'], |
| 181 | + })) as ListObjectsV2ExtendedOutput; |
| 182 | + |
| 183 | + const obj1 = result.Contents!.find(content => content.Key === metaKey1)!; |
| 184 | + const obj2 = result.Contents!.find(ccontent => ccontent.Key === metaKey2)!; |
| 185 | + |
| 186 | + assert.strictEqual(result.$metadata.httpStatusCode, 200); |
| 187 | + assert.strictEqual(obj1['x-amz-meta-foo'], 'bar'); |
| 188 | + assert.strictEqual(obj1['x-amz-meta-baz'], 'qux'); |
| 189 | + assert.strictEqual(obj2['x-amz-meta-foo'], 'hello'); |
| 190 | + assert.strictEqual(obj2['x-amz-meta-baz'], undefined); |
| 191 | + }); |
| 192 | + |
| 193 | + it('should list objects with wildcard user metadata', async () => { |
| 194 | + const result = await s3client.send(new ListObjectsV2ExtendedCommand({ |
| 195 | + Bucket: testConfig.bucketName, |
| 196 | + ObjectAttributes: ['x-amz-meta-*'], |
| 197 | + })) as ListObjectsV2ExtendedOutput; |
| 198 | + |
| 199 | + const obj1 = result.Contents!.find(content => content.Key === metaKey1)!; |
| 200 | + const obj2 = result.Contents!.find(ccontent => ccontent.Key === metaKey2)!; |
| 201 | + |
| 202 | + assert.strictEqual(result.$metadata.httpStatusCode, 200); |
| 203 | + assert.strictEqual(obj1['x-amz-meta-foo'], 'bar'); |
| 204 | + assert.strictEqual(obj1['x-amz-meta-baz'], 'qux'); |
| 205 | + assert.strictEqual(obj2['x-amz-meta-foo'], 'hello'); |
| 206 | + }); |
| 207 | + |
| 208 | + it('should list objects with non-existing user metadata key', async () => { |
| 209 | + const result = await s3client.send(new ListObjectsV2ExtendedCommand({ |
| 210 | + Bucket: testConfig.bucketName, |
| 211 | + ObjectAttributes: ['x-amz-meta-nonexistent'], |
| 212 | + })) as ListObjectsV2ExtendedOutput; |
| 213 | + |
| 214 | + const obj1 = result.Contents!.find(content => content.Key === metaKey1)!; |
| 215 | + |
| 216 | + assert.strictEqual(result.$metadata.httpStatusCode, 200); |
| 217 | + assert.strictEqual(result.Contents?.length, 2); |
| 218 | + assert.strictEqual(obj1['x-amz-meta-nonexistent'], undefined); |
| 219 | + }); |
| 220 | + |
| 221 | + it('should list objects with RestoreStatus combined with user metadata', async () => { |
| 222 | + const result = await s3client.send(new ListObjectsV2ExtendedCommand({ |
| 223 | + Bucket: testConfig.bucketName, |
| 224 | + ObjectAttributes: ['RestoreStatus', 'x-amz-meta-foo'], |
| 225 | + })) as ListObjectsV2ExtendedOutput; |
| 226 | + |
| 227 | + const obj1 = result.Contents!.find(content => content.Key === metaKey1)!; |
| 228 | + |
| 229 | + assert.strictEqual(result.$metadata.httpStatusCode, 200); |
| 230 | + assert.strictEqual(obj1['x-amz-meta-foo'], 'bar'); |
| 231 | + assert.deepStrictEqual(obj1.RestoreStatus, { IsRestoreInProgress: false }); |
| 232 | + }); |
| 233 | + |
| 234 | + it('should list objects with RestoreStatus combined with non-existing user metadata', async () => { |
| 235 | + const result = await s3client.send(new ListObjectsV2ExtendedCommand({ |
| 236 | + Bucket: testConfig.bucketName, |
| 237 | + ObjectAttributes: ['RestoreStatus', 'x-amz-meta-nonexistent'], |
| 238 | + })) as ListObjectsV2ExtendedOutput; |
| 239 | + |
| 240 | + const obj1 = result.Contents!.find(content => content.Key === metaKey1)!; |
| 241 | + |
| 242 | + assert.strictEqual(result.$metadata.httpStatusCode, 200); |
| 243 | + assert.strictEqual(result.Contents?.length, 2); |
| 244 | + assert.strictEqual(obj1['x-amz-meta-nonexistent'], undefined); |
| 245 | + assert.deepStrictEqual(obj1.RestoreStatus, { IsRestoreInProgress: false }); |
| 246 | + }); |
| 247 | + }); |
| 248 | + |
142 | 249 | describe('GetObjectAttributes', () => { |
143 | 250 | const metadataKey = `${testConfig.objectKey}-with-meta`; |
144 | 251 | const metadataBody = 'data-with-metadata'; |
|
0 commit comments