Skip to content

Commit

Permalink
Bypass some checks when running via PHPUnit
Browse files Browse the repository at this point in the history
  • Loading branch information
lux committed Oct 14, 2023
1 parent db5e7eb commit 81b3195
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions apps/user/models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,8 @@ public static function method ($callback) {
* ?>
*/
public static function require_login ($skip_2fa = false) {
if (self::bypass_for_phpunit ()) return true;

$class = get_called_class ();
$res = simple_auth (array ($class, 'verifier'), array ($class, 'method'));
if (!$res) return false;
Expand Down Expand Up @@ -465,6 +467,8 @@ public static function require_acl ($resource) {
* Check if a user is valid.
*/
public static function is_valid ($skip_2fa = false) {
if (self::bypass_for_phpunit ()) return true;

if (is_object (self::$user) && self::$user->session_id == $_SESSION['session_id']) {
if ($skip_2fa) return true;

Expand Down Expand Up @@ -717,4 +721,11 @@ public static function logout ($redirect_to = FALSE, $path = '/', $domain = fals
$controller->redirect ($redirect_to);
}
}

/**
* Returns whether we should bypass certain checks for PHPUnit tests.
*/
private static function bypass_for_phpunit () {
return (ELEFANT_ENV == 'test' && User::$user !== false);
}
}

0 comments on commit 81b3195

Please sign in to comment.