From 989e636d98fc41467650d514d8e1fb5c5342cfa3 Mon Sep 17 00:00:00 2001 From: Robert Helgesson Date: Tue, 19 Mar 2019 23:00:17 +0100 Subject: [PATCH] ssh: add some basic tests --- tests/default.nix | 7 ++-- .../programs/ssh/default-config-expected.conf | 15 ++++++++ tests/modules/programs/ssh/default-config.nix | 16 +++++++++ tests/modules/programs/ssh/default.nix | 4 +++ .../ssh/match-blocks-attrs-expected.conf | 25 ++++++++++++++ .../programs/ssh/match-blocks-attrs.nix | 34 +++++++++++++++++++ 6 files changed, 99 insertions(+), 2 deletions(-) create mode 100644 tests/modules/programs/ssh/default-config-expected.conf create mode 100644 tests/modules/programs/ssh/default-config.nix create mode 100644 tests/modules/programs/ssh/default.nix create mode 100644 tests/modules/programs/ssh/match-blocks-attrs-expected.conf create mode 100644 tests/modules/programs/ssh/match-blocks-attrs.nix diff --git a/tests/default.nix b/tests/default.nix index 42c17819..cf1226d2 100644 --- a/tests/default.nix +++ b/tests/default.nix @@ -26,7 +26,10 @@ import nmt { mbsync = ./modules/programs/mbsync.nix; texlive-minimal = ./modules/programs/texlive-minimal.nix; xresources = ./modules/xresources.nix; - } // pkgs.lib.optionalAttrs pkgs.stdenv.hostPlatform.isLinux { + } + // pkgs.lib.optionalAttrs pkgs.stdenv.hostPlatform.isLinux { i3-keybindings = ./modules/services/window-managers/i3-keybindings.nix; - } // import ./modules/programs/tmux; + } + // import ./modules/programs/tmux + // import ./modules/programs/ssh; } diff --git a/tests/modules/programs/ssh/default-config-expected.conf b/tests/modules/programs/ssh/default-config-expected.conf new file mode 100644 index 00000000..55748ea6 --- /dev/null +++ b/tests/modules/programs/ssh/default-config-expected.conf @@ -0,0 +1,15 @@ + + + + +Host * + ForwardAgent no + Compression no + ServerAliveInterval 0 + HashKnownHosts no + UserKnownHostsFile ~/.ssh/known_hosts + ControlMaster no + ControlPath ~/.ssh/master-%r@%n:%p + ControlPersist no + + diff --git a/tests/modules/programs/ssh/default-config.nix b/tests/modules/programs/ssh/default-config.nix new file mode 100644 index 00000000..e43ee3dc --- /dev/null +++ b/tests/modules/programs/ssh/default-config.nix @@ -0,0 +1,16 @@ +{ config, lib, pkgs, ... }: + +with lib; + +{ + config = { + programs.ssh = { + enable = true; + }; + + nmt.script = '' + assertFileExists home-files/.ssh/config + assertFileContent home-files/.ssh/config ${./default-config-expected.conf} + ''; + }; +} diff --git a/tests/modules/programs/ssh/default.nix b/tests/modules/programs/ssh/default.nix new file mode 100644 index 00000000..d385e4ee --- /dev/null +++ b/tests/modules/programs/ssh/default.nix @@ -0,0 +1,4 @@ +{ + ssh-defaults = ./default-config.nix; + ssh-match-blocks = ./match-blocks-attrs.nix; +} diff --git a/tests/modules/programs/ssh/match-blocks-attrs-expected.conf b/tests/modules/programs/ssh/match-blocks-attrs-expected.conf new file mode 100644 index 00000000..76bbe2e3 --- /dev/null +++ b/tests/modules/programs/ssh/match-blocks-attrs-expected.conf @@ -0,0 +1,25 @@ + + +Host * !github.com + Port 516 + IdentityFile file1 + IdentityFile file2 + +Host abc + ProxyJump jump-host + +Host xyz + ServerAliveInterval 60 + IdentityFile file + +Host * + ForwardAgent no + Compression no + ServerAliveInterval 0 + HashKnownHosts no + UserKnownHostsFile ~/.ssh/known_hosts + ControlMaster no + ControlPath ~/.ssh/master-%r@%n:%p + ControlPersist no + + diff --git a/tests/modules/programs/ssh/match-blocks-attrs.nix b/tests/modules/programs/ssh/match-blocks-attrs.nix new file mode 100644 index 00000000..cb554db2 --- /dev/null +++ b/tests/modules/programs/ssh/match-blocks-attrs.nix @@ -0,0 +1,34 @@ +{ config, lib, pkgs, ... }: + +with lib; + +{ + config = { + programs.ssh = { + enable = true; + matchBlocks = { + abc = { + identityFile = null; + proxyJump = "jump-host"; + }; + + xyz = { + identityFile = "file"; + serverAliveInterval = 60; + }; + + "* !github.com" = { + identityFile = ["file1" "file2"]; + port = 516; + }; + }; + }; + + nmt.script = '' + assertFileExists home-files/.ssh/config + assertFileContent \ + home-files/.ssh/config \ + ${./match-blocks-attrs-expected.conf} + ''; + }; +}