summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHans Nilsson <hans@erlang.org>2020-06-04 17:35:36 +0200
committerHans Nilsson <hans@erlang.org>2020-06-16 11:43:42 +0200
commitf1c67d5a7496af78845f33b70da98f2b7ebe4e03 (patch)
tree56c262cfccb7ad4c82fc749d7539df60e8cbb87b
parent8dc293bb5a7e0d12e681422c5d672c8554441e0c (diff)
downloaderlang-f1c67d5a7496af78845f33b70da98f2b7ebe4e03.tar.gz
ssh: Added missing test case for keyboard-interactive
-rw-r--r--lib/ssh/test/ssh_options_SUITE.erl93
1 files changed, 93 insertions, 0 deletions
diff --git a/lib/ssh/test/ssh_options_SUITE.erl b/lib/ssh/test/ssh_options_SUITE.erl
index 06c5e19456..b6a74e32fa 100644
--- a/lib/ssh/test/ssh_options_SUITE.erl
+++ b/lib/ssh/test/ssh_options_SUITE.erl
@@ -102,6 +102,9 @@ all() ->
server_pwdfun_option,
server_pwdfun_4_option,
server_keyboard_interactive,
+ auth_method_kb_interactive_data_tuple,
+ auth_method_kb_interactive_data_fun3,
+ auth_method_kb_interactive_data_fun4,
{group, dir_options},
ssh_connect_timeout,
ssh_connect_arg4_timeout,
@@ -442,6 +445,96 @@ server_keyboard_interactive(Config) ->
{"bar",2}]).
%%--------------------------------------------------------------------
+auth_method_kb_interactive_data_tuple(Config) ->
+ T = {"abc1", "def1", "ghi1: ", true},
+ amkid(Config, T, T).
+
+auth_method_kb_interactive_data_fun3(Config) ->
+ T = {"abc2", "def2", "ghi2: ", true},
+ amkid(Config, T,
+ fun(_Peer, _User, _Service) -> T end
+ ).
+
+auth_method_kb_interactive_data_fun4(Config) ->
+ T = {"abc3", "def3", "ghi3: ", true},
+ amkid(Config, T,
+ fun(_Peer, _User, _Service, _State) -> T end
+ ).
+
+amkid(Config, {ExpectName,ExpectInstr,ExpectPrompts,ExpectEcho}, OptVal) ->
+ UserDir = proplists:get_value(user_dir, Config),
+ SysDir = proplists:get_value(data_dir, Config),
+ %% Test that the state works
+ Parent = self(),
+ PWDFUN = fun("foo",P="bar",_,S) -> Parent!{P,S},true;
+ (_,P,_,S=undefined) -> Parent!{P,S},{false,1};
+ (_,P,_,S) -> Parent!{P,S}, {false,S+1}
+ end,
+ {Pid, Host, Port} = ssh_test_lib:daemon([{system_dir, SysDir},
+ {user_dir, UserDir},
+ {auth_methods,"keyboard-interactive"},
+ {pwdfun,PWDFUN},
+ {auth_method_kb_interactive_data,OptVal}
+ ]),
+
+ KIFFUN = fun(Name, Instr, PromptInfos) ->
+ K={k,self()},
+ Answer =
+ case get(K) of
+ undefined ->
+ put(K,1),
+ ["incorrect"];
+ 2 ->
+ put(K,3),
+ ["bar"];
+ S->
+ put(K,S+1),
+ ["Bad again"]
+ end,
+ ct:log("keyboard_interact_fun:~n"
+ " Name = ~p~n"
+ " Instruction = ~p~n"
+ " Prompts = ~p~n"
+ "~nAnswer:~n ~p~n",
+ [Name, Instr, PromptInfos, Answer]),
+ case {binary_to_list(Name),
+ binary_to_list(Instr),
+ [{binary_to_list(PI),Echo} || {PI,Echo} <- PromptInfos]
+ } of
+ {ExpectName, ExpectInstr, [{ExpectPrompts,ExpectEcho}]} ->
+ ct:log("Match!", []),
+ Answer;
+ _ ->
+ ct:log("Not match!~n"
+ " ExpectName = ~p~n"
+ " ExpectInstruction = ~p~n"
+ " ExpectPrompts = ~p~n",
+ [ExpectName, ExpectInstr, [{ExpectPrompts,ExpectEcho}]]),
+ ct:fail("no_match")
+ end
+ end,
+ ssh_dbg:start(), ssh_dbg:on(authentication), %% Test dbg code
+ ConnectionRef2 =
+ ssh_test_lib:connect(Host, Port, [{silently_accept_hosts, true},
+ {user, "foo"},
+ {keyboard_interact_fun, KIFFUN},
+ {user_dir, UserDir}]),
+ ssh_dbg:stop(),
+ ssh:close(ConnectionRef2),
+ ssh:stop_daemon(Pid),
+
+ lists:foreach(fun(Expect) ->
+ receive
+ Expect -> ok;
+ Other -> ct:fail("Expect: ~p~nReceived ~p",[Expect,Other])
+ after
+ 2000 -> ct:fail("Timeout expecting ~p",[Expect])
+ end
+ end, [{"incorrect",undefined},
+ {"Bad again",1},
+ {"bar",2}]).
+
+%%--------------------------------------------------------------------
system_dir_option(Config) ->
DirUnread = proplists:get_value(unreadable_dir,Config),
FileRead = proplists:get_value(readable_file,Config),