Commits

Marcin Kasperski  committed fc713b7

Further experiments and tests

  • Participants
  • Parent commits f9d33bc

Comments (0)

Files changed (1)

File experiments/kwallet_by_dbus.pl

 
 my $APP_NAME = "DBUStest";
 my $FOLDER_NAME = "DBUStestfolder";
+my $KEY1 = "Some key";
+my $KEY2 = "Yet another key";
+my $PWD1 = "Very secret";
+my $PWD2 = "Even more secret";
+my $PWD3 = "Uuuuuuuu";
 
 my $dbus = Net::DBus->session()
   or die("KWallet not available (can't access DBus)");
 $handle > 0 or die "No handle"; # decline means -1
 say "Opened, handle = $handle";
 
-my $is_open = $kwallet->isOpen($handle);
-say "is open($handle): $is_open";
-
-my $folders = $kwallet->folderList($handle, $APP_NAME);
-say "Folders = ", join(", ", @$folders);
-
-unless($kwallet->hasFolder($handle, $FOLDER_NAME, $APP_NAME)) {
-    say "Folder $FOLDER_NAME does not exists";
-    $kwallet->createFolder($handle, $FOLDER_NAME, $APP_NAME) or die "Failed to create";
-    say "Folder $FOLDER_NAME created";
-} else {
-    say "Folder $FOLDER_NAME already exists";
+{
+    my $is_open = $kwallet->isOpen($handle);
+    say "is open($handle): $is_open";
 }
 
-my $password = $kwallet->readPassword($handle, $FOLDER_NAME, "Some key", $APP_NAME);
-say "Read password: ", $password || "(undef)";
+{
+    my $folders = $kwallet->folderList($handle, $APP_NAME);
+    say "Folders = ", join(", ", @$folders);
+}
 
-my $sth = $kwallet->writePassword($handle, $FOLDER_NAME, "Some key", "Some pass 1", $APP_NAME);
-say "Wrote password, got $sth";
-# NOn-zero output seems to mean failure
+{
+    unless($kwallet->hasFolder($handle, $FOLDER_NAME, $APP_NAME)) {
+        say "Folder $FOLDER_NAME does not exists";
+        $kwallet->createFolder($handle, $FOLDER_NAME, $APP_NAME) or die "Failed to create";
+        say "Folder $FOLDER_NAME created";
+    } else {
+        say "Folder $FOLDER_NAME already exists";
+    }
+}
 
-my $password = $kwallet->readPassword($handle, $FOLDER_NAME, "Some key", $APP_NAME);
-say "Read password: ", $password || "(undef)";
+{
+    my $password = $kwallet->readPassword($handle, $FOLDER_NAME, $KEY1, $APP_NAME);
+    say "Read password for key $KEY1: ", $password || "(undef)";
+}
 
-my $sth = $kwallet->writePassword($handle, $FOLDER_NAME, "Some key", "Some pass 2", $APP_NAME);
-say "Wrote password, got $sth";
+{
+    my $sth = $kwallet->writePassword($handle, $FOLDER_NAME, $KEY1, $PWD1, $APP_NAME);
+    say "Wrote password $PWD1 under key $KEY1, got $sth";
+    # NOn-zero output seems to mean failure
+}
 
-my $password = $kwallet->readPassword($handle, $FOLDER_NAME, "Some key", $APP_NAME);
-say "Read password: ", $password || "(undef)";
+{
+    my $password = $kwallet->readPassword($handle, $FOLDER_NAME, $KEY1, $APP_NAME);
+    say "Read password for key $KEY1: ", $password || "(undef)";
+}
 
-my $sth = $kwallet->writePassword($handle, $FOLDER_NAME, "Some key", undef, $APP_NAME);
-say "Wrote undef password, got $sth";
+{
+    my $sth = $kwallet->writePassword($handle, $FOLDER_NAME, $KEY1, $PWD2, $APP_NAME);
+    say "Wrote password $PWD2 for key $KEY1, got $sth";
+}
 
-my $password = $kwallet->readPassword($handle, $FOLDER_NAME, "Some key", $APP_NAME);
-say "Read password: ", $password || "(undef)";
+{
+    my $password = $kwallet->readPassword($handle, $FOLDER_NAME, $KEY1, $APP_NAME);
+    say "Read password for key $KEY1: ", $password || "(undef)";
+}
 
+{
+    my $sth = $kwallet->writePassword($handle, $FOLDER_NAME, $KEY1, undef, $APP_NAME);
+    say "Wrote undef password for key $KEY1, got $sth";
+}
 
+{
+    my $password = $kwallet->readPassword($handle, $FOLDER_NAME, $KEY1, $APP_NAME);
+    say "Read password for key $KEY1: ", $password || "(undef)";
+}
 
 
-$kwallet->removeFolder($handle, $FOLDER_NAME, $APP_NAME);
-say "Folder $FOLDER_NAME removed";
+{
+    $kwallet->removeFolder($handle, $FOLDER_NAME, $APP_NAME);
+    say "Folder $FOLDER_NAME removed";
+}
 
-# Po close przy ponownym otwieraniu będzie pytanie (cośtam prosi...), bez tego - nie, mimo końca programu
-$kwallet->close($handle, 1, $APP_NAME); # drugi parametr: force
-say "Closed $handle";
+eval {
+    my $sth = $kwallet->writePassword($handle, $FOLDER_NAME, $KEY2, $PWD3, $APP_NAME);
+    say "Wrote password $PWD3 for key $KEY2 to non-existant folder, got $sth";
+}; if($@) {
+    say "Got error while writing password to non-existant folder: $@";
+}
 
-$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 $KEY2: ", $password || "(undef)";
+}
 
+{
+    # Po close przy ponownym otwieraniu będzie pytanie (cośtam prosi...), bez tego - nie, mimo końca programu
+    $kwallet->close($handle, 1, $APP_NAME); # drugi parametr: force
+    say "Closed $handle";
+}
+
+{
+    my $is_open = $kwallet->isOpen($handle);
+    say "is open($handle): $is_open";
+}
+
+eval {
+    my $sth = $kwallet->readPassword($handle, $FOLDER_NAME, $KEY1, $APP_NAME);
+    say "Read (non-exist) password for key $KEY1 from closed wallet, got $sth";
+}; if($@) {
+    say "Got error while reading password from closed wallet: $@";
+}
+
+eval {
+    my $sth = $kwallet->readPassword($handle, $FOLDER_NAME, $KEY2, $APP_NAME);
+    say "Read password for key $KEY2 from closed wallet, got $sth";
+}; if($@) {
+    say "Got error while reading password from closed wallet: $@";
+}