Browse Source

autopkgtests: Correctly handle unit names that can contain escape sequences

They need to be quoted so that the shell does not parse them.
keep-around/6cb72b59a0a1898939b818d8d210b194cf33a76b
Steve Langasek 5 years ago
committed by Felipe Sateler
parent
commit
b13d642c8a
  1. 66
      t/001-deb-systemd-helper.t

66
t/001-deb-systemd-helper.t

@ -21,7 +21,7 @@ my $dsh = "$FindBin::Bin/../script/deb-systemd-helper";
sub _unit_check {
my ($unit_file, $cmd, $cb, $verb) = @_;
my $retval = system("DPKG_MAINTSCRIPT_PACKAGE=test $dsh $cmd $unit_file");
my $retval = system("DPKG_MAINTSCRIPT_PACKAGE=test $dsh $cmd '$unit_file'");
isnt($retval, -1, 'deb-systemd-helper could be executed');
ok(!($retval & 127), 'deb-systemd-helper did not exit due to a signal');
$cb->($retval >> 8, 0, "random unit file $verb $cmd");
@ -96,7 +96,7 @@ unless ($ENV{'TEST_ON_REAL_SYSTEM'}) {
'multi-user.target.wants does not exist yet');
}
$retval = system("DPKG_MAINTSCRIPT_PACKAGE=test $dsh enable $random_unit");
$retval = system("DPKG_MAINTSCRIPT_PACKAGE=test $dsh enable '$random_unit'");
is($retval, 0, "enable command succeeded");
my $symlink_path = "/etc/systemd/system/multi-user.target.wants/$random_unit";
ok(-l $symlink_path, "$random_unit was enabled");
@ -120,7 +120,7 @@ ok(! -l $symlink_path, 'symlink deleted');
isnt_enabled($random_unit);
is_debian_installed($random_unit);
$retval = system("DPKG_MAINTSCRIPT_PACKAGE=test $dsh enable $random_unit");
$retval = system("DPKG_MAINTSCRIPT_PACKAGE=test $dsh enable '$random_unit'");
is($retval, 0, "enable command succeeded");
isnt_enabled($random_unit);
@ -133,7 +133,7 @@ my $statefile = "/var/lib/systemd/deb-systemd-helper-enabled/$random_unit.dsh-al
ok(-f $statefile, 'state file exists');
$retval = system("DPKG_MAINTSCRIPT_PACKAGE=test _DEB_SYSTEMD_HELPER_PURGE=1 $dsh disable $random_unit");
$retval = system("DPKG_MAINTSCRIPT_PACKAGE=test _DEB_SYSTEMD_HELPER_PURGE=1 $dsh disable '$random_unit'");
is($retval, 0, "disable command succeeded");
ok(! -f $statefile, 'state file does not exist anymore after purging');
isnt_debian_installed($random_unit);
@ -145,7 +145,7 @@ isnt_debian_installed($random_unit);
ok(! -l $symlink_path, 'symlink does not exist yet');
isnt_enabled($random_unit);
$retval = system("DPKG_MAINTSCRIPT_PACKAGE=test $dsh enable $random_unit");
$retval = system("DPKG_MAINTSCRIPT_PACKAGE=test $dsh enable '$random_unit'");
is($retval, 0, "enable command succeeded");
is_enabled($random_unit);
@ -155,7 +155,7 @@ is_debian_installed($random_unit);
# ┃ Verify “disable” removes the symlinks. ┃
# ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
$retval = system("DPKG_MAINTSCRIPT_PACKAGE=test _DEB_SYSTEMD_HELPER_PURGE=1 $dsh disable $random_unit");
$retval = system("DPKG_MAINTSCRIPT_PACKAGE=test _DEB_SYSTEMD_HELPER_PURGE=1 $dsh disable '$random_unit'");
is($retval, 0, "disable command succeeded");
isnt_enabled($random_unit);
@ -167,7 +167,7 @@ isnt_enabled($random_unit);
ok(! -l $symlink_path, 'symlink does not exist yet');
isnt_enabled($random_unit);
$retval = system("DPKG_MAINTSCRIPT_PACKAGE=test $dsh enable $random_unit");
$retval = system("DPKG_MAINTSCRIPT_PACKAGE=test $dsh enable '$random_unit'");
is($retval, 0, "enable command succeeded");
is_enabled($random_unit);
@ -177,7 +177,7 @@ is_debian_installed($random_unit);
# ┃ Verify the “purge” verb works. ┃
# ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
$retval = system("DPKG_MAINTSCRIPT_PACKAGE=test $dsh purge $random_unit");
$retval = system("DPKG_MAINTSCRIPT_PACKAGE=test $dsh purge '$random_unit'");
is($retval, 0, "purge command succeeded");
isnt_enabled($random_unit);
@ -190,7 +190,7 @@ isnt_debian_installed($random_unit);
ok(! -l $symlink_path, 'symlink does not exist yet');
isnt_enabled($random_unit);
$retval = system("DPKG_MAINTSCRIPT_PACKAGE=test $dsh enable $random_unit");
$retval = system("DPKG_MAINTSCRIPT_PACKAGE=test $dsh enable '$random_unit'");
is($retval, 0, "enable command succeeded");
is_enabled($random_unit);
@ -203,12 +203,12 @@ is_debian_installed($random_unit);
my $mask_path = "/etc/systemd/system/$random_unit";
ok(! -l $mask_path, 'mask link does not exist yet');
$retval = system("DPKG_MAINTSCRIPT_PACKAGE=test $dsh mask $random_unit");
$retval = system("DPKG_MAINTSCRIPT_PACKAGE=test $dsh mask '$random_unit'");
is($retval, 0, "mask command succeeded");
ok(-l $mask_path, 'mask link exists');
is(readlink($mask_path), '/dev/null', 'service masked');
$retval = system("DPKG_MAINTSCRIPT_PACKAGE=test $dsh unmask $random_unit");
$retval = system("DPKG_MAINTSCRIPT_PACKAGE=test $dsh unmask '$random_unit'");
is($retval, 0, "unmask command succeeded");
ok(! -e $mask_path, 'mask link does not exist anymore');
@ -216,16 +216,16 @@ ok(! -e $mask_path, 'mask link does not exist anymore');
# ┃ Verify “mask” (when disabled) works the same way ┃
# ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
$retval = system("DPKG_MAINTSCRIPT_PACKAGE=test $dsh disable $random_unit");
$retval = system("DPKG_MAINTSCRIPT_PACKAGE=test $dsh disable '$random_unit'");
is($retval, 0, "disable command succeeded");
ok(! -e $symlink_path, 'symlink no longer exists');
$retval = system("DPKG_MAINTSCRIPT_PACKAGE=test $dsh mask $random_unit");
$retval = system("DPKG_MAINTSCRIPT_PACKAGE=test $dsh mask '$random_unit'");
is($retval, 0, "mask command succeeded");
ok(-l $mask_path, 'mask link exists');
is(readlink($mask_path), '/dev/null', 'service masked');
$retval = system("DPKG_MAINTSCRIPT_PACKAGE=test $dsh unmask $random_unit");
$retval = system("DPKG_MAINTSCRIPT_PACKAGE=test $dsh unmask '$random_unit'");
is($retval, 0, "unmask command succeeded");
ok(! -e $mask_path, 'symlink no longer exists');
@ -238,12 +238,12 @@ symlink('/dev/null', $mask_path);
ok(-l $mask_path, 'mask link exists');
is(readlink($mask_path), '/dev/null', 'service masked');
$retval = system("DPKG_MAINTSCRIPT_PACKAGE=test $dsh mask $random_unit");
$retval = system("DPKG_MAINTSCRIPT_PACKAGE=test $dsh mask '$random_unit'");
is($retval, 0, "mask command succeeded");
ok(-l $mask_path, 'mask link exists');
is(readlink($mask_path), '/dev/null', 'service still masked');
$retval = system("DPKG_MAINTSCRIPT_PACKAGE=test $dsh unmask $random_unit");
$retval = system("DPKG_MAINTSCRIPT_PACKAGE=test $dsh unmask '$random_unit'");
is($retval, 0, "unmask command succeeded");
ok(-l $mask_path, 'mask link exists');
is(readlink($mask_path), '/dev/null', 'service still masked');
@ -270,14 +270,14 @@ close($fh);
ok(-e $mask_path, 'local service file exists');
ok(! -l $mask_path, 'local service file is not a symlink');
$retval = system("DPKG_MAINTSCRIPT_PACKAGE=test $dsh mask $random_unit");
$retval = system("DPKG_MAINTSCRIPT_PACKAGE=test $dsh mask '$random_unit'");
isnt($retval, -1, 'deb-systemd-helper could be executed');
ok(!($retval & 127), 'deb-systemd-helper did not exit due to a signal');
is($retval >> 8, 0, 'deb-systemd-helper exited with exit code 0');
ok(-e $mask_path, 'local service file still exists');
ok(! -l $mask_path, 'local service file is still not a symlink');
$retval = system("DPKG_MAINTSCRIPT_PACKAGE=test $dsh unmask $random_unit");
$retval = system("DPKG_MAINTSCRIPT_PACKAGE=test $dsh unmask '$random_unit'");
isnt($retval, -1, 'deb-systemd-helper could be executed');
ok(!($retval & 127), 'deb-systemd-helper did not exit due to a signal');
is($retval >> 8, 0, 'deb-systemd-helper exited with exit code 0');
@ -290,7 +290,7 @@ unlink($mask_path);
# ┃ Verify Alias= handling. ┃
# ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
$retval = system("DPKG_MAINTSCRIPT_PACKAGE=test $dsh purge $random_unit");
$retval = system("DPKG_MAINTSCRIPT_PACKAGE=test $dsh purge '$random_unit'");
is($retval, 0, "purge command succeeded");
open($fh, '>', $servicefile_path);
@ -309,25 +309,25 @@ close($fh);
isnt_enabled($random_unit);
isnt_enabled('foo\x2dtest.service');
my $alias_path = "/etc/systemd/system/foo\x2dtest.service";
my $alias_path = '/etc/systemd/system/foo\x2dtest.service';
ok(! -l $alias_path, 'alias link does not exist yet');
$retval = system("DPKG_MAINTSCRIPT_PACKAGE=test $dsh enable $random_unit");
$retval = system("DPKG_MAINTSCRIPT_PACKAGE=test $dsh enable '$random_unit'");
is($retval, 0, "enable command succeeded");
is(readlink($alias_path), $servicefile_path, 'correct alias link');
is_enabled($random_unit);
ok(! -l $mask_path, 'mask link does not exist yet');
$retval = system("DPKG_MAINTSCRIPT_PACKAGE=test $dsh mask $random_unit");
$retval = system("DPKG_MAINTSCRIPT_PACKAGE=test $dsh mask '$random_unit'");
is($retval, 0, "mask command succeeded");
is(readlink($alias_path), $servicefile_path, 'correct alias link');
is(readlink($mask_path), '/dev/null', 'service masked');
$retval = system("DPKG_MAINTSCRIPT_PACKAGE=test $dsh unmask $random_unit");
$retval = system("DPKG_MAINTSCRIPT_PACKAGE=test $dsh unmask '$random_unit'");
is($retval, 0, "unmask command succeeded");
is(readlink($alias_path), $servicefile_path, 'correct alias link');
ok(! -l $mask_path, 'mask link does not exist any more');
$retval = system("DPKG_MAINTSCRIPT_PACKAGE=test $dsh disable $random_unit");
$retval = system("DPKG_MAINTSCRIPT_PACKAGE=test $dsh disable '$random_unit'");
isnt_enabled($random_unit);
ok(! -l $alias_path, 'alias link does not exist any more');
@ -335,25 +335,25 @@ ok(! -l $alias_path, 'alias link does not exist any more');
# ┃ Verify Alias/mask with removed package (as in postrm) ┃
# ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
$retval = system("DPKG_MAINTSCRIPT_PACKAGE=test $dsh purge $random_unit");
$retval = system("DPKG_MAINTSCRIPT_PACKAGE=test $dsh purge '$random_unit'");
is($retval, 0, "purge command succeeded");
$retval = system("DPKG_MAINTSCRIPT_PACKAGE=test $dsh enable $random_unit");
$retval = system("DPKG_MAINTSCRIPT_PACKAGE=test $dsh enable '$random_unit'");
is($retval, 0, "enable command succeeded");
is(readlink($alias_path), $servicefile_path, 'correct alias link');
unlink($servicefile_path);
$retval = system("DPKG_MAINTSCRIPT_PACKAGE=test $dsh mask $random_unit");
$retval = system("DPKG_MAINTSCRIPT_PACKAGE=test $dsh mask '$random_unit'");
is($retval, 0, "mask command succeeded with uninstalled unit");
is(readlink($alias_path), $servicefile_path, 'correct alias link');
is(readlink($mask_path), '/dev/null', 'service masked');
$retval = system("DPKG_MAINTSCRIPT_PACKAGE=test $dsh purge $random_unit");
$retval = system("DPKG_MAINTSCRIPT_PACKAGE=test $dsh purge '$random_unit'");
is($retval, 0, "purge command succeeded with uninstalled unit");
ok(! -l $alias_path, 'alias link does not exist any more');
is(readlink($mask_path), '/dev/null', 'service masked');
$retval = system("DPKG_MAINTSCRIPT_PACKAGE=test $dsh unmask $random_unit");
$retval = system("DPKG_MAINTSCRIPT_PACKAGE=test $dsh unmask '$random_unit'");
is($retval, 0, "unmask command succeeded with uninstalled unit");
ok(! -l $mask_path, 'mask link does not exist any more');
@ -378,7 +378,7 @@ close($fh);
isnt_enabled($random_unit);
isnt_enabled('foo\x2dtest.service');
# note that in this case $alias_path and $mask_path are identical
$retval = system("DPKG_MAINTSCRIPT_PACKAGE=test $dsh enable $random_unit");
$retval = system("DPKG_MAINTSCRIPT_PACKAGE=test $dsh enable '$random_unit'");
is($retval, 0, "enable command succeeded");
is_enabled($random_unit);
# systemctl enable does create the alias link even if it's not needed
@ -386,15 +386,15 @@ is_enabled($random_unit);
unlink($servicefile_path);
$retval = system("DPKG_MAINTSCRIPT_PACKAGE=test $dsh mask $random_unit");
$retval = system("DPKG_MAINTSCRIPT_PACKAGE=test $dsh mask '$random_unit'");
is($retval, 0, "mask command succeeded");
is(readlink($mask_path), '/dev/null', 'service masked');
$retval = system("DPKG_MAINTSCRIPT_PACKAGE=test $dsh unmask $random_unit");
$retval = system("DPKG_MAINTSCRIPT_PACKAGE=test $dsh unmask '$random_unit'");
is($retval, 0, "unmask command succeeded");
ok(! -l $mask_path, 'mask link does not exist any more');
$retval = system("DPKG_MAINTSCRIPT_PACKAGE=test $dsh purge $random_unit");
$retval = system("DPKG_MAINTSCRIPT_PACKAGE=test $dsh purge '$random_unit'");
isnt_enabled($random_unit);
ok(! -l $mask_path, 'mask link does not exist any more');

Loading…
Cancel
Save