#!/usr/bin/perl use warnings; use strict; use Test::More tests => 15; BEGIN { use_ok( 'Simba::CA' ); } my $ca = Simba::CA->new({ dbi_file => $ENV{SIMBA_DB_CONN} || "$ENV{HOME}/.dbi/simba_test"}); ok($ca, 'new CA'); my $uid; $uid = $ca->name2uid('root'); ok(defined($uid), 'root has uid'); cmp_ok($uid, '==', 0, 'root has correct uid'); $uid = $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 = $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 = $ca->name2uid('4711'); ok(defined($uid), 'numerical "user name" has uid'); cmp_ok($uid, '==', 4711, 'numerical "user name" has correct uid'); $uid = $ca->name2uid('i.am.quite.sure.that.this.is.not.a.real.username'); ok(defined($uid), 'unknown user has uid'); cmp_ok($uid, '==', $ca->{unknown_uid}, 'unknown user has correct uid'); my $gid = $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'); SKIP: { skip "not running as root", 1 unless $> == 0; mkdir "t/backup"; mkdir "t/backup/1"; open my $fh, '>:raw', 't/backup/1/t1'; print $fh "test\n"; close($fh); chown($ca->{unknown_uid}, $ca->{unknown_gid}, 't/backup/1/t1'); chmod(0644, 't/backup/1/t1'); my $f = { name => 't1', m => time(), s => 5, o => $ca->{unknown_uid}, g => $ca->{unknown_gid}, acl => 'u::rw-,g::r--,o:r--', }; $ca->{last_backup} = 't/backup/1'; ok($ca->present($f), "file with unknown owner is present"); }