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

Do not render error page in tracker debug mode #20966

Merged
merged 3 commits into from
Jul 9, 2023
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 2 additions & 8 deletions core/Tracker/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,7 @@ public function outputException(Tracker $tracker, Exception $e, $statusCode)
$this->logExceptionToErrorLog($e);

if ($tracker->isDebugModeEnabled()) {
Common::sendHeader('Content-Type: text/html; charset=utf-8');
$trailer = '<span style="color: #888888">Backtrace:<br /><pre>' . $e->getTraceAsString() . '</pre></span>';
$headerPage = file_get_contents(PIWIK_INCLUDE_PATH . '/plugins/Morpheus/templates/simpleLayoutHeader.tpl');
$footerPage = file_get_contents(PIWIK_INCLUDE_PATH . '/plugins/Morpheus/templates/simpleLayoutFooter.tpl');
$headerPage = str_replace('{$HTML_TITLE}', 'Matomo &rsaquo; Error', $headerPage);

echo $headerPage . '<p>' . $this->getMessageFromException($e) . '</p>' . $trailer . $footerPage;
echo "\nAn exception occurred: " . $this->getMessageFromException($e) . "\n\n";
} else {
$this->outputApiResponse($tracker);
}
Expand All @@ -84,7 +78,7 @@ public function outputResponse(Tracker $tracker)
}
Common::printDebug("Empty request => Matomo page");
echo "This resource is part of Matomo. Keep full control of your data with the leading free and open source <a href='https://matomo.org' target='_blank' rel='noopener noreferrer nofollow'>web analytics & conversion optimisation platform</a>.<br>\n";
echo "This file is the endpoint for the Matomo tracking API. If you want to access the Matomo UI or use the Reporting API, please use <a href='index.php'>index.php</a> instead.";
echo "This file is the endpoint for the Matomo tracking API. If you want to access the Matomo UI or use the Reporting API, please use <a href='index.php'>index.php</a> instead.\n";
} else {
$this->outputApiResponse($tracker);
Common::printDebug("Nothing to notice => default behaviour");
Expand Down
2 changes: 1 addition & 1 deletion tests/PHPUnit/Integration/TrackerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ public function testMainShouldReturnEmptyPiwikResponseIfNoRequestsAreGiven()

$response = $this->tracker->main($this->getDefaultHandler(), $requestSet);

$expected = "This resource is part of Matomo. Keep full control of your data with the leading free and open source <a href='https://matomo.org' target='_blank' rel='noopener noreferrer nofollow'>web analytics & conversion optimisation platform</a>.<br>\nThis file is the endpoint for the Matomo tracking API. If you want to access the Matomo UI or use the Reporting API, please use <a href='index.php'>index.php</a> instead.";
$expected = "This resource is part of Matomo. Keep full control of your data with the leading free and open source <a href='https://matomo.org' target='_blank' rel='noopener noreferrer nofollow'>web analytics & conversion optimisation platform</a>.<br>\nThis file is the endpoint for the Matomo tracking API. If you want to access the Matomo UI or use the Reporting API, please use <a href='index.php'>index.php</a> instead.\n";
$this->assertEquals($expected, $response);
}

Expand Down
4 changes: 2 additions & 2 deletions tests/PHPUnit/System/TrackerResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public function test_response_ShouldReturnPiwikMessageWithHttp200_InCaseOfEmptyG
$response = Http::sendHttpRequest($url, 10, null, null, 0, false, false, true);
$this->assertEquals(200, $response['status']);

$expected = "This resource is part of Matomo. Keep full control of your data with the leading free and open source <a href='https://matomo.org' target='_blank' rel='noopener noreferrer nofollow'>web analytics & conversion optimisation platform</a>.<br>\nThis file is the endpoint for the Matomo tracking API. If you want to access the Matomo UI or use the Reporting API, please use <a href='index.php'>index.php</a> instead.";
$expected = "This resource is part of Matomo. Keep full control of your data with the leading free and open source <a href='https://matomo.org' target='_blank' rel='noopener noreferrer nofollow'>web analytics & conversion optimisation platform</a>.<br>\nThis file is the endpoint for the Matomo tracking API. If you want to access the Matomo UI or use the Reporting API, please use <a href='index.php'>index.php</a> instead.\n";
$this->assertEquals($expected, $response['data']);
}

Expand All @@ -147,7 +147,7 @@ public function test_response_ShouldReturnPiwikMessageWithHttp400_InCaseOfInvali
$this->assertEquals(400, $response['status']);

$response = $this->sendHttpRequest($url);
$expected = "This resource is part of Matomo. Keep full control of your data with the leading free and open source <a href='https://matomo.org' target='_blank' rel='noopener noreferrer nofollow'>web analytics & conversion optimisation platform</a>.<br>\nThis file is the endpoint for the Matomo tracking API. If you want to access the Matomo UI or use the Reporting API, please use <a href='index.php'>index.php</a> instead.";
$expected = "This resource is part of Matomo. Keep full control of your data with the leading free and open source <a href='https://matomo.org' target='_blank' rel='noopener noreferrer nofollow'>web analytics & conversion optimisation platform</a>.<br>\nThis file is the endpoint for the Matomo tracking API. If you want to access the Matomo UI or use the Reporting API, please use <a href='index.php'>index.php</a> instead.\n";
$this->assertEquals($expected, $response['data']);
}

Expand Down
6 changes: 3 additions & 3 deletions tests/PHPUnit/Unit/Tracker/ResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ public function test_outputException_shouldOutputDebugMessageIfEnabled()

$content = $this->response->getOutput();

self::assertStringContainsString('<title>Matomo &rsaquo; Error</title>', $content);
self::assertStringContainsString('<p>My Custom Message', $content);
self::assertStringContainsString('An exception occurred', $content);
self::assertStringContainsString('My Custom Message', $content);
}

public function test_outputResponse_shouldOutputStandardApiResponse()
Expand Down Expand Up @@ -128,7 +128,7 @@ public function test_outputResponse_shouldOutputPiwikMessage_InCaseNothingWasTra
$tracker->setCountOfLoggedRequests(0);
$this->response->outputResponse($tracker);

$this->assertEquals("This resource is part of Matomo. Keep full control of your data with the leading free and open source <a href='https://matomo.org' target='_blank' rel='noopener noreferrer nofollow'>web analytics & conversion optimisation platform</a>.<br>\nThis file is the endpoint for the Matomo tracking API. If you want to access the Matomo UI or use the Reporting API, please use <a href='index.php'>index.php</a> instead.",
$this->assertEquals("This resource is part of Matomo. Keep full control of your data with the leading free and open source <a href='https://matomo.org' target='_blank' rel='noopener noreferrer nofollow'>web analytics & conversion optimisation platform</a>.<br>\nThis file is the endpoint for the Matomo tracking API. If you want to access the Matomo UI or use the Reporting API, please use <a href='index.php'>index.php</a> instead.\n",
$this->response->getOutput());
}

Expand Down