Skip to content

Commit

Permalink
fix(custom-resources): buffers returned by AwsCustomResource are unus…
Browse files Browse the repository at this point in the history
…able (#9977)

Convert buffers to strings when flattening the API response.

Closes #9969, closes #10017


----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
jogold committed Aug 28, 2020
1 parent c5bb55c commit 7f351ff
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@ export function flatten(object: object): { [key: string]: string } {
{},
...function _flatten(child: any, path: string[] = []): any {
return [].concat(...Object.keys(child)
.map(key =>
typeof child[key] === 'object' && child[key] !== null
? _flatten(child[key], path.concat([key]))
: ({ [path.concat([key]).join('.')]: child[key] }),
));
.map(key => {
const childKey = Buffer.isBuffer(child[key]) ? child[key].toString('utf8') : child[key];
return typeof childKey === 'object' && childKey !== null
? _flatten(childKey, path.concat([key]))
: ({ [path.concat([key]).join('.')]: childKey });
}));
}(object),
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,24 @@ test('flatten correctly flattens a nested object', () => {
});
});

test('flatten correctly flattens an object with buffers', () => {
expect(flatten({
body: Buffer.from('body'),
nested: {
buffer: Buffer.from('buffer'),
array: [
Buffer.from('array.0'),
Buffer.from('array.1'),
],
},
})).toEqual({
'body': 'body',
'nested.buffer': 'buffer',
'nested.array.0': 'array.0',
'nested.array.1': 'array.1',
});
});

test('installs the latest SDK', async () => {
const tmpPath = '/tmp/node_modules/aws-sdk';

Expand Down Expand Up @@ -455,4 +473,7 @@ test('installs the latest SDK', async () => {
expect(request.isDone()).toBeTruthy();

expect(() => require.resolve(tmpPath)).not.toThrow();

// clean up aws-sdk install
await fs.remove(tmpPath);
});

0 comments on commit 7f351ff

Please sign in to comment.