Bug 36822: LDAP - Rearrange Auth_with_ldap.pm so it picks up on mock config from test file

Without this rearrangement, C4::Context->config('useldapserver') is always 0.
It seems that because its inside a BEGIN block, the mock coming from .t file does not get picked up

Signed-off-by: David Nind <david@davidnind.com>
Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>
(cherry picked from commit e3d071ac54)
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
This commit is contained in:
Pedro Amorim 2024-10-25 14:38:09 +00:00 committed by Lucas Gass
parent a9b9f587ce
commit 8d9d78493d
1 changed files with 5 additions and 8 deletions

View File

@ -82,14 +82,9 @@ BEGIN {
get_template_and_user haspermission create_basic_session
);
$ldap = C4::Context->config('useldapserver') || 0;
$cas = C4::Context->preference('casAuthentication');
$caslogout = C4::Context->preference('casLogout');
if ($ldap) {
require C4::Auth_with_ldap;
import C4::Auth_with_ldap qw(checkpw_ldap);
}
if ($cas) {
require C4::Auth_with_cas; # no import
import C4::Auth_with_cas qw(check_api_auth_cas checkpw_cas login_cas logout_cas login_cas_url logout_if_required multipleAuth getMultipleAuth);
@ -1986,15 +1981,17 @@ sub checkpw {
my $passwd_ok = 0;
my $patron;
# Note: checkpw_* routines returns:
# 1 if auth is ok
# 0 if auth is nok
# -1 if user bind failed (LDAP only)
$ldap = C4::Context->config('useldapserver') || 0;
if ( $ldap && defined($password) ) {
my ( $retval, $retcard, $retuserid );
( $retval, $retcard, $retuserid, $patron ) = checkpw_ldap(@_); # EXTERNAL AUTH
require C4::Auth_with_ldap;
import C4::Auth_with_ldap qw(checkpw_ldap);
( $retval, $retcard, $retuserid, $patron ) = C4::Auth_with_ldap::checkpw_ldap(@_); # EXTERNAL AUTH
if ( $retval == 1 ) {
@return = ( $retval, $retcard, $retuserid, $patron );
$passwd_ok = 1;