diff options
author | Thomas Steur <tsteur@users.noreply.github.com> | 2020-03-18 06:04:12 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-03-18 06:04:12 +0300 |
commit | f0c246cb3a4db3021da7552f6779d56613799414 (patch) | |
tree | 42ddf7a9c2e086df78ffc40dfc23af74f8dd3a39 /tests/PHPUnit/Fixtures | |
parent | e493fee87c983e02001a7d9438cefe58141a38af (diff) |
App specific token_auths (#15410)
* some initial work
* add security page
* backing up some code
* more functionality
* adjust more UI parts
* adjust more code
* more tweaks
* add todo note
* few tweaks
* make sure date is in right format
* fix not existing column
* few fixes
* available hashes
* use different hash algo so tests run on php 5
* fix name of aglorithm
* trying to fix some tests
* another try to fix some tests
* more fixes
* more fixes
* few fixes
* update template
* fix some tests
* fix test
* fixing some tests
* various test fixes
* more fixes
* few more tests
* more tests
* various tweaks
* add translations
* add some ui tests
* fix selector
* tweaks
* trying to fix some ui tests
* fallback to regular authentication if needed
* fix call authenticate on null
* fix user settings
* fix some tests
* few fixes
* fix more ui tests
* update schema
* Update plugins/CoreHome/angularjs/widget-loader/widgetloader.directive.js
Co-Authored-By: Stefan Giehl <stefan@matomo.org>
* fix maps are not showing data
* trying to fix some tests
* set correct token
* trying to fix tracking failure
* minor tweaks and fixes
* fix more tests
* fix screenshot test
* trigger event so brute force logic is executed
* test no fallback to actual authentication
* allow fallback
* apply review feedback
* fix some tests
* fix tests
* make sure location values from query params are limited properly before attempting a db insert
* make sure plugin uninstall migration reloads plugins, make sure 4.0.0-b1 migration removes unique index that is no longer used, use defaults extra file in SqlDump to get test to run on travis
* Fix UI tests.
* update expected screenshot
Co-authored-by: Stefan Giehl <stefan@matomo.org>
Co-authored-by: diosmosis <diosmosis@users.noreply.github.com>
Diffstat (limited to 'tests/PHPUnit/Fixtures')
-rw-r--r-- | tests/PHPUnit/Fixtures/OmniFixture.php | 25 | ||||
-rw-r--r-- | tests/PHPUnit/Fixtures/SqlDump.php | 16 | ||||
-rw-r--r-- | tests/PHPUnit/Fixtures/UITestFixture.php | 7 |
3 files changed, 45 insertions, 3 deletions
diff --git a/tests/PHPUnit/Fixtures/OmniFixture.php b/tests/PHPUnit/Fixtures/OmniFixture.php index 626580574c..10730fc674 100644 --- a/tests/PHPUnit/Fixtures/OmniFixture.php +++ b/tests/PHPUnit/Fixtures/OmniFixture.php @@ -12,6 +12,7 @@ use Piwik\Common; use Piwik\Date; use Piwik\Db; use Piwik\Option; +use Piwik\Plugins\UsersManager\Model; use ReflectionClass; use Piwik\Plugins\SitesManager\API as SitesManagerAPI; use Piwik\Tests\Framework\Fixture; @@ -23,9 +24,11 @@ use Piwik\Tests\Framework\Fixture; class OmniFixture extends Fixture { const DEFAULT_SEGMENT = "browserCode==FF"; + const OMNIFIXTURE_SUPERUSER_TOKEN = '9ad1de7f8b329ab919d854c556f860c1'; public $month = '2012-01'; public $idSite = 'all'; + public $dateTime = '2012-02-01'; /** @@ -122,6 +125,19 @@ class OmniFixture extends Fixture return $result; } + public static function getTokenAuth() + { + $model = new \Piwik\Plugins\UsersManager\Model(); + $user = $model->getUser(self::ADMIN_USER_LOGIN); + + if (!empty($user)) { + if ($model->getUserByTokenAuth(self::OMNIFIXTURE_SUPERUSER_TOKEN)) { + return self::OMNIFIXTURE_SUPERUSER_TOKEN; + } + } + return parent::getTokenAuth(); + } + public function setUp(): void { $firstFixture = array_shift($this->fixtures); @@ -135,7 +151,14 @@ class OmniFixture extends Fixture $this->setUpFixture($fixture); } - Db::query(sprintf('UPDATE %s SET token_auth = "9ad1de7f8b329ab919d854c556f860c1" WHERE login = "superUserLogin"', Common::prefixTable('user'))); + $model = new Model(); + + if (!$model->getUserByTokenAuth(self::OMNIFIXTURE_SUPERUSER_TOKEN)) { + $model->addTokenAuth(self::ADMIN_USER_LOGIN, self::OMNIFIXTURE_SUPERUSER_TOKEN, 'omnifixture token', Date::now()->getDatetime()); + } + if (!$model->getUserByTokenAuth(self::ADMIN_USER_TOKEN)) { + $model->addTokenAuth(self::ADMIN_USER_LOGIN, self::ADMIN_USER_TOKEN, 'omnifixture token default', Date::now()->getDatetime()); + } Option::set("Tests.forcedNowTimestamp", $this->now->getTimestamp()); } diff --git a/tests/PHPUnit/Fixtures/SqlDump.php b/tests/PHPUnit/Fixtures/SqlDump.php index 94cddf0bc5..abfcb31338 100644 --- a/tests/PHPUnit/Fixtures/SqlDump.php +++ b/tests/PHPUnit/Fixtures/SqlDump.php @@ -63,7 +63,9 @@ class SqlDump extends Fixture $host = Config::getInstance()->database['host']; Config::getInstance()->database['tables_prefix'] = $this->tablesPrefix; - $cmd = "mysql -h \"$host\" -u \"$user\" \"--password=$password\" {$this->dbName} < \"" . $deflatedDumpPath . "\" 2>&1"; + $defaultsFile = $this->makeMysqlDefaultsFile($user, $password); + + $cmd = "mysql --defaults-extra-file=\"$defaultsFile\" -h \"$host\" {$this->dbName} < \"" . $deflatedDumpPath . "\" 2>&1"; exec($cmd, $output, $return); if ($return !== 0) { throw new Exception("Failed to load sql dump: " . implode("\n", $output)); @@ -105,4 +107,16 @@ class SqlDump extends Fixture fclose($outfile); return $bytesRead; } + + private function makeMysqlDefaultsFile($user, $password) + { + $contents = "[client] +user=$user +password=$password\n"; + + $path = PIWIK_INCLUDE_PATH . '/mysqldefaults.conf'; + file_put_contents($path, $contents); + + return $path; + } }
\ No newline at end of file diff --git a/tests/PHPUnit/Fixtures/UITestFixture.php b/tests/PHPUnit/Fixtures/UITestFixture.php index dd4dadea0a..1d0cc5ff5c 100644 --- a/tests/PHPUnit/Fixtures/UITestFixture.php +++ b/tests/PHPUnit/Fixtures/UITestFixture.php @@ -35,6 +35,7 @@ use Piwik\Plugins\SegmentEditor\API as APISegmentEditor; use Piwik\Plugins\UserCountry\LocationProvider; use Piwik\Plugins\UsersManager\API as UsersManagerAPI; use Piwik\Plugins\SitesManager\API as SitesManagerAPI; +use Piwik\Plugins\UsersManager\Model; use Piwik\Plugins\UsersManager\UserUpdater; use Piwik\Plugins\VisitsSummary\API as VisitsSummaryAPI; use Piwik\ReportRenderer; @@ -85,6 +86,8 @@ class UITestFixture extends SqlDump LocationProvider::setCurrentProvider(GeoIp2\Php::ID); IPAnonymizer::deactivate(); + self::createSuperUser(false); + $this->addOverlayVisits(); $this->addNewSitesForSiteSelector(); @@ -137,6 +140,8 @@ class UITestFixture extends SqlDump parent::performSetUp($setupEnvironmentOnly); + self::createSuperUser(false); + $this->createSegments(); $this->setupDashboards(); @@ -299,7 +304,7 @@ class UITestFixture extends SqlDump $oldGet = $_GET; $_GET['idSite'] = 1; - $_GET['token_auth'] = Piwik::getCurrentUserTokenAuth(); + $_GET['token_auth'] = \Piwik\Piwik::getCurrentUserTokenAuth(); // collect widgets & sort them so widget order is not important $allWidgets = Request::processRequest('API.getWidgetMetadata', array( |