Skip to content

Commit

Permalink
Merge remote-tracking branch 'remotes/dev/1.10' into 1.10
Browse files Browse the repository at this point in the history
  • Loading branch information
rgrebenchuk committed Sep 16, 2016
2 parents e5bcfbf + 2974c18 commit f870907
Show file tree
Hide file tree
Showing 8 changed files with 102 additions and 30 deletions.
8 changes: 8 additions & 0 deletions UPGRADE-1.10.3.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
UPGRADE FROM 1.10.2 to 1.10.3
=============================

####CaseBundle
- `OroCRM/Bundle/CaseBundle/Entity/CaseMailboxProcessSettings` extends `OroCRM\Bundle\CaseBundle\Model\ExtendCaseMailboxProcessSettings`

####SalesBundle
- `OroCRM/Bundle/SalesBundle/Entity/LeadMailboxProcessSettings` extends `OroCRM\Bundle\SalesBundle\Model\ExtendLeadMailboxProcessSettings`
Original file line number Diff line number Diff line change
Expand Up @@ -42,21 +42,24 @@ public function testValidate($collection, $type, $expectedViolationsMessages = [
/** @var \PHPUnit_Framework_MockObject_MockObject|ExecutionContextInterface $context */
$context = $this->getMockForAbstractClass('Symfony\Component\Validator\ExecutionContextInterface');

$this->validator->initialize($context);
if (!$expectedViolationsMessages) {
$context->expects($this->never())
->method('addViolationAt');
} else {
foreach ($expectedViolationsMessages as $key => $expectedViolationsMessage) {
$context->expects($this->at($key))
->method('addViolationAt')
->with($this->equalTo($type), $this->equalTo($expectedViolationsMessage), $this->isType('array'));
}
}

/** @var \PHPUnit_Framework_MockObject_MockObject|CategoriesConstraint $constraint */
$constraint = $this->getMock('OroCRM\Bundle\AnalyticsBundle\Validator\CategoriesConstraint');

foreach ($expectedViolationsMessages as $key => $expectedViolationsMessage) {
$context->expects($this->at($key))
->method('addViolationAt')
->with($this->equalTo($type), $this->equalTo($expectedViolationsMessage), $this->isType('array'));
}

$constraint->expects($this->any())
->method('getType')
->will($this->returnValue($type));

$this->validator->initialize($context);
$this->validator->validate($collection, $constraint);
}

Expand Down
45 changes: 28 additions & 17 deletions src/OroCRM/Bundle/AnalyticsBundle/Validator/CategoriesValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,6 @@ protected function validateOrder(PersistentCollection $value, CategoriesConstrai
$isIncreasing = $this->isIncreasing($orderedByIndex);
$orderedByValueArray = $value->toArray();

$isValid = true;

if ($isIncreasing) {
$inversion = 1;
$criteria = Criteria::ASC;
Expand All @@ -145,21 +143,7 @@ protected function validateOrder(PersistentCollection $value, CategoriesConstrai
$criteria = Criteria::DESC;
}

usort(
$orderedByValueArray,
function (RFMMetricCategory $item1, RFMMetricCategory $item2) use (&$isValid, $inversion) {
$minValue1 = $item1->getMinValue();
$minValue2 = $item2->getMinValue();

if ($minValue1 === $minValue2 ||
(!is_null($item1->getMaxValue()) && $item1->getMaxValue() <= $minValue1)) {
$isValid = false;
}

return (($minValue1 < $minValue2) ? 1 : -1) * $inversion;
}
);

$isValid = $this->orderByValue($orderedByValueArray, $inversion);
if (!$isValid || $orderedByValueArray !== $orderedByIndex->toArray()) {
$this->context->addViolationAt($constraint->getType(), $constraint->message, ['%order%' => $criteria]);
}
Expand All @@ -182,4 +166,31 @@ protected function isIncreasing(Collection $orderedByIndex)
return is_null($orderedByIndex->first()->getMinValue())
&& is_null($orderedByIndex->last()->getMaxValue());
}

/**
* @param array $value
* @param int $inversion
*
* @return boolean
*/
protected function orderByValue(array &$value, $inversion)
{
$isValid = true;
uasort(
$value,
function (RFMMetricCategory $item1, RFMMetricCategory $item2) use (&$isValid, $inversion) {
$minValue1 = $item1->getMinValue();
$minValue2 = $item2->getMinValue();

if ($minValue1 === $minValue2 ||
(!is_null($item1->getMaxValue()) && $item1->getMaxValue() <= $minValue1)) {
$isValid = false;
}

return (($minValue1 < $minValue2) ? -1 : 1) * $inversion;
}
);

return $isValid;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public function getSummarizedStatistic(Campaign $campaign)
'DATE(trackingEvent.loggedAt) as loggedAtDate',
]
)
->andWhere('trackingEvent.website IS NOT NULL')
->andWhere('trackingEvent.code = :trackingEventCode')
->andWhere('DATE(trackingEvent.loggedAt) < DATE(:today)')
->setParameter('trackingEventCode', $campaign->getCode())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use OroCRM\Bundle\MagentoBundle\Provider\ExtensionVersionAwareInterface;
use OroCRM\Bundle\MagentoBundle\Provider\Iterator\StoresSoapIterator;
use OroCRM\Bundle\MagentoBundle\Provider\Transport\SoapTransport;
use OroCRM\Bundle\MagentoBundle\Utils\ValidationUtils;

class SoapController extends Controller
{
Expand Down Expand Up @@ -56,7 +57,8 @@ public function checkAction(Request $request)
'adminUrl' => $transport->getAdminUrl(),
];
} catch (\Exception $e) {
$this->get('logger')->critical(sprintf('MageCheck error: %s: %s', $e->getCode(), $e->getMessage()));
$message = ValidationUtils::sanitizeSecureInfo($e->getMessage());
$this->get('logger')->critical(sprintf('MageCheck error: %s: %s', $e->getCode(), $message));
}

return new JsonResponse($response);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace OroCRM\Bundle\MagentoBundle\EventListener;

use Oro\Bundle\IntegrationBundle\Event\SyncEvent;
use OroCRM\Bundle\MagentoBundle\Utils\ValidationUtils;

class IntegrationSyncAfterEventListener
{
Expand All @@ -20,10 +21,7 @@ public function process(SyncEvent $event)
$jobResult = $event->getJobResult();
$exceptions = array_map(
function ($exception) {
if (is_string($exception)) {
return preg_replace('#(<apiKey.*?>)(.*)(</apiKey>)#i', '$1***$3', $exception);
}

$exception = ValidationUtils::sanitizeSecureInfo($exception);
return $exception;
},
$jobResult->getFailureExceptions()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,37 @@ public function entityProvider()
'should not provoke error, show default message' => [$cartStatus, self::TEST_DEFAULT_MESSAGE]
];
}

/**
* @dataProvider messageProvider
*
* @param string $exceptionMessage
* @param string $expectedMessage
*/
public function testSanitizeSecureInfo($exceptionMessage, $expectedMessage)
{
$sanitisedMessage = ValidationUtils::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>'
]
];
}
}
16 changes: 16 additions & 0 deletions src/OroCRM/Bundle/MagentoBundle/Utils/ValidationUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,20 @@ public static function guessValidationMessagePrefix($entity)

return $prefix;
}

/**
* Sanitise 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 f870907

Please sign in to comment.