Commit 9738b3db authored by Xavier Guimard's avatar Xavier Guimard

perltidy

parent 6823a6e0
......@@ -14,11 +14,26 @@ use MIME::Base64;
my $dbsalt = shift;
my $password = shift;
# Create functions
use Digest::SHA;
$dbh->sqlite_create_function( 'sha256', 1, sub { my $p = shift; return unpack('H*', Digest::SHA->new(256)->add(pack('H*', $p))->digest); } );
$dbh->sqlite_create_function( 'sha512', 1, sub { my $p = shift; return unpack('H*', Digest::SHA->new(512)->add(pack('H*', $p))->digest); } );
$dbh->sqlite_create_function(
'sha256', 1,
sub {
my $p = shift;
return
unpack( 'H*',
Digest::SHA->new(256)->add( pack( 'H*', $p ) )->digest );
}
);
$dbh->sqlite_create_function(
'sha512', 1,
sub {
my $p = shift;
return
unpack( 'H*',
Digest::SHA->new(512)->add( pack( 'H*', $p ) )->digest );
}
);
# convert password to hexa
my $passwordh = unpack "H*", $password;
......@@ -38,7 +53,7 @@ use MIME::Base64;
if ( @rows == 1 ) {
$self->logger->debug(
"Successfully hashed password with $dbmethod hash function in database"
"Successfully hashed password with $dbmethod hash function in database"
);
# convert salt to binary
......@@ -50,7 +65,8 @@ use MIME::Base64;
return encode_base64( $res . $dbsaltb, '' );
}
else {
$self->userLogger->warn("Unable to check password with '$dbmethod'");
$self->userLogger->warn(
"Unable to check password with '$dbmethod'");
return "";
}
......@@ -58,9 +74,6 @@ use MIME::Base64;
}
}
use Test::More;
use strict;
use IO::String;
......@@ -72,21 +85,27 @@ my $mainTests = 3;
eval { unlink 't/userdb.db' };
SKIP: {
eval { require DBI; require DBD::SQLite; use Digest::SHA};
eval { require DBI; require DBD::SQLite; use Digest::SHA };
if ($@) {
skip 'DBD::SQLite not found', $mainTests;
}
my $dbh = DBI->connect("dbi:SQLite:dbname=t/userdb.db");
$dbh->do('CREATE TABLE users (user text,password text,name text)');
# password secret1
$dbh->do("INSERT INTO users VALUES ('dwho','secret1','Doctor who')");
# password secret2
$dbh->do("INSERT INTO users VALUES ('rtyler','{sha256}NSJNDTRl106FX41poTbnnHROo1pnXTOTNgoyfL9jWaI=','Rose Tyler')");
$dbh->do(
"INSERT INTO users VALUES ('rtyler','{sha256}NSJNDTRl106FX41poTbnnHROo1pnXTOTNgoyfL9jWaI=','Rose Tyler')"
);
# password secret3
$dbh->do("INSERT INTO users VALUES ('jsmith','{ssha512}wr0zU/I6f7U4bVoeOlJnNFbhF0a9np59LUeNnhokohVI/wiNzt8Y4JujfOfNQiGuiVgY+xrYggfmgpke6KdjxKS7W0GR1ZCe','John Smith')");
$dbh->do(
"INSERT INTO users VALUES ('jsmith','{ssha512}wr0zU/I6f7U4bVoeOlJnNFbhF0a9np59LUeNnhokohVI/wiNzt8Y4JujfOfNQiGuiVgY+xrYggfmgpke6KdjxKS7W0GR1ZCe','John Smith')"
);
my $client = LLNG::Manager::Test->new(
{
ini => {
......@@ -114,8 +133,7 @@ SKIP: {
# Try to authenticate against plaintext password
ok(
$res = $client->_post(
'/',
IO::String->new('user=dwho&password=secret1'),
'/', IO::String->new('user=dwho&password=secret1'),
length => 26
),
'Authentication against plaintext password'
......@@ -127,27 +145,25 @@ SKIP: {
# Try to authenticate against static hashed password
ok(
$res = $client->_post(
'/',
IO::String->new('user=rtyler&password=secret2'),
'/', IO::String->new('user=rtyler&password=secret2'),
length => 28
),
'Authentication against static SHA-256 hashed password'
);
expectOK($res);
my $id = expectCookie($res);
$id = expectCookie($res);
$client->logout($id);
# Try to authenticate against salted password
ok(
$res = $client->_post(
'/',
IO::String->new('user=jsmith&password=secret3'),
'/', IO::String->new('user=jsmith&password=secret3'),
length => 28
),
'Authentication against salted SHA-512 password'
);
expectOK($res);
my $id = expectCookie($res);
$id = expectCookie($res);
$client->logout($id);
clean_sessions();
......
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