diff options
author | Thomas Steur <tsteur@users.noreply.github.com> | 2019-05-10 20:41:55 +0300 |
---|---|---|
committer | diosmosis <diosmosis@users.noreply.github.com> | 2019-05-10 20:41:55 +0300 |
commit | 7cb39cec843e8516fe49516e6d9a4fd44263fac5 (patch) | |
tree | ef6d3f1fd8be103eb4c966a4377b54b6f8259205 /plugins/TwoFactorAuth | |
parent | c6eb52339f3fc496ac43b55c4a0de8d161edbff4 (diff) |
added missing 2fa test (#14439)
Diffstat (limited to 'plugins/TwoFactorAuth')
-rw-r--r-- | plugins/TwoFactorAuth/.gitignore | 1 | ||||
-rw-r--r-- | plugins/TwoFactorAuth/tests/Fixtures/SimpleFixtureTrackFewVisits.php | 43 | ||||
-rw-r--r-- | plugins/TwoFactorAuth/tests/System/TwoFactorAuthTest.php | 83 |
3 files changed, 127 insertions, 0 deletions
diff --git a/plugins/TwoFactorAuth/.gitignore b/plugins/TwoFactorAuth/.gitignore new file mode 100644 index 0000000000..c8c9480010 --- /dev/null +++ b/plugins/TwoFactorAuth/.gitignore @@ -0,0 +1 @@ +tests/System/processed/*xml
\ No newline at end of file diff --git a/plugins/TwoFactorAuth/tests/Fixtures/SimpleFixtureTrackFewVisits.php b/plugins/TwoFactorAuth/tests/Fixtures/SimpleFixtureTrackFewVisits.php new file mode 100644 index 0000000000..b8b4468407 --- /dev/null +++ b/plugins/TwoFactorAuth/tests/Fixtures/SimpleFixtureTrackFewVisits.php @@ -0,0 +1,43 @@ +<?php +/** + * Piwik - free/libre analytics platform + * + * @link http://piwik.org + * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later + */ +namespace Piwik\Plugins\TwoFactorAuth\tests\Fixtures; + +use Piwik\Date; +use Piwik\Tests\Framework\Fixture; + +/** + * Generates tracker testing data for our TwoFactorAuthTest + * + * This Simple fixture adds one website and tracks one visit with couple pageviews and an ecommerce conversion + */ +class SimpleFixtureTrackFewVisits extends Fixture +{ + public $dateTime = '2013-01-23 01:23:45'; + public $idSite = 1; + + public function setUp() + { + $this->setUpWebsite(); + Fixture::createSuperUser(true); + $this->createSuperUser = true; + } + + public function tearDown() + { + // empty + } + + private function setUpWebsite() + { + if (!self::siteCreated($this->idSite)) { + $idSite = self::createWebsite($this->dateTime, $ecommerce = 1); + $this->assertSame($this->idSite, $idSite); + } + } + +}
\ No newline at end of file diff --git a/plugins/TwoFactorAuth/tests/System/TwoFactorAuthTest.php b/plugins/TwoFactorAuth/tests/System/TwoFactorAuthTest.php new file mode 100644 index 0000000000..b412096345 --- /dev/null +++ b/plugins/TwoFactorAuth/tests/System/TwoFactorAuthTest.php @@ -0,0 +1,83 @@ +<?php +/** + * Piwik - free/libre analytics platform + * + * @link http://piwik.org + * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later + */ + +namespace Piwik\Plugins\TwoFactorAuth\tests\System; + +use Piwik\Plugins\TwoFactorAuth\tests\Fixtures\SimpleFixtureTrackFewVisits; +use Piwik\Tests\Framework\TestCase\SystemTestCase; +use Piwik\Container\StaticContainer; +use Piwik\Piwik; +use Piwik\Plugins\TwoFactorAuth\Dao\RecoveryCodeDao; +use Piwik\Plugins\TwoFactorAuth\Dao\TwoFaSecretRandomGenerator; +use Piwik\Plugins\TwoFactorAuth\SystemSettings; +use Piwik\Plugins\TwoFactorAuth\TwoFactorAuthentication; +use Piwik\Plugins\UsersManager\API; +use Piwik\Tests\Framework\Fixture; +use Piwik\Tests\Framework\Mock\FakeAccess; + +/** + * @group TwoFactorAuth + * @group TwoFactorAuthTest + * @group Plugins + */ +class TwoFactorAuthTest extends SystemTestCase +{ + /** + * @var SimpleFixtureTrackFewVisits + */ + public static $fixture = null; // initialized below class definition + + /** + * @var RecoveryCodeDao + */ + private $dao; + + /** + * @var SystemSettings + */ + private $settings; + + /** + * @var TwoFactorAuthentication + */ + private $twoFa; + + public function setUp() + { + parent::setUp(); + + $this->dao = StaticContainer::get(RecoveryCodeDao::class); + $this->settings = new SystemSettings(); + $secretGenerator = new TwoFaSecretRandomGenerator(); + $this->twoFa = new TwoFactorAuthentication($this->settings, $this->dao, $secretGenerator); + + self::$fixture->loginAsSuperUser(); + } + + public function test_onRequestDispatchEnd_notRequired() + { + $this->settings->twoFactorAuthRequired->setValue(true); + $html = '<html>'.Piwik::getCurrentUserTokenAuth().'</html>'; + $expected = '<html>'.Piwik::getCurrentUserTokenAuth().'</html>'; + Piwik::postEvent('Request.dispatch.end', array(&$html, 'module', 'action', array())); + $this->assertSame($expected, $html); + } + + public static function getOutputPrefix() + { + return ''; + } + + public static function getPathToTestDirectory() + { + return dirname(__FILE__); + } + +} + +TwoFactorAuthTest::$fixture = new SimpleFixtureTrackFewVisits();
\ No newline at end of file |