File: test10.pl

package info (click to toggle)
adduser 3.153
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,560 kB
  • sloc: perl: 9,407; sh: 189; makefile: 22
file content (56 lines) | stat: -rw-r--r-- 1,588 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/perl -w


use strict;
use lib_test;

my $username = find_unused_name(); 
my $comment;
my $cmd;

sub testusercomment {
    my ($username, $comment, $fail_expected) = @_;
    $fail_expected ||= 0;
    $cmd = 'adduser --comment="'. $comment. '" --home=/nonexistent --disabled-password '. "$username";
    if (!defined (getpwnam($username))) {
        print "Testing $cmd... ";
        `$cmd`;
        my $error = ($?>>8);
        if( $fail_expected > 0 ) {
            assert(check_user_not_exist ($username));
        } else {
            if ($error) {
                print "failed\n  adduser returned an errorcode != 0 ($error)\n";
                exit $error;
            }
            assert(check_user_exist ($username));
            assert(check_user_comment ($username, $comment));
        }

    }

    $cmd = "deluser $username";
    if (defined (getpwnam($username))) {
        print "Testing $cmd... ";
        `$cmd`;
        my $error = ($?>>8);
        if ($error) {
            print "failed\n  adduser returned an errorcode != 0 ($error)\n";
            exit $error;
        }
        assert(check_user_not_exist ($username));
        print "ok\n";
    }
}

testusercomment($username, "Tom");
testusercomment($username, "Tom Omalley");
testusercomment($username, "Tom O\'Malley");
testusercomment($username, "Tom O\'Mälléy");
testusercomment($username, "Tomaß O\'Mälléy");
testusercomment($username, "Éom O\'Mälléy");
testusercomment($username, "Éoœm O\'Mälléy");
testusercomment($username, "Tom:Malley", 1);

# vim: tabstop=4 shiftwidth=4 expandtab