diff --git a/packages/snaps-rpc-methods/jest.config.js b/packages/snaps-rpc-methods/jest.config.js index e5ee2eb01e..015ebd2bcd 100644 --- a/packages/snaps-rpc-methods/jest.config.js +++ b/packages/snaps-rpc-methods/jest.config.js @@ -10,7 +10,7 @@ module.exports = deepmerge(baseConfig, { ], coverageThreshold: { global: { - branches: 91.81, + branches: 92.07, functions: 96.96, lines: 97.51, statements: 96.97, diff --git a/packages/snaps-rpc-methods/src/restricted/notify.test.ts b/packages/snaps-rpc-methods/src/restricted/notify.test.ts index 3c662c155e..aeecba1a38 100644 --- a/packages/snaps-rpc-methods/src/restricted/notify.test.ts +++ b/packages/snaps-rpc-methods/src/restricted/notify.test.ts @@ -229,7 +229,7 @@ describe('snap_notify', () => { expect(() => getValidatedParams({ type: NotificationType.InApp, message: '' }), ).toThrow( - 'Must specify a non-empty string "message" less than 50 characters long.', + 'Must specify a non-empty string "message" less than 500 characters long.', ); }); @@ -237,14 +237,14 @@ describe('snap_notify', () => { expect(() => getValidatedParams({ type: NotificationType.InApp, message: 123 }), ).toThrow( - 'Must specify a non-empty string "message" less than 50 characters long.', + 'Must specify a non-empty string "message" less than 500 characters long.', ); }); - it('throws an error if the message is larger than 50 characters', () => { + it('throws an error if the message is larger than or equal to 50 characters for native notifications', () => { expect(() => getValidatedParams({ - type: NotificationType.InApp, + type: NotificationType.Native, message: 'test_msg_test_msg_test_msg_test_msg_test_msg_test_msg_test_msg_test_msg_test_msg_test_msg_test_msg', }), @@ -253,6 +253,18 @@ describe('snap_notify', () => { ); }); + it('throws an error if the message is larger than or equal to 500 characters for in app notifications', () => { + expect(() => + getValidatedParams({ + type: NotificationType.InApp, + message: + 'test_msg_test_msg_test_msg_test_msg_test_msg_test_msg_test_msg_test_msg_test_msg_test_msg_test_msg_test_msg_test_msg_test_msg_test_msg_test_msg_test_msg_test_msg_test_msg_test_msg_test_msg_test_msg_test_msg_test_msg_test_msg_test_msg_test_msg_test_msg_test_msg_test_msg_test_msg_test_msg_test_msg_test_msg_test_msg_test_msg_test_msg_test_msg_test_msg_test_msg_test_msg_test_msg_test_msg_test_msg_test_msg_test_msg_test_msg_test_msg_test_msg_test_msg_test_msg_test_msg_test_msg_test_msg_test_msg_test_msg_test_msg_test_msg_test_msg_test_msg_test_msg_test_msg_test_msg_test_msg_test_msg_test_msg', + }), + ).toThrow( + 'Must specify a non-empty string "message" less than 500 characters long.', + ); + }); + it('returns valid parameters', () => { expect(getValidatedParams(validParams)).toStrictEqual(validParams); }); diff --git a/packages/snaps-rpc-methods/src/restricted/notify.ts b/packages/snaps-rpc-methods/src/restricted/notify.ts index fdf3001be3..8c4c11f882 100644 --- a/packages/snaps-rpc-methods/src/restricted/notify.ts +++ b/packages/snaps-rpc-methods/src/restricted/notify.ts @@ -173,13 +173,27 @@ export function getValidatedParams(params: unknown): NotifyParams { }); } + const isNotString = !message || typeof message !== 'string'; // Set to the max message length on a Mac notification for now. - if (!message || typeof message !== 'string' || message.length >= 50) { + if ( + type === NotificationType.Native && + (isNotString || message.length >= 50) + ) { throw rpcErrors.invalidParams({ message: 'Must specify a non-empty string "message" less than 50 characters long.', }); } + if ( + type === NotificationType.InApp && + (isNotString || message.length >= 500) + ) { + throw rpcErrors.invalidParams({ + message: + 'Must specify a non-empty string "message" less than 500 characters long.', + }); + } + return params as NotificationArgs; }