mirrored from git://git.moodle.org/moodle.git
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MDL-72173 behat: Add alternative login file for behat
- Loading branch information
1 parent
0ec02c2
commit 962570b
Showing
1 changed file
with
59 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?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/>. | ||
// phpcs:disable moodle.Files.RequireLogin.Missing | ||
// phpcs:disable moodle.PHP.ForbiddenFunctions.Found | ||
|
||
/** | ||
* Fast login end point for BEHAT TESTS ONLY. | ||
* | ||
* @package theme_cfz | ||
* @author Guy Thomas | ||
* @copyright 2021 Class Technologies Inc. {@link https://www.class.com/} | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
require(__DIR__.'/../../../config.php'); | ||
|
||
$behatrunning = defined('BEHAT_SITE_RUNNING') && BEHAT_SITE_RUNNING; | ||
if (!$behatrunning) { | ||
die; | ||
} | ||
|
||
$username = required_param('username', PARAM_ALPHANUMEXT); | ||
// Note - with behat, the password is always the same as the username. | ||
$password = $username; | ||
|
||
$failurereason = null; | ||
$user = authenticate_user_login($username, $password, true, $failurereason, false); | ||
if ($failurereason) { | ||
error_log("Failed to login as behat step for $username with reason: " . $failurereason); | ||
throw new Exception($failurereason); | ||
} | ||
if (!complete_user_login($user)) { | ||
throw new Exception("Failed to login as behat step for $username"); | ||
} | ||
|
||
$redirecturl = optional_param('redirecturl', null, PARAM_URL); | ||
$redirecturl = $redirecturl ?? $CFG->wwwroot; | ||
|
||
if (optional_param('forceeditmode', false, PARAM_INT)) { | ||
$sesskey = sesskey(); | ||
$url = new moodle_url($redirecturl); | ||
$url->param('edit', 1); | ||
$url->param('sesskey', $sesskey); | ||
$redirecturl = $url.''; | ||
} | ||
|
||
redirect($redirecturl); |