Add update actions to integration test

This commit is contained in:
Winter 2022-01-18 14:25:06 -05:00 committed by Taeer Bar-Yam
parent 3d61cccadd
commit 4e139ebfa4

View file

@ -1,56 +1,90 @@
args@{ pkgs ? <nixpkgs>, ... }: args@{ pkgs ? <nixpkgs>, ... }:
with (import "${pkgs}/lib");
import "${pkgs}/nixos/tests/make-test-python.nix" import "${pkgs}/nixos/tests/make-test-python.nix"
{ (
name = "agenix-integration"; let
sshdConf = {
enable = true;
hostKeys = [{ type = "ed25519"; path = "/etc/ssh/ssh_host_ed25519_key"; }];
};
in
rec {
name = "agenix-integration";
nodes.system1 = { config, ... }: { nodes.system1 = { config, ... }: {
imports = [ imports = [
../modules/age.nix ../modules/age.nix
./install_ssh_host_keys.nix ./install_ssh_host_keys.nix
]; ];
services.openssh = { services.openssh = sshdConf;
enable = true;
hostKeys = [{ type = "ed25519"; path = "/etc/ssh/ssh_host_ed25519_key"; }];
};
age.secrets.passwordfile-user1.file = ../example/passwordfile-user1.age; age.secrets.passwordfile-user1.file = ../example/passwordfile-user1.age;
users = { users = {
mutableUsers = false; mutableUsers = false;
users = { users = {
user1 = { user1 = {
isNormalUser = true; isNormalUser = true;
passwordFile = config.age.secrets.passwordfile-user1.path; passwordFile = config.age.secrets.passwordfile-user1.path;
};
};
}; };
}; };
};
};
testScript = nodes.system2 = {
let imports = [
user = "user1"; ../modules/age.nix
password = "password1234"; ./install_ssh_host_keys.nix
in ];
''
system1.wait_for_unit("multi-user.target") services.openssh = sshdConf;
system1.wait_until_succeeds("pgrep -f 'agetty.*tty1'")
system1.sleep(2) age.secrets.ex1 = {
system1.send_key("alt-f2") file = ../example/passwordfile-user1.age;
system1.wait_until_succeeds("[ $(fgconsole) = 2 ]") action = "echo bar > /tmp/foo";
system1.wait_for_unit("getty@tty2.service") };
system1.wait_until_succeeds("pgrep -f 'agetty.*tty2'") };
system1.wait_until_tty_matches(2, "login: ")
system1.send_chars("${user}\n") nodes.system2After = recursiveUpdate nodes.system2 {
system1.wait_until_tty_matches(2, "login: ${user}") age.secrets.ex1.file = ../example/secret1.age;
system1.wait_until_succeeds("pgrep login") };
system1.sleep(2)
system1.send_chars("${password}\n") testScript =
system1.send_chars("whoami > /tmp/1\n") let
system1.wait_for_file("/tmp/1") user = "user1";
assert "${user}" in system1.succeed("cat /tmp/1") password = "password1234";
''; in
} { nodes, ... }:
''
system1.start()
system2.start()
system1.wait_for_unit("multi-user.target")
system1.wait_until_succeeds("pgrep -f 'agetty.*tty1'")
system1.sleep(2)
system1.send_key("alt-f2")
system1.wait_until_succeeds("[ $(fgconsole) = 2 ]")
system1.wait_for_unit("getty@tty2.service")
system1.wait_until_succeeds("pgrep -f 'agetty.*tty2'")
system1.wait_until_tty_matches(2, "login: ")
system1.send_chars("${user}\n")
system1.wait_until_tty_matches(2, "login: ${user}")
system1.wait_until_succeeds("pgrep login")
system1.sleep(2)
system1.send_chars("${password}\n")
system1.send_chars("whoami > /tmp/1\n")
system1.wait_for_file("/tmp/1")
assert "${user}" in system1.succeed("cat /tmp/1")
system2.wait_for_unit("multi-user.target")
system2.wait_until_fails("grep bar /tmp/foo")
system2.wait_until_succeeds("${nodes.system2After.config.system.build.toplevel}/bin/switch-to-configuration test")
system2.wait_until_succeeds("grep bar /tmp/foo")
'';
}
)
args args