Skip to content

Commit 3386240

Browse files
authored
Merge pull request #26 from maciej-szlosarczyk/handle-commandless-hello
Handle hello that is not nested under command element
2 parents 0557c85 + eab9fae commit 3386240

3 files changed

Lines changed: 48 additions & 2 deletions

File tree

apps/epp_proxy/src/epp_xml.erl

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,22 @@
66

77
%% Get command from an xmlElement. Otherwise return undefined.
88
get_command(Record)
9+
when is_record(Record, xmlElement) ->
10+
case xmerl_xpath:string("name(/epp/*[1])", Record) of
11+
{xmlObj, string, "hello"} -> "hello";
12+
{xmlObj, string, "command"} -> get_command1(Record);
13+
{xmlObj, string, []} -> undefined
14+
end;
15+
get_command(_) -> undefined.
16+
17+
get_command1(Record)
918
when is_record(Record, xmlElement) ->
1019
case xmerl_xpath:string("name(/epp/command/*[1])",
1120
Record)
1221
of
1322
{xmlObj, string, []} -> undefined;
1423
{xmlObj, string, Command} -> Command
15-
end;
16-
get_command(_) -> undefined.
24+
end.
1725

1826
%% xml_erl expects a list of characters, so let's give it to it.
1927
%% Otherwise return an error tuple.

apps/epp_proxy/test/tcp_client_SUITE.erl

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
-export([frame_size_test_case/1,
99
greetings_test_case/1,
1010
session_test_case/1,
11+
simple_hello_test_case/1,
1112
valid_command_test_case/1,
1213
long_message_test_case/1,
1314
invalid_command_test_case/1,
@@ -18,6 +19,7 @@ all() ->
1819
[frame_size_test_case,
1920
greetings_test_case,
2021
session_test_case,
22+
simple_hello_test_case,
2123
valid_command_test_case,
2224
long_message_test_case,
2325
invalid_command_test_case,
@@ -51,6 +53,17 @@ greetings_test_case(Config) ->
5153
match_data(Data, "<greeting>"),
5254
ok.
5355

56+
simple_hello_test_case(Config) ->
57+
Options = proplists:get_value(tcp_options, Config),
58+
{ok, Socket} = gen_tcp:connect("localhost", 1180, Options, 2000),
59+
_Data = receive_data(Socket),
60+
ok = send_data(hello_command(), Socket),
61+
HelloResponse = receive_data(Socket),
62+
match_data(HelloResponse,
63+
"<extURI>urn:ietf:params:xml:ns:secDNS-1.1</extURI>"),
64+
match_data(HelloResponse, "https://epp.tld.ee/schema/eis-1.0.xsd"),
65+
ok.
66+
5467
session_test_case(Config) ->
5568
Options = proplists:get_value(tcp_options, Config),
5669
{ok, Socket} = gen_tcp:connect("localhost", 1180, Options, 2000),
@@ -212,6 +225,12 @@ match_data(Data, Pattern) ->
212225
{ok, MatchPattern} = re:compile(Pattern),
213226
{match, _Captured} = re:run(Data, MatchPattern).
214227

228+
hello_command() ->
229+
<<"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>",
230+
"<epp xmlns=\"https://epp.tld.ee/schema/epp-ee-1.0.xsd\">",
231+
"<hello/>",
232+
"</epp>">>.
233+
215234
login_command() ->
216235
<<"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n"
217236
"<epp xmlns=\"https://epp.tld.ee/schema/epp-ee-1.0.xsd\">\n"

apps/epp_proxy/test/tls_client_SUITE.erl

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
-export([frame_size_test_case/1,
99
greetings_test_case/1,
1010
session_test_case/1,
11+
simple_hello_test_case/1,
1112
valid_command_test_case/1,
1213
long_message_test_case/1,
1314
invalid_command_test_case/1,
@@ -19,6 +20,7 @@ all() ->
1920
[frame_size_test_case,
2021
greetings_test_case,
2122
session_test_case,
23+
simple_hello_test_case,
2224
valid_command_test_case,
2325
long_message_test_case,
2426
invalid_command_test_case,
@@ -60,6 +62,17 @@ greetings_test_case(Config) ->
6062
match_data(Data, "<greeting>"),
6163
ok.
6264

65+
simple_hello_test_case(Config) ->
66+
Options = proplists:get_value(ssl_options, Config),
67+
{ok, Socket} = ssl:connect("localhost", 1443, Options, 2000),
68+
_Data = receive_data(Socket),
69+
ok = send_data(hello_command(), Socket),
70+
HelloResponse = receive_data(Socket),
71+
match_data(HelloResponse,
72+
"<extURI>urn:ietf:params:xml:ns:secDNS-1.1</extURI>"),
73+
match_data(HelloResponse, "https://epp.tld.ee/schema/eis-1.0.xsd"),
74+
ok.
75+
6376
session_test_case(Config) ->
6477
Options = proplists:get_value(ssl_options, Config),
6578
{ok, Socket} = ssl:connect("localhost", 1443, Options, 2000),
@@ -229,6 +242,12 @@ match_data(Data, Pattern) ->
229242
{ok, MatchPattern} = re:compile(Pattern),
230243
{match, _Captured} = re:run(Data, MatchPattern).
231244

245+
hello_command() ->
246+
<<"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>",
247+
"<epp xmlns=\"https://epp.tld.ee/schema/epp-ee-1.0.xsd\">",
248+
"<hello/>",
249+
"</epp>">>.
250+
232251
login_command() ->
233252
<<"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n"
234253
"<epp xmlns=\"https://epp.tld.ee/schema/epp-ee-1.0.xsd\">\n"

0 commit comments

Comments
 (0)