chiark / gitweb /
new alarm workings
[chiark-utils.git] / cprogs / really.testcases
1 #!/usr/bin/perl
2
3 $testuser=   'testac';
4 $testgroup=  'testac';
5 $testuid=    1000;
6 $testgid=    1000;
7 @testxgids=  qw(1000);
8 $numgid=     50008;
9 $othergroup= 'daemon';
10 $othergid=   1;
11
12 sub parseid ($) {
13     my ($id) = @_;
14     my $orgid= $id;
15     my $out= '';
16     my $part;
17     chomp($id);
18     $id =~ s/^uid=// or return $id =~ m/\n/ ? "ERROR: $`" : "ERROR: $id";
19     $id =~ s/^(\d+)// or return $orgid;
20     $out= $1;
21     $id =~ s/^\([^\)]+\)//; $id =~ s/^\s+// or return $orgid;
22     $id =~ s/^gid=(\d+)// or return $orgid;
23     $out.= " $1";
24     $id =~ s/^\([^\)]+\)//; $id =~ s/^\s+// or return $orgid;
25     $id =~ s/^groups=// or return $orgid;
26     for $part (split(/,/,$id)) {
27         $part =~ s/^(\d+)// or return $orgid;
28         $out.= " $1";
29         $part =~ s/^\([^\)]+\)//; $part eq '' or return $orgid;
30     }
31     return $out;
32 }
33
34 $org= `id`;
35 $org =~ m/^uid=\d+\(([^\)]+)\) gid=\d+\(([^\)]+)\) / or die "$org ?";
36 $orguser= $1; $orggroup= $2;
37 $org= parseid($org);
38 $org =~ m/^\d+ \d+ / or die $org;
39 ($orguid,$orggid,@orgxgids)= split(/ /,$org);
40
41 $tests= <<END;
42 -u $testuser
43 $testuid $testgid @testxgids
44
45 -u $testuser -z
46 ERROR: -z|--groupsclear must be accompanied by some groups
47
48 -u $testuser -g $othergroup
49 $testuid $othergid @testxgids $othergid
50
51 -u $testuser -z -g $othergroup
52 ERROR: -u|--user may not be used with -z|--groupsclear
53
54 -u $testuser -G $numgid -g $othergroup
55 $testuid $numgid @testxgids $numgid $othergid
56
57 -u $testuser -z -G $numgid -g $othergroup
58 ERROR: -u|--user may not be used with -z|--groupsclear
59
60 -u $testuser -g $testgroup -G $testgid
61 $testuid $testgid @testxgids
62
63 -u $testuser -z -g $testgroup -G $testgid
64 ERROR: -u|--user may not be used with -z|--groupsclear
65
66 -u $testuser -g $othergroup -g $testgroup -G $testgid
67 $testuid $othergid @testxgids $othergid
68
69 -u $testuser -z -g $othergroup -g $testgroup -G $testgid
70 ERROR: -u|--user may not be used with -z|--groupsclear
71
72 -u $testuser -G $numgid -g $othergroup -g $testgroup -G $testgid
73 $testuid $numgid @testxgids $numgid $othergid
74
75 -u $testuser -z -G $numgid -g $othergroup -g $testgroup -G $testgid
76 ERROR: -u|--user may not be used with -z|--groupsclear
77
78
79 0 $orggid @orgxgids
80
81 -i $testuser
82 $testuid $orggid @orgxgids
83
84 -i $testuser -z
85 ERROR: -z|--groupsclear must be accompanied by some groups
86
87 -i $testuser -g $othergroup
88 $testuid $othergid @orgxgids $othergid
89
90 -i $testuser -z -g $othergroup
91 $testuid $othergid $othergid
92
93 -i $testuser -G $numgid -g $othergroup
94 $testuid $numgid @orgxgids $numgid $othergid
95
96 -i $testuser -z -G $numgid -g $othergroup
97 $testuid $numgid $numgid $othergid
98
99 -i $testuser -g $orggroup -G $orggid
100 $testuid $orggid @orgxgids
101
102 -i $testuser -z -g $orggroup -G $orggid
103 $testuid $orggid $orggid
104
105 -i $testuser -g $othergroup -g $orggroup -G $orggid
106 $testuid $othergid @orgxgids $othergid
107
108 -i $testuser -z -g $othergroup -g $orggroup -G $orggid
109 $testuid $othergid $othergid $orggid
110
111 -i $testuser -G $numgid -g $othergroup -g $orggroup -G $orggid
112 $testuid $numgid @orgxgids $numgid $othergid
113
114 -i $testuser -z -G $numgid -g $othergroup -g $orggroup -G $orggid
115 $testuid $numgid $numgid $othergid $orggid
116
117
118 0 $orggid @orgxgids
119
120 -z
121 ERROR: -z|--groupsclear must be accompanied by some groups
122
123 -g $othergroup
124 $orguid $othergid @orgxgids $othergid
125
126 -z -g $othergroup
127 $orguid $othergid $othergid
128
129 -G $numgid -g $othergroup
130 $orguid $numgid @orgxgids $numgid $othergid
131
132 -z -G $numgid -g $othergroup
133 $orguid $numgid $numgid $othergid
134
135 -g $orggroup -G $orggid
136 $orguid $orggid @orgxgids
137
138 -z -g $orggroup -G $orggid
139 $orguid $orggid $orggid
140
141 -g $othergroup -g $orggroup -G $orggid
142 $orguid $othergid @orgxgids $othergid
143
144 -z -g $othergroup -g $orggroup -G $orggid
145 $orguid $othergid $othergid $orggid
146
147 -G $numgid -g $othergroup -g $orggroup -G $orggid
148 $orguid $numgid @orgxgids $numgid $othergid
149
150 -z -G $numgid -g $othergroup -g $orggroup -G $orggid
151 $orguid $numgid $numgid $othergid $orggid
152
153
154 ERROR: sorry: Permission denied
155 ./really-test -u $testuser -g staff
156 END
157
158 @tests= split(/\n/,$tests);
159 for ($i=0; $i<$#tests; $i+=3) {
160     $out= `$tests[$i+2] ./really-test $tests[$i] id 2>&1`;
161     $newout= parseid($out);
162     print("OK $tests[$i] ($tests[$i+2])\n"), next if $newout eq $tests[$i+1];
163     die "$newout != $tests[$i+1] ($tests[$i]) $i";
164 }