Source

perl/keyring/kdewallet / t / 06-recovering-with-app-change.t

#!perl -T

use strict;
use warnings;
#use Test::More tests => 11;
use Test::More skip_all => "Currently app and group are meaningful. To be decided whether to keep this behaviour";

use Passwd::Keyring::KDEWallet;

my $USER = "Herakliusz";
my $DOMAIN = "test domain";
my $PWD = "arcytajne haslo";

my $orig_ring = Passwd::Keyring::KDEWallet->new(app=>"Passwd::Keyring::Unit tests", group=>"Yet so");

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

ok( ! defined($orig_ring->get_password($USER, $DOMAIN)), "initially unset");

$orig_ring->set_password($USER, $PWD, $DOMAIN);
ok(1, "set password");

ok( $orig_ring->get_password($USER, $DOMAIN) eq $PWD, "normal get works");


# Another object with the same app/group

my $ring = Passwd::Keyring::KDEWallet->new(app=>"Passwd::Keyring::Unit tests", group=>"Yet so");

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

ok( $ring->get_password($USER, $DOMAIN) eq $PWD, "get from another ring with the same data works");

# Only group changes

$ring = Passwd::Keyring::KDEWallet->new(app=>"Passwd::Keyring::Unit tests", group=>"It has changed");

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

ok( $ring->get_password($USER, $DOMAIN) eq $PWD, "get from another ring with different group works");

# App and group change

$ring = Passwd::Keyring::KDEWallet->new(app=>"Something else", group=>"Yet Yet so");

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

ok( $ring->get_password($USER, $DOMAIN) eq $PWD, "get from another ring with changed app and group works");


# Cleanup
ok( $orig_ring->clear_password($USER, $DOMAIN) eq 1, "clearing");