From 3e2d646cbe158e889799fd9420bb25802a486d5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Garc=C3=ADa=20Garz=C3=B3n?= Date: Thu, 9 Dec 2021 23:34:56 +0100 Subject: [PATCH 1/3] Fixed order id in tests --- sermepa/sermepa_test.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/sermepa/sermepa_test.py b/sermepa/sermepa_test.py index c97e862..b481db1 100755 --- a/sermepa/sermepa_test.py +++ b/sermepa/sermepa_test.py @@ -3,6 +3,7 @@ from __future__ import unicode_literals import unittest +import random import base64 import json @@ -21,11 +22,6 @@ except ImportError: config = None -def randhex(nbytes): - import random - return "{1:0{0}x}".format(nbytes*2,random.getrandbits(nbytes*8)) - - class Generator_Test(unittest.TestCase): # back2back data taken from PHP example @@ -57,6 +53,9 @@ class Generator_Test(unittest.TestCase): signature = 'Ejse86yr96Xbr1mf6UvQLoTPwwTyFiLXM+2uT09i9nY=' signatureversion = 'HMAC_SHA256_V1' + def new_order_id(self): + nbytes=6 + return "{1:0{0}x}".format(nbytes*2,random.getrandbits(nbytes*8)) def test_encodePayload(self): self.assertEqual( @@ -179,7 +178,7 @@ def test_sendingPost_testing(self): Ds_Merchant_MerchantData = "COBRAMENT QUOTA SOCI", Ds_Merchant_MerchantName = "SOM ENERGIA, SCCL", Ds_Merchant_MerchantURL = "https://testing.somenergia.coop:5001/pagament/notificacio", - Ds_Merchant_Order = randhex(nbytes=6), # "20167db2f375", + Ds_Merchant_Order = self.new_order_id(), Ds_Merchant_ProductDescription = "Alta de soci SOMENERGIA", Ds_Merchant_SumTotal = "10000", Ds_Merchant_Terminal = "1", @@ -210,7 +209,7 @@ def test_sendingPost_testing_invalidSignature(self): Ds_Merchant_MerchantData = "COBRAMENT QUOTA SOCI", Ds_Merchant_MerchantName = "SOM ENERGIA, SCCL", Ds_Merchant_MerchantURL = "https://testing.somenergia.coop:5001/pagament/notificacio", - Ds_Merchant_Order = randhex(nbytes=6), # "20167db2f375", + Ds_Merchant_Order = self.new_order_id(), Ds_Merchant_ProductDescription = "Alta de soci SOMENERGIA", Ds_Merchant_SumTotal = "10000", Ds_Merchant_Terminal = "1", @@ -241,7 +240,7 @@ def test_sendingPost_testingFails_invalidUser(self): Ds_Merchant_MerchantData = "COBRAMENT QUOTA SOCI", Ds_Merchant_MerchantName = "SOM ENERGIA, SCCL", Ds_Merchant_MerchantURL = "https://testing.somenergia.coop:5001/pagament/notificacio", - Ds_Merchant_Order = randhex(nbytes=6), # "20167db2f375", + Ds_Merchant_Order = self.new_order_id(), Ds_Merchant_ProductDescription = "Alta de soci SOMENERGIA", Ds_Merchant_SumTotal = "10000", Ds_Merchant_Terminal = "1", From 88c028d21beac3dda11d3b94fdb3d532b9c88252 Mon Sep 17 00:00:00 2001 From: Benjami Date: Thu, 2 Dec 2021 08:40:23 +0100 Subject: [PATCH 2/3] decodeSignedData not raise exception if redsys sends unexpected param --- sermepa/__init__.py | 4 ---- sermepa/sermepa_test.py | 20 ++++++++++---------- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/sermepa/__init__.py b/sermepa/__init__.py index 48fdaee..4670d8c 100644 --- a/sermepa/__init__.py +++ b/sermepa/__init__.py @@ -280,10 +280,6 @@ def error(message): camell = _notification_fields_upper[key] data[camell]=data[key] del data[key] - continue - - if key not in _notification_fields: - error("Bad parameter '{}'".format(key)) return data diff --git a/sermepa/sermepa_test.py b/sermepa/sermepa_test.py index b481db1..ffc823f 100755 --- a/sermepa/sermepa_test.py +++ b/sermepa/sermepa_test.py @@ -411,19 +411,19 @@ def test_decodeSignedData_badSignature(self): msg = cm.exception.args[0] self.assertEqual(msg, 'Bad signature') - def test_decodeSignedData_badParam(self): + def test_decodeSignedData_unexpectedParam(self): json_data = '{"Ds_Order":"666", "Bad":"value"}' base64_data = base64.urlsafe_b64encode(b(json_data)) signature = signPayload(self.secret, base64_data, urlsafe=True) - with self.assertRaises(SignatureError) as cm: - decodeSignedData( - self.merchantkey, - Ds_MerchantParameters = base64_data, - Ds_Signature = signature, - Ds_SignatureVersion = self.signatureversion, - ) - msg = cm.exception.args[0] - self.assertEqual(msg, "Bad parameter 'Bad'") + + data = decodeSignedData( + self.merchantkey, + Ds_MerchantParameters=base64_data, + Ds_Signature=signature, + Ds_SignatureVersion=self.signatureversion, + ) + + self.assertEqual(data, dict(Ds_Order='666', Bad='value')) def test_decodeSignedData_upperCaseOrder(self): json_data = '{"DS_ORDER":"666"}' From 2934e706ce69ebda14d26e817414d88cd8f817e7 Mon Sep 17 00:00:00 2001 From: Benjami Date: Tue, 7 Dec 2021 09:09:00 +0100 Subject: [PATCH 3/3] Update version --- README.md | 4 ++++ setup.py | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 3fe9ef9..1bc337c 100644 --- a/README.md +++ b/README.md @@ -44,6 +44,10 @@ redsystest = dict( # Clave para tests ``` ## Changelog +### sermepa 1.0.4-dev + +- When sermepa revice an unexpected param in `decodeSignedData` method not will raise `SignatureError` + ### sermepa 1.0.2 (2020-09-16) - Accept `Ds_ProcessedPayMethod` parameter set diff --git a/setup.py b/setup.py index 209fca4..fee9c58 100755 --- a/setup.py +++ b/setup.py @@ -12,7 +12,7 @@ setup( name='sermepa', - version='1.0.3', + version='1.0.4-dev', description = __doc__.strip(), author='GISCE Enginyeria', author_email='devel@gisce.net',