Ejegg has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/385483 )

Change subject: Unit tests for Adyen multi-skin switching
......................................................................

Unit tests for Adyen multi-skin switching

Change-Id: I32d9580da2990d0c4df20ce2688fd28273856109
---
M adyen_gateway/AdyenHostedSignature.php
M tests/phpunit/Adapter/Adyen/AdyenTest.php
M tests/phpunit/TestConfiguration.php
3 files changed, 64 insertions(+), 2 deletions(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/DonationInterface 
refs/changes/83/385483/1

diff --git a/adyen_gateway/AdyenHostedSignature.php 
b/adyen_gateway/AdyenHostedSignature.php
index 3ac51bd..4fad1b8 100644
--- a/adyen_gateway/AdyenHostedSignature.php
+++ b/adyen_gateway/AdyenHostedSignature.php
@@ -1,8 +1,8 @@
 <?php
 
 class AdyenHostedSignature implements StagingHelper {
-       /*
-        * Send our fraud score to Adyen so we can see it in the console
+       /**
+        * Sign the Adyen API request
         */
        public function stage( GatewayType $adapter, $normalized, &$stagedData 
) {
                $params = $adapter->buildRequestParams();
diff --git a/tests/phpunit/Adapter/Adyen/AdyenTest.php 
b/tests/phpunit/Adapter/Adyen/AdyenTest.php
index 9250e9c..aab4ba9 100644
--- a/tests/phpunit/Adapter/Adyen/AdyenTest.php
+++ b/tests/phpunit/Adapter/Adyen/AdyenTest.php
@@ -186,6 +186,32 @@
                // TODO inspect the queue message
        }
 
+       /**
+        * Test that we verify the signature with the alternate skin code's HMAC
+        */
+       public function testDonorReturnSuccessAltSkin() {
+               $init = $this->getDonorTestData();
+               $init['payment_method'] = 'cc';
+               $init['payment_submethod'] = 'visa';
+               $init['language'] = 'FR';
+               $init['order_id'] = '55555';
+               $session['Donor'] = $init;
+               $this->setUpRequest( $init, $session );
+               $gateway = $this->getFreshGatewayObject( array() );
+               $result = $gateway->processDonorReturn( array(
+                       'authResult' => 'AUTHORISED',
+                       'merchantReference' => '55555.1',
+                       'merchantSig' => 
'/uzhDRZ3zSzFNLgBj4tI6pHYDynVQAqCeKcJWsXeWo0=',
+                       'paymentMethod' => 'visa',
+                       'pspReference' => '123987612346789',
+                       'shopperLocale' => 'fr_FR',
+                       'skinCode' => 'altskin',
+                       'title' => 'Special:AdyenGatewayResult'
+               ) );
+               $this->assertFalse( $result->isFailed() );
+               $this->assertEmpty( $result->getErrors() );
+       }
+
        public function testDonorReturnFailure() {
                $init = $this->getDonorTestData();
                $init['payment_method'] = 'cc';
@@ -207,4 +233,36 @@
                ) );
                $this->assertTrue( $result->isFailed() );
        }
+
+       /**
+        * Test that we choose the correct HMAC based on skinCode
+        */
+       public function testSignatureAltSkin() {
+               $init = $this->getDonorTestData();
+               $gateway = $this->getFreshGatewayObject($init);
+               $toSign = [
+                       'allowedMethods' => 'card',
+                       'billingAddress.street' => $init['street_address'],
+                       'billingAddress.city' => $init['city'],
+                       'billingAddress.postalCode' => $init['postal_code'],
+                       'billingAddress.stateOrProvince' => 
$init['state_province'],
+                       'billingAddress.country' => $init['country'],
+                       'billingAddress.houseNumberOrName' => 'NA',
+                       'billingAddressType' => 2,
+                       'card.cardHolderName' => $init['first_name'] . ' ' . 
$init['last_name'],
+                       'currencyCode' => $init['currency'],
+                       'merchantAccount' => 'wikitest',
+                       'merchantReference' => 123456,
+                       'paymentAmount' => ( $init['amount'] ) * 100,
+                       'skinCode' => 'testskin',
+                       'shopperLocale' => 'fr_US',
+                       'shopperEmail' => 'nob...@wikimedia.org',
+                       'offset' => '52',
+               ];
+               $defaultSig = AdyenHostedSignature::calculateSignature( 
$gateway, $toSign );
+               $toSign['skinCode'] = 'altskin';
+               $altSig = AdyenHostedSignature::calculateSignature( $gateway, 
$toSign );
+               $this->assertEquals( 
'xoI76zyUFjjBzubzSPEopAgoA9Bt7PjwQAi5QHk/GKo=', $defaultSig );
+               $this->assertEquals( 
'UKMVUkWR5GqsgfUEtqZalzh+kTa7kXyrDw9nbj4D/0Q=', $altSig );
+       }
 }
diff --git a/tests/phpunit/TestConfiguration.php 
b/tests/phpunit/TestConfiguration.php
index 6394ab0..3cf3e1d 100644
--- a/tests/phpunit/TestConfiguration.php
+++ b/tests/phpunit/TestConfiguration.php
@@ -161,6 +161,10 @@
                        'SharedSecret' => 
'C7F1D9E29479CF18131063A742CD2703FB9D48BAB0160693045E3FB7B8508E59',
                        'Name' => 'default',
                ],
+               'altskin' => [
+                       'SharedSecret' => 
'A78B329F29872E21291063A742CD2703FB9D48BAB01606930421291063A742CD',
+                       'Name' => 'redirect',
+               ]
        ],
 );
 

-- 
To view, visit https://gerrit.wikimedia.org/r/385483
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I32d9580da2990d0c4df20ce2688fd28273856109
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/DonationInterface
Gerrit-Branch: master
Gerrit-Owner: Ejegg <ej...@ejegg.com>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to