perl/keyring/kdewallet / t / 05-many-sets-and-gets-with-name.t

#!perl -T

use strict;
use warnings;
use Test::More;

if($ENV{DESKTOP_SESSION} || $ENV{DBUS_SESSION_BUS_ADDRESS}) {
    plan tests => 20;
} else {
    plan skip_all => "Keyring not available (not running under KDE/Gnome/other desktop session), skipping tests";
}


use Passwd::Keyring::KDEWallet;

my $REALM_A = 'my@@realm';
my $REALM_B = 'bum trala la';
my $REALM_C = 'other realm';

my $USER1 = "Paul Anton";
my $USER2 = "Gżegąź";
my $USER4 = "-la-san-ty-";

my $PWD1 = "secret-Paul";
my $PWD1_ALT = "secret-Paul2 ąąąą";
my $PWD2 = "secret-Greg";
my $PWD4 = "secret-Duke";

SKIP: {

    my $ring; 
    eval {
        $ring = Passwd::Keyring::KDEWallet->new(app=>"Passwd::Keyring::KDEWallet", group=>"Unit tests (secrets)");
    }; if($@) {
        if($@ =~ /^KWallet not available/) {
            skip "KWallet not available ($@)", 20;
        } else {
            die $@;
        }
    }

    ok( defined($ring) && ref $ring eq 'Passwd::Keyring::KDEWallet',   'new() works' );

    $ring->set_password($USER1, $PWD1, $REALM_B);
    $ring->set_password($USER2, $PWD2, $REALM_B); #
    $ring->set_password($USER1, $PWD1_ALT, $REALM_C);
    $ring->set_password($USER4, $PWD4, $REALM_B);

    ok( 1, "set_password works" );

    ok( $ring->get_password($USER1, $REALM_B) eq $PWD1, "get works");

    ok( $ring->get_password($USER2, $REALM_B) eq $PWD2, "get works");

    ok( $ring->get_password($USER1, $REALM_C) eq $PWD1_ALT, "get works");

    ok( $ring->get_password($USER4, $REALM_B) eq $PWD4, "get works");

    $ring->clear_password($USER1, $REALM_B);
    ok(1, "clear_password works");

    ok( ! defined($ring->get_password($USER1, $REALM_A)), "get works");

    ok( ! defined($ring->get_password($USER2, $REALM_A)), "get works");

    ok( $ring->get_password($USER2, $REALM_B) eq $PWD2, "get works");

    ok( $ring->get_password($USER1, $REALM_C) eq $PWD1_ALT, "get works");

    ok( $ring->get_password($USER4, $REALM_B) eq $PWD4, "get works");

    ok( $ring->clear_password($USER2, $REALM_B) eq 1, "clear clears");

    ok( ! defined($ring->get_password($USER2, $REALM_A)), "clear cleared");

    ok( $ring->get_password($USER1, $REALM_C) eq $PWD1_ALT, "get works");

    ok( $ring->get_password($USER4, $REALM_B) eq $PWD4, "get works");

    ok( $ring->clear_password($USER1, $REALM_C) eq 1, "clear clears");

    ok( $ring->clear_password($USER4, $REALM_B) eq 1, "clear clears");

    ok( ! defined($ring->get_password($USER1, $REALM_C)), "clear cleared");
    ok( ! defined($ring->get_password($USER4, $REALM_B)), "clear cleared");

}
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.