mirror of
https://codeberg.org/scip/Crypt--PWSafe3.git
synced 2025-12-16 20:21:01 +01:00
Added deleterecord method and test for it.
Note: I am not sure about return value. Currently I return "did I delete sth flag", alternatively one could return deleted record, or even croak if record was not there.
This commit is contained in:
@@ -470,6 +470,26 @@ sub modifyrecord {
|
|||||||
$this->markmodified();
|
$this->markmodified();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub deleterecord {
|
||||||
|
#
|
||||||
|
# delete a record identified by the given uuid, if present
|
||||||
|
#
|
||||||
|
# returns 1 if record was actually removed, 0 if it was not present
|
||||||
|
my($this, $uuid) = @_;
|
||||||
|
|
||||||
|
if (! exists $this->{record}->{$uuid}) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
delete $this->{record}->{$uuid};
|
||||||
|
|
||||||
|
# mark vault as modified
|
||||||
|
$this->markmodified();
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
sub markmodified {
|
sub markmodified {
|
||||||
#
|
#
|
||||||
# mark the vault as modified by setting the appropriate header fields
|
# mark the vault as modified by setting the appropriate header fields
|
||||||
|
|||||||
25
t/run.t
25
t/run.t
@@ -108,6 +108,31 @@ eval {
|
|||||||
};
|
};
|
||||||
ok(!$@, "modify some header fields ($@)");
|
ok(!$@, "modify some header fields ($@)");
|
||||||
|
|
||||||
|
### 6 delete
|
||||||
|
eval {
|
||||||
|
my $vault6 = new Crypt::PWSafe3(file => 't/3.out', password => 'tom');
|
||||||
|
my $uuid = $vault6->newrecord(user => 'xxx', passwd => 'y');
|
||||||
|
$vault6->save(file=>'t/6.out');
|
||||||
|
|
||||||
|
my $rvault6 = new Crypt::PWSafe3(file => 't/6.out', password => 'tom');
|
||||||
|
my $rec = $rvault6->getrecord($uuid);
|
||||||
|
if ($rec->user ne 'xxx') {
|
||||||
|
die "oop way record change failed";
|
||||||
|
}
|
||||||
|
$rvault6->deleterecord($uuid);
|
||||||
|
if ($rvault6->getrecord($uuid)) {
|
||||||
|
die "deleted record still present in open vault";
|
||||||
|
}
|
||||||
|
$vault6->save(file=>'t/6a.out');
|
||||||
|
|
||||||
|
my $rvault6a = new Crypt::PWSafe3(file => 't/6a.out', password => 'tom');
|
||||||
|
if ($rvault6->getrecord($uuid)) {
|
||||||
|
die "deleted record reappears after save and reload";
|
||||||
|
}
|
||||||
|
};
|
||||||
|
ok(!$@, "delete record\n" . $@ . "\n");
|
||||||
|
|
||||||
|
|
||||||
### clean temporary files
|
### clean temporary files
|
||||||
unlink('t/3.out');
|
unlink('t/3.out');
|
||||||
unlink('t/4.out');
|
unlink('t/4.out');
|
||||||
|
|||||||
Reference in New Issue
Block a user