Skip to content

Commit

Permalink
fix(auth): properly log out in LDAP
Browse files Browse the repository at this point in the history
  • Loading branch information
frankiejol committed Dec 14, 2020
1 parent 0664d2b commit cbe6d3a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
8 changes: 4 additions & 4 deletions lib/Ravada/Auth/LDAP.pm
Original file line number Diff line number Diff line change
Expand Up @@ -440,14 +440,14 @@ sub _login_bind {
for my $user (@user) {
my $dn = $user->dn;
$found++;
my $mesg = $LDAP_ADMIN->bind($dn, password => $password);
if ( !$mesg->code() ) {
my $ldap = _connect_ldap($dn, $password);
if ( $ldap ) {
$self->{_auth} = 'bind';
$self->{_ldap_entry} = $user;
return 1;
}
warn "ERROR: ".$mesg->code." : ".$mesg->error. " : Bad credentials for $dn"
if $Ravada::DEBUG && $mesg->code;
warn "ERROR: Bad credentials for $dn"
if $Ravada::DEBUG && $@;
}
return 0;
}
Expand Down
23 changes: 21 additions & 2 deletions t/mojo/10_login.t
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,22 @@ sub test_copy_without_prepare($clone) {
remove_machines($clone);
}

sub test_logout_ldap {
my ($username, $password) = ( new_domain_name(),$$);
my $user = create_ldap_user( $username, $password);

$t->post_ok('/login' => form => {login => $username, password => $password});
is($t->tx->res->code(),302);

$t->ua->get($URL_LOGOUT);

$t->post_ok('/login' => form => {login => $username, password => 'bigtime'});
is($t->tx->res->code(),403);

$t->post_ok('/login' => form => {login => $username, password => $password});
is($t->tx->res->code(),302);
}

########################################################################################

init('/etc/ravada.conf',0);
Expand All @@ -195,16 +211,19 @@ if (!rvd_front->ping_backend) {
exit;
}

remove_old_domains_req();

$t = Test::Mojo->new($SCRIPT);
$t->ua->inactivity_timeout(900);
$t->ua->connect_timeout(60);
my @bases;
my @clones;

test_logout_ldap();

test_login_fail();


remove_old_domains_req();

for my $vm_name (@{rvd_front->list_vm_types} ) {

diag("Testing new machine in $vm_name");
Expand Down

0 comments on commit cbe6d3a

Please sign in to comment.