Test::Unix::User - Test::Builder based tests for Unix users and home directories


Test-Unix-User documentation  | view source Contained in the Test-Unix-User distribution.

Index


NAME

Top

Test::Unix::User - Test::Builder based tests for Unix users and home directories

VERSION

Top

Version 0.02

SYNOPSIS

Top

    use Test::Unix::User tests => 2;

    user_ok({ name => 'nik', uid => 1000, ... },
            "Verify nik's account");

    homedir_ok({ name => 'nik', perm => 0755, ... },
               "Verify nik's home directory");

Test::Unix::User automatically exports user_ok() and homedir_ok() to make it easier to test whether or not the Unix users and home directories on the system have been correctly configured.

Test::Unix::User uses Test::Builder, so plays nicely with Test::Simple, Test::More, and other Test::Builder based modules.

FUNCTIONS

Top

user_ok($spec, [ $test_name ]);

user_ok() tests that an account exists that matches the given specification.

The specification is a hashref that consists of one or more keys. Keys are taken from the User::pwent module, and are name, passwd, uid, gid, change, age, quota, comment, class, gecos, dir, shell, and expire. Some of these may not be supported on your platform. See User::pwent for more details.

Each value associated with a key is the value that that entry is supposed to have.

Only the name key is mandatory, the others are optional. If they are not present in the specification then they are not checked.

The $test_name is optional. If it is not present then a sensible one is generated following the form

    Checking user '$user' ($key, $key, $key, ...)

homedir_ok($spec, [ $test_name ]);

homedir_ok() checks that the home directory for a given user exists and matches the specification.

The specification is a hashref that consists of one or more keys. Valid keys are name, uid, gid, owner, group, and perm.

The name key is mandatory, the other keys are optional.

The $test_name is optional. If it is not present then a sensible one is generated following the form.

    Home directory for user '$user' ($key, $key, $key, ...)

Use uid when you want to check the numeric user id assigned to the directory, irrespective of the user name that is assigned to that uid. Use owner when you are interested in the name of the owner, without being concerned about the numeric UID. Use both of these together to ensure that the UID and the owner name match.

gid is to group as uid is to owner.

EXAMPLES

Top

Verify that an account exists

    user_ok({ name => 'nik' }, "'nik' exists as a user");

Verify that the account exists, that it has a given UID, and that the home directory and shell match. Omit the test name, rely on the default.

    user_ok({ name => 'nik', uid => 1001, dir => '/home/nik', 
	      shell => '/bin/sh');

Check that the home directory for 'nik' exists. Use an automatically generated test name.

    homedir_ok({ name => 'nik' });

Test that nik's home directory is owned by the 'nik' user, without worrying what UID is assigned to that user.

    homedir_ok({ name => 'nik', owner => 'nik' });

Ensure that nik's home directory is owned by uid 1000, and that uid 1000 maps back to the 'nik' user

    homedir_ok({ name => 'nik', uid => 1000, owner => 'nik');

Check the permissions on the home directory, and supply our own test name.

    homedir_ok({ name => 'nik', perm => 0755 },
               "Nik's home directory is correctly set");

SEE ALSO

Top

Test::Simple, Test::Builder, User::pwent.

AUTHOR

Top

Nik Clayton, nik@FreeBSD.org

BUGS

Top

Please report any bugs or feature requests to bug-test-unix-user@rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Test-Unix-User. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

COPYRIGHT & LICENSE

Top


Test-Unix-User documentation  | view source Contained in the Test-Unix-User distribution.