Skip to content

Commit

Permalink
nixos/tests/chromium: Run tests as normal user
Browse files Browse the repository at this point in the history
The tests have failed because Chromium has started up displaying the
following error message in a dialog window:

  Chromium can not be run as root.

  Please start Chromium as a normal user. If you need to run as root for
  development, rerun with the --no-sandbox flag.

So let's run as user "alice" and pass all commands using the small
helper function "ru" (to keep it short, it's for "Run as User").

Tested it by running the "stable" test on x86_64-linux.

Signed-off-by: aszlig <aszlig@redmoonstudios.org>
Reported-by: @globin
(cherry picked from commit cd10e3c)
  • Loading branch information
aszlig authored and obadz committed Feb 11, 2017
1 parent 8dc4af6 commit e76c8ac
Showing 1 changed file with 21 additions and 18 deletions.
39 changes: 21 additions & 18 deletions nixos/tests/chromium.nix
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ mapAttrs (channel: chromiumPkg: makeTest rec {

enableOCR = true;

machine.imports = [ ./common/x11.nix ];
machine.imports = [ ./common/user-account.nix ./common/x11.nix ];
machine.virtualisation.memorySize = 2047;
machine.services.xserver.displayManager.auto.user = "alice";
machine.environment.systemPackages = [ chromiumPkg ];

startupHTML = pkgs.writeText "chromium-startup.html" ''
Expand All @@ -43,31 +44,37 @@ mapAttrs (channel: chromiumPkg: makeTest rec {
xdoScript = pkgs.writeText "${name}.xdo" text;
in "${pkgs.xdotool}/bin/xdotool '${xdoScript}'";
in ''
# Run as user alice
sub ru ($) {
my $esc = $_[0] =~ s/'/'\\${"'"}'/gr;
return "su - alice -c '$esc'";
}
sub createNewWin {
$machine->nest("creating a new Chromium window", sub {
$machine->execute("${xdo "new-window" ''
$machine->execute(ru "${xdo "new-window" ''
search --onlyvisible --name "startup done"
windowfocus --sync
windowactivate --sync
''}");
$machine->execute("${xdo "new-window" ''
$machine->execute(ru "${xdo "new-window" ''
key Ctrl+n
''}");
});
}
sub closeWin {
Machine::retry sub {
$machine->execute("${xdo "close-window" ''
$machine->execute(ru "${xdo "close-window" ''
search --onlyvisible --name "new tab"
windowfocus --sync
windowactivate --sync
''}");
$machine->execute("${xdo "close-window" ''
$machine->execute(ru "${xdo "close-window" ''
key Ctrl+w
''}");
for (1..20) {
my ($status, $out) = $machine->execute("${xdo "wait-for-close" ''
my ($status, $out) = $machine->execute(ru "${xdo "wait-for-close" ''
search --onlyvisible --name "new tab"
''}");
return 1 if $status != 0;
Expand All @@ -80,7 +87,7 @@ mapAttrs (channel: chromiumPkg: makeTest rec {
my $ret = 0;
$machine->nest("waiting for new Chromium window to appear", sub {
for (1..20) {
my ($status, $out) = $machine->execute("${xdo "wait-for-window" ''
my ($status, $out) = $machine->execute(ru "${xdo "wait-for-window" ''
search --onlyvisible --name "new tab"
windowfocus --sync
windowactivate --sync
Expand Down Expand Up @@ -113,13 +120,9 @@ mapAttrs (channel: chromiumPkg: makeTest rec {
$machine->waitForX;
my $url = "file://${startupHTML}";
my $args = "--user-data-dir=/tmp/chromium-${channel}";
$machine->execute(
"ulimit -c unlimited; ".
"chromium $args \"$url\" & disown"
);
$machine->execute(ru "ulimit -c unlimited; chromium \"$url\" & disown");
$machine->waitForText(qr/startup done/);
$machine->waitUntilSucceeds("${xdo "check-startup" ''
$machine->waitUntilSucceeds(ru "${xdo "check-startup" ''
search --sync --onlyvisible --name "startup done"
# close first start help popup
key -delay 1000 Escape
Expand All @@ -134,29 +137,29 @@ mapAttrs (channel: chromiumPkg: makeTest rec {
$machine->screenshot("startup_done");
testNewWin "check sandbox", sub {
$machine->succeed("${xdo "type-url" ''
$machine->succeed(ru "${xdo "type-url" ''
search --sync --onlyvisible --name "new tab"
windowfocus --sync
type --delay 1000 "chrome://sandbox"
''}");
$machine->succeed("${xdo "submit-url" ''
$machine->succeed(ru "${xdo "submit-url" ''
search --sync --onlyvisible --name "new tab"
windowfocus --sync
key --delay 1000 Return
''}");
$machine->screenshot("sandbox_info");
$machine->succeed("${xdo "submit-url" ''
$machine->succeed(ru "${xdo "submit-url" ''
search --sync --onlyvisible --name "sandbox status"
windowfocus --sync
''}");
$machine->succeed("${xdo "submit-url" ''
$machine->succeed(ru "${xdo "submit-url" ''
key --delay 1000 Ctrl+a Ctrl+c
''}");
my $clipboard = $machine->succeed("${pkgs.xclip}/bin/xclip -o");
my $clipboard = $machine->succeed(ru "${pkgs.xclip}/bin/xclip -o");
die "sandbox not working properly: $clipboard"
unless $clipboard =~ /namespace sandbox.*yes/mi
&& $clipboard =~ /pid namespaces.*yes/mi
Expand Down

0 comments on commit e76c8ac

Please sign in to comment.