Skip to content

Commit 085ad42

Browse files
committed
Clean up tests a little and only run them as an administrator
1 parent 0a9898c commit 085ad42

File tree

1 file changed

+44
-63
lines changed

1 file changed

+44
-63
lines changed

t/netadmin.t

Lines changed: 44 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,84 +1,65 @@
1-
#test for Perl NetAdmin Module Extension.
2-
#Written by [email protected]
1+
use strict;
2+
use warnings;
3+
4+
use Test;
35

46
BEGIN {
5-
require Win32 unless defined &Win32::IsWin95;
6-
if (Win32::IsWin95) {
7-
print"1..0 # skip This module does not work on Win95\n";
7+
eval {require Win32};
8+
unless (defined &Win32::IsAdminUser && Win32::IsAdminUser()) {
9+
print"1..0 # skip Must be running as an administrator\n";
810
exit 0;
911
}
1012
};
1113

12-
use Win32::NetAdmin;
13-
14-
Win32::NetAdmin::GetDomainController('', '', $serverName);
14+
use Win32::NetAdmin qw(:DEFAULT UserCreate UserDelete UserGetAttributes
15+
LocalGroupCreate LocalGroupGetAttributes LocalGroupAddUsers
16+
LocalGroupIsMember LocalGroupDelete);
1517

16-
$serverName = '';
17-
$userName = 'TestUser';
18-
$password = 'password';
19-
$passwordAge = 0;
20-
$privilege = USER_PRIV_USER;
21-
$homeDir = 'c:\\';
22-
$comment = 'This is a test user';
23-
$flags = UF_SCRIPT;
24-
$scriptpath = 'C:\\';
25-
$groupName = 'TestGroup';
26-
$groupComment = "This is a test group";
18+
my $serverName = '';
19+
my $userName = 'TestUser';
20+
my $password = 'password';
21+
my $passwordAge = 0;
22+
my $privilege = USER_PRIV_USER;
23+
my $homeDir = 'c:\\';
24+
my $comment = 'This is a test user';
25+
my $flags = UF_SCRIPT;
26+
my $scriptpath = 'C:\\';
27+
my $groupName = 'TestGroup';
28+
my $groupComment = "This is a test group";
2729

28-
print "1..15\n";
30+
plan tests => 15;
2931

30-
# TODO: Check to make sure current account has rights to Create user accounts etc.
32+
ok(UserCreate($serverName, $userName, $password, $passwordAge, $privilege,
33+
$homeDir, $comment, $flags, $scriptpath));
3134

32-
Win32::NetAdmin::UserCreate($serverName, $userName, $password, $passwordAge, $privilege, $homeDir, $comment, $flags, $scriptpath) || print "not ";
33-
print "ok 1\n";
35+
ok(UserGetAttributes($serverName, $userName,
36+
my $Getpassword, my $GetpasswordAge, my $Getprivilege,
37+
my $GethomeDir, my $Getcomment, my $Getflags, my $Getscriptpath));
3438

35-
Win32::NetAdmin::UserGetAttributes($serverName, $userName, my $getpassword, $GetpasswordAge, $Getprivilege, $GethomeDir, $Getcomment, $Getflags, $Getscriptpath) || print "not ";
36-
print "ok 2\n";
39+
ok($passwordAge <= $GetpasswordAge && $passwordAge+5 >= $GetpasswordAge);
3740

38-
($passwordAge <= $GetpasswordAge && $passwordAge+5 >= $GetpasswordAge) || print "not ";
39-
print "ok 3\n";
40-
41-
if($serverName eq '')
42-
{
43-
# on a server this will be zero
44-
($Getprivilege == 0) || print "not ";
41+
if ($serverName eq '') {
42+
# on a server this will be zero
43+
ok($Getprivilege == 0);
4544
}
46-
else
47-
{
48-
($privilege == $Getprivilege) || print "not ";
45+
else {
46+
ok($privilege == $Getprivilege);
4947
}
50-
print "ok 4\n";
51-
52-
($homeDir eq $GethomeDir) || print "not ";
53-
print "ok 5\n";
54-
55-
($comment eq $Getcomment) || print "not ";
56-
print "ok 6\n";
57-
58-
($flags == ($Getflags&USER_PRIV_MASK)) || print "not ";
59-
print "ok 7\n";
60-
61-
($scriptpath eq $Getscriptpath) || print "not ";
62-
print "ok 8\n";
63-
64-
Win32::NetAdmin::LocalGroupCreate($serverName, $groupName, $groupComment) || print "not ";
65-
print "ok 9\n";
6648

67-
Win32::NetAdmin::LocalGroupGetAttributes($serverName, $groupName, $GetgroupComment) || print "not ";
68-
print "ok 10\n";
49+
ok($homeDir, $GethomeDir);
50+
ok($comment, $Getcomment);
51+
ok($flags == ($Getflags&USER_PRIV_MASK));
52+
ok($scriptpath, $Getscriptpath);
6953

70-
($groupComment eq $GetgroupComment) || print "not ";
71-
print "ok 11\n";
54+
ok(LocalGroupCreate($serverName, $groupName, $groupComment));
7255

73-
Win32::NetAdmin::LocalGroupAddUsers($serverName, $groupName, $userName) || print "not ";
74-
print "ok 12\n";
56+
ok(LocalGroupGetAttributes($serverName, $groupName, my $GetgroupComment));
57+
ok($groupComment, $GetgroupComment);
7558

76-
Win32::NetAdmin::LocalGroupIsMember($serverName, $groupName, $userName) || print "not ";
77-
print "ok 13\n";
59+
ok(LocalGroupAddUsers($serverName, $groupName, $userName));
7860

79-
Win32::NetAdmin::LocalGroupDelete($serverName, $groupName) || print "not ";
80-
print "ok 14\n";
61+
ok(LocalGroupIsMember($serverName, $groupName, $userName));
8162

82-
Win32::NetAdmin::UserDelete($serverName, $userName) || print "not ";
83-
print "ok 15\n";
63+
ok(LocalGroupDelete($serverName, $groupName));
8464

65+
ok(UserDelete($serverName, $userName));

0 commit comments

Comments
 (0)