squashed commit

This commit is contained in:
hoangvv
2026-09-18 13:55:25 +07:00
commit 039c98d4d0
45882 changed files with 24235585 additions and 0 deletions
+5
View File
@@ -0,0 +1,5 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from . import common
from . import test_payment_transaction
from . import test_processing_flows
+43
View File
@@ -0,0 +1,43 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo.addons.payment.tests.http_common import PaymentHttpCommon
class APSCommon(PaymentHttpCommon):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.aps = cls._prepare_provider('aps', update_values={
'aps_merchant_identifier': '123456abc',
'aps_access_code': 'dummy',
'aps_sha_request': 'dummy',
'aps_sha_response': 'dummy',
})
cls.provider = cls.aps
cls.notification_data = {
'access_code': cls.provider.aps_access_code,
'amount': cls.amount,
'authorization_code': '123456',
'card_holder_name': 'Mitchell',
'card_number': '************1111',
'command': 'PURCHASE',
'currency': 'USD',
'customer_email': ' admin@yourcompany.example.com',
'customer_ip': '123.456.78.90',
'eci': 'ECOMMERCE',
'expiry_date': '2212',
'fort_id': '169996210006464984',
'language': 'en',
'merchant_identifier': cls.provider.aps_merchant_identifier,
'merchant_reference': cls.reference,
'payment_option': 'VISA',
'response_code': '14000',
'response_message': 'Success',
'signature': '6d2bb7904ac6141a0c10375c70fd417616c740bb1ddab862a224777880aa3600',
'status': '14',
'token_name': '123abc456def789',
}
@@ -0,0 +1,72 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo.tests import tagged
from odoo.tools import mute_logger
from odoo.addons.payment import utils as payment_utils
from odoo.addons.payment_aps.controllers.main import APSController
from odoo.addons.payment_aps.tests.common import APSCommon
@tagged('post_install', '-at_install')
class TestPaymentTransaction(APSCommon):
def test_reference_contains_only_valid_characters(self):
""" Test that transaction references are made of only alphanumerics and/or '-' and '_'. """
for prefix in (None, '', 'S0001', 'INV/20222/001', 'dummy ref'):
reference = self.env['payment.transaction']._compute_reference('aps', prefix=prefix)
self.assertRegex(reference, r'^[\w-]+$')
def test_no_item_missing_from_rendering_values(self):
""" Test that the rendered values are conform to the transaction fields. """
self.env['ir.config_parameter'].set_param('web.base.url', 'http://127.0.0.1:8069')
self.patch(self, 'base_url', lambda: 'http://127.0.0.1:8069')
tx = self._create_transaction(flow='redirect')
converted_amount = payment_utils.to_minor_currency_units(self.amount, self.currency)
expected_values = {
'command': 'PURCHASE',
'access_code': self.provider.aps_access_code,
'merchant_identifier': self.provider.aps_merchant_identifier,
'merchant_reference': tx.reference,
'payment_option': 'UNKNOWN',
'amount': str(converted_amount),
'currency': self.currency.name,
'language': tx.partner_lang[:2],
'customer_email': tx.partner_id.email_normalized,
'return_url': self._build_url(APSController._return_url),
'signature': 'c9b9f35a607606c045f8882e762a4a4a35572cf230fe1cd45fa18d7c8681aeb9',
'api_url': self.provider._aps_get_api_url(),
}
self.assertEqual(tx._get_specific_rendering_values(None), expected_values)
@mute_logger('odoo.addons.payment.models.payment_transaction')
def test_no_input_missing_from_redirect_form(self):
""" Test that the no key is not omitted from the rendering values. """
tx = self._create_transaction(flow='redirect')
expected_input_keys = [
'command',
'access_code',
'merchant_identifier',
'merchant_reference',
'amount',
'currency',
'language',
'customer_email',
'signature',
'payment_option',
'return_url',
]
processing_values = tx._get_processing_values()
form_info = self._extract_values_from_html_form(processing_values['redirect_form_html'])
self.assertEqual(form_info['action'], 'https://sbcheckout.payfort.com/FortAPI/paymentPage')
self.assertEqual(form_info['method'], 'post')
self.assertListEqual(list(form_info['inputs'].keys()), expected_input_keys)
def test_processing_notification_data_confirms_transaction(self):
""" Test that the transaction state is set to 'done' when the notification data indicate a
successful payment. """
tx = self._create_transaction(flow='redirect')
tx._process_notification_data(self.notification_data)
self.assertEqual(tx.state, 'done')
@@ -0,0 +1,94 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from unittest.mock import patch
from werkzeug.exceptions import Forbidden
from odoo.tests import tagged
from odoo.tools import mute_logger
from odoo.addons.payment_aps.controllers.main import APSController
from odoo.addons.payment_aps.tests.common import APSCommon
@tagged('post_install', '-at_install')
class TestProcessingFlows(APSCommon):
@mute_logger('odoo.addons.payment_aps.controllers.main')
def test_redirect_notification_triggers_processing(self):
""" Test that receiving a redirect notification triggers the processing of the notification
data. """
self._create_transaction(flow='redirect')
url = self._build_url(APSController._return_url)
with patch(
'odoo.addons.payment_aps.controllers.main.APSController._verify_notification_signature'
), patch(
'odoo.addons.payment.models.payment_transaction.PaymentTransaction'
'._handle_notification_data'
) as handle_notification_data_mock:
self._make_http_post_request(url, data=self.notification_data)
self.assertEqual(handle_notification_data_mock.call_count, 1)
@mute_logger('odoo.addons.payment_aps.controllers.main')
def test_webhook_notification_triggers_processing(self):
""" Test that receiving a valid webhook notification triggers the processing of the
notification data. """
self._create_transaction('redirect')
url = self._build_url(APSController._webhook_url)
with patch(
'odoo.addons.payment_aps.controllers.main.APSController._verify_notification_signature'
), patch(
'odoo.addons.payment.models.payment_transaction.PaymentTransaction'
'._handle_notification_data'
) as handle_notification_data_mock:
self._make_http_post_request(url, data=self.notification_data)
self.assertEqual(handle_notification_data_mock.call_count, 1)
@mute_logger('odoo.addons.payment_aps.controllers.main')
def test_redirect_notification_triggers_signature_check(self):
""" Test that receiving a redirect notification triggers a signature check. """
self._create_transaction('redirect')
url = self._build_url(APSController._return_url)
with patch(
'odoo.addons.payment_aps.controllers.main.APSController._verify_notification_signature'
) as signature_check_mock, patch(
'odoo.addons.payment.models.payment_transaction.PaymentTransaction'
'._handle_notification_data'
):
self._make_http_post_request(url, data=self.notification_data)
self.assertEqual(signature_check_mock.call_count, 1)
@mute_logger('odoo.addons.payment_aps.controllers.main')
def test_webhook_notification_triggers_signature_check(self):
""" Test that receiving a webhook notification triggers a signature check. """
self._create_transaction('redirect')
url = self._build_url(APSController._webhook_url)
with patch(
'odoo.addons.payment_aps.controllers.main.APSController._verify_notification_signature'
) as signature_check_mock, patch(
'odoo.addons.payment.models.payment_transaction.PaymentTransaction'
'._handle_notification_data'
):
self._make_http_post_request(url, data=self.notification_data)
self.assertEqual(signature_check_mock.call_count, 1)
def test_accept_notification_with_valid_signature(self):
""" Test the verification of a notification with a valid signature. """
tx = self._create_transaction('redirect')
self._assert_does_not_raise(
Forbidden, APSController._verify_notification_signature, self.notification_data, tx
)
@mute_logger('odoo.addons.payment_aps.controllers.main')
def test_reject_notification_with_missing_signature(self):
""" Test the verification of a notification with a missing signature. """
tx = self._create_transaction('redirect')
payload = dict(self.notification_data, signature=None)
self.assertRaises(Forbidden, APSController._verify_notification_signature, payload, tx)
@mute_logger('odoo.addons.payment_aps.controllers.main')
def test_reject_notification_with_invalid_signature(self):
""" Test the verification of a notification with an invalid signature. """
tx = self._create_transaction('redirect')
payload = dict(self.notification_data, signature='dummy')
self.assertRaises(Forbidden, APSController._verify_notification_signature, payload, tx)