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

Change subject: Get some static Config access out of Authenticator
......................................................................

Get some static Config access out of Authenticator

Provide credentials via constructor params

Bug: T158374
Change-Id: I59c54829f4ac197ca9c5681f338a415c9abb6764
---
M PaymentProviders/Ingenico/Authenticator.php
M PaymentProviders/Ingenico/Tests/phpunit/AuthenticatorTest.php
M SmashPig.yaml
3 files changed, 24 insertions(+), 20 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/wikimedia/fundraising/SmashPig 
refs/changes/00/338300/1

diff --git a/PaymentProviders/Ingenico/Authenticator.php 
b/PaymentProviders/Ingenico/Authenticator.php
index bbb3333..cbb389c 100644
--- a/PaymentProviders/Ingenico/Authenticator.php
+++ b/PaymentProviders/Ingenico/Authenticator.php
@@ -11,24 +11,28 @@
  */
 class Authenticator {
 
+       protected $keyId;
+       protected $secret;
+
+       public function __construct( $keyId, $secret ) {
+               $this->keyId = $keyId;
+               $this->secret = $secret;
+       }
+
        public function signRequest( OutboundRequest $request ) {
-               $config = Context::get()->getConfiguration();
 
                $toSign = $this->getStringToSign( $request );
-               $secretApiKey = $config->val( 'credentials/api-secret' );
 
                $signature = base64_encode(
                        hash_hmac(
                                'sha256',
                                $toSign,
-                               $secretApiKey,
+                               $this->secret,
                                true
                        )
                );
 
-               $apiKeyId = $config->val( 'credentials/api-key-id' );
-
-               $authHeader = "GCS v1HMAC:$apiKeyId:$signature";
+               $authHeader = "GCS v1HMAC:{$this->keyId}:$signature";
                $request->setHeader( 'Authorization', $authHeader );
        }
 
diff --git a/PaymentProviders/Ingenico/Tests/phpunit/AuthenticatorTest.php 
b/PaymentProviders/Ingenico/Tests/phpunit/AuthenticatorTest.php
index b9d9fd9..d242f6a 100644
--- a/PaymentProviders/Ingenico/Tests/phpunit/AuthenticatorTest.php
+++ b/PaymentProviders/Ingenico/Tests/phpunit/AuthenticatorTest.php
@@ -14,14 +14,16 @@
  */
 class AuthenticatorTest extends BaseSmashPigUnitTestCase {
 
+       /**
+        * @var Authenticator
+        */
+       protected $authenticator;
+
        public function setUp() {
-               $config = $this->setConfig( 'ingenico' );
-               $config->override( array(
-                       'credentials' => array(
-                               'api-key-id' => '5e45c937b9db33ae',
-                               'api-secret' => 
'I42Zf4pVnRdroHfuHnRiJjJ2B6+22h0yQt/R3nZR8Xg='
-                       )
-               ) );
+               $this->authenticator = new Authenticator(
+                       '5e45c937b9db33ae',
+                       'I42Zf4pVnRdroHfuHnRiJjJ2B6+22h0yQt/R3nZR8Xg='
+               );
                parent::setUp();
        }
 
@@ -31,8 +33,7 @@
        public function testBasicSignature() {
                $request = new OutboundRequest( 
'https://api.globalcollect.com/v1/9991/tokens/123456789' );
                $request->setHeader( 'Date', 'Fri, 06 Jun 2014 13:39:43 GMT' );
-               $authenticator = new Authenticator();
-               $authenticator->signRequest( $request );
+               $this->authenticator->signRequest( $request );
                $headers = $request->getHeaders();
                $this->assertEquals(
                        'GCS 
v1HMAC:5e45c937b9db33ae:J5LjfSBvrQNhu7gG0gvifZt+IWNDReGCmHmBmth6ueI=',
@@ -43,8 +44,7 @@
        public function testEncodedQuery() {
                $request = new OutboundRequest( 
'https://api.globalcollect.com/v1/consumer/ANDR%C3%89E/?q=na%20me' );
                $request->setHeader( 'Date', 'Fri, 06 Jun 2014 13:39:43 GMT' );
-               $authenticator = new Authenticator();
-               $authenticator->signRequest( $request );
+               $this->authenticator->signRequest( $request );
                $headers = $request->getHeaders();
                $this->assertEquals(
                        'GCS 
v1HMAC:5e45c937b9db33ae:x9S2hQmLhLTbpK0YdTuYCD8TB4D+Kf60tNW0Xw5Xls0=',
diff --git a/SmashPig.yaml b/SmashPig.yaml
index ce84b07..db44c38 100644
--- a/SmashPig.yaml
+++ b/SmashPig.yaml
@@ -446,12 +446,12 @@
 
     credentials:
         merchant-id: 1234
-        api-key-id: 'apiKey'
-        api-secret: 'apiSecret'
 
     authenticator:
         class: SmashPig\PaymentProviders\Ingenico\Authenticator
-        constructor-parameters: []
+        constructor-parameters:
+            - 'apiKey'
+            - 'apiSecret'
 
     bank-cache:
         key: SMASHPIG_INGENICO_IDEAL_BANK_LIST

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I59c54829f4ac197ca9c5681f338a415c9abb6764
Gerrit-PatchSet: 1
Gerrit-Project: wikimedia/fundraising/SmashPig
Gerrit-Branch: master
Gerrit-Owner: Ejegg <eeggles...@wikimedia.org>

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

Reply via email to