Projet

Général

Profil

0001-ogone-handle-properly-unicode-params-13592.patch

Serghei Mihai (congés, retour 15/05), 20 octobre 2016 19:17

Télécharger (2,78 ko)

Voir les différences:

Subject: [PATCH 1/2] ogone: handle properly unicode params (#13592)

 eopayment/ogone.py  |  6 ++++--
 tests/test_ogone.py | 13 ++++++++-----
 2 files changed, 12 insertions(+), 7 deletions(-)
eopayment/ogone.py
6 6

  
7 7
from common import (PaymentCommon, PaymentResponse, FORM, CANCELLED, PAID,
8 8
        ERROR, Form, DENIED, ACCEPTED, ORDERID_TRANSACTION_SEPARATOR,
9
        ResponseError)
9
        ResponseError, force_byte)
10 10
def N_(message): return message
11 11

  
12 12
ENVIRONMENT_TEST = 'TEST'
......
458 458
        values = params.items()
459 459
        values = [(a.upper(), b) for a, b in values]
460 460
        values = sorted(values)
461
        values = ['%s=%s' % (a, b) for a, b in values if a in keep]
461
        values = [force_byte('%s=%s' % (a, b)) for a, b in values if a in keep]
462
        key = force_byte(key)
462 463
        tosign = key.join(values)
463 464
        tosign += key
465
        tosign = force_byte(tosign)
464 466
        hashing = getattr(hashlib, algo)
465 467
        return hashing(tosign).hexdigest().upper()
466 468

  
tests/test_ogone.py
1
# -*- coding: utf-8 -*-
2

  
1 3
from unittest import TestCase
2 4
import urllib
3 5

  
......
5 7
import eopayment.ogone as ogone
6 8
from eopayment import ResponseError
7 9

  
8
PSPID = '2352566'
10
PSPID = u'2352566ö'
9 11

  
10 12
BACKEND_PARAMS = {
11 13
    'environment': ogone.ENVIRONMENT_TEST,
12 14
    'pspid': PSPID,
13
    'sha_in': 'secret',
14
    'sha_out': 'secret'
15
    'sha_in': u'sécret',
16
    'sha_out': u'sécret',
17
    'automatic_return_url': u'http://example.com/autömatic_réturn_url'
15 18
}
16 19

  
17 20
class OgoneTests(TestCase):
......
19 22
    def test_request(self):
20 23
        ogone_backend = eopayment.Payment('ogone', BACKEND_PARAMS)
21 24
        amount = '42.42'
22
        order_id = 'myorder'
25
        order_id = u'my ordér'
23 26
        reference, kind, what = ogone_backend.request(amount=amount,
24 27
                                        orderid=order_id, email='foo@example.com')
25 28
        self.assertEqual(len(reference), 30)
......
30 33
        self.assertEqual(root.attrib['method'], 'POST')
31 34
        self.assertEqual(root.attrib['action'], ogone.ENVIRONMENT_TEST_URL)
32 35
        values = {
33
            'CURRENCY': 'EUR',
36
            'CURRENCY': u'EUR',
34 37
            'ORDERID': reference,
35 38
            'PSPID': PSPID,
36 39
            'EMAIL': 'foo@example.com',
37
-