Skip to content

Commit

Permalink
fix(amplify-provider-awscloudformation): use amplify prompts for warn…
Browse files Browse the repository at this point in the history
…ings (#8731)
  • Loading branch information
danielleadams committed Nov 9, 2021
1 parent 8ff558b commit 98840ec
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 27 deletions.
Expand Up @@ -19,7 +19,7 @@ describe('sandbox mode helpers', () => {
},
} as unknown as $TSContext;

jest.spyOn(prompts.printer, 'info').mockImplementation();
jest.spyOn(prompts.printer, 'warn').mockImplementation();
jest.spyOn(apiKeyHelpers, 'hasApiKey').mockReturnValue(apiKeyPresent);
});

Expand All @@ -32,14 +32,10 @@ describe('sandbox mode helpers', () => {
it('displays warning', async () => {
await showSandboxModePrompts(ctx);

expect(prompts.printer.info).toBeCalledWith(
`
⚠️ WARNING: Global Sandbox Mode has been enabled, which requires a valid API key. If
you'd like to disable, remove ${chalk.green('"input AMPLIFY { globalAuthRule: AuthRule = { allow: public } }"')}
from your GraphQL schema and run 'amplify push' again. If you'd like to proceed with
sandbox mode disabled, do not create an API Key.
`,
'yellow',
expect(prompts.printer.warn).toBeCalledWith(
` Global Sandbox Mode has been enabled, which requires a valid API key. If you'd like to disable, remove ${chalk.green(
'"input AMPLIFY { globalAuthRule: AuthRule = { allow: public } }"',
)} from your GraphQL schema and run 'amplify push' again. If you'd like to proceed with sandbox mode disabled, do not create an API Key.\n`,
);
expect(ctx.amplify.invokePluginMethod).toBeCalledWith(ctx, 'api', undefined, 'promptToAddApiKey', [ctx]);
});
Expand All @@ -50,11 +46,8 @@ sandbox mode disabled, do not create an API Key.
it('prints sandbox api key message', () => {
showGlobalSandboxModeWarning();

expect(prompts.printer.info).toBeCalledWith(
`
⚠️ WARNING: your GraphQL API currently allows public create, read, update, and delete access to all models via an API Key. To configure PRODUCTION-READY authorization rules, review: https://docs.amplify.aws/cli/graphql-transformer/auth
`,
'yellow',
expect(prompts.printer.warn).toBeCalledWith(
` WARNING: Your GraphQL API currently allows public create, read, update, and delete access to all models via an API Key. To configure PRODUCTION-READY authorization rules, review: https://docs.amplify.aws/cli/graphql-transformer/auth\n`,
);
});
});
Expand Down
Expand Up @@ -11,25 +11,21 @@ const PUBLIC = 'public';

export async function showSandboxModePrompts(context: $TSContext): Promise<any> {
if (!hasApiKey()) {
printer.info(
`
⚠️ WARNING: Global Sandbox Mode has been enabled, which requires a valid API key. If
you'd like to disable, remove ${chalk.green('"input AMPLIFY { globalAuthRule: AuthRule = { allow: public } }"')}
from your GraphQL schema and run 'amplify push' again. If you'd like to proceed with
sandbox mode disabled, do not create an API Key.
`,
'yellow',
printer.warn(
` Global Sandbox Mode has been enabled, which requires a valid API key. If ` +
`you'd like to disable, remove ${chalk.green('"input AMPLIFY { globalAuthRule: AuthRule = { allow: public } }"')} ` +
`from your GraphQL schema and run 'amplify push' again. If you'd like to proceed with ` +
`sandbox mode disabled, do not create an API Key.\n`,
);
return await context.amplify.invokePluginMethod(context, 'api', undefined, 'promptToAddApiKey', [context]);
}
}

export function showGlobalSandboxModeWarning(): void {
printer.info(
`
⚠️ WARNING: your GraphQL API currently allows public create, read, update, and delete access to all models via an API Key. To configure PRODUCTION-READY authorization rules, review: https://docs.amplify.aws/cli/graphql-transformer/auth
`,
'yellow',
printer.warn(
` WARNING: Your GraphQL API currently allows public create, read, update, and delete ` +
`access to all models via an API Key. To configure PRODUCTION-READY authorization rules, ` +
`review: https://docs.amplify.aws/cli/graphql-transformer/auth\n`,
);
}

Expand Down

0 comments on commit 98840ec

Please sign in to comment.