-
Notifications
You must be signed in to change notification settings - Fork 351
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CRM-8434: Hide API key from batch ERROR during Magento synchronizatio…
…n (#12577) * CRM-8434: Hide API key from batch ERROR during Magento synchronization - removed sensitive data from Exception message during creation
- Loading branch information
1 parent
6593bd3
commit 9729405
Showing
3 changed files
with
68 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
src/Oro/Bundle/IntegrationBundle/Test/Unit/Utils/SecureErrorMessageHelperTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>' | ||
] | ||
]; | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
src/Oro/Bundle/IntegrationBundle/Utils/SecureErrorMessageHelper.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |