simba/t/01_ca.t

64 lines
1.4 KiB
Perl
Raw Normal View History

#!/usr/bin/perl
use warnings;
use strict;
use Test::More 'no_plan';
BEGIN { use_ok( 'Simba::CA' ); }
my $ca = Simba::CA->new();
ok($ca, 'new CA');
my $uid;
$uid = Simba::CA::name2uid('root');
ok(defined($uid), 'root has uid');
cmp_ok($uid, '==', 0, 'root has correct uid');
$uid = Simba::CA::name2uid('bin');
ok(defined($uid), 'bin has uid');
my $bin_uid;
{
open(my $fd, '<', '/etc/passwd');
while (<$fd>) {
if (/^bin:[^:]*:(\d+):/) {
$bin_uid = $1;
}
}
}
cmp_ok($uid, '==', $bin_uid, 'bin has correct uid');
$uid = Simba::CA::name2uid('daemon');
ok(defined($uid), 'daemon has uid');
my $daemon_uid;
{
open(my $fd, '<', '/etc/passwd');
while (<$fd>) {
if (/^daemon:[^:]*:(\d+):/) {
$daemon_uid = $1;
}
}
}
cmp_ok($uid, '==', $daemon_uid, 'daemon has correct uid');
$uid = Simba::CA::name2uid('4711');
ok(defined($uid), 'numerical "user name" has uid');
cmp_ok($uid, '==', 4711, 'numerical "user name" has correct uid');
$uid = Simba::CA::name2uid('i.am.quite.sure.that.this.is.not.a.real.username');
ok(defined($uid), 'unknown user has uid');
cmp_ok($uid, '==', -2, 'unknown user has correct uid');
my $gid = Simba::CA::name2gid('adm');
ok(defined($gid), 'adm has gid');
my $adm_gid;
{
open(my $fd, '<', '/etc/group');
while (<$fd>) {
if (/^adm:[^:]*:(\d+):/) {
$adm_gid = $1;
}
}
}
cmp_ok($gid, '==', $adm_gid, 'adm has correct gid');