public void TestNotificationRequestItemHmac() { string key = "DFB1EB5485895CFA84146406857104ABB4CBCABDC8AAF103A624C8F6A3EAAB00"; var expectedSign = "ipnxGCaUZ4l8TUW75a71/ghd2Fe5ffvX0pV4TLTntIc="; var additionalData = new Dictionary <string, string> { { Constants.AdditionalData.HmacSignature, expectedSign } }; var notificationRequestItem = new NotificationRequestItem { PspReference = "pspReference", OriginalReference = "originalReference", MerchantAccountCode = "merchantAccount", MerchantReference = "reference", Amount = new Model.Amount("EUR", 1000), EventCode = "EVENT", Success = true, AdditionalData = additionalData }; var hmacValidator = new HmacValidator(); var data = hmacValidator.GetDataToSign(notificationRequestItem); Assert.AreEqual("pspReference:originalReference:merchantAccount:reference:1000:EUR:EVENT:true", data); var encrypted = hmacValidator.CalculateHmac(notificationRequestItem, key); Assert.AreEqual(expectedSign, encrypted); notificationRequestItem.AdditionalData[Constants.AdditionalData.HmacSignature] = expectedSign; Assert.IsTrue(hmacValidator.IsValidHmac(notificationRequestItem, key)); notificationRequestItem.AdditionalData[Constants.AdditionalData.HmacSignature] = "notValidSign"; Assert.IsFalse(hmacValidator.IsValidHmac(notificationRequestItem, key)); }
public void TestHmacCalculationNotificationRequestWithSpecialChars() { string key = "66B61474A0AA3736BA8789EDC6D6CD9EBA0C4F414A554E32A407F849C045C69D"; var mockPath = GetMockFilePath("Mocks/notification-response-refund-fail.json"); var response = MockFileToString(mockPath); var hmacValidator = new HmacValidator(); var notificationRequest = JsonOperation.Deserialize <NotificationRequest>(response); var notificationItem = notificationRequest.NotificationItemContainers[0].NotificationItem; var isValidHmac = hmacValidator.IsValidHmac(notificationItem, key); Assert.IsTrue(isValidHmac); }