Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add signed webhook test for multi event payload #1271

Merged
merged 1 commit into from
Apr 29, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 40 additions & 1 deletion packages/eventwebhook/src/eventwebhook.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,38 @@ describe('EventWebhook', () => {
]
) + '\r\n'; // Be sure to include the trailing carriage return and newline!

const PUBLIC_KEY_MULTIPLE = 'MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEQ4LIFtWztlsF7skFqOncjD1lun4H5w8XOhyOArHW9RcIx/FfEzx6cikC/yPfUvwaX/JScE7Fc9CJD2afQ9Ok3Q==';
const SIGNATURE_MULTIPLE = 'MEYCIQC/I4o6vCgqRYrTljjoVWB/GRWNtxeePlLMHr3x9ETeRQIhAIpV+03nREPTTHWSW0wIOA0EoMPdcNgXa70yCaqDJlu5';
const TIMESTAMP_MULTIPLE = 1619651159;
const eventsPayloadMultiple = [
{
email: '[email protected]',
event: 'processed',
send_at: 0,
sg_event_id: 'cHJvY2Vzc2VkLTE5OTQyMTEyLXFOd0JMZ1BRUWpXNkRKdktRd1NBYnctMA',
sg_message_id: 'qNwBLgPQQjW6DJvKQwSAbw.filterdrecv-canary-547b64655b-cw6zx-1-6089EA4A-56.0',
'smtp-id': '<[email protected]>',
timestamp: 1619651146,
},
{
email: '[email protected]',
event: 'bounce',
ip: '167.89.101.76',
reason: '552 5.2.2 The email account that you tried to reach is over quota and inactive. Please direct the recipient to https://support.google.com/mail/?p=OverQuotaPerm c17si1130468pgv.34 - gsmtp',
sg_event_id: 'Ym91bmNlLTAtMTk5NDIxMTItcU53QkxnUFFRalc2REp2S1F3U0Fidy0w',
sg_message_id: 'qNwBLgPQQjW6DJvKQwSAbw.filterdrecv-canary-547b64655b-cw6zx-1-6089EA4A-56.0',
'smtp-id': '<[email protected]>',
status: '5.2.2',
timestamp: 1619651147,
tls: 1,
type: 'blocked',
},
];
const PAYLOAD_MULTIPLE_EVENTS = JSON.stringify(eventsPayloadMultiple).split('},{').join('},\r\n{') + '\r\n'; // Be sure to include the trailing carriage return and newline after each event


describe('#verifySignature()', () => {
it('should verify a valid signature', () => {
it('should verify a valid single event signature', () => {
expect(verify(
PUBLIC_KEY,
PAYLOAD,
Expand All @@ -28,6 +58,15 @@ describe('EventWebhook', () => {
)).to.equal(true);
});

it('should verify a valid multi event signature', () => {
expect(verify(
PUBLIC_KEY_MULTIPLE,
PAYLOAD_MULTIPLE_EVENTS,
SIGNATURE_MULTIPLE,
TIMESTAMP_MULTIPLE
)).to.equal(true);
});

it('should reject for invalid key', () => {
expect(verify(
'MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEqTxd43gyp8IOEto2LdIfjRQrIbsd4SXZkLW6jDutdhXSJCWHw8REntlo7aNDthvj+y7GjUuFDb/R1NGe1OPzpA==',
Expand Down