Skip to content

Commit

Permalink
CRM-8434: Hide API key from batch ERROR during Magento synchronizatio…
Browse files Browse the repository at this point in the history
…n (#12577)

* CRM-8434: Hide API key from batch ERROR during Magento synchronization
- removed sensitive data from Exception message during creation
  • Loading branch information
rhoman authored and dnahrebecki committed Aug 16, 2017
1 parent 6593bd3 commit 9729405
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Oro\Bundle\IntegrationBundle\Exception;

use Oro\Bundle\IntegrationBundle\Utils\SecureErrorMessageHelper;

class SoapConnectionException extends TransportException
{
/**
Expand Down Expand Up @@ -34,6 +36,8 @@ public static function createFromResponse($response, \Exception $exception = nul
$message .= str_pad('[code]', 20, ' ', STR_PAD_RIGHT) . $code . PHP_EOL;
$message .= PHP_EOL;

$message = SecureErrorMessageHelper::sanitizeSecureInfo($message);

$newException = new static($message, $exceptionCode, $exception);
if ($exception instanceof \SoapFault) {
$newException->setFaultCode($exception->faultcode);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

namespace Oro\Bundle\IntegrationBundle\Tests\Unit\Utils;

use Oro\Bundle\IntegrationBundle\Utils\SecureErrorMessageHelper;

class SecureErrorMessageHelperTest extends \PHPUnit_Framework_TestCase
{

/**
* @dataProvider messageProvider
*
* @param string $exceptionMessage
* @param string $expectedMessage
*/
public function testSanitizeSecureInfo($exceptionMessage, $expectedMessage)
{
$sanitisedMessage = SecureErrorMessageHelper::sanitizeSecureInfo($exceptionMessage);
$this->assertEquals($expectedMessage, $sanitisedMessage);
}

/**
* @return array
*/
public function messageProvider()
{
return [
'some other text' => [
'$exceptionMessage' => 'some message text',
'$expectedMessage' => 'some message text'
],
'sanitized exception message' => [
'$exceptionMessage' => '<?xml version="1.0" encoding="UTF-8"?>' .
'<SOAP-ENV:Body><ns1:login><username xsi:type="xsd:string">abc</username>' .
'<apiKey xsi:type="xsd:string">abcabc1</apiKey></ns1:login></SOAP-ENV:Body></SOAP-ENV:Envelope>',
'$expectedMessage' => '<?xml version="1.0" encoding="UTF-8"?>' .
'<SOAP-ENV:Body><ns1:login><username xsi:type="xsd:string">abc</username>' .
'<apiKey xsi:type="xsd:string">***</apiKey></ns1:login></SOAP-ENV:Body></SOAP-ENV:Envelope>'
]
];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace Oro\Bundle\IntegrationBundle\Utils;

class SecureErrorMessageHelper
{
/**
* Sanitize error message for secure info
*
* @param string
*
* @return string
*/
public static function sanitizeSecureInfo($message)
{
if (is_string($message)) {
return preg_replace('#(<apiKey.*?>)(.*)(</apiKey>)#i', '$1***$3', $message);
}

return $message;
}
}

0 comments on commit 9729405

Please sign in to comment.