blob: 4f32be926482031206434efdb54cbe2cd188da9a (
plain)
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
|
<?php
/**
* Piwik - free/libre analytics platform
*
* @link https://matomo.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();
|