1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
<?php
/**
* Matomo - free/libre analytics platform
*
* @link https://matomo.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*/
namespace Piwik\Tests\Integration;
use Piwik\Access;
use Piwik\Auth;
use Piwik\Container\StaticContainer;
use Piwik\FrontController;
use Piwik\Http;
use Piwik\Session;
use Piwik\Session\SessionFingerprint;
use Piwik\Tests\Framework\Fixture;
use Piwik\Tests\Framework\TestCase\IntegrationTestCase;
class FrontControllerTest extends IntegrationTestCase
{
public function test_fatalErrorStackTracesReturned()
{
$url = Fixture::getRootUrl() . '/tests/resources/trigger-fatal.php?format=json';
$response = Http::sendHttpRequest($url, self::isTravisCI() ? 2 : 20);
$response = json_decode($response, $isAssoc = true);
$response['message'] = $this->cleanMessage($response['message']);
$this->assertEquals('error', $response['result']);
$expectedFormat = <<<FORMAT
Allowed memory size of %s bytes exhausted (tried to allocate %s bytes) on {includePath}/tests/resources/trigger-fatal.php(22) #0 {includePath}/tests/resources/trigger-fatal.php(35): MyClass->triggerError(arg1="argval", arg2="another") #1 {includePath}/tests/resources/trigger-fatal.php(51): MyDerivedClass::staticMethod() #2 {includePath}/tests/resources/trigger-fatal.php(57): myFunction()
FORMAT;
$this->assertStringMatchesFormat($expectedFormat, $response['message']);
}
public function test_thrownExceptionInFrontControllerPrintsBacktrace()
{
$url = Fixture::getRootUrl() . '/tests/resources/trigger-fatal-exception.php?format=json';
$response = Http::sendHttpRequest($url, self::isTravisCI() ? 2 : 20);
$response = json_decode($response, $isAssoc = true);
$response['message'] = $this->cleanMessage($response['message']);
$this->assertEquals('error', $response['result']);
$expectedFormat = <<<FORMAT
test message on {includePath}/tests/resources/trigger-fatal-exception.php(23) #0 [internal function]: {closure}('CoreHome', 'index', Array) #1 {includePath}/core/EventDispatcher.php(141): call_user_func_array(Object(Closure), Array) #2 {includePath}/core/Piwik.php(845): Piwik\EventDispatcher->postEvent('Request.dispatc...', Array, false, Array) #3 {includePath}/core/FrontController.php(602): Piwik\Piwik::postEvent('Request.dispatc...', Array) #4 {includePath}/core/FrontController.php(168): Piwik\FrontController->doDispatch('CoreHome', 'index', Array) #5 {includePath}/tests/resources/trigger-fatal-exception.php(31): Piwik\FrontController->dispatch('CoreHome', 'index') #6 {main}
FORMAT;
$this->assertStringMatchesFormat($expectedFormat, $response['message']);
}
/**
* @runInSeparateProcess
*/
public function test_authImplementationConfigured_EvenIfSessionAuthSucceeds()
{
Session::start();
Access::getInstance()->setSuperUserAccess(false);
$sessionFingerprint = new SessionFingerprint();
$sessionFingerprint->initialize('superUserLogin', Fixture::getTokenAuth());
FrontController::getInstance()->init();
/** @var \Piwik\Plugins\Login\Auth $auth */
$auth = StaticContainer::get(Auth::class);
$this->assertInstanceOf(\Piwik\Plugins\Login\Auth::class, $auth);
$this->assertEquals('superUserLogin', $auth->getLogin());
$this->assertEquals(Fixture::getTokenAuth(), $auth->getTokenAuth());
}
private function cleanMessage($message)
{
$message = trim($message);
$message = str_replace(PIWIK_INCLUDE_PATH, '{includePath}', $message);
return $message;
}
/**
* @param Fixture $fixture
*/
protected static function configureFixture($fixture)
{
parent::configureFixture($fixture);
$fixture->createSuperUser = true;
}
}
|