-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Update test to add HMAC and paymentLinkId * Add test to with invalid HMAC and paymentLinkId * Check first matching element
- Loading branch information
Showing
3 changed files
with
75 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// @ts-check | ||
const { test, expect } = require('@playwright/test'); | ||
|
||
// test webhook is rejected (invalid HMAC signature) | ||
test('Webhook Notification', async ({ request }) => { | ||
const notifications = await request.post(`/api/webhooks/notifications`, { | ||
data: { | ||
"live": "false", | ||
"notificationItems":[ | ||
{ | ||
"NotificationRequestItem":{ | ||
"additionalData":{ | ||
"hmacSignature":"INVALID_HMAC_SIGNATURE", | ||
"paymentLinkId":"PL1234567890" // note: add paymentLinkId for Pay by Link | ||
}, | ||
"eventCode":"AUTHORISATION", | ||
"success":"true", | ||
"eventDate":"2019-06-28T18:03:50+01:00", | ||
"merchantAccountCode":"YOUR_MERCHANT_ACCOUNT", | ||
"pspReference": "7914073381342284", | ||
"merchantReference": "YOUR_REFERENCE", | ||
"amount": { | ||
"value":24999, | ||
"currency":"EUR" | ||
} | ||
} | ||
} | ||
] | ||
} | ||
}); | ||
|
||
/// Verify notification is not accepted (invalid HMAC) | ||
|
||
// Status code not 404 (verify webhook is found) | ||
expect(notifications.status()).not.toEqual(404); | ||
|
||
// Status code not 200 (verify webhook does not accept the notification ie HMAC invalid) | ||
expect(notifications.status()).not.toEqual(200); | ||
|
||
// Body response does not contain [accepted] | ||
notifications.text() | ||
.then(value => {expect(value).not.toEqual("[accepted]");} ); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,47 @@ | ||
// @ts-check | ||
const { test, expect } = require('@playwright/test'); | ||
const utilities = require('../utilities'); | ||
|
||
// test webhook is successfully delivered | ||
test('Webhook Notification', async ({ request }) => { | ||
|
||
var notificationRequestItem = { | ||
"eventCode":"AUTHORISATION", | ||
"success":"true", | ||
"eventDate":"2019-06-28T18:03:50+01:00", | ||
"merchantAccountCode":"YOUR_MERCHANT_ACCOUNT", | ||
"pspReference": "7914073381342284", | ||
"merchantReference": "YOUR_REFERENCE", | ||
"amount": { | ||
"value":1130, | ||
"currency":"EUR" | ||
} | ||
}; | ||
|
||
// calculate signature from payload | ||
const hmacSignature = await utilities.calculateHmacSignature(notificationRequestItem); | ||
// add hmacSignature to 'additionalData' | ||
// note: add paymentLinkId for Pay by Link | ||
notificationRequestItem["additionalData"] = | ||
{"hmacSignature" : ""+hmacSignature+"", paymentLinkId : "PL1234567890"} | ||
|
||
// POST webhook | ||
const notifications = await request.post(`/api/webhooks/notifications`, { | ||
data: { | ||
"live": "false", | ||
"notificationItems":[ | ||
{ | ||
"NotificationRequestItem":{ | ||
"additionalData":{ | ||
"hmacSignature":"+JWKfq4ynALK+FFzGgHnp1jSMQJMBJeb87dlph24sXw=", | ||
"paymentLinkId":"PLXXXXXXXXXXXX" | ||
}, | ||
"eventCode":"AUTHORISATION", | ||
"success":"true", | ||
"eventDate":"2019-06-28T18:03:50+01:00", | ||
"merchantAccountCode":"YOUR_MERCHANT_ACCOUNT", | ||
"pspReference": "7914073381342284", | ||
"merchantReference": "YOUR_REFERENCE", | ||
"amount": { | ||
"value":1000, | ||
"currency":"EUR" | ||
} | ||
} | ||
} | ||
"NotificationRequestItem": notificationRequestItem | ||
} | ||
] | ||
} | ||
}); | ||
|
||
/// Verify notification is not accepted (invalid HMAC) | ||
// Verify status code | ||
expect(notifications.status()).toEqual(200); | ||
|
||
// Status code not 404 (verify webhook is found) | ||
expect(notifications.status()).not.toEqual(404); | ||
|
||
// Status code not 200 (verify webhook does not accept the notification ie HMAC invalid) | ||
expect(notifications.status()).not.toEqual(200); | ||
|
||
// Body response does not contain [accepted] | ||
// Verify body response | ||
notifications.text() | ||
.then(value => {expect(value).not.toEqual("[accepted]");} ); | ||
.then(value => {expect(value).toEqual("[accepted]");} ); | ||
}); | ||
|