diff options
author | Frederik Rietdijk <fridh@fridh.nl> | 2019-08-31 10:04:20 +0200 |
---|---|---|
committer | Frederik Rietdijk <fridh@fridh.nl> | 2019-08-31 10:04:20 +0200 |
commit | ad1d58c6227abf2a9c80311eb09166a532384ed2 (patch) | |
tree | 852498ff298f9b01c0d2c8b4c883da1a00912260 /nixos/tests | |
parent | ebe4fd146b29c92fb59f243f75e46afc9f1a9048 (diff) | |
parent | fc74ba8291a8a93cba428de6bc2e7c8c7f9330f4 (diff) | |
download | nixpkgs-ad1d58c6227abf2a9c80311eb09166a532384ed2.tar nixpkgs-ad1d58c6227abf2a9c80311eb09166a532384ed2.tar.gz nixpkgs-ad1d58c6227abf2a9c80311eb09166a532384ed2.tar.bz2 nixpkgs-ad1d58c6227abf2a9c80311eb09166a532384ed2.tar.lz nixpkgs-ad1d58c6227abf2a9c80311eb09166a532384ed2.tar.xz nixpkgs-ad1d58c6227abf2a9c80311eb09166a532384ed2.tar.zst nixpkgs-ad1d58c6227abf2a9c80311eb09166a532384ed2.zip |
Merge staging-next into staging
Diffstat (limited to 'nixos/tests')
-rw-r--r-- | nixos/tests/acme.nix | 98 | ||||
-rw-r--r-- | nixos/tests/all-tests.nix | 1 | ||||
-rw-r--r-- | nixos/tests/magnetico.nix | 28 | ||||
-rw-r--r-- | nixos/tests/systemd.nix | 10 | ||||
-rw-r--r-- | nixos/tests/xfce4-14.nix | 33 |
5 files changed, 155 insertions, 15 deletions
diff --git a/nixos/tests/acme.nix b/nixos/tests/acme.nix index 4669a092433..8cfdea4a16e 100644 --- a/nixos/tests/acme.nix +++ b/nixos/tests/acme.nix @@ -3,19 +3,49 @@ let in import ./make-test.nix { name = "acme"; - nodes = { + nodes = rec { letsencrypt = ./common/letsencrypt; + acmeStandalone = { config, pkgs, ... }: { + imports = [ commonConfig ]; + networking.firewall.allowedTCPPorts = [ 80 ]; + networking.extraHosts = '' + ${config.networking.primaryIPAddress} standalone.com + ''; + security.acme.certs."standalone.com" = { + webroot = "/var/lib/acme/acme-challenges"; + }; + systemd.targets."acme-finished-standalone.com" = {}; + systemd.services."acme-standalone.com" = { + wants = [ "acme-finished-standalone.com.target" ]; + before = [ "acme-finished-standalone.com.target" ]; + }; + services.nginx.enable = true; + services.nginx.virtualHosts."standalone.com" = { + locations."/.well-known/acme-challenge".root = "/var/lib/acme/acme-challenges"; + }; + }; + webserver = { config, pkgs, ... }: { imports = [ commonConfig ]; networking.firewall.allowedTCPPorts = [ 80 443 ]; networking.extraHosts = '' - ${config.networking.primaryIPAddress} example.com + ${config.networking.primaryIPAddress} a.example.com + ${config.networking.primaryIPAddress} b.example.com ''; + # A target remains active. Use this to probe the fact that + # a service fired eventhough it is not RemainAfterExit + systemd.targets."acme-finished-a.example.com" = {}; + systemd.services."acme-a.example.com" = { + wants = [ "acme-finished-a.example.com.target" ]; + before = [ "acme-finished-a.example.com.target" ]; + }; + services.nginx.enable = true; - services.nginx.virtualHosts."example.com" = { + + services.nginx.virtualHosts."a.example.com" = { enableACME = true; forceSSL = true; locations."/".root = pkgs.runCommand "docroot" {} '' @@ -23,17 +53,63 @@ in import ./make-test.nix { echo hello world > "$out/index.html" ''; }; + + nesting.clone = [ + ({pkgs, ...}: { + + networking.extraHosts = '' + ${config.networking.primaryIPAddress} b.example.com + ''; + systemd.targets."acme-finished-b.example.com" = {}; + systemd.services."acme-b.example.com" = { + wants = [ "acme-finished-b.example.com.target" ]; + before = [ "acme-finished-b.example.com.target" ]; + }; + services.nginx.virtualHosts."b.example.com" = { + enableACME = true; + forceSSL = true; + locations."/".root = pkgs.runCommand "docroot" {} '' + mkdir -p "$out" + echo hello world > "$out/index.html" + ''; + }; + }) + ]; }; client = commonConfig; }; - testScript = '' - $letsencrypt->waitForUnit("default.target"); - $letsencrypt->waitForUnit("boulder.service"); - $webserver->waitForUnit("default.target"); - $webserver->waitForUnit("acme-certificates.target"); - $client->waitForUnit("default.target"); - $client->succeed('curl https://example.com/ | grep -qF "hello world"'); - ''; + testScript = {nodes, ...}: + let + newServerSystem = nodes.webserver2.config.system.build.toplevel; + switchToNewServer = "${newServerSystem}/bin/switch-to-configuration test"; + in + # Note, waitForUnit does not work for oneshot services that do not have RemainAfterExit=true, + # this is because a oneshot goes from inactive => activating => inactive, and never + # reaches the active state. To work around this, we create some mock target units which + # get pulled in by the oneshot units. The target units linger after activation, and hence we + # can use them to probe that a oneshot fired. It is a bit ugly, but it is the best we can do + '' + $client->waitForUnit("default.target"); + $letsencrypt->waitForUnit("default.target"); + $letsencrypt->waitForUnit("boulder.service"); + + subtest "can request certificate with HTTPS-01 challenge", sub { + $acmeStandalone->waitForUnit("default.target"); + $acmeStandalone->succeed("systemctl start acme-standalone.com.service"); + $acmeStandalone->waitForUnit("acme-finished-standalone.com.target"); + }; + + subtest "Can request certificate for nginx service", sub { + $webserver->waitForUnit("acme-finished-a.example.com.target"); + $client->succeed('curl https://a.example.com/ | grep -qF "hello world"'); + }; + + subtest "Can add another certificate for nginx service", sub { + $webserver->succeed("/run/current-system/fine-tune/child-1/bin/switch-to-configuration test"); + $webserver->waitForUnit("acme-finished-b.example.com.target"); + $client->succeed('curl https://b.example.com/ | grep -qF "hello world"'); + }; + ''; } diff --git a/nixos/tests/all-tests.nix b/nixos/tests/all-tests.nix index e3e4ddab72c..557ee78df7c 100644 --- a/nixos/tests/all-tests.nix +++ b/nixos/tests/all-tests.nix @@ -278,6 +278,7 @@ in xautolock = handleTest ./xautolock.nix {}; xdg-desktop-portal = handleTest ./xdg-desktop-portal.nix {}; xfce = handleTest ./xfce.nix {}; + xfce4-14 = handleTest ./xfce4-14.nix {}; xmonad = handleTest ./xmonad.nix {}; xrdp = handleTest ./xrdp.nix {}; xss-lock = handleTest ./xss-lock.nix {}; diff --git a/nixos/tests/magnetico.nix b/nixos/tests/magnetico.nix new file mode 100644 index 00000000000..bc7aef653ee --- /dev/null +++ b/nixos/tests/magnetico.nix @@ -0,0 +1,28 @@ +import ./make-test.nix ({ pkgs, ...} : { + name = "magnetico"; + meta = with pkgs.stdenv.lib.maintainers; { + maintainers = [ rnhmjoj ]; + }; + + machine = { ... }: { + imports = [ ../modules/profiles/minimal.nix ]; + + networking.firewall.allowedTCPPorts = [ 9000 ]; + + services.magnetico = { + enable = true; + crawler.port = 9000; + web.credentials.user = "$2y$12$P88ZF6soFthiiAeXnz64aOWDsY3Dw7Yw8fZ6GtiqFNjknD70zDmNe"; + }; + }; + + testScript = + '' + startAll; + $machine->waitForUnit("magneticod"); + $machine->waitForUnit("magneticow"); + $machine->succeed("${pkgs.curl}/bin/curl -u user:password http://localhost:8080"); + $machine->succeed("${pkgs.curl}/bin/curl -u user:wrongpwd http://localhost:8080") =~ "Unauthorised." or die; + $machine->shutdown(); + ''; +}) diff --git a/nixos/tests/systemd.nix b/nixos/tests/systemd.nix index 1c201e3b5dc..4b71b4d6759 100644 --- a/nixos/tests/systemd.nix +++ b/nixos/tests/systemd.nix @@ -71,11 +71,13 @@ import ./make-test.nix ({ pkgs, ... }: { # Regression test for https://github.com/NixOS/nixpkgs/issues/35268 subtest "file system with x-initrd.mount is not unmounted", sub { + $machine->succeed('mountpoint -q /test-x-initrd-mount'); $machine->shutdown; - $machine->waitForUnit('multi-user.target'); - # If the file system was unmounted during the shutdown the file system - # has a last mount time, because the file system wasn't checked. - $machine->fail('dumpe2fs /dev/vdb | grep -q "^Last mount time: *n/a"'); + system('qemu-img', 'convert', '-O', 'raw', + 'vm-state-machine/empty2.qcow2', 'x-initrd-mount.raw'); + my $extinfo = `${pkgs.e2fsprogs}/bin/dumpe2fs x-initrd-mount.raw`; + die "File system was not cleanly unmounted: $extinfo" + unless $extinfo =~ /^Filesystem state: *clean$/m; }; subtest "systemd-shutdown works", sub { diff --git a/nixos/tests/xfce4-14.nix b/nixos/tests/xfce4-14.nix new file mode 100644 index 00000000000..d9b10aabaa1 --- /dev/null +++ b/nixos/tests/xfce4-14.nix @@ -0,0 +1,33 @@ +import ./make-test.nix ({ pkgs, ...} : { + name = "xfce4-14"; + + machine = + { pkgs, ... }: + + { imports = [ ./common/user-account.nix ]; + + services.xserver.enable = true; + + services.xserver.displayManager.auto.enable = true; + services.xserver.displayManager.auto.user = "alice"; + + services.xserver.desktopManager.xfce4-14.enable = true; + }; + + testScript = + '' + $machine->waitForX; + $machine->waitForFile("/home/alice/.Xauthority"); + $machine->succeed("xauth merge ~alice/.Xauthority"); + $machine->waitForWindow(qr/xfce4-panel/); + $machine->sleep(10); + + # Check that logging in has given the user ownership of devices. + $machine->succeed("getfacl /dev/snd/timer | grep -q alice"); + + $machine->succeed("su - alice -c 'DISPLAY=:0.0 xfce4-terminal &'"); + $machine->waitForWindow(qr/Terminal/); + $machine->sleep(10); + $machine->screenshot("screen"); + ''; +}) |