diff options
author | Daniel Friesel <derf@finalrewind.org> | 2011-07-04 13:22:36 +0200 |
---|---|---|
committer | Daniel Friesel <derf@finalrewind.org> | 2011-07-04 13:22:36 +0200 |
commit | 2d2355dfd840a100a50b3d349be5d9c88d6de2f8 (patch) | |
tree | 5eefb3949c3acb10c1d2519cfd2d61096fec777e | |
parent | afebe00e35d17c3b2de1317be73fd9c89f1776b5 (diff) |
More advanced App::Raps2 tests
-rw-r--r-- | lib/App/Raps2.pm | 6 | ||||
-rw-r--r-- | t/29-app-raps2-store.t | 59 |
2 files changed, 63 insertions, 2 deletions
diff --git a/lib/App/Raps2.pm b/lib/App/Raps2.pm index 878ba9d..d515548 100644 --- a/lib/App/Raps2.pm +++ b/lib/App/Raps2.pm @@ -141,8 +141,10 @@ sub ui { sub pw_save { my ( $self, %data ) = @_; - $data{file} //= $self->{xdg_data} . "/$data{name}"; - $data{salt} //= $self->pw->create_salt(); + $data{file} //= $self->{xdg_data} . "/$data{name}"; + $data{login} //= q{}; + $data{salt} //= $self->pw->create_salt(); + $data{url} //= q{}; my $pass_hash = $self->pw->encrypt( $data{password}, $data{salt} ); my $extra_hash = ( diff --git a/t/29-app-raps2-store.t b/t/29-app-raps2-store.t new file mode 100644 index 0000000..759030d --- /dev/null +++ b/t/29-app-raps2-store.t @@ -0,0 +1,59 @@ +#!/usr/bin/env perl +use strict; +use warnings; +use 5.010; + +use Test::More; + +eval "use Test::MockObject"; +plan skip_all => 'Test::MockObject required' if $@; + +$ENV{XDG_CONFIG_HOME} = 't/config'; +$ENV{XDG_DATA_HOME} = 't/data'; + +plan tests => 9; + +my $mock = Test::MockObject->new(); +$mock->fake_module( 'Term::ReadLine', new => sub { return bless( {}, $_[0] ) }, +); + +use_ok('App::Raps2'); + +my $r2 = App::Raps2->new( master_password => 'sekrit' ); +isa_ok( $r2, 'App::Raps2' ); + +ok( -e 't/config/raps2/password', 'config file created' ); + +$r2->pw_save( + password => 'foopass', + name => 'test1' + ), + + ok( -e 't/data/raps2/test1', 'Save password test1' ); + +is( $r2->pw_load( name => 'test1' )->{password}, + 'foopass', 'Password for test1 loaded ok' ); + +$r2->pw_save( + password => 'foopass', + file => 't/data/raps2/test2', + url => 'murl', + login => 'mlogin', + extra => 'mextra', + ), + + is( $r2->pw_load_info( file => 't/data/raps2/test2' )->{url}, + 'murl', 'Password info loaded ok (url)' ); + +is( $r2->pw_load_info( file => 't/data/raps2/test2' )->{login}, + 'mlogin', 'Password info loaded ok (login)' ); + +is( $r2->pw_load( file => 't/data/raps2/test2' )->{password}, + 'foopass', 'Password for test2 loaded ok' ); + +is( $r2->pw_load( file => 't/data/raps2/test2' )->{extra}, + 'mextra', 'Extra for test2 loaded ok' ); + +unlink('t/data/raps2/test1'); +unlink('t/data/raps2/test2'); +unlink('t/config/raps2/password'); |