X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=t%2Fentry.t;h=8a6d5ebdb15b251c8bb2e96c4adb826ea293be18;hb=8ccefe1cedea9b0886a44ad096aa5710528eaac7;hp=6de80287b9974251d272b644971f22a824d6ac3d;hpb=05e0bcef1c2165c556b910314312866dc4a667b7;p=chaz%2Fp5-File-KDBX diff --git a/t/entry.t b/t/entry.t index 6de8028..8a6d5eb 100644 --- a/t/entry.t +++ b/t/entry.t @@ -18,7 +18,7 @@ subtest 'Construction' => sub { is $entry->{username}, 'foo', 'username is in the object still'; is $entry->username, '', 'username is not the UserName string'; - like exception { $entry->kdbx }, qr/disassociated from a KDBX database/, 'Dies if disassociated'; + like exception { $entry->kdbx }, qr/disconnected/, 'Dies if disconnected'; $entry->kdbx(my $kdbx = File::KDBX->new); is $entry->kdbx, $kdbx, 'Set a database after instantiation'; @@ -30,7 +30,12 @@ subtest 'Construction' => sub { is $entry->username, 'bar', 'username is set correctly as the UserName string'; cmp_deeply $entry, noclass({ - auto_type => {}, + auto_type => { + associations => [], + data_transfer_obfuscation => 0, + default_sequence => "{USERNAME}{TAB}{PASSWORD}{ENTER}", + enabled => bool(1), + }, background_color => "", binaries => {}, custom_data => {}, @@ -73,6 +78,14 @@ subtest 'Construction' => sub { }), 'Entry data contains UserName string and the rest default attributes'; }; +subtest 'Accessors' => sub { + my $entry = File::KDBX::Entry->new; + + $entry->creation_time('2022-02-02 12:34:56'); + cmp_ok $entry->creation_time, '==', 1643805296, 'Creation time coerced into a Time::Piece (epoch)'; + is $entry->creation_time->datetime, '2022-02-02T12:34:56', 'Creation time coerced into a Time::Piece'; +}; + subtest 'Custom icons' => sub { plan tests => 10; my $gif = pack('H*', '4749463839610100010000ff002c00000000010001000002003b'); @@ -131,4 +144,29 @@ subtest 'Update UUID' => sub { or diag explain $entry2->url; }; +subtest 'Auto-type' => sub { + my $kdbx = File::KDBX->new; + + my $entry = $kdbx->add_entry(title => 'Meh'); + $entry->add_auto_type_association({ + window => 'Boring Store', + keystroke_sequence => 'yeesh', + }); + $entry->add_auto_type_association({ + window => 'Friendly Bank', + keystroke_sequence => 'blah', + }); + + my $window_title = 'Friendly'; + my $entries = $kdbx->entries(auto_type => 1) + ->filter(sub { + my ($ata) = grep { $_->{window} =~ /\Q$window_title\E/i } @{$_->auto_type_associations}; + return [$_, $ata->{keystroke_sequence} || $_->auto_type_default_sequence] if $ata; + }); + cmp_ok $entries->count, '==', 1, 'Find auto-type window association'; + + (undef, my $keys) = @{$entries->next}; + is $keys, 'blah', 'Select the correct association'; +}; + done_testing;