From 81b31955b054dc75c2769e11ac2bfa7fbecfadf8 Mon Sep 17 00:00:00 2001 From: lux Date: Sat, 14 Oct 2023 11:55:57 -0500 Subject: [PATCH] Bypass some checks when running via PHPUnit --- apps/user/models/User.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/apps/user/models/User.php b/apps/user/models/User.php index f8e12f89..15b70169 100644 --- a/apps/user/models/User.php +++ b/apps/user/models/User.php @@ -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; @@ -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; @@ -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); + } }