Bug 23473: Don't allow setting blank passwords via import

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
This commit is contained in:
Nick Clemens 2020-01-08 14:24:04 +00:00 committed by Martin Renvoize
parent 8c7ae857a2
commit 9a6134710d
No known key found for this signature in database
GPG Key ID: 422B469130441A0F
3 changed files with 16 additions and 3 deletions

View File

@ -303,7 +303,7 @@ sub import_patrons {
);
}
}
if ($overwrite_passwords){
if ($overwrite_passwords && defined $borrower{password} && $borrower{password} ne ''){
try {
$patron->set_password({ password => $borrower{password} });
}

View File

@ -248,7 +248,7 @@
<ul>
<li>
<input class="overwrite_passwords" type="checkbox" id="overwrite_passwords" name="overwrite_passwords" disabled/>
<label class="overwrite_passwords" for="overwrite_passwords">Replace patron passwords with those in the file</label>
<label class="overwrite_passwords" for="overwrite_passwords">Replace patron passwords with those in the file (blank passwords will be ignored)</label>
</li
</ul>
</li>

View File

@ -435,7 +435,7 @@ subtest 'test_import_with_cardnumber_0' => sub {
};
subtest 'test_import_with_password_overwrite' => sub {
plan tests => 4;
plan tests => 6;
#Remove possible existing user to avoid clashes
my $ernest = Koha::Patrons->find({ userid => 'ErnestP' });
@ -447,6 +447,7 @@ subtest 'test_import_with_password_overwrite' => sub {
my $csv_headers = 'surname,userid,branchcode,categorycode,password';
my $csv_password = "Worrell,ErnestP,$branchcode,$categorycode,Ernest1";
my $csv_password_change = "Worrell,ErnestP,$branchcode,$categorycode,Vern1";
my $csv_blank_password = "Worel,ErnestP,$branchcode,$categorycode,";
my $defaults = { cardnumber => "" }; #currently all the defaults come as "" if not filled
#Make the test files for importing
@ -457,6 +458,10 @@ subtest 'test_import_with_password_overwrite' => sub {
open(my $handle_2, "<", $filename_2) or die "cannot open < $filename_2: $!";
my $params_2 = { file => $handle_2, matchpoint => 'userid', overwrite_passwords => 1, overwrite_cardnumber => 1};
my $filename_3 = make_csv($temp_dir, $csv_headers, $csv_blank_password);
open(my $handle_3, "<", $filename_3) or die "cannot open < $filename_3: $!";
my $params_3 = { file => $handle_3, matchpoint => 'userid', overwrite_passwords => 1, overwrite_cardnumber => 1};
my $result = $patrons_import->import_patrons($params_1, $defaults);
like($result->{feedback}->[1]->{value}, qr/^Worrell \/ \d+/, 'First borrower imported as expected');
@ -471,6 +476,14 @@ subtest 'test_import_with_password_overwrite' => sub {
isnt($ernest->password,$orig_pass,"New patron is overwritten, password is overwritten");
isnt($ernest->password,'Vern',"Password is overwritten and is encrypted from value provided");
#Save info to check not changed
$orig_pass = $ernest->password;
$result = $patrons_import->import_patrons($params_3, $defaults);
$ernest = Koha::Patrons->find({ userid => 'ErnestP' });
is($ernest->surname,'Worel',"Patron is overwritten, surname changed");
is($ernest->password,$orig_pass,"Patron was overwritten but password is not overwritten if blank");
};