Marcin Kasperski avatar Marcin Kasperski committed 7ee8eae

Inititating development by shameless copy

Comments (0)

Files changed (25)

+https://Mekk@bitbucket.org/Mekk/perl-keyring-osxkeychain
+syntax: regexp
+
+~$
+^_build/
+^Build$
+^blib/
+^MYMETA\.
+\.c$
+\.o$
+\.pyc$
+\.bak$
+^META\.
+^Makefile\.PL
+^Passwd-Keyring-Gnome-.*\.tar\.gz$
+^Makefile$
+^pm_to_blib$
+use 5.006;
+use strict;
+use warnings;
+use Module::Build;
+use ExtUtils::PkgConfig;
+
+my %gnome_keyring_pkg_info = ExtUtils::PkgConfig->find("gnome-keyring-1");
+
+my $builder = Module::Build->new(
+    module_name         => 'Passwd::Keyring::Gnome',
+    license             => 'perl',
+    dynamic_config      => 1,
+
+    needs_compiler => 1,
+    extra_compiler_flags => $gnome_keyring_pkg_info{cflags},
+    extra_linker_flags => $gnome_keyring_pkg_info{libs},
+
+    build_requires => {
+        'Module::Build' => '0.19', # xs
+        'ExtUtils::CBuilder' => 0,
+        'Test::More' => 0,
+        'Test::Pod::Coverage' => '1.0.8',
+    },
+    configure_requires => {
+        'Module::Build' => '0.36',
+    },
+    requires => {
+        'perl' => 5.006,
+    },
+
+    create_makefile_pl => 'traditional',
+    add_to_cleanup      => [ 'Passwd-Keyring-Gnome-*' ],
+
+    create_readme       => 1,
+    dist_author         => q{Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl>},
+    dist_version_from   => 'lib/Passwd/Keyring/Gnome.pm',
+    meta_merge => {
+        keywords => [ qw/ passwords security secure-storage keyring GNOME seahorse gnome-keyring / ],
+        resources => {
+            license     => 'http://dev.perl.org/licenses/',
+            homepage    => 'http://bitbucket.org/Mekk/perl-keyring-gnome',
+            repository => 'http://bitbucket.org/Mekk/perl-keyring-gnome',
+            bugtracker => 'https://bitbucket.org/Mekk/perl-keyring-gnome/issues',
+        },
+    },
+);
+
+$builder->create_build_script();
+Revision history for Keyring-OSXKeychain
+
+
+Passwd::Keyring::Gnome
+
+Passwd::Keyring is about using secure storage for passwords
+and other credentials used in perl scripts and applications.
+
+Passwd::Keyring::Gnome uses GNOME Keyring API to securely
+preserve passwords and is available to people using GNOME 
+desktop environment.
+
+INSTALLATION
+
+To install this module, run the following commands:
+
+	perl Build.PL
+	./Build
+	./Build test
+	./Build install
+
+SUPPORT AND DOCUMENTATION
+
+After installing, you can find documentation for this module with the
+perldoc command.
+
+    perldoc Keyring::Gnome
+
+You can also look for information at:
+
+    http://bitbucket.org/Mekk/perl-keyring
+
+
+LICENSE AND COPYRIGHT
+
+Copyright (C) 2012 Marcin Kasperski
+
+This program is free software; you can redistribute it and/or modify it
+under the terms of either: the GNU General Public License as published
+by the Free Software Foundation; or the Artistic License.
+
+See http://dev.perl.org/licenses/ for more information.
+
+Build.PL
+Changes
+INSTALL
+lib/Passwd/Keyring/Gnome.pm
+lib/Passwd/Keyring/Gnome.xs
+Makefile.PL
+MANIFEST			This list of files
+META.json
+META.yml
+README
+t/00-load.t
+t/01-set-and-get.t
+t/02-is-persistent.t
+t/03-many-sets-and-gets.t
+t/04-recovering-in-sep-prog.t
+t/05-many-sets-and-gets-with-name.t
+t/06-recovering-with-app-change.t
+t/07-ugly-chars.t
+t/08-verylong-params.t
+t/boilerplate.t
+t/cpan-meta-json.t
+t/cpan-meta.t
+t/manifest.t
+t/pod-coverage.t
+t/pod.t
+
+#!start included /usr/share/perl/5.14/ExtUtils/MANIFEST.SKIP
+# Avoid version control files.
+\bRCS\b
+\bCVS\b
+\bSCCS\b
+,v$
+\B\.svn\b
+\B\.git\b
+\B\.gitignore\b
+\b_darcs\b
+\B\.cvsignore$
+
+# Avoid VMS specific MakeMaker generated files
+\bDescrip.MMS$
+\bDESCRIP.MMS$
+\bdescrip.mms$
+
+# Avoid Makemaker generated and utility files.
+\bMANIFEST\.bak
+\bMakefile$
+\bblib/
+\bMakeMaker-\d
+\bpm_to_blib\.ts$
+\bpm_to_blib$
+\bblibdirs\.ts$         # 6.18 through 6.25 generated this
+
+# Avoid Module::Build generated and utility files.
+\bBuild$
+\b_build/
+\bBuild.bat$
+\bBuild.COM$
+\bBUILD.COM$
+\bbuild.com$
+
+# Avoid temp and backup files.
+~$
+\.old$
+\#$
+\b\.#
+\.bak$
+\.tmp$
+\.#
+\.rej$
+
+# Avoid OS-specific files/dirs
+# Mac OSX metadata
+\B\.DS_Store
+# Mac OSX SMB mount metadata files
+\B\._
+
+# Avoid Devel::Cover and Devel::CoverX::Covered files.
+\bcover_db\b
+\bcovered\b
+
+# Avoid MYMETA files
+^MYMETA\.
+#!end included /usr/share/perl/5.14/ExtUtils/MANIFEST.SKIP
+
+# Avoid configuration metadata file
+^MYMETA\.
+
+# Avoid Module::Build generated and utility files.
+\bBuild$
+\bBuild.bat$
+\b_build
+\bBuild.COM$
+\bBUILD.COM$
+\bbuild.com$
+^MANIFEST\.SKIP
+
+# Avoid archives of this distribution
+\bPasswd-Keyring-Gnome-[\d\.\_]+
+
+# Repo-related
+^\.hg
+^\.bitbucket\.url
+^version_hook\.py
+^ignore\.txt
+^make_release\.pl
+
+# Produced
+^lib/Passwd/Keyring/Gnome\.[co]$
+blib*
+Makefile
+Makefile.old
+Build
+Build.bat
+_build*
+pm_to_blib*
+*.tar.gz
+.lwpcookies
+cover_db
+pod2htm*.tmp
+Passwd-Keyring-Gnome-*

lib/Passwd/Keyring/OSXKeychain.pm

+package Passwd::Keyring::Gnome;
+
+use warnings;
+use strict;
+#use parent 'Keyring';
+
+require DynaLoader;
+#require AutoLoader;
+
+use base 'DynaLoader';
+
+=head1 NAME
+
+Passwd::Keyring::Gnome - Password storage implementation based on GNOME Keyring.
+
+=head1 VERSION
+
+Version 0.2502
+
+=cut
+
+our $VERSION = '0.2502';
+
+bootstrap Passwd::Keyring::Gnome $VERSION;
+
+=head1 SYNOPSIS
+
+Gnome Keyring based implementation of L<Keyring>. Provide secure
+storage for passwords and similar sensitive data.
+
+    use Passwd::Keyring::Gnome;
+
+    my $keyring = Passwd::Keyring::Gnome->new(
+         app=>"blahblah scraper",
+         group=>"Johnny web scrapers",
+    );
+
+    my $username = "John";  # or get from .ini, or from .argv...
+
+    my $password = $keyring->get_password($username, "blahblah.com");
+    unless( $password ) {
+        $password = <somehow interactively prompt for password>;
+
+        # securely save password for future use
+        $keyring->set_password($username, "blahblah.com");
+    }
+
+    login_somewhere_using($username, $password);
+    if( password_was_wrong ) {
+        $keyring->clear_password($username, "blahblah.com");
+    }
+
+Note: see L<Passwd::Keyring::Auto::KeyringAPI> for detailed comments
+on keyring method semantics (this document is installed with
+C<Passwd::Keyring::Auto> package).
+
+=head1 SUBROUTINES/METHODS
+
+=head2 new(app=>'app name', group=>'passwords folder')
+
+Initializes the processing. Croaks if gnome keyring does not 
+seem to be available.
+
+Handled named parameters: 
+
+- app - symbolic application name (not used at the moment, but can be
+  used in future as comment and in prompts, so set sensibly)
+
+- group - name for the password group (will be visible in seahorse so
+  can be used by end user to manage passwords, different group means
+  different password set, a few apps may share the same group if they
+  need to use the same passwords set)
+
+=cut
+
+sub new {
+    my ($cls, %opts) = @_;
+    my $self = {
+        app => $opts{app} || 'Passwd::Keyring',
+        group => $opts{group} || 'Passwd::Keyring unclassified passwords',
+    };
+    bless $self;
+
+    # TODO: catch and rethrow exceptions
+    my $name = Passwd::Keyring::Gnome::_get_default_keyring_name();
+    croak ("Gnome Keyring seems unavailable") unless $name;
+
+    return $self;
+}
+
+=head2 set_password(username, password, domain)
+
+Sets (stores) password identified by given domain for given user 
+
+=cut
+
+sub set_password {
+    my ($self, $user_name, $user_password, $domain) = @_;
+    Passwd::Keyring::Gnome::_set_password($user_name, $user_password, $domain,
+                                          $self->{app}, $self->{group});
+}
+
+=head2 get_password($user_name, $domain)
+
+Reads previously stored password for given user in given app.
+If such password can not be found, returns undef.
+
+=cut
+
+sub get_password {
+    my ($self, $user_name, $domain) = @_;
+    my $pwd = Passwd::Keyring::Gnome::_get_password($user_name, $domain,
+                                                    $self->{app}, $self->{group});
+    #return undef if (!defined($pwd)) or $pwd eq "";
+    return $pwd;
+}
+
+=head2 clear_password($user_name, $domain)
+
+Removes given password (if present)
+
+Returns how many passwords actually were removed 
+
+=cut
+
+sub clear_password {
+    my ($self, $user_name, $domain) = @_;
+    return Passwd::Keyring::Gnome::_clear_password(
+        $user_name, $domain, $self->{app}, $self->{group});
+}
+
+=head2 is_persistent
+
+Returns info, whether this keyring actually saves passwords persistently.
+
+(true in this case)
+
+=cut
+
+sub is_persistent {
+    my ($self) = @_;
+    return 1;
+}
+
+
+=head1 AUTHOR
+
+Marcin Kasperski
+
+=head1 BUGS
+
+Please report any bugs or feature requests to 
+issue tracker at L<https://bitbucket.org/Mekk/perl-keyring-gnome>.
+
+=head1 SUPPORT
+
+You can find documentation for this module with the perldoc command.
+
+    perldoc Passwd::Keyring::Gnome
+
+You can also look for information at:
+
+L<http://search.cpan.org/~mekk/Passwd-Keyring-Gnome/>
+
+Source code is tracked at:
+
+L<https://bitbucket.org/Mekk/perl-keyring-gnome>
+
+=head1 LICENSE AND COPYRIGHT
+
+Copyright 2012 Marcin Kasperski.
+
+This program is free software; you can redistribute it and/or modify it
+under the terms of either: the GNU General Public License as published
+by the Free Software Foundation; or the Artistic License.
+
+See http://dev.perl.org/licenses/ for more information.
+
+=cut
+
+
+1; # End of Passwd::Keyring::Gnome
+
+#!perl -T
+
+use Test::More tests => 1;
+
+BEGIN {
+    use_ok( 'Passwd::Keyring::Gnome' ) || print "Bail out!\n";
+}
+
+diag( "Testing Passwd::Keyring::Gnome $Passwd::Keyring::Gnome::VERSION, Perl $], $^X" );
+diag( "Consider spawning  seahorse  and checking whether all passwords are properly wiped after tests" );

t/01-set-and-get.t

+#!perl -T
+
+use strict;
+use warnings;
+use Test::Simple tests => 8;
+
+use Passwd::Keyring::Gnome;
+
+my $ring = Passwd::Keyring::Gnome->new;
+
+ok( defined($ring) && ref $ring eq 'Passwd::Keyring::Gnome',   'new() works' );
+
+my $USER = 'John';
+my $PASSWORD = 'verysecret';
+
+$ring->set_password($USER, $PASSWORD, 'my@@domain');
+
+ok( 1, "set_password works" );
+
+ok( $ring->get_password($USER, 'my@@domain') eq $PASSWORD, "get recovers");
+
+ok( $ring->clear_password($USER, 'my@@domain') eq 1, "clear_password removed one password" );
+
+ok( !defined($ring->get_password($USER, 'my@@domain')), "no password after clear");
+
+ok( $ring->clear_password($USER, 'my@@domain') eq 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" );

t/02-is-persistent.t

+#!perl -T
+
+use strict;
+use warnings;
+use Test::Simple tests => 2;
+
+use Passwd::Keyring::Gnome;
+
+my $ring = Passwd::Keyring::Gnome->new;
+
+ok( defined($ring) && ref $ring eq 'Passwd::Keyring::Gnome',   'new() works' );
+
+ok( $ring->is_persistent eq 1, "is_persistent knows we are persistent");
+

t/03-many-sets-and-gets.t

+#!perl -T
+
+use strict;
+use warnings;
+use Test::Simple tests => 11;
+
+use Passwd::Keyring::Gnome;
+
+my $PSEUDO_DOMAIN = 'my@@domain';
+my $OTHER_DOMAIN = 'other domain';
+
+my $ring = Passwd::Keyring::Gnome->new(app=>"Passwd::Keyring::Gnome", group=>"Unit tests");
+
+ok( defined($ring) && ref $ring eq 'Passwd::Keyring::Gnome',   'new() works' );
+
+$ring->set_password("Paul", "secret-Paul", $PSEUDO_DOMAIN);
+$ring->set_password("Gregory", "secret-Greg", $PSEUDO_DOMAIN);#
+$ring->set_password("Paul", "secret-Paul2", $OTHER_DOMAIN);
+$ring->set_password("Duke", "secret-Duke", $PSEUDO_DOMAIN);
+
+ok( 1, "set_password works" );
+
+ok( $ring->get_password("Paul", $PSEUDO_DOMAIN) eq 'secret-Paul', "get works");
+
+ok( $ring->get_password("Gregory", $PSEUDO_DOMAIN) eq 'secret-Greg', "get works");
+
+ok( $ring->get_password("Paul", $OTHER_DOMAIN) eq 'secret-Paul2', "get works");
+
+ok( $ring->get_password("Duke", $PSEUDO_DOMAIN) eq 'secret-Duke', "get works");
+
+ok( $ring->clear_password("Paul", $PSEUDO_DOMAIN) eq 1, "clear_password removed 1");
+
+ok( ! defined($ring->get_password("Paul", $PSEUDO_DOMAIN)), "get works");
+
+ok( $ring->get_password("Gregory", $PSEUDO_DOMAIN) eq 'secret-Greg', "get works");
+
+ok( $ring->get_password("Paul", $OTHER_DOMAIN) eq 'secret-Paul2', "get works");
+
+ok( $ring->get_password("Duke", $PSEUDO_DOMAIN) eq 'secret-Duke', "get works");
+
+
+# Note: cleanup is performed by test 04, we test passing data to
+#       separate program.

t/04-recovering-in-sep-prog.t

+#!perl -T
+
+use strict;
+use warnings;
+use Test::Simple tests => 13;
+
+use Passwd::Keyring::Gnome;
+
+my $PSEUDO_DOMAIN = 'my@@domain';
+my $OTHER_DOMAIN = 'other domain';
+
+my $ring = Passwd::Keyring::Gnome->new(app=>"Passwd::Keyring::Gnome", group=>"Unit tests");
+
+ok( defined($ring) && ref $ring eq 'Passwd::Keyring::Gnome',   'new() works' );
+
+ok( ! defined($ring->get_password("Paul", $PSEUDO_DOMAIN)), "get works");
+
+ok( $ring->get_password("Gregory", $PSEUDO_DOMAIN) eq 'secret-Greg', "get works");
+
+ok( $ring->get_password("Paul", $OTHER_DOMAIN) eq 'secret-Paul2', "get works");
+
+ok( $ring->get_password("Duke", $PSEUDO_DOMAIN) eq 'secret-Duke', "get works");
+
+ok( $ring->clear_password("Gregory", $PSEUDO_DOMAIN) eq 1, "clear clears");
+
+ok( ! defined($ring->get_password("Gregory", $PSEUDO_DOMAIN)), "clear cleared");
+
+ok( $ring->get_password("Paul", $OTHER_DOMAIN) eq 'secret-Paul2', "get works");
+
+ok( $ring->get_password("Duke", $PSEUDO_DOMAIN) eq 'secret-Duke', "get works");
+
+ok( $ring->clear_password("Paul", $OTHER_DOMAIN) eq 1, "clear clears");
+
+ok( $ring->clear_password("Duke", $PSEUDO_DOMAIN) eq 1, "clear clears");
+
+ok( ! defined($ring->get_password("Paul", $PSEUDO_DOMAIN)), "clear cleared");
+ok( ! defined($ring->get_password("Duke", $PSEUDO_DOMAIN)), "clear cleared");
+
+
+

t/05-many-sets-and-gets-with-name.t

+#!perl -T
+
+use strict;
+use warnings;
+use Test::Simple tests => 20;
+
+use Passwd::Keyring::Gnome;
+
+my $DOMAIN_A = 'my@@domain';
+my $DOMAIN_B = 'bum trala la';
+my $DOMAIN_C = 'other domain';
+
+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";
+
+my $ring = Passwd::Keyring::Gnome->new(app=>"Passwd::Keyring::Gnome", group=>"Unit tests (secrets)");
+
+ok( defined($ring) && ref $ring eq 'Passwd::Keyring::Gnome',   'new() works' );
+
+$ring->set_password($USER1, $PWD1, $DOMAIN_B);
+$ring->set_password($USER2, $PWD2, $DOMAIN_B);#
+$ring->set_password($USER1, $PWD1_ALT, $DOMAIN_C);
+$ring->set_password($USER4, $PWD4, $DOMAIN_B);
+
+ok( 1, "set_password works" );
+
+ok( $ring->get_password($USER1, $DOMAIN_B) eq $PWD1, "get works");
+
+ok( $ring->get_password($USER2, $DOMAIN_B) eq $PWD2, "get works");
+
+ok( $ring->get_password($USER1, $DOMAIN_C) eq $PWD1_ALT, "get works");
+
+ok( $ring->get_password($USER4, $DOMAIN_B) eq $PWD4, "get works");
+
+$ring->clear_password($USER1, $DOMAIN_B);
+ok(1, "clear_password works");
+
+ok( ! defined($ring->get_password($USER1, $DOMAIN_A)), "get works");
+
+ok( ! defined($ring->get_password($USER2, $DOMAIN_A)), "get works");
+
+ok( $ring->get_password($USER2, $DOMAIN_B) eq $PWD2, "get works");
+
+ok( $ring->get_password($USER1, $DOMAIN_C) eq $PWD1_ALT, "get works");
+
+ok( $ring->get_password($USER4, $DOMAIN_B) eq $PWD4, "get works");
+
+ok( $ring->clear_password($USER2, $DOMAIN_B) eq 1, "clear clears");
+
+ok( ! defined($ring->get_password($USER2, $DOMAIN_A)), "clear cleared");
+
+ok( $ring->get_password($USER1, $DOMAIN_C) eq $PWD1_ALT, "get works");
+
+ok( $ring->get_password($USER4, $DOMAIN_B) eq $PWD4, "get works");
+
+ok( $ring->clear_password($USER1, $DOMAIN_C) eq 1, "clear clears");
+
+ok( $ring->clear_password($USER4, $DOMAIN_B) eq 1, "clear clears");
+
+ok( ! defined($ring->get_password($USER1, $DOMAIN_C)), "clear cleared");
+ok( ! defined($ring->get_password($USER4, $DOMAIN_B)), "clear cleared");
+
+
+
+
+

t/06-recovering-with-app-change.t

+#!perl -T
+
+use strict;
+use warnings;
+use Test::More tests => 16;
+
+use Passwd::Keyring::Gnome;
+
+my $USER = "Herakliusz";
+my $DOMAIN = "test domain";
+my $PWD = "arcytajne haslo";
+my $PWD2 = "inny sekret";
+
+my $APP1 = "Passwd::Keyring::Unit tests (1)";
+my $APP2 = "Passwd::Keyring::Unit tests (2)";
+my $GROUP1 = "Passwd::Keyring::Unit tests - group 1";
+my $GROUP2 = "Passwd::Keyring::Unit tests - group 2";
+my $GROUP3 = "Passwd::Keyring::Unit tests - group 3";
+
+my @cleanups;
+
+{
+    my $ring = Passwd::Keyring::Gnome->new(app=>$APP1, group=>$GROUP1);
+
+    ok( defined($ring) && ref $ring eq 'Passwd::Keyring::Gnome',   'new() works' );
+
+    ok( ! defined($ring->get_password($USER, $DOMAIN)), "initially unset");
+
+    $ring->set_password($USER, $PWD, $DOMAIN);
+    ok(1, "set password");
+
+    ok( $ring->get_password($USER, $DOMAIN) eq $PWD, "normal get works");
+
+    push @cleanups, sub {
+        ok( $ring->clear_password($USER, $DOMAIN) eq 1, "clearing");
+    };
+}
+
+
+# Another object with the same app and group
+
+{
+    my $ring = Passwd::Keyring::Gnome->new(app=>$APP1, group=>$GROUP1);
+
+    ok( defined($ring) && ref $ring eq 'Passwd::Keyring::Gnome', 'second new() works' );
+
+    ok( $ring->get_password($USER, $DOMAIN) eq $PWD, "get from another ring with the same data works");
+}
+
+# Only app changes
+{
+    my $ring = Passwd::Keyring::Gnome->new(app=>$APP2, group=>$GROUP1);
+
+    ok( defined($ring) && ref $ring eq 'Passwd::Keyring::Gnome', 'third new() works' );
+
+    ok( $ring->get_password($USER, $DOMAIN) eq $PWD, "get from another ring with changed app but same group works");
+}
+
+# Only group changes
+my $sec_ring;
+{
+    my $ring = Passwd::Keyring::Gnome->new(app=>$APP1, group=>$GROUP2);
+
+    ok( defined($ring) && ref $ring eq 'Passwd::Keyring::Gnome', 'third new() works' );
+
+    ok( ! defined($ring->get_password($USER, $DOMAIN)), "changing group forces another password");
+
+    # To test whether original won't be spoiled
+    $ring->set_password($USER, $PWD2, $DOMAIN);
+
+    push @cleanups, sub {
+        ok( $ring->clear_password($USER, $DOMAIN) eq 1, "clearing");
+    };
+}
+
+# App and group change
+{
+    my $ring = Passwd::Keyring::Gnome->new(app=>$APP2, group=>$GROUP3);
+
+    ok( defined($ring) && ref $ring eq 'Passwd::Keyring::Gnome', 'third new() works' );
+
+    ok( ! defined($ring->get_password($USER, $DOMAIN)), "changing group and app forces another password");
+
+}
+
+# Re-reading original to check whether it was properly kept
+{
+    my $ring = Passwd::Keyring::Gnome->new(app=>$APP1, group=>$GROUP1);
+
+    ok( defined($ring) && ref $ring eq 'Passwd::Keyring::Gnome', 'second new() works' );
+
+    ok( $ring->get_password($USER, $DOMAIN) eq $PWD, "get original after changes in other group works");
+}
+
+# Cleanup
+foreach my $cleanup (@cleanups) {
+    $cleanup->();
+}
+

t/07-ugly-chars.t

+#!perl -T
+
+use strict;
+use warnings;
+use Test::Simple tests => 4;
+
+use Passwd::Keyring::Gnome;
+
+my $UGLY_NAME = "Joh ## no ^^ »ąćęłóśż«";
+my $UGLY_PWD =  "«tajne hasło»";
+my $UGLY_DOMAIN = '«do»–main';
+
+my $ring = Passwd::Keyring::Gnome->new(app=>"Passwd::Gnome::Keyring unit tests", group=>"Ugly chars");
+
+ok( defined($ring) && ref $ring eq 'Passwd::Keyring::Gnome',   'new() works' );
+
+$ring->set_password($UGLY_NAME, $UGLY_PWD, $UGLY_DOMAIN);
+
+ok( 1, "set_password with ugly chars works" );
+
+ok( $ring->get_password($UGLY_NAME, $UGLY_DOMAIN) eq $UGLY_PWD, "get works with ugly characters");
+
+ok( $ring->clear_password($UGLY_NAME, $UGLY_DOMAIN) eq 1, "clear clears");
+

t/08-verylong-params.t

+#!perl -T
+
+use strict;
+use warnings;
+use Test::Simple tests => 4;
+
+use Passwd::Keyring::Gnome;
+
+my $APP = "Passwd::Gnome::Keyring unit test 08 ";
+$APP .= "X" x (256 - length($APP));
+my $GROUP = "Passwd::Gnome::Keyring unit tests ";
+$GROUP .= "X" x (256 - length($GROUP));
+
+my $USER = "A" x 256;
+my $PWD =  "B" x 256;
+my $DOMAIN = 'C' x 256;
+
+my $ring = Passwd::Keyring::Gnome->new(
+    app=>$APP, group=>$GROUP);
+
+ok( defined($ring) && ref $ring eq 'Passwd::Keyring::Gnome',   'new() works with long params' );
+
+$ring->set_password($USER, $PWD, $DOMAIN);
+
+ok( 1, "set_password with long params works" );
+
+ok( $ring->get_password($USER, $DOMAIN) eq $PWD, "get_password with long params works");
+
+ok( $ring->clear_password($USER, $DOMAIN) eq 1, "clear_password with long params works");
+
+#!perl -T
+
+use 5.006;
+use strict;
+use warnings;
+use Test::More tests => 3;
+
+sub not_in_file_ok {
+    my ($filename, %regex) = @_;
+    open( my $fh, '<', $filename )
+        or die "couldn't open $filename for reading: $!";
+
+    my %violated;
+
+    while (my $line = <$fh>) {
+        while (my ($desc, $regex) = each %regex) {
+            if ($line =~ $regex) {
+                push @{$violated{$desc}||=[]}, $.;
+            }
+        }
+    }
+
+    if (%violated) {
+        fail("$filename contains boilerplate text");
+        diag "$_ appears on lines @{$violated{$_}}" for keys %violated;
+    } else {
+        pass("$filename contains no boilerplate text");
+    }
+}
+
+sub module_boilerplate_ok {
+    my ($module) = @_;
+    not_in_file_ok($module =>
+        'the great new $MODULENAME'   => qr/ - The great new /,
+        'boilerplate description'     => qr/Quick summary of what the module/,
+        'stub function definition'    => qr/function[12]/,
+    );
+}
+
+TODO: {
+  local $TODO = "Need to replace the boilerplate text";
+
+  not_in_file_ok(README =>
+    "The README is used..."       => qr/The README is used/,
+    "'version information here'"  => qr/to provide version information/,
+  );
+
+  not_in_file_ok(Changes =>
+    "placeholder date/time"       => qr(Date/time)
+  );
+
+  module_boilerplate_ok('lib/Passwd/Keyring/Gnome.pm');
+
+
+}
+

t/cpan-meta-json.t

+use Test::More;
+eval "use Test::CPAN::Meta::JSON";
+plan skip_all => "Test::CPAN::Meta::JSON required for testing META.json" if $@;
+meta_json_ok();
+use Test::More;
+eval "use Test::CPAN::Meta";
+plan skip_all => "Test::CPAN::Meta required for testing META.yml" if $@;
+meta_yaml_ok();
+#!perl -T
+
+use strict;
+use warnings;
+use Test::More;
+
+unless ( $ENV{RELEASE_TESTING} ) {
+    plan( skip_all => "Author tests not required for installation" );
+}
+
+eval "use Test::CheckManifest 0.9";
+plan skip_all => "Test::CheckManifest 0.9 required" if $@;
+ok_manifest();
+use strict;
+use warnings;
+use Test::More;
+
+# Ensure a recent version of Test::Pod::Coverage
+my $min_tpc = 1.08;
+eval "use Test::Pod::Coverage $min_tpc";
+plan skip_all => "Test::Pod::Coverage $min_tpc required for testing POD coverage"
+    if $@;
+
+# Test::Pod::Coverage doesn't require a minimum Pod::Coverage version,
+# but older versions don't recognize some common documentation styles
+my $min_pc = 0.18;
+eval "use Pod::Coverage $min_pc";
+plan skip_all => "Pod::Coverage $min_pc required for testing POD coverage"
+    if $@;
+
+all_pod_coverage_ok();
+#!perl -T
+
+use strict;
+use warnings;
+use Test::More;
+
+# Ensure a recent version of Test::Pod
+my $min_tp = 1.22;
+eval "use Test::Pod $min_tp";
+plan skip_all => "Test::Pod $min_tp required for testing POD" if $@;
+
+all_pod_files_ok();
+# -*- coding: utf-8 -*-
+
+"""
+Updating version number on "hg tag".
+
+To use:
+
+  [hooks]
+  pre-tag=python:version_hook.py:version_update
+
+Note: pre-tag, not pretag! In the latter the changeset being tagged
+is already set.
+"""
+
+VERSION = "0.2502"
+
+UPDATED_FILES = [
+    "lib/Passwd/Keyring/Gnome.pm",
+    ]
+
+def _patch_perl_files(ui, new_version_no):
+    """
+    Patches all perl files to new version number, returns modified files.
+    """
+    import os, re
+    version_regexps = [
+        re.compile(r"^(?P<pfx>our +\$VERSION *= *').*?(?P<sfx>'.*)$"),
+        re.compile(r"^(?P<pfx>Version +)\d+\.\d+(\.\d+)?(?P<sfx>\.? *)$"),
+        ]
+
+    location = os.path.dirname(__file__)
+    updated_files = []
+    for candidate in UPDATED_FILES:
+        full_name = os.path.join(location, candidate)
+        changes = 0
+        file_lines = []
+        ui.note("Checking file %s\n" % candidate)
+        with open(full_name, "r") as input:
+            for line in input.readlines():
+                m = None
+                for rgxp in version_regexps:
+                    m = rgxp.search(line)
+                    if m:
+                        ui.note("Patching line %s" % line)
+                        break
+                if m:
+                    file_lines.append(
+                        m.group('pfx') + new_version_no + m.group('sfx') + "\n")
+                    changes += 1
+                else:
+                    file_lines.append(line)
+        if changes:
+            ui.status("Version updater: Replacing old version number with {0:>s} in {1}\n".format(new_version_no, full_name))
+            with open(full_name, "w") as output:
+                output.writelines(file_lines)
+            updated_files.append(full_name)
+    return updated_files
+    
+def version_update(repo, ui, hooktype, pats, opts, **kwargs):
+    """
+    Method used in mercurial version-update hook. Don't call directly.
+    """
+    import re
+    import mercurial.commands
+
+    # Regexps for handled version number syntaxes
+    tag_regexps = [
+        # something_1-2, something-1.2 and similar
+        re.compile(r"[^-_0-9][-_](?P<major>[0-9]+)[-_\.](?P<minor>[0-9]+)$"),
+        # 1.2, 1-2, 1_2
+        re.compile(r"^(?P<major>[0-9]+)[-_\.](?P<minor>[0-9]+)$"),
+        ]
+
+    if opts.get('local'):
+        ui.note("Version updater: ignoring local tag\n")
+        return
+    if opts.get('remove'):
+        ui.note("Version updater: ignoring tag removal\n")
+        return
+    if opts.get('rev'):
+        ui.note("Version updater: ignoring tag placed by rev\n")
+        return
+
+    if len(pats) != 1:
+        ui.warn("Version updater: unexpected arguments, pats=%s\n" % pats)
+        return True # means fail
+
+    tag_name = pats[0]
+
+    version_no = None
+    for tag_regexp in tag_regexps:
+        m = tag_regexp.search(tag_name)
+        if m:
+            version_no = "{major:>s}.{minor:>s}".format(**m.groupdict())
+            break
+    if not version_no:
+        ui.warn("Version updater: Given tag does not seem to be versioned. Please make proper tags (1.2, xxxx_1-2, xaear-aera-1.2 or similar\n")
+        return True # means fail
+
+    if version_no == VERSION:
+        ui.note("Version updater: version number {0:>s} is already correct\n".format(version_no))
+        return False # means OK
+
+    # Regexp for VERSION= line
+    py_version_regexp = re.compile(r"^VERSION *= *")
+
+    my_name = __file__
+    if my_name.endswith(".pyc") or my_name.endswith(".pyo"):
+        my_name = my_name[:-1]
+
+    ui.status("Version updater: Replacing old version number {0:>s} with {1:>s} in {2}\n".format(
+        VERSION, version_no, my_name))
+
+    file_lines = []
+    changes = 0
+    with open(my_name, "r") as input:
+        for line in input.readlines():
+            if py_version_regexp.search(line):
+                file_lines.append('VERSION = "%s"\n' % version_no)
+                changes += 1
+            else:
+                file_lines.append(line)
+    if not changes:
+        ui.warn("Version updater: Line starting with VERSION= not found in {0:>s}.\nPlease correct this file and retry\n".format(my_name))
+        return True #means fail
+    with open(my_name, "w") as output:
+        output.writelines(file_lines)
+
+    updated_perl_files = _patch_perl_files(ui, version_no)
+
+    ui.note("Commiting updated version number\n")
+    mercurial.commands.commit(
+        ui, repo,
+        my_name,
+        *updated_perl_files,
+        message="Version number set to %s" % version_no)
+    return False #means ok
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.