File: test8.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 (111 lines) | stat: -rw-r--r-- 2,799 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#!/usr/bin/perl -w

# expect:
#  - a new system user $USER
#  - Added to all groups in extra_groups
#  - a new group
#  - $USER added to new group
#  - Removal of $USER works
#  - removal of new group works
#  - system users do not get added to extra_groups

use strict;
use lib_test;

my $username = find_unused_name(); 
my $cmd = "adduser --comment test --disabled-password --add-extra-groups $username";

my %config;

my @adduserconf=("/etc/adduser.conf");
preseed_config(\@adduserconf,\%config);

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_exist ($username));

        foreach my $group (split ' ', $config{"extra_groups"}) {
          assert(check_user_in_group($username,$group));
        }
	print "ok\n";
}

my $newgroup = find_unused_name();

$cmd = "addgroup $newgroup";
unless (defined getgrnam($newgroup)) {
        print "Testing $cmd... ";
        `$cmd`;
        my $error = ($?>>8);
        if ($error) {
            print "failed\n  addgroup returned an errorcode != 0 ($error)\n";
            exit $error;
        }
        assert(check_group_exist ($newgroup));
        print "ok\n";
}

$cmd = "adduser $username $newgroup";
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_in_group ($username,$newgroup));
   print "ok\n";
}

$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";
	`rm -rf /home/$username`;
}

$cmd = "delgroup $newgroup";
unless (!defined getgrnam($newgroup)) {
        print "Testing $cmd... ";
        `$cmd`;
        my $error = ($?>>8);
        if ($error) {
            print "failed\n  delgroup returned an errorcode != 0 ($error)\n";
            exit $error;
        }
        assert(!check_group_exist ($newgroup));
        print "ok\n";
}

my $sysusername = find_unused_name(); 
$cmd = "adduser --system --comment test --disabled-password --add-extra-groups $sysusername";

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

        foreach my $group (split ' ', $config{"extra_groups"}) {
          assert(!check_user_in_group($username,$group));
        }
	print "ok\n";
}