Fix integration test

This commit is contained in:
Winter 2022-01-18 14:22:15 -05:00 committed by Taeer Bar-Yam
parent 2b8f414fa6
commit 3d61cccadd
2 changed files with 33 additions and 36 deletions

View file

@ -8,7 +8,6 @@
( (
umask u=rw,g=,o= umask u=rw,g=,o=
cp ${../example_keys/system1} /etc/ssh/ssh_host_ed25519_key cp ${../example_keys/system1} /etc/ssh/ssh_host_ed25519_key
touch /etc/ssh/ssh_host_rsa_key
) )
''; '';

View file

@ -1,25 +1,22 @@
{ args@{ pkgs ? <nixpkgs>, ... }:
nixpkgs ? <nixpkgs>,
pkgs ? import <nixpkgs> { inherit system; config = {}; },
system ? builtins.currentSystem
} @args:
import "${nixpkgs}/nixos/tests/make-test-python.nix" ({ pkgs, ...}: { import "${pkgs}/nixos/tests/make-test-python.nix"
{
name = "agenix-integration"; name = "agenix-integration";
nodes.system1 = { config, lib, ... }: { nodes.system1 = { config, ... }: {
imports = [ imports = [
../modules/age.nix ../modules/age.nix
./install_ssh_host_keys.nix ./install_ssh_host_keys.nix
]; ];
services.openssh.enable = true; services.openssh = {
enable = true;
age.secrets.passwordfile-user1 = { hostKeys = [{ type = "ed25519"; path = "/etc/ssh/ssh_host_ed25519_key"; }];
file = ../example/passwordfile-user1.age;
}; };
age.secrets.passwordfile-user1.file = ../example/passwordfile-user1.age;
users = { users = {
mutableUsers = false; mutableUsers = false;
@ -30,29 +27,30 @@ import "${nixpkgs}/nixos/tests/make-test-python.nix" ({ pkgs, ...}: {
}; };
}; };
}; };
}; };
testScript = testScript =
let let
user = "user1"; user = "user1";
password = "password1234"; password = "password1234";
in '' in
system1.wait_for_unit("multi-user.target") ''
system1.wait_until_succeeds("pgrep -f 'agetty.*tty1'") system1.wait_for_unit("multi-user.target")
system1.sleep(2) system1.wait_until_succeeds("pgrep -f 'agetty.*tty1'")
system1.send_key("alt-f2") system1.sleep(2)
system1.wait_until_succeeds("[ $(fgconsole) = 2 ]") system1.send_key("alt-f2")
system1.wait_for_unit("getty@tty2.service") system1.wait_until_succeeds("[ $(fgconsole) = 2 ]")
system1.wait_until_succeeds("pgrep -f 'agetty.*tty2'") system1.wait_for_unit("getty@tty2.service")
system1.wait_until_tty_matches(2, "login: ") system1.wait_until_succeeds("pgrep -f 'agetty.*tty2'")
system1.send_chars("${user}\n") system1.wait_until_tty_matches(2, "login: ")
system1.wait_until_tty_matches(2, "login: ${user}") system1.send_chars("${user}\n")
system1.wait_until_succeeds("pgrep login") system1.wait_until_tty_matches(2, "login: ${user}")
system1.sleep(2) system1.wait_until_succeeds("pgrep login")
system1.send_chars("${password}\n") system1.sleep(2)
system1.send_chars("whoami > /tmp/1\n") system1.send_chars("${password}\n")
system1.wait_for_file("/tmp/1") system1.send_chars("whoami > /tmp/1\n")
assert "${user}" in system1.succeed("cat /tmp/1") system1.wait_for_file("/tmp/1")
''; assert "${user}" in system1.succeed("cat /tmp/1")
}) args '';
}
args