HealthCheck-Diagnostic-FilePermissions

 view release on metacpan or  search on metacpan

lib/HealthCheck/Diagnostic/FilePermissions.pm  view on Meta::CPAN


    return {
        status => 'OK',
        info   => qq{Permissions are $actual for '$file'},
    };
}

sub check_owner {
    my ($self, $file, $owner) = @_;

    my $actual = getpwuid( ( stat $file )[4] );
    return {
        status => 'CRITICAL',
        info   => qq{Owner should be $owner but is $actual for '$file'},
    } unless $actual eq $owner;

    return {
        status => 'OK',
        info   => qq{Owner is $owner for '$file'},
    };
}

t/HealthCheck-Diagnostic-FilePermissions.t  view on Meta::CPAN

], 'Pass when sending in a string for the file list.' );

# Check that we can use a sub to generate the file names.
eq_or_diff( $run_check_or_error->(
    files => sub { $filename, $filename2 },
), [
    'OK', qq{Permissions are correct for '$filename' and '$filename2'},
], 'Pass when sending in a sub for the file list.' );

SKIP: {
     skip "chmod, getpwuid, or getgrgid not supported"
        if $^O eq 'MSWin32';

    # Check for permissions on the file.
    chmod( 0755, $filename );
    $diagnostic = HealthCheck::Diagnostic::FilePermissions->new(
        files       => [ $filename ],
        permissions => '493', # 0755 in decimal
    );
    eq_or_diff( $run_check_or_error->( $diagnostic ), [
        'OK', qq{Permissions are 0755 for '$filename'},

t/HealthCheck-Diagnostic-FilePermissions.t  view on Meta::CPAN

    # Test that it dies when we pass invalid access parameters.
    my %f = ( files => $filename );
    like $run_check_or_error->( %f, access => { write => 1, faker => 1 } ),
        qr/Invalid access parameter: faker/,
        'Fail when an access parameter hash is invalid.';
    like $run_check_or_error->( %f, access => 'wrx!e' ),
        qr/Invalid access parameter: e/,
        'Fail when an access parameter string is invalid.';

    # Test that we check for the group and owner correctly.
    my $owner = getpwuid( ( stat $filename )[4] );
    my $group = getgrgid( ( stat $filename )[5] );
    eq_or_diff( $run_check_or_error->( %f, owner => $owner ), [
        'OK', qq{Owner is $owner for '$filename'},
    ], 'Pass when the owner is correct.' );
    eq_or_diff( $run_check_or_error->( %f, group => $group ), [
        'OK', qq{Group is $group for '$filename'},
    ], 'Pass when the group is correct.' );
    eq_or_diff(
        $run_check_or_error->( %f, owner => $owner, group => $group ), [
        'OK', qq{Permissions are correct for '$filename'},



( run in 0.360 second using v1.01-cache-2.11-cpan-8d75d55dd25 )