lemonldap-ng/lemonldap-ng-portal/t/28-AuthChoice-and-password.t

120 lines
3.6 KiB
Perl
Raw Permalink Normal View History

2016-07-07 22:55:27 +02:00
use Test::More;
use strict;
use IO::String;
require 't/test-lib.pm';
my $res;
2018-10-09 22:42:43 +02:00
my $maintests = 10;
2016-07-07 22:55:27 +02:00
2019-08-29 10:04:06 +02:00
my $userdb = tempdb();
2016-07-07 22:55:27 +02:00
SKIP: {
eval { require DBI; require DBD::SQLite; };
if ($@) {
2018-02-08 21:55:21 +01:00
skip 'DBD::SQLite not found', $maintests;
2016-07-07 22:55:27 +02:00
}
2018-02-08 21:55:21 +01:00
skip 'LLNGTESTLDAP is not set', $maintests unless ( $ENV{LLNGTESTLDAP} );
2017-12-21 21:38:54 +01:00
require 't/test-ldap.pm';
2019-08-29 10:04:06 +02:00
my $dbh = DBI->connect("dbi:SQLite:dbname=$userdb");
2016-07-07 22:55:27 +02:00
$dbh->do('CREATE TABLE users (user text,password text,name text)');
$dbh->do("INSERT INTO users VALUES ('dwho','dwho','Doctor who')");
2019-02-07 09:27:56 +01:00
my $client = LLNG::Manager::Test->new( {
2016-11-14 13:34:46 +01:00
ini => {
2018-10-09 22:45:40 +02:00
logLevel => 'error',
useSafeJail => 1,
authentication => 'Choice',
userDB => 'Same',
passwordDB => 'Choice',
portalRequireOldPassword => 1,
2016-07-07 22:55:27 +02:00
2016-11-14 13:34:46 +01:00
authChoiceParam => 'test',
authChoiceModules => {
ldap => 'LDAP;LDAP;LDAP',
sql => 'DBI;DBI;DBI',
slave => 'Slave;LDAP;LDAP',
2016-11-14 13:34:46 +01:00
},
2016-07-07 22:55:27 +02:00
2019-08-29 10:04:06 +02:00
dbiAuthChain => "dbi:SQLite:dbname=$userdb",
2016-11-14 13:34:46 +01:00
dbiAuthUser => '',
dbiAuthPassword => '',
dbiAuthTable => 'users',
dbiAuthLoginCol => 'user',
dbiAuthPasswordCol => 'password',
dbiAuthPasswordHash => '',
2016-07-07 22:55:27 +02:00
2017-12-21 21:38:54 +01:00
ldapServer => 'ldap://127.0.0.1:19389/',
ldapBase => 'ou=users,dc=example,dc=com',
managerDn => 'cn=admin,dc=example,dc=com',
managerPassword => 'admin',
slaveUserHeader => 'My-Test',
slaveExportedVars => {
name => 'Name',
}
2016-11-14 13:34:46 +01:00
}
2016-07-07 22:55:27 +02:00
}
);
2017-01-15 23:04:35 +01:00
# Test LDAP and SQL
2016-07-07 22:55:27 +02:00
foreach my $postString (
2017-12-21 21:38:54 +01:00
'user=dwho&password=dwho&test=ldap',
2016-07-07 22:55:27 +02:00
'user=dwho&password=dwho&test=sql'
)
{
2019-06-01 11:48:07 +02:00
# Try to authenticate
2016-07-07 22:55:27 +02:00
# -------------------
2018-07-12 09:04:05 +02:00
ok( $res = $client->_get( '/', accept => 'text/html' ), 'Get menu' );
my @form = ( $res->[2]->[0] =~ m#<form.*?</form>#sg );
2019-07-02 20:03:40 +02:00
ok( @form == 3, 'Display 3 choices' ) or explain( scalar(@form), 3 );
2018-07-06 12:15:14 +02:00
foreach (@form) {
2018-07-12 09:04:05 +02:00
expectForm( [ $res->[0], $res->[1], [$_] ], undef, undef, 'test' );
2018-07-06 12:15:14 +02:00
}
2016-07-07 22:55:27 +02:00
ok(
2016-11-14 13:34:46 +01:00
$res = $client->_post(
2016-07-07 22:55:27 +02:00
'/', IO::String->new($postString),
2018-07-06 12:15:14 +02:00
length => length($postString),
accept => 'text/html',
2016-07-07 22:55:27 +02:00
),
'Auth query'
);
2016-12-23 11:02:21 +01:00
my $id = expectCookie($res);
2018-10-09 22:42:43 +02:00
ok(
$res = $client->_post(
'/',
IO::String->new(
'oldpassword=dwho&newpassword=test&confirmpassword=test'),
cookie => "lemonldap=$id",
accept => 'application/json',
length => 54
),
'Change password'
);
expectOK($res);
$client->logout($id);
my $tmp = $postString;
$tmp =~ s/password=dwho/password=test/;
ok(
$res = $client->_post(
'/',
IO::String->new($tmp),
length => length($tmp),
),
'Auth query with new password'
);
expectOK($res);
$id = expectCookie($res);
2016-11-14 13:34:46 +01:00
$client->logout($id);
2016-07-07 22:55:27 +02:00
}
clean_sessions();
}
2018-02-08 21:55:21 +01:00
count($maintests);
2017-12-21 21:38:54 +01:00
stopLdapServer() if $ENV{LLNGTESTLDAP};
clean_sessions();
2016-07-07 22:55:27 +02:00
done_testing( count() );