wp-pay-gateways /
buckaroo
| 1 | <?php |
||||||
| 2 | /** |
||||||
| 3 | * Signature test |
||||||
| 4 | * |
||||||
| 5 | * @author Pronamic <[email protected]> |
||||||
| 6 | * @copyright 2005-2021 Pronamic |
||||||
| 7 | * @license GPL-3.0-or-later |
||||||
| 8 | * @package Pronamic\WordPress\Pay\Gateways\Buckaroo |
||||||
| 9 | */ |
||||||
| 10 | |||||||
| 11 | namespace Pronamic\WordPress\Pay\Gateways\Buckaroo; |
||||||
| 12 | |||||||
| 13 | /** |
||||||
| 14 | * Title: Buckaroo signature test. |
||||||
| 15 | * Description: |
||||||
| 16 | * Copyright: 2005-2021 Pronamic |
||||||
| 17 | * Company: Pronamic |
||||||
| 18 | * |
||||||
| 19 | * @link http://pronamic.nl/wp-content/uploads/2013/04/BPE-3.0-Gateway-HTML.1.02.pdf |
||||||
| 20 | * @author Remco Tolsma |
||||||
| 21 | * @version 2.0.4 |
||||||
| 22 | */ |
||||||
| 23 | class SignatureTest extends \WP_UnitTestCase { |
||||||
| 24 | /** |
||||||
| 25 | * Test get signature. |
||||||
| 26 | * |
||||||
| 27 | * @param array $data Data for signature. |
||||||
| 28 | * |
||||||
| 29 | * @dataProvider provider_case_mix |
||||||
| 30 | */ |
||||||
| 31 | public function test_get_signature( $data ) { |
||||||
| 32 | $signature = Security::get_signature( $data ); |
||||||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||||||
| 33 | |||||||
| 34 | $this->assertEquals( '84e9802d60d727ade4a845c43033051d5758ce25', $signature ); |
||||||
| 35 | } |
||||||
| 36 | |||||||
| 37 | /** |
||||||
| 38 | * Test signature filter. |
||||||
| 39 | * |
||||||
| 40 | * @param array $data Data for signature. |
||||||
| 41 | * |
||||||
| 42 | * @dataProvider provider_case_mix |
||||||
| 43 | */ |
||||||
| 44 | public function test_signature_filter( $data ) { |
||||||
| 45 | $data = Security::filter_data( $data ); |
||||||
| 46 | |||||||
| 47 | $this->assertArrayNotHasKey( 'random_1234567890', $data ); |
||||||
| 48 | } |
||||||
| 49 | |||||||
| 50 | /** |
||||||
| 51 | * Test create signature. |
||||||
| 52 | * |
||||||
| 53 | * @param array $data Data for signature. |
||||||
| 54 | * |
||||||
| 55 | * @dataProvider provider |
||||||
| 56 | */ |
||||||
| 57 | public function test_create_signature( $data ) { |
||||||
| 58 | $secret_key = '29E9BEB3F3428B2BCAA678DEC489A86A'; |
||||||
| 59 | |||||||
| 60 | $data = Util::urldecode( $data ); |
||||||
|
0 ignored issues
–
show
The method
urldecode() does not exist on Pronamic\WordPress\Pay\Gateways\Buckaroo\Util.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. Loading history...
|
|||||||
| 61 | |||||||
| 62 | $signature = Security::get_signature( $data ); |
||||||
| 63 | |||||||
| 64 | $signature_check = Security::create_signature( $data, $secret_key ); |
||||||
| 65 | |||||||
| 66 | $this->assertEquals( $signature, $signature_check ); |
||||||
| 67 | } |
||||||
| 68 | |||||||
| 69 | /** |
||||||
| 70 | * Data provider for signature. |
||||||
| 71 | * |
||||||
| 72 | * @return array |
||||||
| 73 | */ |
||||||
| 74 | public function provider() { |
||||||
| 75 | $data = array( |
||||||
| 76 | 'BRQ_AMOUNT' => '50.00', |
||||||
| 77 | 'BRQ_CURRENCY' => 'EUR', |
||||||
| 78 | 'BRQ_CUSTOMER_NAME' => 'J.+de+Tèster', |
||||||
| 79 | 'BRQ_INVOICENUMBER' => '1234567890', |
||||||
| 80 | 'BRQ_PAYMENT' => 'F978A56A36D04217BD93157E2B14A578', |
||||||
| 81 | 'BRQ_PAYMENT_METHOD' => 'ideal', |
||||||
| 82 | 'BRQ_SERVICE_IDEAL_CONSUMERBIC' => 'RABONL2U', |
||||||
| 83 | 'BRQ_SERVICE_IDEAL_CONSUMERIBAN' => 'NL44RABO0123456789', |
||||||
| 84 | 'BRQ_SERVICE_IDEAL_CONSUMERISSUER' => 'Rabobank', |
||||||
| 85 | 'BRQ_SERVICE_IDEAL_CONSUMERNAME' => 'J.+de+Tèster', |
||||||
| 86 | 'BRQ_STATUSCODE' => '190', |
||||||
| 87 | 'BRQ_STATUSCODE_DETAIL' => 'S001', |
||||||
| 88 | 'BRQ_STATUSMESSAGE' => 'Payment+successfully+processed', |
||||||
| 89 | 'BRQ_TEST' => 'true', |
||||||
| 90 | 'BRQ_TIMESTAMP' => '2014-01-01+12:00:00', |
||||||
| 91 | 'BRQ_TRANSACTIONS' => '098F6BCD4621D373CADE4E832627B4F6', |
||||||
| 92 | 'BRQ_WEBSITEKEY' => 'fpK0odPM3A', |
||||||
| 93 | 'BRQ_SIGNATURE' => '84e9802d60d727ade4a845c43033051d5758ce25', |
||||||
| 94 | ); |
||||||
| 95 | |||||||
| 96 | return array( |
||||||
| 97 | array( $data ), |
||||||
| 98 | ); |
||||||
| 99 | } |
||||||
| 100 | |||||||
| 101 | /** |
||||||
| 102 | * Data provider for case mix. |
||||||
| 103 | * |
||||||
| 104 | * @return array |
||||||
| 105 | */ |
||||||
| 106 | public function provider_case_mix() { |
||||||
| 107 | $data_mixcase = array( |
||||||
| 108 | 'Brq_amount' => '55.00', |
||||||
| 109 | 'Brq_currency' => 'EUR', |
||||||
| 110 | 'Brq_customer_name' => 'J.+de+Tèster', |
||||||
| 111 | 'Brq_invoicenumber' => '1389773524', |
||||||
| 112 | 'Brq_payment' => 'F978A56A36D04217BD93157E2B14A578', |
||||||
| 113 | 'Brq_payment_method' => 'ideal', |
||||||
| 114 | 'Brq_service_ideal_consumerbic' => 'RABONL2U', |
||||||
| 115 | 'Brq_service_ideal_consumeriban' => 'NL44RABO0123456789', |
||||||
| 116 | 'Brq_service_ideal_consumerissuer' => 'Rabobank', |
||||||
| 117 | 'Brq_service_ideal_consumername' => 'J.+de+Tèster', |
||||||
| 118 | 'Brq_statuscode' => '190', |
||||||
| 119 | 'Brq_statuscode_detail' => 'S001', |
||||||
| 120 | 'Brq_statusmessage' => 'Payment+successfully+processed', |
||||||
| 121 | 'Brq_test' => 'true', |
||||||
| 122 | 'Brq_timestamp' => '2014-01-01+12:00:00', |
||||||
| 123 | 'Brq_transactions' => '098F6BCD4621D373CADE4E832627B4F6', |
||||||
| 124 | 'Brq_websitekey' => 'fpK0odPM3A', |
||||||
| 125 | 'Brq_signature' => '84e9802d60d727ade4a845c43033051d5758ce25', |
||||||
| 126 | 'random_1234567890' => 'random_1234567890', |
||||||
| 127 | ); |
||||||
| 128 | |||||||
| 129 | $data_uppercase = array_change_key_case( $data_mixcase, CASE_UPPER ); |
||||||
| 130 | $data_lowercase = array_change_key_case( $data_mixcase, CASE_LOWER ); |
||||||
| 131 | |||||||
| 132 | return array( |
||||||
| 133 | array( $data_mixcase ), |
||||||
| 134 | array( $data_uppercase ), |
||||||
| 135 | array( $data_lowercase ), |
||||||
| 136 | ); |
||||||
| 137 | } |
||||||
| 138 | } |
||||||
| 139 |