App-LXC-Container
view release on metacpan or search on metacpan
'3rd test with mocked local net OK';
output_like # 4 - insert fails
{ eval '$_->_local_net();'; }
qr{^$},
qr{^nft: insert rule inet lxc forward jump localfilter: mockup failed$},
'4th test with mocked local net OK';
output_like # 5 - 2nd add fails
{ eval '$_->_local_net();'; }
qr{^$},
qr{^nft: add rule inet lxc localfilter ip saddr .+ reject: mockup failed$},
'5th test with mocked local net OK';
#########################################################################
# testing set-up of user accounts in (modified!) container:
_setup_dir('/etc');
_setup_file('/etc/passwd',
'root:x:0:0:root:/root:/bin/sh',
'daemon:x:1:1:daemon:/bin:/usr/sbin/nologin');
_setup_file('/etc/shadow',
'root:!:19191:0:99999:99:::',
'daemon:*:19191:0:99999:99:::');
_setup_file('/etc/group',
'root:x:0:',
'daemon:x:1:',
'other:x:42:some,root,one',
'dummy:x:12345:dummy');
_setup_file('/etc/gshadow',
'root:*::',
'daemon:*::');
$App::LXC::Container::Run::_root_etc = TMP_PATH . '/etc/';
_remove_file('/lxc/run-test-1/etc/group');
_remove_file('/lxc/run-test-1/etc/gshadow');
_remove_file('/lxc/run-test-1/etc/passwd');
_remove_file('/lxc/run-test-1/etc/shadow');
_remove_dir(TMP_PATH . '/lxc/run-test-1/etc');
eval '$_->_prepare_user();';
like($@,
qr{^can't open .+/run-test-1/etc/group': No such file or directory$re_eval},
'non-existing target /etc has correct output (for /etc/group)');
_setup_dir('/lxc/run-test-1/etc');
_setup_file('/lxc/run-test-1/etc/gshadow'); # for successful unlink of it
_chmod(0, '/etc/shadow');
eval '$_->_prepare_user();';
like($@,
qr{can't open .+tmp/etc/shadow': Permission denied$re_eval},
'failing read-access to mocked /etc/shadow has correct output');
_chmod(0644, '/etc/shadow');
_chmod(0555, '/lxc/run-test-1/etc');
eval '$_->_prepare_user();';
like($@,
qr{can't remove .+tmp/lxc/run-test-1/etc/group': Permission denied$re_eval},
'failing write-access to target /etc has correct output');
_chmod(0755, '/lxc/run-test-1/etc');
$_->{mounts}{'/etc'} = 1;
output_like
{ $_->_prepare_user(); }
qr{^$}, qr{^$},
'_prepare_user for mapped /etc looks correct';
delete $_->{mounts}{'/etc'};
$_->{mounts}{'/etc/group'} = 1;
$_->{mounts}{'/etc/gshadow'} = 1;
$_->{mounts}{'/etc/passwd'} = 1;
my $re_account_files = 'group gshadow passwd shadow';
output_like
{ $_->_prepare_user(); }
qr{^$},
qr{^broken user mapping - check mounting of $re_account_files$re_msg_tail},
'_prepare_user for only 3 mapped account files looks correct';
$_->{mounts}{'/etc/shadow'} = 1;
output_like
{ $_->_prepare_user(); }
qr{^$}, qr{^$},
'_prepare_user for all 4 mapped account files looks correct';
#########################################################################
# check writing of startup script for 1st configuration:
_remove_file('/lxc/run-test-1/lxc-run.sh');
_setup_file('/lxc/run-test-1/lxc-run.sh');
_chmod(0444, '/lxc/run-test-1/lxc-run.sh');
eval '$_->_write_init_sh();';
like($@,
qr{can't open .+tmp/lxc/run-test-1/lxc-run.sh': Permission denied$re_eval},
'failing write-access to startup script lxc-run.sh has correct output');
_remove_file('/lxc/run-test-1/lxc-run.sh');
$_->{running} = 0;
eval '$_->_write_init_sh();';
is($@, '', 'creating minimal startup script run without problems');
check_config_file(TMP_PATH . '/lxc/run-test-1/lxc-run.sh',
{DISPLAY => '!DISPLAY',
PULSE => '!PULSE_SERVER',
XAUTHORITY => '!XAUTHORITY',
cd => 'cd "/"',
dns => '!nameserver',
exec => "exec 'do' 'it'",
gateway => '!gateway',
route => '!route',
shebang => '#!/bin/sh'});
$_->{running} = 1;
eval '$_->_write_init_sh();';
is($@, '', 'creating 2nd minimal startup script run without problems');
check_config_file(TMP_PATH . '/lxc/run-test-1/lxc-run.sh',
{DISPLAY => '!DISPLAY',
PULSE => '!PULSE_SERVER',
XAUTHORITY => '!XAUTHORITY',
cd => 'cd "/"',
dns => '!nameserver',
exec => "exec 'do' 'it'",
gateway => '!gateway',
route => '!route',
shebang => '#!/bin/sh'});
$_->{user} = 'bin';
eval '$_->_write_init_sh();';
is($@, '', 'creating variant 1 for other user run without problems');
check_config_file(TMP_PATH . '/lxc/run-test-1/lxc-run.sh',
{DISPLAY => '!DISPLAY',
PULSE => '!PULSE_SERVER',
XAUTHORITY => '!XAUTHORITY',
cd => 'cd "/"',
dns => '!nameserver',
exec =>
"exec su bin -s /bin/sh -c 'do \"\\\$@\"' -- dummy_argv0 'it'",
gateway => '!gateway',
route => '!route',
shebang => '#!/bin/sh'});
$_->{command} = ['do'];
eval '$_->_write_init_sh();';
is($@, '', 'creating variant 2 for other user run without problems');
check_config_file(TMP_PATH . '/lxc/run-test-1/lxc-run.sh',
( run in 2.094 seconds using v1.01-cache-2.11-cpan-364913b4093 )