2 #include "../../../tests/catch2/catch.hpp"
5 #define SSHDIGGER_TEST_NOINDI
6 #define SSHDIGGER_TEST_NOLOG
7 #include "../sshDigger.hpp"
26 SCENARIO(
"sshDigger Configuration",
"[sshDigger]" )
28 GIVEN(
"a config file with 1 tunnel")
30 WHEN(
"the tunnel is fully specified and matches configName")
32 mx::app::writeConfigFile(
"/tmp/sshDigger_test.conf", {
"tunnel1",
"tunnel1",
"tunnel1" },
33 {
"remoteHost",
"localPort",
"remotePort" },
34 {
"exao2",
"80",
"81" } );
37 mx::app::appConfigurator config;
38 config.readConfig(
"/tmp/sshDigger_test.conf");
52 WHEN(
"the tunnel is fully specified and matches configName, includes monitorPort")
54 mx::app::writeConfigFile(
"/tmp/sshDigger_test.conf", {
"tunnel1",
"tunnel1",
"tunnel1" ,
"tunnel1"},
55 {
"remoteHost",
"localPort",
"remotePort",
"monitorPort" },
56 {
"exao2",
"80",
"81" ,
"6000"} );
59 mx::app::appConfigurator config;
60 config.readConfig(
"/tmp/sshDigger_test.conf");
75 WHEN(
"no unused sections")
77 mx::app::writeConfigFile(
"/tmp/sshDigger_test.conf", {},
81 mx::app::appConfigurator config;
82 config.readConfig(
"/tmp/sshDigger_test.conf");
93 WHEN(
"the tunnel does not match configName")
95 mx::app::writeConfigFile(
"/tmp/sshDigger_test.conf", {
"tunnel1",
"tunnel1",
"tunnel1" },
96 {
"remoteHost",
"localPort",
"remotePort" },
97 {
"exao2",
"80",
"81" } );
100 mx::app::appConfigurator config;
101 config.readConfig(
"/tmp/sshDigger_test.conf");
112 WHEN(
"no remote host")
114 mx::app::writeConfigFile(
"/tmp/sshDigger_test.conf", {
"tunnel1",
"tunnel1" },
115 {
"localPort",
"remotePort" },
119 mx::app::appConfigurator config;
120 config.readConfig(
"/tmp/sshDigger_test.conf");
130 WHEN(
"no local port")
132 mx::app::writeConfigFile(
"/tmp/sshDigger_test.conf", {
"tunnel1",
"tunnel1" },
133 {
"remoteHost",
"remotePort" },
136 mx::app::appConfigurator config;
137 config.readConfig(
"/tmp/sshDigger_test.conf");
147 WHEN(
"no remote port")
149 mx::app::writeConfigFile(
"/tmp/sshDigger_test.conf", {
"tunnel1",
"tunnel1" },
150 {
"remoteHost",
"localPort" },
153 mx::app::appConfigurator config;
154 config.readConfig(
"/tmp/sshDigger_test.conf");
165 GIVEN(
"a config file with 2 tunnels")
167 WHEN(
"the tunnels are fully specified and match their configNames")
169 mx::app::writeConfigFile(
"/tmp/sshDigger_test.conf", {
"tunnel1",
"tunnel1",
"tunnel1",
"tunnel2",
"tunnel2",
"tunnel2" },
170 {
"remoteHost",
"localPort",
"remotePort",
"remoteHost",
"localPort",
"remotePort" },
171 {
"exao2",
"80",
"81",
"exao3",
"85",
"86" } );
174 mx::app::appConfigurator config;
175 config.readConfig(
"/tmp/sshDigger_test.conf");
199 WHEN(
"No tunnels match configName")
201 mx::app::writeConfigFile(
"/tmp/sshDigger_test.conf", {
"tunnel1",
"tunnel1",
"tunnel1",
"tunnel2",
"tunnel2",
"tunnel2" },
202 {
"remoteHost",
"localPort",
"remotePort",
"remoteHost",
"localPort",
"remotePort" },
203 {
"exao2",
"80",
"81",
"exao3",
"85",
"86" } );
205 mx::app::appConfigurator config;
206 config.readConfig(
"/tmp/sshDigger_test.conf");
217 WHEN(
"no remote host in first tunnel")
219 mx::app::writeConfigFile(
"/tmp/sshDigger_test.conf", {
"tunnel1",
"tunnel1",
"tunnel2",
"tunnel2",
"tunnel2" },
220 {
"localPort",
"remotePort",
"remoteHost",
"localPort",
"remotePort" },
221 {
"80",
"81",
"exao3",
"85",
"86" } );
225 mx::app::appConfigurator config;
226 config.readConfig(
"/tmp/sshDigger_test.conf");
246 WHEN(
"no remote host in 2nd tunnel")
248 mx::app::writeConfigFile(
"/tmp/sshDigger_test.conf", {
"tunnel1",
"tunnel1",
"tunnel1",
"tunnel2",
"tunnel2" },
249 {
"remoteHost",
"localPort",
"remotePort",
"localPort",
"remotePort" },
250 {
"exao2",
"80",
"81",
"85",
"86" } );
253 mx::app::appConfigurator config;
254 config.readConfig(
"/tmp/sshDigger_test.conf");
274 WHEN(
"no local port in first tunnel")
276 mx::app::writeConfigFile(
"/tmp/sshDigger_test.conf", {
"tunnel1",
"tunnel1",
"tunnel2",
"tunnel2",
"tunnel2" },
277 {
"remoteHost",
"remotePort",
"remoteHost",
"localPort",
"remotePort" },
278 {
"exao2",
"81",
"exao3",
"85",
"86" } );
282 mx::app::appConfigurator config;
283 config.readConfig(
"/tmp/sshDigger_test.conf");
303 WHEN(
"no local port in second tunnel")
305 mx::app::writeConfigFile(
"/tmp/sshDigger_test.conf", {
"tunnel1",
"tunnel1",
"tunnel1",
"tunnel2",
"tunnel2" },
306 {
"remoteHost",
"localPort",
"remotePort",
"remoteHost",
"remotePort" },
307 {
"exao2",
"80",
"81",
"exao3",
"86" } );
309 mx::app::appConfigurator config;
310 config.readConfig(
"/tmp/sshDigger_test.conf");
329 WHEN(
"no remote port in first tunnel")
331 mx::app::writeConfigFile(
"/tmp/sshDigger_test.conf", {
"tunnel1",
"tunnel1",
"tunnel2",
"tunnel2",
"tunnel2" },
332 {
"remoteHost",
"localPort",
"remoteHost",
"localPort",
"remotePort" },
333 {
"exao2",
"80",
"exao3",
"85",
"86" } );
337 mx::app::appConfigurator config;
338 config.readConfig(
"/tmp/sshDigger_test.conf");
357 WHEN(
"no remote port in second tunnel")
359 mx::app::writeConfigFile(
"/tmp/sshDigger_test.conf", {
"tunnel1",
"tunnel1",
"tunnel1",
"tunnel2",
"tunnel2" },
360 {
"remoteHost",
"localPort",
"remotePort",
"remoteHost",
"localPort" },
361 {
"exao2",
"80",
"81",
"exao3",
"85" } );
363 mx::app::appConfigurator config;
364 config.readConfig(
"/tmp/sshDigger_test.conf");
385 SCENARIO(
"sshDigger tunnel exec preparation",
"[sshDigger]" )
387 GIVEN(
"a config file with 1 tunnel")
389 WHEN(
"creating the tunnelSpec")
391 mx::app::writeConfigFile(
"/tmp/sshDigger_test.conf", {
"tunnel1",
"tunnel1",
"tunnel1" },
392 {
"remoteHost",
"localPort",
"remotePort" },
393 {
"exao2",
"80",
"81" } );
396 mx::app::appConfigurator config;
397 config.readConfig(
"/tmp/sshDigger_test.conf");
408 WHEN(
"creating the exec argv vector")
410 mx::app::writeConfigFile(
"/tmp/sshDigger_test.conf", {
"tunnel1",
"tunnel1",
"tunnel1" },
411 {
"remoteHost",
"localPort",
"remotePort" },
412 {
"exao2",
"80",
"81" } );
415 mx::app::appConfigurator config;
416 config.readConfig(
"/tmp/sshDigger_test.conf");
424 std::vector<std::string> argsV;
427 REQUIRE( argsV[0] ==
"autossh");
431 REQUIRE( argsV[4] ==
"80:localhost:81");
The MagAO-X SSH tunnel manager.
int loadConfigImpl(mx::app::appConfigurator &_config)
Implementation of loadConfig logic, separated for testing.
std::string tunnelSpec()
Create the tunnel specification string, [localPort]:localhost:[remotePort].
void genArgsV(std::vector< std::string > &argsV)
Generate the argv vector for the exec of autossh.
void configName(const std::string &cn)
#define SSHDIGGER_E_NOLOCALPORT
#define SSHDIGGER_E_NOTUNNELFOUND
#define SSHDIGGER_E_NOREMOTEPORT
#define SSHDIGGER_E_NOHOSTNAME
#define SSHDIGGER_E_NOTUNNELS
SCENARIO("sshDigger Configuration", "[sshDigger]")