Anonymous avatar Anonymous committed 49bb417

Polished and finished, initial version works on par with gnome

Comments (0)

Files changed (3)

experiments/kwallet_by_dbus.pl

 $handle > 0 or die "No handle"; # decline means -1
 say "Opened, handle = $handle";
 
+sub report_value {
+    my $value = shift;
+    return $value if defined($value);
+    return "(undef)";
+}
+
 {
     my $is_open = $kwallet->isOpen($handle);
     say "is open($handle): $is_open";
 
 {
     my $password = $kwallet->readPassword($handle, $FOLDER_NAME, $KEY1, $APP_NAME);
-    say "Read password for key $KEY1: ", $password || "(undef)";
+    say "Read password for key $KEY1: ", report_value($password);
 }
 
 {
 
 {
     my $password = $kwallet->readPassword($handle, $FOLDER_NAME, $KEY1, $APP_NAME);
-    say "Read password for key $KEY1: ", $password || "(undef)";
+    say "Read password for key $KEY1: ", report_value($password);
 }
 
 {
 
 {
     my $password = $kwallet->readPassword($handle, $FOLDER_NAME, $KEY1, $APP_NAME);
-    say "Read password for key $KEY1: ", $password || "(undef)";
+    say "Read password for key $KEY1: ", report_value($password);
 }
 
 {
 
 {
     my $password = $kwallet->readPassword($handle, $FOLDER_NAME, $KEY1, $APP_NAME);
-    say "Read password for key $KEY1: ", $password || "(undef)";
+    say "Read password for key $KEY1: ", report_value($password);
 }
 
 
 
 {
     my $password = $kwallet->readPassword($handle, $FOLDER_NAME, $KEY2, $APP_NAME);
-    say "Read password for key $KEY2: ", $password || "(undef)";
+    say "Read password for key $KEY2: ", report_value($password);
 }
 
 {
     say "Cleared password for key $KEY2, got $sth";
 }
 
+
+{
+    my $password = $kwallet->readPassword($handle, $FOLDER_NAME, $KEY2, $APP_NAME);
+    say "Read (cleared) password for key $KEY2: ", report_value($password);
+}
+
 {
     my $sth = $kwallet->removeEntry($handle, $FOLDER_NAME, $KEY2, $APP_NAME);
     say "Cleared non-existing password for key $KEY2, got $sth";
 
 {
     my $password = $kwallet->readPassword($handle, $FOLDER_NAME, $KEY2, $APP_NAME);
-    say "Read password for key $KEY2: ", $password || "(undef)";
+    say "Read (cleared) password for key $KEY2: ", report_value($password);
 }
 
 

lib/Passwd/Keyring/KDEWallet.pm

     $self->_open_if_not_open();
     my $reply = $self->{kwallet}->readPassword(
         $self->{handle}, $self->{group}, "$domain || $user_name", $self->{app});
+    # In case of missing passsword we get empty string. I do not know
+    # whether it is possible to distinguish missing password from empty password,
+    # but empty passwords are exotic enough to ignore.
+    return undef if ! defined($reply) or $reply eq '';
     return $reply;
 }
 
     $self->_open_if_not_open();
     my $status = $self->{kwallet}->removeEntry(
         $self->{handle}, $self->{group}, "$domain || $user_name", $self->{app});
-    if($status >= 0) {
+    if($status == 0) {
         return 1;
     } else {
         # TODO: classify failures

t/01-set-and-get.t

 
 use strict;
 use warnings;
-use Test::Simple tests => 8;
+use Test::More tests => 8;
 
 use Passwd::Keyring::KDEWallet;
 
 
 my $USER = 'John';
 my $PASSWORD = 'verysecret';
+my $DOMAIN = 'some simple domain';
 
-$ring->set_password($USER, $PASSWORD, 'my@@domain');
+$ring->set_password($USER, $PASSWORD, $DOMAIN);
 
 ok( 1, "set_password works" );
 
-ok( $ring->get_password($USER, 'my@@domain') eq $PASSWORD, "get recovers");
+is( $ring->get_password($USER, $DOMAIN), $PASSWORD, "get recovers");
 
-ok( $ring->clear_password($USER, 'my@@domain') eq 1, "clear_password removed one password" );
+is( $ring->clear_password($USER, $DOMAIN), 1, "clear_password removed one password" );
 
-ok( !defined($ring->get_password($USER, 'my@@domain')), "no password after clear");
+is( $ring->get_password($USER, $DOMAIN), undef, "no password after clear");
 
-ok( $ring->clear_password($USER, 'my@@domain') eq 0, "clear_password again has nothing to clear" );
+is( $ring->clear_password($USER, $DOMAIN), 0, "clear_password again has nothing to clear" );
 
-ok( $ring->clear_password("Non user", 'my@@domain') eq 0, "clear_password for unknown user has nothing to clear" );
-ok( $ring->clear_password("$USER", 'non domain') eq 0, "clear_password for unknown domain has nothing to clear" );
+is( $ring->clear_password("Non user", $DOMAIN), 0, "clear_password for unknown user has nothing to clear" );
+is( $ring->clear_password("$USER", 'non domain'), 0, "clear_password for unknown domain has nothing to clear" );
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.