diff options
author | diosmosis <diosmosis@users.noreply.github.com> | 2018-08-17 13:23:56 +0300 |
---|---|---|
committer | Matthieu Aubry <mattab@users.noreply.github.com> | 2018-08-17 13:23:56 +0300 |
commit | a7216adb43c8242b64863cb072d861f21ddcfb54 (patch) | |
tree | d49b9735218a11460b86636c8c17e60504274df1 /tests | |
parent | 7b584f9a788fd044d886c18d699d0bf778c63e6b (diff) |
Always set Auth interface in DI to the correct plugin's Auth implementation (#13279)
* Make sure Auth interface is always set even if session auth succeeds.
* Add failing test.
* Fix FrontControllerTest
* Put hash token authentication back since it is still in use in plugins.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/PHPUnit/Integration/FrontControllerTest.php | 33 |
1 files changed, 32 insertions, 1 deletions
diff --git a/tests/PHPUnit/Integration/FrontControllerTest.php b/tests/PHPUnit/Integration/FrontControllerTest.php index c5aecf7987..9277e9b261 100644 --- a/tests/PHPUnit/Integration/FrontControllerTest.php +++ b/tests/PHPUnit/Integration/FrontControllerTest.php @@ -8,7 +8,12 @@ namespace Piwik\Tests\Integration; +use Piwik\Access; +use Piwik\Auth; +use Piwik\Container\StaticContainer; +use Piwik\FrontController; use Piwik\Http; +use Piwik\Session\SessionFingerprint; use Piwik\Tests\Framework\Fixture; use Piwik\Tests\Framework\TestCase\IntegrationTestCase; @@ -42,14 +47,40 @@ FORMAT; $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(780): Piwik\EventDispatcher->postEvent('Request.dispatc...', Array, false, NULL)#3 {includePath}/core/FrontController.php(538): Piwik\Piwik::postEvent('Request.dispatc...', Array)#4 {includePath}/core/FrontController.php(146): Piwik\FrontController->doDispatch('CoreHome', 'index', NULL)#5 {includePath}/tests/resources/trigger-fatal-exception.php(31): Piwik\FrontController->dispatch('CoreHome', 'index')#6 {main} +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(780): Piwik\EventDispatcher->postEvent('Request.dispatc...', Array, false, NULL)#3 {includePath}/core/FrontController.php(540): Piwik\Piwik::postEvent('Request.dispatc...', Array)#4 {includePath}/core/FrontController.php(146): Piwik\FrontController->doDispatch('CoreHome', 'index', NULL)#5 {includePath}/tests/resources/trigger-fatal-exception.php(31): Piwik\FrontController->dispatch('CoreHome', 'index')#6 {main} FORMAT; $this->assertStringMatchesFormat($expectedFormat, $response['message']); } + public function test_authImplementationConfigured_EvenIfSessionAuthSucceeds() + { + Access::getInstance()->setSuperUserAccess(false); + + $sessionFingerprint = new SessionFingerprint(); + $sessionFingerprint->initialize('superUserLogin'); + + 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) { return str_replace(PIWIK_INCLUDE_PATH, '{includePath}', $message); } + + /** + * @param Fixture $fixture + */ + protected static function configureFixture($fixture) + { + parent::configureFixture($fixture); + $fixture->createSuperUser = true; + } }
\ No newline at end of file |