Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Invalid clickthrough value exception #10444

Merged
merged 5 commits into from Nov 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 13 additions & 6 deletions app/bundles/PageBundle/Controller/PublicController.php
Expand Up @@ -379,17 +379,24 @@ public function trackingImageAction()
*/
public function trackingAction(Request $request)
{
$notSuccessResponse = new JsonResponse(
[
'success' => 0,
]
);
if (!$this->get('mautic.security')->isAnonymous()) {
return new JsonResponse(
[
'success' => 0,
]
);
return $notSuccessResponse;
}

/** @var \Mautic\PageBundle\Model\PageModel $model */
$model = $this->getModel('page');
$model->hitPage(null, $this->request);

try {
$model->hitPage(null, $this->request);
} catch (InvalidDecodedStringException $invalidDecodedStringException) {
// do not track invalid ct
return $notSuccessResponse;
}

/** @var ContactTracker $contactTracker */
$contactTracker = $this->get(ContactTracker::class);
Expand Down
44 changes: 44 additions & 0 deletions app/bundles/PageBundle/Tests/Controller/PublicControllerTest.php
Expand Up @@ -466,6 +466,50 @@ function (string $eventName, TrackingEvent $event) {
);
}

public function testTrackingActionWithInvalidCt()
{
$request = new Request();

$pageModel = $this->createMock(PageModel::class);
$pageModel->expects($this->once())->method('hitPage')->willReturnCallback(
function () {
throw new InvalidDecodedStringException();
}
);

$modelFactory = $this->createMock(ModelFactory::class);
$modelFactory->expects($this->once())
->method('getModel')
->with('page')
->willReturn($pageModel);

$security = $this->createMock(CorePermissions::class);
$security->expects($this->once())
->method('isAnonymous')
->willReturn(true);

$container = $this->createMock(Container::class);
$container->method('get')
->will(
$this->returnValueMap(
[
['mautic.security', Container::EXCEPTION_ON_INVALID_REFERENCE, $security],
['mautic.model.factory', Container::EXCEPTION_ON_INVALID_REFERENCE, $modelFactory],
]
)
);

$publicController = new PublicController();
$publicController->setContainer($container);
$publicController->setRequest($request);

$response = $publicController->trackingAction($request);
$this->assertEquals(
['success' => 0],
json_decode($response->getContent(), true)
);
}

public function testTrackingImageAction()
{
$this->client->request('GET', '/mtracking.gif?url=http%3A%2F%2Fmautic.org');
Expand Down