2021-04-16 16:09:30 +00:00
|
|
|
use feature 'unicode_strings';
|
|
|
|
use strict;
|
2021-08-19 20:36:43 +00:00
|
|
|
use warnings;
|
2021-04-16 16:09:30 +00:00
|
|
|
use Setup;
|
2022-02-09 18:40:51 +00:00
|
|
|
use Hydra::Helper::Exec;
|
2021-04-16 16:09:30 +00:00
|
|
|
|
|
|
|
my %ctx = test_init();
|
|
|
|
|
|
|
|
require Hydra::Schema;
|
|
|
|
require Hydra::Model::DB;
|
|
|
|
|
|
|
|
use Test2::V0;
|
|
|
|
|
|
|
|
my $db = Hydra::Model::DB->new;
|
|
|
|
hydra_setup($db);
|
|
|
|
|
|
|
|
subtest "hydra-init upgrades user's password hashes from sha1 to sha1 inside Argon2" => sub {
|
|
|
|
my $alice = $db->resultset('Users')->create({
|
|
|
|
"username" => "alice",
|
|
|
|
"emailaddress" => 'alice@nixos.org',
|
|
|
|
"password" => "8843d7f92416211de9ebb963ff4ce28125932878" # SHA1 of "foobar"
|
|
|
|
});
|
|
|
|
my $janet = $db->resultset('Users')->create({
|
|
|
|
"username" => "janet",
|
|
|
|
"emailaddress" => 'janet@nixos.org',
|
|
|
|
"password" => "!"
|
|
|
|
});
|
|
|
|
$janet->setPassword("foobar");
|
|
|
|
|
|
|
|
is($alice->password, "8843d7f92416211de9ebb963ff4ce28125932878", "Alices's sha1 is stored in the database");
|
2024-07-30 23:19:40 +00:00
|
|
|
my ($res, $stdout, $stderr) = captureStdoutStderr(30, ("hydra-init"));
|
2021-04-16 16:09:30 +00:00
|
|
|
if ($res != 0) {
|
|
|
|
is($stdout, "");
|
|
|
|
is($stderr, "");
|
|
|
|
}
|
|
|
|
is($res, 0, "hydra-init should exit zero");
|
|
|
|
|
|
|
|
subtest "Alice had their password updated in place" => sub {
|
|
|
|
my $updatedAlice = $db->resultset('Users')->find({ username => "alice" });
|
|
|
|
isnt($updatedAlice, undef);
|
|
|
|
isnt($updatedAlice->password, "8843d7f92416211de9ebb963ff4ce28125932878", "The password was updated in place.");
|
|
|
|
|
|
|
|
my $storedPassword = $updatedAlice->password;
|
|
|
|
ok($updatedAlice->check_password("foobar"), "Their password validates");
|
|
|
|
isnt($storedPassword, $updatedAlice->password, "The password is upgraded in place.");
|
|
|
|
};
|
|
|
|
|
|
|
|
subtest "Janet did not have their password change" => sub {
|
|
|
|
my $updatedJanet = $db->resultset('Users')->find({ username => "janet" });
|
|
|
|
isnt($updatedJanet, undef);
|
|
|
|
is($updatedJanet->password, $janet->password, "The password was not updated in place.");
|
|
|
|
|
|
|
|
ok($updatedJanet->check_password("foobar"), "Their password validates");
|
|
|
|
is($updatedJanet->password, $janet->password, "The password is not upgraded in place.");
|
|
|
|
};
|
|
|
|
|
|
|
|
subtest "Running hydra-init don't break Alice or Janet's passwords" => sub {
|
2024-07-30 23:19:40 +00:00
|
|
|
my ($res, $stdout, $stderr) = captureStdoutStderr(30, ("hydra-init"));
|
2021-04-16 16:09:30 +00:00
|
|
|
is($res, 0, "hydra-init should exit zero");
|
|
|
|
|
|
|
|
my $updatedAlice = $db->resultset('Users')->find({ username => "alice" });
|
|
|
|
ok($updatedAlice->check_password("foobar"), "Alice's password validates");
|
|
|
|
|
|
|
|
my $updatedJanet = $db->resultset('Users')->find({ username => "janet" });
|
|
|
|
ok($updatedJanet->check_password("foobar"), "Janet's password validates");
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
done_testing;
|