Commit 2eafb602 authored by Yadd's avatar Yadd
Browse files

LDAP auth works (#595)

parent 085ac825
......@@ -22,13 +22,14 @@ sub process {
while ( my $sub = shift @{ $req->steps } ) {
if ( ref $sub ) {
$self->lmLog( "Processing code ref", 'debug' );
last if ( $sub->($req) );
last if ( $err = $sub->($req) );
}
else {
$self->lmLog( "Processing $sub", 'debug' );
last if ( $err = $self->$sub($req) );
}
}
$self->lmLog( "Returned error: $err", 'debug' ) if ($err);
return $err;
}
......
......@@ -12,7 +12,7 @@ our $VERSION = '2.0.0';
has ldap => (
is => 'rw',
lazy => 1,
builder => 'newLdap';
builder => 'newLdap',
);
sub newLdap {
......@@ -90,7 +90,7 @@ has filter => (
$filter =~
s/\$req->\{sessionInfo\}->\{(_?password|mail)\}/\$req->{datas}->{$1}/g;
$_[0]->{p}->lmLog( "LDAP transformed filter: $filter", 'debug' );
$filter = "sub{my(\$self,\$req)=\@_;return \"$filter\";}";
$filter = "sub{my(\$req)=\$_[0];return \"$filter\";}";
return eval $filter;
}
);
......@@ -130,9 +130,9 @@ sub getUser {
'error' );
return PE_BADCREDENTIALS;
}
unless ( $req->datas->entry( $mesg->entry(0) ) ) {
unless ( $req->datas->{entry} = $mesg->entry(0) ) {
my $user = $req->{mail} || $req->{user};
$self->_sub( 'userError', "$user was not found in LDAP directory" );
$self->p->userError("$user was not found in LDAP directory");
return PE_BADCREDENTIALS;
}
$req->datas->{dn} = $req->datas->{entry}->dn();
......
use Test::More;
use strict;
use IO::String;
require 't/test-lib.pm';
my $res;
SKIP: {
skip 'No LDAP server given', 3 unless ( $ENV{LDAPSERVER} );
init(
{
logLevel => 'debug',
useSafeJail => 1,
authentication => 'LDAP',
userDB => 'LDAP',
LDAPFilter => $ENV{LDAPFILTER} || '(cn=$user)',
ldapServer => $ENV{LDAPSERVER},
ldapBase => $ENV{LDAPBASE},
managerDn => $ENV{MANAGERDN} || '',
managerPassword => $ENV{MANAGERPASSWORD} || '',
}
);
my $postString = 'user='
. ( $ENV{LDAPACCOUNT} || 'dwho' )
. '&password='
. ( $ENV{LDAPPWD} || 'dwho' );
# Try yo authenticate
# -------------------
ok(
$res = &client->_post(
'/', '',
IO::String->new('user=dwho&password=dwho'),
'application/x-www-form-urlencoded',
length($postString)
),
'Auth query'
);
ok( $res->[0] == 200, 'Response is 200' ) or explain( $res->[0], 200 );
my $cookies = getCookies($res);
my $id;
ok( $id = $cookies->{lemonldap}, 'Get cookie' )
or explain( $res, 'Set-Cookie: something' );
clean_sessions();
}
count(3);
done_testing( count() );
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment