Proyectos de Subversion Moodle

Rev

Rev 11 | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
<?php
2
// This file is part of Moodle - http://moodle.org/
3
//
4
// Moodle is free software: you can redistribute it and/or modify
5
// it under the terms of the GNU General Public License as published by
6
// the Free Software Foundation, either version 3 of the License, or
7
// (at your option) any later version.
8
//
9
// Moodle is distributed in the hope that it will be useful,
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
// GNU General Public License for more details.
13
//
14
// You should have received a copy of the GNU General Public License
15
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
16
 
17
namespace factor_grace;
18
 
19
/**
20
 * Tests for grace factor.
21
 *
22
 * @package     factor_grace
23
 * @author      Peter Burnett <peterburnett@catalyst-au.net>
24
 * @copyright   Catalyst IT
25
 * @license     http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
26
 */
1441 ariadna 27
final class factor_test extends \advanced_testcase {
1 efrain 28
 
29
    /**
30
     * Test affecting factors
31
     *
32
     * @covers ::get_affecting_factors
33
     * @return void
34
     */
11 efrain 35
    public function test_affecting_factors(): void {
1 efrain 36
        $this->resetAfterTest(true);
37
        $user = $this->getDataGenerator()->create_user();
38
        $this->setUser($user);
39
 
1441 ariadna 40
        // Disable the email factor (enabled by default).
41
        set_config('enabled', 0, 'factor_email');
42
 
1 efrain 43
        $grace = \tool_mfa\plugininfo\factor::get_factor('grace');
44
        $affecting = $grace->get_affecting_factors();
45
        $this->assertEquals(0, count($affecting));
46
 
47
        set_config('enabled', 1, 'factor_totp');
48
        $totpfactor = \tool_mfa\plugininfo\factor::get_factor('totp');
49
        $totpdata = [
50
            'secret' => 'fakekey',
51
            'devicename' => 'fakedevice',
52
        ];
53
        $totpfactor->setup_user_factor((object) $totpdata);
54
 
55
        // Confirm that MFA is the only affecting factor.
56
        $affecting = $grace->get_affecting_factors();
57
        $this->assertEquals(1, count($affecting));
58
        $totp = reset($affecting);
59
        $this->assertTrue($totp instanceof \factor_totp\factor);
60
 
61
        // Now put it in the ignorelist.
62
        set_config('ignorelist', 'totp', 'factor_grace');
63
        // Confirm that MFA is the only affecting factor.
64
        $affecting = $grace->get_affecting_factors();
65
        $this->assertEquals(0, count($affecting));
66
    }
67
}