Skip to content

Commit 392ad9b

Browse files
committed
fixup! Support the new API GetObjectAttributes
1 parent c7a132b commit 392ad9b

File tree

4 files changed

+43
-38
lines changed

4 files changed

+43
-38
lines changed

lib/api/apiUtils/object/parseAttributesHeader.js

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,14 @@ const { allowedObjectAttributes } = require('../../../../constants');
88
* @throws {Error} - InvalidRequest if header is missing/empty, InvalidArgument if attribute is invalid
99
*/
1010
function parseAttributesHeaders(headers) {
11-
const raw = headers['x-amz-object-attributes'] || '';
12-
13-
const attributes = raw
14-
.split(',')
15-
.map(s => s.trim())
16-
.filter(s => s !== '');
17-
11+
const attributes = headers['x-amz-object-attributes']?.split(',').map(attr => attr.trim()) ?? [];
1812
if (attributes.length === 0) {
1913
throw errorInstances.InvalidRequest.customizeDescription(
2014
'The x-amz-object-attributes header specifying the attributes to be retrieved is either missing or empty',
2115
);
2216
}
2317

24-
const invalids = attributes.filter(s => !allowedObjectAttributes.has(s));
25-
if (invalids.length > 0) {
18+
if (attributes.some(attr => !allowedObjectAttributes.has(attr))) {
2619
throw errorInstances.InvalidArgument.customizeDescription('Invalid attribute name specified.');
2720
}
2821

tests/functional/aws-node-sdk/test/object/objectGetAttributes.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,10 @@ describe('objectGetAttributes', () => {
5151
ObjectAttributes: [],
5252
})
5353
.promise();
54-
assert.fail('Expected InvalidRequest error');
54+
assert.fail('Expected InvalidArgument error');
5555
} catch (err) {
56-
assert.strictEqual(err.code, 'InvalidRequest');
57-
assert.strictEqual(
58-
err.message,
59-
'The x-amz-object-attributes header specifying the attributes to be retrieved is either missing or empty',
60-
);
56+
assert.strictEqual(err.code, 'InvalidArgument');
57+
assert.strictEqual(err.message, 'Invalid attribute name specified.');
6158
}
6259
});
6360

tests/unit/api/apiUtils/object/parseAttributesHeader.js

Lines changed: 36 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,47 +12,52 @@ describe('parseAttributesHeaders', () => {
1212
err => {
1313
assert(err.is);
1414
assert.strictEqual(err.is.InvalidRequest, true);
15-
assert(err.description.includes('missing or empty'));
15+
assert.strictEqual(
16+
err.description,
17+
'The x-amz-object-attributes header specifying the attributes to be retrieved is either missing or empty',
18+
);
1619
return true;
1720
},
1821
);
1922
});
2023

21-
it('should throw InvalidRequest error when header is empty string', () => {
24+
it('should throw InvalidArgument error when header is empty string', () => {
2225
const headers = { 'x-amz-object-attributes': '' };
2326

2427
assert.throws(
2528
() => parseAttributesHeaders(headers),
2629
err => {
2730
assert(err.is);
28-
assert.strictEqual(err.is.InvalidRequest, true);
29-
assert(err.description.includes('missing or empty'));
31+
assert.strictEqual(err.is.InvalidArgument, true);
32+
assert.strictEqual(err.description, 'Invalid attribute name specified.');
3033
return true;
3134
},
3235
);
3336
});
3437

35-
it('should throw InvalidRequest error when header contains only whitespace', () => {
38+
it('should throw InvalidArgument error when header contains only whitespace', () => {
3639
const headers = { 'x-amz-object-attributes': ' ' };
3740

3841
assert.throws(
3942
() => parseAttributesHeaders(headers),
4043
err => {
4144
assert(err.is);
42-
assert.strictEqual(err.is.InvalidRequest, true);
45+
assert.strictEqual(err.is.InvalidArgument, true);
46+
assert.strictEqual(err.description, 'Invalid attribute name specified.');
4347
return true;
4448
},
4549
);
4650
});
4751

48-
it('should throw InvalidRequest error when header contains only commas', () => {
52+
it('should throw InvalidArgument error when header contains only commas', () => {
4953
const headers = { 'x-amz-object-attributes': ',,,' };
5054

5155
assert.throws(
5256
() => parseAttributesHeaders(headers),
5357
err => {
5458
assert(err.is);
55-
assert.strictEqual(err.is.InvalidRequest, true);
59+
assert.strictEqual(err.is.InvalidArgument, true);
60+
assert.strictEqual(err.description, 'Invalid attribute name specified.');
5661
return true;
5762
},
5863
);
@@ -68,7 +73,7 @@ describe('parseAttributesHeaders', () => {
6873
err => {
6974
assert(err.is);
7075
assert.strictEqual(err.is.InvalidArgument, true);
71-
assert(err.description.includes('Invalid attribute name'));
76+
assert.strictEqual(err.description, 'Invalid attribute name specified.');
7277
return true;
7378
},
7479
);
@@ -82,6 +87,7 @@ describe('parseAttributesHeaders', () => {
8287
err => {
8388
assert(err.is);
8489
assert.strictEqual(err.is.InvalidArgument, true);
90+
assert.strictEqual(err.description, 'Invalid attribute name specified.');
8591
return true;
8692
},
8793
);
@@ -95,6 +101,7 @@ describe('parseAttributesHeaders', () => {
95101
err => {
96102
assert(err.is);
97103
assert.strictEqual(err.is.InvalidArgument, true);
104+
assert.strictEqual(err.description, 'Invalid attribute name specified.');
98105
return true;
99106
},
100107
);
@@ -173,20 +180,32 @@ describe('parseAttributesHeaders', () => {
173180
assert.deepStrictEqual(result, ['ETag', 'ObjectSize']);
174181
});
175182

176-
it('should handle extra commas between attributes', () => {
183+
it('should throw InvalidArgument for extra commas between attributes', () => {
177184
const headers = { 'x-amz-object-attributes': 'ETag,,ObjectSize' };
178-
const result = parseAttributesHeaders(headers);
179185

180-
assert(Array.isArray(result));
181-
assert.deepStrictEqual(result, ['ETag', 'ObjectSize']);
186+
assert.throws(
187+
() => parseAttributesHeaders(headers),
188+
err => {
189+
assert(err.is);
190+
assert.strictEqual(err.is.InvalidArgument, true);
191+
assert.strictEqual(err.description, 'Invalid attribute name specified.');
192+
return true;
193+
},
194+
);
182195
});
183196

184-
it('should handle leading and trailing commas', () => {
197+
it('should throw InvalidArgument for leading and trailing commas', () => {
185198
const headers = { 'x-amz-object-attributes': ',ETag,ObjectSize,' };
186-
const result = parseAttributesHeaders(headers);
187199

188-
assert(Array.isArray(result));
189-
assert.deepStrictEqual(result, ['ETag', 'ObjectSize']);
200+
assert.throws(
201+
() => parseAttributesHeaders(headers),
202+
err => {
203+
assert(err.is);
204+
assert.strictEqual(err.is.InvalidArgument, true);
205+
assert.strictEqual(err.description, 'Invalid attribute name specified.');
206+
return true;
207+
},
208+
);
190209
});
191210
});
192211
});

tests/unit/api/objectGetAttributes.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -127,12 +127,8 @@ describe('objectGetAttributes API', () => {
127127
await objectGetAttributesAsync(authInfo, testGetRequest, log);
128128
assert.fail('Expected error was not thrown');
129129
} catch (err) {
130-
assert.strictEqual(err.is.InvalidRequest, true);
131-
assert.strictEqual(
132-
err.description,
133-
'The x-amz-object-attributes header specifying the attributes ' +
134-
'to be retrieved is either missing or empty',
135-
);
130+
assert.strictEqual(err.is.InvalidArgument, true);
131+
assert.strictEqual(err.description, 'Invalid attribute name specified.');
136132
}
137133
});
138134

0 commit comments

Comments
 (0)