summaryrefslogtreecommitdiffstats
path: root/testsuite/test9.pl
blob: 6281e59dec6a6fbf15e1e1ef4ef948d206fc05a6 (plain)
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
112
113
114
115
116
117
118
119
120
121
122
#!/usr/bin/perl -w

# expect:
#  - a new non-system group $groupname
#  - readding the group fails
#  - readding the group as a system group fails
#  - a new system group $groupname
#  - readding the group succeeds
#  - readding the group as a non-system group fails

use strict;

use lib_test;

my $error;
my $output;
my $groupname = find_unused_name();
my $cmd = "addgroup $groupname";

if (!defined (getgrnam($groupname))) {
	print "Testing (9.1) $cmd... ";
	$output=`$cmd 2>&1`;
	$error = ($?>>8);
	if ($error) {
	  print "failed\n  $cmd returned an errorcode != 0 ($error)\n";
	  exit $error;
	}
        if ($output !~ /^Adding group `addusertest\d+' \(GID \d+\) ...\nDone\.\n$/) {
          print "failed\n  $cmd returned unexpected output ($output)\n";
	  exit 1;
	}
	assert(check_group_exist ($groupname));

	print "ok\n";
}

# now testing whether adding the group again fails as it should

print "Testing (9.2) $cmd... ";
$output=`$cmd 2>&1`;
$error = ($?>>8);
if ($error ne 1) {
  print "failed\n  $cmd returned an errorcode != 1 ($error)\n";
  exit 1;
}
if ($output !~ /^addgroup: The group `addusertest\d+' already exists\.\n$/ ) {
  print "failed\n  $cmd returned unexpected output ($output)\n";
  exit 1;
}
print "ok\n";

# now testing whether adding the group again (as a system group)
# fails as it should (#405905)

$cmd = "addgroup --system $groupname";
print "Testing (9.3) $cmd... ";
$output=`$cmd 2>&1`;
$error = ($?>>8);
if ($error ne 1) {
  print "failed\n  $cmd returned an errorcode != 1 ($error)\n";
  exit $error;
}
if ($output !~ /^addgroup: The group `addusertest\d+' already exists and is not a system group. Exiting.$/ ) {
  print "failed\n  $cmd returned unexpected output ($output)\n";
  exit 1;
}
print "ok\n";

my $sysgroupname = find_unused_name();
$cmd = "addgroup --system $sysgroupname";

if (!defined (getgrnam($sysgroupname))) {
	print "Testing (9.4) $cmd... ";
	$output=`$cmd 2>&1`;
	$error = ($?>>8);
	if ($error) {
	  print "failed\n  $cmd returned an errorcode != 0 ($error)\n";
	  exit $error;
	}
        if ($output !~ /^Adding group `addusertest\d+' \(GID \d+\) ...\nDone\.\n$/ ) {
	  print "failed\n  $cmd returned unexpected output ($output)\n";
	  exit 1;
	}
	assert(check_group_exist ($sysgroupname));

	print "ok\n";
}

# now testing whether adding the group again passes as it should
# ("already exists as a system group")

$cmd = "addgroup --system $sysgroupname" ;
print "Testing (9.5) $cmd... ";
$output=`$cmd 2>&1`;
$error = ($?>>8);
if ($error) {
  print "failed\n  $cmd returned an errorcode != 0 ($error)\n";
  exit $error;
}
if ($output !~ /^addgroup: The group `addusertest\d+' already exists as a system group\. Exiting\.\n$/ ) {
  print "failed\n  $cmd returned unexpected output ($output)\n";
  exit 1;
}
print "ok\n";

# now testing whether adding the group again (as a normal group)
# fails as it should

$cmd = "addgroup $sysgroupname";
print "Testing (9.6) $cmd... ";
$output=`$cmd 2>&1`;
$error = ($?>>8);
if ($error ne 1) {
  print "failed\n  $cmd returned an errorcode != 1 ($error)\n";
  exit 1;
}
if ($output !~ /^addgroup: The group `addusertest\d+' already exists\.$/ ) {
  print "failed\n  $cmd returned unexpected output ($output)\n";
  exit 1;
}
print "ok\n";