diff options
author | Patrik Nyblom <[email protected]> | 2011-05-13 11:35:28 +0200 |
---|---|---|
committer | Patrik Nyblom <[email protected]> | 2011-05-13 11:35:28 +0200 |
commit | 9adf0bd69ee0b1823efdb7eab0d453114d7198ce (patch) | |
tree | 46d19c7e42db4fd76da2dd3da68394cf7f162195 | |
parent | eb26a54528e824f8f08af49d47281201bd8fefe3 (diff) | |
download | otp-9adf0bd69ee0b1823efdb7eab0d453114d7198ce.tar.gz otp-9adf0bd69ee0b1823efdb7eab0d453114d7198ce.tar.bz2 otp-9adf0bd69ee0b1823efdb7eab0d453114d7198ce.zip |
Mend epmd testcases that test remote access
-rw-r--r-- | erts/epmd/test/epmd_SUITE.erl | 139 |
1 files 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,[<<S:16>>,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,[<<S:16>>,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 |