diff options
author | Hans Nilsson <hans@erlang.org> | 2020-06-15 10:37:54 +0200 |
---|---|---|
committer | Hans Nilsson <hans@erlang.org> | 2020-06-16 11:44:25 +0200 |
commit | 67de05f32fec56aa7d549fb11c5dbc9b783bd217 (patch) | |
tree | 6a901f5af295ddb59ee1d3ed11da809f81fed608 | |
parent | 239582811a385d2123fd0a7055ceedf2ff7ed41f (diff) | |
download | erlang-67de05f32fec56aa7d549fb11c5dbc9b783bd217.tar.gz |
ssh: Check user_dir_fun option
-rw-r--r-- | lib/ssh/test/ssh_options_SUITE.erl | 57 | ||||
-rw-r--r-- | lib/ssh/test/ssh_test_lib.erl | 18 |
2 files changed, 70 insertions, 5 deletions
diff --git a/lib/ssh/test/ssh_options_SUITE.erl b/lib/ssh/test/ssh_options_SUITE.erl index b6a74e32fa..5769cc8f0a 100644 --- a/lib/ssh/test/ssh_options_SUITE.erl +++ b/lib/ssh/test/ssh_options_SUITE.erl @@ -62,7 +62,8 @@ system_dir_option/1, unexpectedfun_option_client/1, unexpectedfun_option_server/1, - user_dir_option/1, + user_dir_option/1, + user_dir_fun_option/1, connectfun_disconnectfun_server/1, hostkey_fingerprint_check/1, hostkey_fingerprint_check_md5/1, @@ -147,6 +148,7 @@ groups() -> max_sessions_sftp_start_channel_sequential ]}, {dir_options, [], [user_dir_option, + user_dir_fun_option, system_dir_option]} ]. @@ -555,7 +557,7 @@ system_dir_option(Config) -> ct:fail("Didn't detect that option is a plain file", []) end. - +%%-------------------------------------------------------------------- user_dir_option(Config) -> DirUnread = proplists:get_value(unreadable_dir,Config), FileRead = proplists:get_value(readable_file,Config), @@ -577,6 +579,44 @@ user_dir_option(Config) -> end. %%-------------------------------------------------------------------- +user_dir_fun_option(Config) -> + DataDir = proplists:get_value(data_dir, Config), + PrivDir = proplists:get_value(priv_dir, Config), + SysDir = filename:join(PrivDir,"system"), + ssh_test_lib:setup_all_host_keys(DataDir, SysDir), + UserDir = filename:join(PrivDir,"user"), + ssh_test_lib:setup_all_user_keys(DataDir, UserDir), + + Parent = self(), + Ref = make_ref(), + {Pid, Host, Port} = ssh_test_lib:daemon([{system_dir, SysDir}, + {user_dir_fun, fun(User) -> + ct:log("user_dir_fun called ~p",[User]), + Parent ! {user,Ref,User}, + UserDir + end}, + {failfun, fun ssh_test_lib:failfun/2}]), + _ConnectionRef = + ssh_test_lib:connect(Host, Port, [{silently_accept_hosts, true}, + {user, "foo"}, + {user_dir, UserDir}, + {auth_methods,"publickey"}, + {user_interaction, false}]), + receive + {user,Ref,"foo"} -> + ssh:stop_daemon(Pid), + ok; + {user,Ref,What} -> + ssh:stop_daemon(Pid), + ct:log("Got ~p",[What]), + {fail, bad_userid} + after 2000 -> + ssh:stop_daemon(Pid), + {fail,timeout_in_receive} + end. + + +%%-------------------------------------------------------------------- %%% validate client that uses the 'ssh_msg_debug_fun' option ssh_msg_debug_fun_option_client(Config) -> UserDir = proplists:get_value(user_dir, Config), @@ -1128,7 +1168,7 @@ id_string_random_client(Config) -> receive {id,Server,Id="SSH-2.0-Erlang"++_} -> ct:fail("Unexpected id: ~s.",[Id]); - {id,Server,Rnd="SSH-2.0-"++_} -> + {id,Server,Rnd="SSH-2.0-"++ID} when 4=<length(ID),length(ID)=<7 -> %% Add 2 for CRLF ct:log("Got correct ~s",[Rnd]); {id,Server,Id} -> ct:fail("Unexpected id: ~s.",[Id]) @@ -1157,14 +1197,21 @@ id_string_own_string_server_trail_space(Config) -> %%-------------------------------------------------------------------- id_string_random_server(Config) -> - {_Server, Host, Port} = ssh_test_lib:std_daemon(Config, [{id_string,random}]), + %% Check undocumented format of id_string. First a bad variant: + {error,{eoptions,_}} = ssh:daemon(0, [{id_string,{random,8,6}}]), + %% And then a correct one: + {_Server, Host, Port} = ssh_test_lib:std_daemon(Config, [{id_string,{random,6,8}}]), {ok,S1}=ssh_test_lib:gen_tcp_connect(Host,Port,[{active,false},{packet,line}]), {ok,"SSH-2.0-"++Rnd} = gen_tcp:recv(S1, 0, 2000), case Rnd of "Erlang"++_ -> ct:log("Id=~p",[Rnd]), {fail,got_default_id}; "Olle\r\n" -> {fail,got_previous_tests_value}; - _ -> ct:log("Got ~s.",[Rnd]) + _ when 8=<length(Rnd),length(Rnd)=<10 -> %% Add 2 for CRLF + ct:log("Got correct ~s",[Rnd]); + _ -> + ct:log("Got wrong sized ~s.",[Rnd]), + {fail,got_wrong_size} end. %%-------------------------------------------------------------------- diff --git a/lib/ssh/test/ssh_test_lib.erl b/lib/ssh/test/ssh_test_lib.erl index f8fe4392b9..8a0c209eb2 100644 --- a/lib/ssh/test/ssh_test_lib.erl +++ b/lib/ssh/test/ssh_test_lib.erl @@ -1024,6 +1024,24 @@ setup_all_host_keys(DataDir, SysDir) -> end end, [], ssh_transport:supported_algorithms(public_key)). + +setup_all_user_keys(DataDir, UserDir) -> + lists:foldl(fun(Alg, OkAlgs) -> + try + ok = ssh_test_lib:setup_user_key(Alg, DataDir, UserDir) + of + ok -> [Alg|OkAlgs] + catch + error:{badmatch, {error,enoent}} -> + OkAlgs; + C:E:S -> + ct:log("Exception in ~p:~p for alg ~p: ~p:~p~n~p", + [?MODULE,?FUNCTION_NAME,Alg,C,E,S]), + OkAlgs + end + end, [], ssh_transport:supported_algorithms(public_key)). + + setup_user_key(SshAlg, DataDir, UserDir) -> file:make_dir(UserDir), %% Copy private user key to user's dir |