From 9adf0bd69ee0b1823efdb7eab0d453114d7198ce Mon Sep 17 00:00:00 2001 From: Patrik Nyblom Date: Fri, 13 May 2011 11:35:28 +0200 Subject: Mend epmd testcases that test remote access --- erts/epmd/test/epmd_SUITE.erl | 139 +++++++++++++++++++++++------------------- 1 file changed, 76 insertions(+), 63 deletions(-) diff --git a/erts/epmd/test/epmd_SUITE.erl b/erts/epmd/test/epmd_SUITE.erl index 72c890503d..27de129e62 100644 --- a/erts/epmd/test/epmd_SUITE.erl +++ b/erts/epmd/test/epmd_SUITE.erl @@ -780,42 +780,43 @@ no_nonlocal_register(suite) -> no_nonlocal_register(doc) -> ["Ensure that we cannot register throug a nonlocal connection"]; no_nonlocal_register(Config) when is_list(Config) -> + ?line case {os:find_executable("ssh"),ct:get_config(ssh_proxy_host)} of + {SSH,Name} when is_list(Name), is_list(SSH) -> + do_no_nonlocal_register(Config,Name); + {false,_} -> + {skip, "No ssh command found to create proxy"}; + _ -> + {skip, "No ssh_proxy_host configured in ts.config"} + end. +do_no_nonlocal_register(Config,SSHHost) when is_list(Config) -> ?line ok = epmdrun(), - ?line {ok,Ifs} = inet:getiflist(), - ?line Addr0 = [ inet:ifget(I, [addr]) || I <- Ifs ], - ?line Addr1 = [ A || {ok,[{addr,A}]} <- Addr0], - ?line Addr = lists:filter(fun({127,_,_,_}) -> - false; - (_) -> - true - end,Addr1), - %% Now we should have all non loopback interface addresses, - %% none should accept a alive2 registration. - ?line Res = lists:map(fun(Ad={A1,A2,A3,A4}) -> - try - Name = "gurka_"++ - integer_to_list(A1)++"_"++ - integer_to_list(A2)++"_"++ - integer_to_list(A3)++"_"++ - integer_to_list(A4), - Bname = list_to_binary(Name), - NameS = byte_size(Bname), - ?line Bin= <<$x:8,4747:16,$M:8,0:8,5:16, - 5:16,NameS:16,Bname/binary, - 0:16>>, - ?line S = size(Bin), - {ok, E} = connect(Ad), - gen_tcp:send(E,[<>,Bin]), - closed = recv(E,1), - gen_tcp:close(E), - true - catch - _:_ -> - false - end - end, Addr), - erlang:display(Res), - ?line true = alltrue(Res), + ?line ProxyPort = proxy_port(), + ?line ok = ssh_proxy(SSHHost,ProxyPort), + Res = try + ?line Name = "gurka_" + %++ + %integer_to_list(A1)++"_"++ + %integer_to_list(A2)++"_"++ + %integer_to_list(A3)++"_"++ + %integer_to_list(A4) + , + ?line Bname = list_to_binary(Name), + ?line NameS = byte_size(Bname), + ?line Bin= <<$x:8,4747:16,$M:8,0:8,5:16, + 5:16,NameS:16,Bname/binary, + 0:16>>, + ?line S = size(Bin), + ?line {ok, E} = connect("localhost",ProxyPort,passive), + ?line gen_tcp:send(E,[<>,Bin]), + ?line closed = recv(E,1), + ?line gen_tcp:close(E), + true + catch + _:_ -> + false + end, + %erlang:display(Res), + true = Res, ok. no_nonlocal_kill(suite) -> @@ -823,35 +824,34 @@ no_nonlocal_kill(suite) -> no_nonlocal_kill(doc) -> ["Ensure that we cannot kill through nonlocal connection"]; no_nonlocal_kill(Config) when is_list(Config) -> + ?line case {os:find_executable("ssh"),ct:get_config(ssh_proxy_host)} of + {SSH,Name} when is_list(Name), is_list(SSH) -> + do_no_nonlocal_kill(Config,Name); + {false,_} -> + {skip, "No ssh command found to create proxy"}; + _ -> + {skip, "No ssh_proxy_host configured in ts.config"} + end. +do_no_nonlocal_kill(Config,SSHHost) when is_list(Config) -> ?line ok = epmdrun(), - ?line {ok,Ifs} = inet:getiflist(), - ?line Addr0 = [ inet:ifget(I, [addr]) || I <- Ifs ], - ?line Addr1 = [ A || {ok,[{addr,A}]} <- Addr0], - ?line Addr = lists:filter(fun({127,_,_,_}) -> - false; - (_) -> - true - end,Addr1), - %% Now we should have all non loopback interface addresses, - %% none should accept a alive2 registration. - ?line Res = lists:map(fun(Ad) -> - try - {ok, E} = connect(Ad), - M = [?EPMD_KILL_REQ], - send(E, [size16(M), M]), - closed = recv(E,2), - gen_tcp:close(E), - sleep(?MEDIUM_PAUSE), - {ok, E2} = connect(Ad), - gen_tcp:close(E2), - true - catch - _:_ -> - false - end - end, Addr), - erlang:display(Res), - ?line true = alltrue(Res), + ?line ProxyPort = proxy_port(), + ?line ok = ssh_proxy(SSHHost,ProxyPort), + Res = try + {ok, E} = connect("localhost",ProxyPort,passive), + M = [?EPMD_KILL_REQ], + send(E, [size16(M), M]), + closed = recv(E,2), + gen_tcp:close(E), + sleep(?MEDIUM_PAUSE), + {ok, E2} = connect("localhost",ProxyPort,passive), + gen_tcp:close(E2), + true + catch + _:_ -> + false + end, + %erlang:display(Res), + true = Res, ok. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% no_live_killing(doc) -> @@ -896,6 +896,19 @@ cleanup() -> true end. +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Start an ssh channel to simulate remote access + +proxy_port() -> + ?PORT+1. + +ssh_proxy(SSHHost,ProxyPort) -> + ?line Host = lists:nth(2,string:tokens(atom_to_list(node()),"@")), + % Requires proxy to be a unix host with the command 'read' accessible + ?line osrun("ssh -L localhost:"++integer_to_list(ProxyPort)++":"++Host++":" + ++integer_to_list(?PORT)++" "++SSHHost++" read"). + + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Normal debug start of epmd -- cgit v1.2.3 From 7069ebf67ea417fa5b5cc13d83aa23db92c751eb Mon Sep 17 00:00:00 2001 From: Patrik Nyblom Date: Wed, 18 May 2011 15:56:53 +0200 Subject: Make ssh proxy work with older versions of ssh --- erts/epmd/test/epmd_SUITE.erl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erts/epmd/test/epmd_SUITE.erl b/erts/epmd/test/epmd_SUITE.erl index 27de129e62..6889ec0b34 100644 --- a/erts/epmd/test/epmd_SUITE.erl +++ b/erts/epmd/test/epmd_SUITE.erl @@ -905,7 +905,7 @@ proxy_port() -> ssh_proxy(SSHHost,ProxyPort) -> ?line Host = lists:nth(2,string:tokens(atom_to_list(node()),"@")), % Requires proxy to be a unix host with the command 'read' accessible - ?line osrun("ssh -L localhost:"++integer_to_list(ProxyPort)++":"++Host++":" + ?line osrun("ssh -L "++integer_to_list(ProxyPort)++":"++Host++":" ++integer_to_list(?PORT)++" "++SSHHost++" read"). -- cgit v1.2.3