Skip to content

Commit 0173f7f

Browse files
author
rjabhi
committed
fix(migrate): add validation for path after file://
1 parent 00b25b7 commit 0173f7f

2 files changed

Lines changed: 14 additions & 0 deletions

File tree

packages/amplify-migration/src/commands/gen2/execute/execute_command.test.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,17 @@ describe('Gen2ExecuteCommand', () => {
5252
);
5353
});
5454

55+
it('should fail command when resourceMappings only has file://', async () => {
56+
const parser = yargs().command(new Gen2ExecuteCommand() as unknown as CommandModule);
57+
await assert.rejects(
58+
() => runCommandAsync(parser, 'execute --from foo --to bar --resourceMappings file://'),
59+
(err: Error) => {
60+
assert.equal(err.message, 'Expected resourceMap to have a path after file://');
61+
return true;
62+
},
63+
);
64+
});
65+
5566
it('should fail command when resourceMappings is invalid JSON', async () => {
5667
stubReadFile.mockResolvedValue('invalid json');
5768
const parser = yargs().command(new Gen2ExecuteCommand() as unknown as CommandModule);

packages/amplify-migration/src/commands/gen2/execute/execute_command.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ export class Gen2ExecuteCommand implements CommandModule<object, ExecuteCommandO
7474
throw new Error(`Expected resourceMap to start with ${FILE_PROTOCOL_PREFIX}`);
7575
}
7676
const resourceMapPath = resourceMappings.split(FILE_PROTOCOL_PREFIX)[1];
77+
if (!resourceMapPath) {
78+
throw new Error(`Expected resourceMap to have a path after ${FILE_PROTOCOL_PREFIX}`);
79+
}
7780
const resourceMappingsFromFile = await fs.readFile(resourceMapPath, { encoding: 'utf-8' });
7881
try {
7982
parsedResourceMappings = JSON.parse(resourceMappingsFromFile);

0 commit comments

Comments
 (0)