| Línea 13... | 
            Línea 13... | 
          
          
            | 13 | 
            //
  | 
            13 | 
            //
  | 
          
          
            | 14 | 
            // You should have received a copy of the GNU General Public License
  | 
            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/>.
  | 
            15 | 
            // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
  | 
          
          
            | Línea 16... | 
            Línea 16... | 
          
          
            | 16 | 
             
  | 
            16 | 
             
  | 
          
          
            | 17 | 
            namespace tool_mfa;
  | 
            - | 
               | 
          
          
            | 18 | 
            use tool_mfa\tool_mfa_trait;
  | 
            - | 
               | 
          
          
            | 19 | 
             
  | 
            - | 
               | 
          
          
            | 20 | 
            defined('MOODLE_INTERNAL') || die();
  | 
            - | 
               | 
          
          
            | Línea 21... | 
            Línea 17... | 
          
          
            | 21 | 
            require_once(__DIR__ . '/tool_mfa_trait.php');
  | 
            17 | 
            namespace tool_mfa;
  | 
          
          
            | 22 | 
             
  | 
            18 | 
             
  | 
          
          
            | 23 | 
            /**
  | 
            19 | 
            /**
  | 
          
          
            | 24 | 
             * Tests for MFA manager class.
  | 
            20 | 
             * Tests for MFA manager class.
  | 
          
          
            | 25 | 
             *
  | 
            21 | 
             *
  | 
          
          
            | 26 | 
             * @package     tool_mfa
  | 
            22 | 
             * @package     tool_mfa
  | 
          
          
            | 27 | 
             * @author      Peter Burnett <peterburnett@catalyst-au.net>
  | 
            23 | 
             * @author      Peter Burnett <peterburnett@catalyst-au.net>
  | 
          
          
            | 28 | 
             * @copyright   Catalyst IT
  | 
            24 | 
             * @copyright   Catalyst IT
  | 
          
          
            | 29 | 
             * @license     http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  | 
            25 | 
             * @license     http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  | 
          
          
            | Línea 30... | 
            Línea 26... | 
          
          
            | 30 | 
             */
  | 
            26 | 
             */
  | 
          
          
            | Línea 31... | 
            Línea 27... | 
          
          
            | 31 | 
            class manager_test extends \advanced_testcase {
  | 
            27 | 
            final class manager_test extends \advanced_testcase {
  | 
          
          
            | 32 | 
             
  | 
            28 | 
             
  | 
          
          
            | 33 | 
                use tool_mfa_trait;
  | 
            29 | 
                use \tool_mfa\tests\mfa_settings_trait;
  | 
          
          
            | 34 | 
             
  | 
            30 | 
             
  | 
          
          
            | Línea 88... | 
            Línea 84... | 
          
          
            | 88 | 
             
  | 
            84 | 
             
  | 
          
          
            | 89 | 
                    // Create and login a user.
  | 
            85 | 
                    // Create and login a user.
  | 
          
          
            | 90 | 
                    $user = $this->getDataGenerator()->create_user();
  | 
            86 | 
                    $user = $this->getDataGenerator()->create_user();
  | 
          
          
            | Línea -... | 
            Línea 87... | 
          
          
            | - | 
               | 
            87 | 
                    $this->setUser($user);
  | 
          
          
            | - | 
               | 
            88 | 
             
  | 
          
          
            | - | 
               | 
            89 | 
                    // Disable the email factor (enabled by default).
  | 
          
          
            | 91 | 
                    $this->setUser($user);
  | 
            90 | 
                    set_config('enabled', 0, 'factor_email');
  | 
          
          
            | 92 | 
             
  | 
            91 | 
             
  | 
          
          
            | Línea 93... | 
            Línea 92... | 
          
          
            | 93 | 
                    // Check for fail status with no factors.
  | 
            92 | 
                    // Check for fail status with no factors.
  | 
          
          
            | 94 | 
                    $this->assertEquals(\tool_mfa\plugininfo\factor::STATE_FAIL, \tool_mfa\manager::get_status());
  | 
            93 | 
                    $this->assertEquals(\tool_mfa\plugininfo\factor::STATE_FAIL, \tool_mfa\manager::get_status());
  | 
          
          
            | Línea 155... | 
            Línea 154... | 
          
          
            | 155 | 
                /**
  | 
            154 | 
                /**
  | 
          
          
            | 156 | 
                 * The data provider for whether urls should be redirected or not
  | 
            155 | 
                 * The data provider for whether urls should be redirected or not
  | 
          
          
            | 157 | 
                 *
  | 
            156 | 
                 *
  | 
          
          
            | 158 | 
                 * @return  array
  | 
            157 | 
                 * @return  array
  | 
          
          
            | 159 | 
                 */
  | 
            158 | 
                 */
  | 
          
          
            | 160 | 
                public static function should_redirect_urls_provider() {
  | 
            159 | 
                public static function should_redirect_urls_provider(): array {
  | 
          
          
            | 161 | 
                    $badurl1 = new \moodle_url('/');
  | 
            160 | 
                    $badurl1 = new \moodle_url('/');
  | 
          
          
            | 162 | 
                    $badparam1 = $badurl1->out();
  | 
            161 | 
                    $badparam1 = $badurl1->out();
  | 
          
          
            | 163 | 
                    $badurl2 = new \moodle_url('admin/tool/mfa/auth.php');
  | 
            162 | 
                    $badurl2 = new \moodle_url('admin/tool/mfa/auth.php');
  | 
          
          
            | 164 | 
                    $badparam2 = $badurl2->out();
  | 
            163 | 
                    $badparam2 = $badurl2->out();
  | 
          
          
            | 165 | 
                    return [
  | 
            164 | 
                    return [
  | 
          
          
            | Línea 239... | 
            Línea 238... | 
          
          
            | 239 | 
                    unset($notsetup->firstname);
  | 
            238 | 
                    unset($notsetup->firstname);
  | 
          
          
            | 240 | 
                    $this->setUser($notsetup);
  | 
            239 | 
                    $this->setUser($notsetup);
  | 
          
          
            | 241 | 
                    $this->assertEquals(\tool_mfa\manager::NO_REDIRECT, \tool_mfa\manager::should_require_mfa($badurl, false));
  | 
            240 | 
                    $this->assertEquals(\tool_mfa\manager::NO_REDIRECT, \tool_mfa\manager::should_require_mfa($badurl, false));
  | 
          
          
            | 242 | 
                    $this->setUser($user);
  | 
            241 | 
                    $this->setUser($user);
  | 
          
          
            | Línea 243... | 
            Línea -... | 
          
          
            | 243 | 
             
  | 
            - | 
               | 
          
          
            | 244 | 
                    // Enrolment.
  | 
            - | 
               | 
          
          
            | 245 | 
                    $enrolurl = new \moodle_url('/enrol/index.php');
  | 
            - | 
               | 
          
          
            | 246 | 
                    $this->assertEquals(\tool_mfa\manager::REDIRECT, \tool_mfa\manager::should_require_mfa($badurl, false));
  | 
            - | 
               | 
          
          
            | 247 | 
                    $this->assertEquals(\tool_mfa\manager::NO_REDIRECT, \tool_mfa\manager::should_require_mfa($enrolurl, false));
  | 
            - | 
               | 
          
          
            | 248 | 
             
  | 
            242 | 
             
  | 
          
          
            | 249 | 
                    // Guest User.
  | 
            243 | 
                    // Guest User.
  | 
          
          
            | 250 | 
                    $this->assertEquals(\tool_mfa\manager::REDIRECT, \tool_mfa\manager::should_require_mfa($badurl, false));
  | 
            244 | 
                    $this->assertEquals(\tool_mfa\manager::REDIRECT, \tool_mfa\manager::should_require_mfa($badurl, false));
  | 
          
          
            | 251 | 
                    $this->setGuestUser();
  | 
            245 | 
                    $this->setGuestUser();
  | 
          
          
            | 252 | 
                    $this->assertEquals(\tool_mfa\manager::NO_REDIRECT, \tool_mfa\manager::should_require_mfa($badurl, false));
  | 
            246 | 
                    $this->assertEquals(\tool_mfa\manager::NO_REDIRECT, \tool_mfa\manager::should_require_mfa($badurl, false));
  | 
          
          
            | Línea 264... | 
            Línea 258... | 
          
          
            | 264 | 
                    $this->assertEquals(\tool_mfa\manager::REDIRECT, \tool_mfa\manager::should_require_mfa($badurl, false));
  | 
            258 | 
                    $this->assertEquals(\tool_mfa\manager::REDIRECT, \tool_mfa\manager::should_require_mfa($badurl, false));
  | 
          
          
            | 265 | 
                    $this->setAdminUser();
  | 
            259 | 
                    $this->setAdminUser();
  | 
          
          
            | 266 | 
                    \core\session\manager::loginas($user2->id, $syscontext, false);
  | 
            260 | 
                    \core\session\manager::loginas($user2->id, $syscontext, false);
  | 
          
          
            | 267 | 
                    $this->assertEquals(\tool_mfa\manager::NO_REDIRECT, \tool_mfa\manager::should_require_mfa($badurl, false));
  | 
            261 | 
                    $this->assertEquals(\tool_mfa\manager::NO_REDIRECT, \tool_mfa\manager::should_require_mfa($badurl, false));
  | 
          
          
            | 268 | 
                    $this->setUser($user);
  | 
            262 | 
                    $this->setUser($user);
  | 
          
          
            | - | 
               | 
            263 | 
             
  | 
          
          
            | - | 
               | 
            264 | 
                    // Access logocompact via pluginfile.
  | 
          
          
            | - | 
               | 
            265 | 
                    $logourl = new \moodle_url('/pluginfile.php/1/core_admin/logocompact/');
  | 
          
          
            | - | 
               | 
            266 | 
                    $this->assertEquals(\tool_mfa\manager::NO_REDIRECT, \tool_mfa\manager::should_require_mfa($logourl, false));
  | 
          
          
            | - | 
               | 
            267 | 
             
  | 
          
          
            | - | 
               | 
            268 | 
                    // Access logo via pluginfile.
  | 
          
          
            | - | 
               | 
            269 | 
                    $logourl = new \moodle_url('/pluginfile.php/1/core_admin/logo/');
  | 
          
          
            | - | 
               | 
            270 | 
                    $this->assertEquals(\tool_mfa\manager::NO_REDIRECT, \tool_mfa\manager::should_require_mfa($logourl, false));
  | 
          
          
            | - | 
               | 
            271 | 
             
  | 
          
          
            | - | 
               | 
            272 | 
                    // Access favicon via pluginfile.
  | 
          
          
            | - | 
               | 
            273 | 
                    $logourl = new \moodle_url('/pluginfile.php/1/core_admin/favicon/');
  | 
          
          
            | - | 
               | 
            274 | 
                    $this->assertEquals(\tool_mfa\manager::NO_REDIRECT, \tool_mfa\manager::should_require_mfa($logourl, false));
  | 
          
          
            | - | 
               | 
            275 | 
             
  | 
          
          
            | - | 
               | 
            276 | 
                    // Access guidance files.
  | 
          
          
            | - | 
               | 
            277 | 
                    $guideurl = new \moodle_url('/pluginfile.php/1/tool_mfa/guidance/0/capybara.png');
  | 
          
          
            | - | 
               | 
            278 | 
                    $this->assertEquals(\tool_mfa\manager::NO_REDIRECT, \tool_mfa\manager::should_require_mfa($guideurl, false));
  | 
          
          
            | - | 
               | 
            279 | 
             
  | 
          
          
            | - | 
               | 
            280 | 
                    // Access private area.
  | 
          
          
            | - | 
               | 
            281 | 
                    $user3 = $this->getDataGenerator()->create_user();
  | 
          
          
            | - | 
               | 
            282 | 
                    $privateurl = new \moodle_url("/pluginfile.php/{$user3->id}/user/private/privatefile.png");
  | 
          
          
            | - | 
               | 
            283 | 
                    $this->assertEquals(\tool_mfa\manager::REDIRECT, \tool_mfa\manager::should_require_mfa($privateurl, false));
  | 
          
          
            | 269 | 
                }
  | 
            284 | 
                }
  | 
          
          
            | Línea 270... | 
            Línea 285... | 
          
          
            | 270 | 
             
  | 
            285 | 
             
  | 
          
          
            | 271 | 
                /**
  | 
            286 | 
                /**
  | 
          
          
            | 272 | 
                 * Tests should require the mfa redirection loop
  | 
            287 | 
                 * Tests should require the mfa redirection loop
  | 
          
          
            | Línea 371... | 
            Línea 386... | 
          
          
            | 371 | 
                    $this->resetAfterTest(true);
  | 
            386 | 
                    $this->resetAfterTest(true);
  | 
          
          
            | 372 | 
                    $user = $this->getDataGenerator()->create_user();
  | 
            387 | 
                    $user = $this->getDataGenerator()->create_user();
  | 
          
          
            | 373 | 
                    $this->setUser($user);
  | 
            388 | 
                    $this->setUser($user);
  | 
          
          
            | 374 | 
                    set_config('enabled', 1, 'factor_nosetup');
  | 
            389 | 
                    set_config('enabled', 1, 'factor_nosetup');
  | 
          
          
            | 375 | 
                    set_config('enabled', 1, 'tool_mfa');
  | 
            390 | 
                    set_config('enabled', 1, 'tool_mfa');
  | 
          
          
            | - | 
               | 
            391 | 
                    // Disable the email factor (enabled by default).
  | 
          
          
            | - | 
               | 
            392 | 
                    set_config('enabled', 0, 'factor_email');
  | 
          
          
            | Línea 376... | 
            Línea 393... | 
          
          
            | 376 | 
             
  | 
            393 | 
             
  | 
          
          
            | 377 | 
                    // Capability Check.
  | 
            394 | 
                    // Capability Check.
  | 
          
          
            | 378 | 
                    $this->assertTrue(\tool_mfa\manager::is_ready());
  | 
            395 | 
                    $this->assertTrue(\tool_mfa\manager::is_ready());
  | 
          
          
            | 379 | 
                    // Swap to role without capability.
  | 
            396 | 
                    // Swap to role without capability.
  |