2016-07-20 22:47:43 +02:00
|
|
|
use Test::More;
|
|
|
|
use strict;
|
|
|
|
use IO::String;
|
|
|
|
|
|
|
|
require 't/test-lib.pm';
|
|
|
|
|
|
|
|
my $res;
|
2018-02-08 21:55:21 +01:00
|
|
|
my $maintests = 3;
|
2016-07-20 22:47:43 +02:00
|
|
|
|
|
|
|
eval { unlink 't/userdb.db' };
|
|
|
|
|
|
|
|
SKIP: {
|
|
|
|
eval { require DBI; require DBD::SQLite; };
|
|
|
|
if ($@) {
|
2018-02-08 21:55:21 +01:00
|
|
|
skip 'DBD::SQLite not found', $maintests;
|
2016-07-20 22:47:43 +02:00
|
|
|
}
|
|
|
|
my $dbh = DBI->connect("dbi:SQLite:dbname=t/userdb.db");
|
|
|
|
$dbh->do('CREATE TABLE users (user text,password text,name text)');
|
|
|
|
$dbh->do("INSERT INTO users VALUES ('dwho','dwho','Doctor who')");
|
2016-11-14 13:34:46 +01:00
|
|
|
my $client = LLNG::Manager::Test->new(
|
2016-07-20 22:47:43 +02:00
|
|
|
{
|
2016-11-14 13:34:46 +01:00
|
|
|
ini => {
|
|
|
|
logLevel => 'error',
|
|
|
|
useSafeJail => 1,
|
|
|
|
authentication => 'DBI',
|
2017-02-05 10:13:20 +01:00
|
|
|
userDB => 'Same',
|
2016-11-14 13:34:46 +01:00
|
|
|
dbiAuthChain => 'dbi:SQLite:dbname=t/userdb.db',
|
|
|
|
dbiAuthUser => '',
|
|
|
|
dbiAuthPassword => '',
|
|
|
|
dbiAuthTable => 'users',
|
|
|
|
dbiAuthLoginCol => 'user',
|
|
|
|
dbiAuthPasswordCol => 'password',
|
|
|
|
dbiAuthPasswordHash => '',
|
2017-11-02 17:42:01 +01:00
|
|
|
dbiDynamicHashEnabled => 0,
|
2016-11-14 13:34:46 +01:00
|
|
|
passwordDB => 'DBI',
|
|
|
|
portalRequireOldPassword => 1,
|
|
|
|
}
|
2016-07-20 22:47:43 +02:00
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2017-11-02 17:42:01 +01:00
|
|
|
# Try to authenticate
|
2016-07-20 22:47:43 +02:00
|
|
|
# -------------------
|
|
|
|
ok(
|
2016-11-14 13:34:46 +01:00
|
|
|
$res = $client->_post(
|
2016-07-20 22:47:43 +02:00
|
|
|
'/',
|
|
|
|
IO::String->new('user=dwho&password=dwho'),
|
|
|
|
length => 23
|
|
|
|
),
|
|
|
|
'Auth query'
|
|
|
|
);
|
2016-12-23 07:41:03 +01:00
|
|
|
expectOK($res);
|
|
|
|
my $id = expectCookie($res);
|
2016-07-20 22:47:43 +02:00
|
|
|
|
|
|
|
ok(
|
2016-11-14 13:34:46 +01:00
|
|
|
$res = $client->_post(
|
2016-07-20 22:47:43 +02:00
|
|
|
'/',
|
|
|
|
IO::String->new(
|
|
|
|
'oldpassword=dwho&newpassword=test&confirmpassword=test'),
|
|
|
|
cookie => "lemonldap=$id",
|
|
|
|
accept => 'application/json',
|
|
|
|
length => 54
|
|
|
|
),
|
|
|
|
'Change password'
|
|
|
|
);
|
2016-12-23 07:41:03 +01:00
|
|
|
expectOK($res);
|
2016-11-14 13:34:46 +01:00
|
|
|
$client->logout($id);
|
2016-07-20 22:47:43 +02:00
|
|
|
ok(
|
2016-11-14 13:34:46 +01:00
|
|
|
$res = $client->_post(
|
2016-07-20 22:47:43 +02:00
|
|
|
'/',
|
|
|
|
IO::String->new('user=dwho&password=test'),
|
|
|
|
cookie => "lemonldap=$id",
|
|
|
|
length => 23
|
|
|
|
),
|
|
|
|
'Auth query with new password'
|
|
|
|
);
|
2016-12-23 07:41:03 +01:00
|
|
|
expectOK($res);
|
|
|
|
$id = expectCookie($res);
|
2016-07-20 22:47:43 +02:00
|
|
|
|
2016-11-14 13:34:46 +01:00
|
|
|
$client->logout($id);
|
2016-07-20 22:47:43 +02:00
|
|
|
clean_sessions();
|
|
|
|
}
|
|
|
|
eval { unlink 't/userdb.db' };
|
2018-02-08 21:55:21 +01:00
|
|
|
count($maintests);
|
2016-07-20 22:47:43 +02:00
|
|
|
done_testing( count() );
|