Skip to content

Commit

Permalink
Merge pull request #26 from maciej-szlosarczyk/handle-commandless-hello
Browse files Browse the repository at this point in the history
Handle hello that is not nested under command element
  • Loading branch information
vohmar authored Oct 7, 2019
2 parents 0557c85 + eab9fae commit 3386240
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 2 deletions.
12 changes: 10 additions & 2 deletions apps/epp_proxy/src/epp_xml.erl
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,22 @@

%% Get command from an xmlElement. Otherwise return undefined.
get_command(Record)
when is_record(Record, xmlElement) ->
case xmerl_xpath:string("name(/epp/*[1])", Record) of
{xmlObj, string, "hello"} -> "hello";
{xmlObj, string, "command"} -> get_command1(Record);
{xmlObj, string, []} -> undefined
end;
get_command(_) -> undefined.

get_command1(Record)
when is_record(Record, xmlElement) ->
case xmerl_xpath:string("name(/epp/command/*[1])",
Record)
of
{xmlObj, string, []} -> undefined;
{xmlObj, string, Command} -> Command
end;
get_command(_) -> undefined.
end.

%% xml_erl expects a list of characters, so let's give it to it.
%% Otherwise return an error tuple.
Expand Down
19 changes: 19 additions & 0 deletions apps/epp_proxy/test/tcp_client_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
-export([frame_size_test_case/1,
greetings_test_case/1,
session_test_case/1,
simple_hello_test_case/1,
valid_command_test_case/1,
long_message_test_case/1,
invalid_command_test_case/1,
Expand All @@ -18,6 +19,7 @@ all() ->
[frame_size_test_case,
greetings_test_case,
session_test_case,
simple_hello_test_case,
valid_command_test_case,
long_message_test_case,
invalid_command_test_case,
Expand Down Expand Up @@ -51,6 +53,17 @@ greetings_test_case(Config) ->
match_data(Data, "<greeting>"),
ok.

simple_hello_test_case(Config) ->
Options = proplists:get_value(tcp_options, Config),
{ok, Socket} = gen_tcp:connect("localhost", 1180, Options, 2000),
_Data = receive_data(Socket),
ok = send_data(hello_command(), Socket),
HelloResponse = receive_data(Socket),
match_data(HelloResponse,
"<extURI>urn:ietf:params:xml:ns:secDNS-1.1</extURI>"),
match_data(HelloResponse, "https://epp.tld.ee/schema/eis-1.0.xsd"),
ok.

session_test_case(Config) ->
Options = proplists:get_value(tcp_options, Config),
{ok, Socket} = gen_tcp:connect("localhost", 1180, Options, 2000),
Expand Down Expand Up @@ -212,6 +225,12 @@ match_data(Data, Pattern) ->
{ok, MatchPattern} = re:compile(Pattern),
{match, _Captured} = re:run(Data, MatchPattern).

hello_command() ->
<<"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>",
"<epp xmlns=\"https://epp.tld.ee/schema/epp-ee-1.0.xsd\">",
"<hello/>",
"</epp>">>.

login_command() ->
<<"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n"
"<epp xmlns=\"https://epp.tld.ee/schema/epp-ee-1.0.xsd\">\n"
Expand Down
19 changes: 19 additions & 0 deletions apps/epp_proxy/test/tls_client_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
-export([frame_size_test_case/1,
greetings_test_case/1,
session_test_case/1,
simple_hello_test_case/1,
valid_command_test_case/1,
long_message_test_case/1,
invalid_command_test_case/1,
Expand All @@ -19,6 +20,7 @@ all() ->
[frame_size_test_case,
greetings_test_case,
session_test_case,
simple_hello_test_case,
valid_command_test_case,
long_message_test_case,
invalid_command_test_case,
Expand Down Expand Up @@ -60,6 +62,17 @@ greetings_test_case(Config) ->
match_data(Data, "<greeting>"),
ok.

simple_hello_test_case(Config) ->
Options = proplists:get_value(ssl_options, Config),
{ok, Socket} = ssl:connect("localhost", 1443, Options, 2000),
_Data = receive_data(Socket),
ok = send_data(hello_command(), Socket),
HelloResponse = receive_data(Socket),
match_data(HelloResponse,
"<extURI>urn:ietf:params:xml:ns:secDNS-1.1</extURI>"),
match_data(HelloResponse, "https://epp.tld.ee/schema/eis-1.0.xsd"),
ok.

session_test_case(Config) ->
Options = proplists:get_value(ssl_options, Config),
{ok, Socket} = ssl:connect("localhost", 1443, Options, 2000),
Expand Down Expand Up @@ -229,6 +242,12 @@ match_data(Data, Pattern) ->
{ok, MatchPattern} = re:compile(Pattern),
{match, _Captured} = re:run(Data, MatchPattern).

hello_command() ->
<<"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>",
"<epp xmlns=\"https://epp.tld.ee/schema/epp-ee-1.0.xsd\">",
"<hello/>",
"</epp>">>.

login_command() ->
<<"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n"
"<epp xmlns=\"https://epp.tld.ee/schema/epp-ee-1.0.xsd\">\n"
Expand Down

0 comments on commit 3386240

Please sign in to comment.