Authen-Prepare
view release on metacpan or search on metacpan
t/01.passfile.t view on Meta::CPAN
my $entry = join( q{:}, @$arg_ref{qw(hostname username)} ) . q{:testpass};
open $fh, '>', $filename or die $!;
print $fh qq{$entry\n};
if ( defined $callback && ref $callback eq 'CODE' ) {
$callback->($fh);
}
chmod oct('0600'), $filename;
return $filename;
}
sub add_passfile_comment {
my ($fh) = @_;
print $fh qq{# commentedhost:user:wrongpass\n};
print $fh qq{*:user:rightpass\n};
return;
t/01.passfile.t view on Meta::CPAN
ok( defined $password, 'Retrieved password' );
is( $password, 'defaultpass', 'password is correct' );
unlink $passfile;
}
sub test_check_passfile {
my $passfile = create_passfile( \%arg );
my $authen = Authen::Prepare->new( {%arg} );
chmod oct('0000'), $passfile;
throws_ok { $authen->_check_passfile() }
qr{Unable to read unspecified password file},
q{Dies with unspecified password file};
$authen->passfile($passfile);
my $err_prefix = qr{Unable to use password file};
lives_ok { chmod oct('0604'), $passfile; } q{chmod 0644};
throws_ok { $authen->_check_passfile() } qr/other/,
q{Dies with 'other' permissions};
lives_ok { chmod oct('0640'), $passfile; } q{chmod 0640};
throws_ok { $authen->_check_passfile() } qr/group/,
q{Dies with 'group' permissions};
lives_ok { chmod oct('0600'), $passfile; } q{chmod 0640};
lives_ok { $authen->_check_passfile() }
q{Successfully reads password file};
unlink $passfile;
throws_ok { $authen->_check_passfile() } $err_prefix,
q{Dies with unreadable password file};
}
#------------------------------------------------------------------------------
( run in 0.449 second using v1.01-cache-2.11-cpan-496ff517765 )