Skip to content

Commit

Permalink
test: configuradorfnmt nixos module request certificate
Browse files Browse the repository at this point in the history
  • Loading branch information
nilp0inter committed Jan 7, 2025
1 parent 9f790ea commit 49c372e
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 0 deletions.
8 changes: 8 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,19 @@
default = self'.packages.autofirma;
};
checks = {
# NixOS Modules
## AutoFirma
nixos-autofirma-cli-sign-document = pkgs.callPackage ./nix/tests/nixos/autofirma/cli/sign-document.nix { inherit self; };
nixos-autofirma-firefoxIntegration-sign-document = pkgs.callPackage ./nix/tests/nixos/autofirma/firefoxIntegration/sign-document.nix { inherit self; };
## Configurador FNMT-RCM
nixos-configuradorfnmt-firefoxIntegration-request = pkgs.callPackage ./nix/tests/nixos/configuradorfnmt/firefoxIntegration/request-certificate.nix { inherit self; };

# Home Manager Modules
## AutoFirma
hm-as-nixos-module-autofirma-cli-sign-document = pkgs.callPackage ./nix/tests/hm-as-nixos-module/autofirma/cli/sign-document.nix { inherit self home-manager; };
hm-as-nixos-module-autofirma-firefoxIntegration-sign-document = pkgs.callPackage ./nix/tests/hm-as-nixos-module/autofirma/firefoxIntegration/sign-document.nix { inherit self home-manager; };
## Configurador FNMT-RCM
hm-as-nixos-module-configuradorfnmt-firefoxIntegration-request = pkgs.callPackage ./nix/tests/hm-as-nixos-module/configuradorfnmt/firefoxIntegration/request-certificate.nix { inherit self home-manager; };
};
};
};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
{ self, pkgs, home-manager, lib }:
let
stateVersion = "${lib.versions.major lib.version}.${lib.versions.minor lib.version}";
in

pkgs.nixosTest {
name = "test-hm-as-nixos-module-configuradorfnmt-firefoxIntegration-request-certificate";
nodes.machine = { config, pkgs, modulesPath, ... }: {
imports = [
home-manager.nixosModules.home-manager
(modulesPath + "./../tests/common/x11.nix")
];

test-support.displayManager.auto.user = "configuradorfnmt-user";

users.users.configuradorfnmt-user = {
isNormalUser = true;
};

home-manager.users.configuradorfnmt-user = {config, ... }: {
imports = [
self.homeManagerModules.configuradorfnmt
];
programs.firefox.enable = true;
programs.firefox.profiles.default.id = 0;
programs.firefox.profiles.default.settings."network.protocol-handler.expose.fnmtcr" = true;

programs.configuradorfnmt.enable = true;
programs.configuradorfnmt.firefoxIntegration.profiles.default.enable = true;

home.packages = [
(pkgs.writeScriptBin "open-configuradorfnmt-via-firefox" ''
cat <<'EOF' > /tmp/configuradorfnmt.html
<html>
<head>
<meta http-equiv="refresh" content="0;url=fnmtcr://request?fileid=0">
</head>
<body>
<p>Redirecting to configuradorfnmt...</p>
</body>
</html>
EOF
${lib.getExe config.programs.firefox.finalPackage} /tmp/configuradorfnmt.html
'')
];
home.stateVersion = stateVersion;
};

environment.systemPackages = with pkgs; [
xorg.xhost.out
];
system.stateVersion = stateVersion;
};

testScript = ''
def user_cmd(cmd):
return f"su -l configuradorfnmt-user --shell /bin/sh -c $'export XDG_RUNTIME_DIR=/run/user/$UID ; {cmd}'"
machine.wait_for_unit("default.target")
machine.wait_for_x()
# Authorize root (testScript user) to connect to the user's X server
machine.succeed(user_cmd("xhost +local:"))
# Open firefox and allow it to import AutoConfig settings
machine.execute(user_cmd("firefox >&2 &"))
machine.wait_for_window("Mozilla Firefox")
machine.sleep(5)
# Open an fnmtcr:// URL in Firefox
machine.execute(user_cmd("open-configuradorfnmt-via-firefox"))
# Wait for the ConfiguradorFNMT-RCM window to appear
machine.wait_for_window('Introduzca la contraseña', 30)
machine.sleep(5)
machine.screenshot("screen")
'';
}

0 comments on commit 49c372e

Please sign in to comment.