diff --git a/apps/epp_proxy/test/epp_http_client_SUITE.erl b/apps/epp_proxy/test/epp_http_client_SUITE.erl index 65f4eb5..fcf9f53 100644 --- a/apps/epp_proxy/test/epp_http_client_SUITE.erl +++ b/apps/epp_proxy/test/epp_http_client_SUITE.erl @@ -19,7 +19,7 @@ hello_request_builder_test_case(_Config) -> cl_trid => "EE-123456789", raw_frame => "", headers => [{"User-Agent", <<"EPP proxy">>}]}, Request = epp_http_client:request_builder(RequestMap), - ExpectedTuple = {epp_request,get,"http://localhost:9292/epp/session/hello", + ExpectedTuple = {epp_request,get,"http://localhost:9292/session/hello", [], [<<"session=Random; Version=1">>], [{"User-Agent",<<"EPP proxy">>}], "hello"}, @@ -32,7 +32,7 @@ error_request_builder_test_case(_Config) -> message => <<"Expected better XML">>, headers => [{"User-Agent", <<"EPP proxy">>}]}, Request = epp_http_client:request_builder(RequestMap), - ExpectedTuple = {epp_request,get,"http://localhost:9292/epp/error", + ExpectedTuple = {epp_request,get,"http://localhost:9292/error", [{<<"code">>,<<"2001">>}, {<<"msg">>,<<"Expected better XML">>}, {<<"clTRID">>,"EE-123456789"}], @@ -48,7 +48,7 @@ command_request_builder_test_case(_Config) -> headers => [{"User-Agent", <<"EPP proxy">>}]}, Request = epp_http_client:request_builder(RequestMap), ExpectedTuple = {epp_request,post, - "http://localhost:9292/epp/command/create", + "http://localhost:9292/command/create", {multipart, [{<<"raw_frame">>,"Some XML here"}, {<<"clTRID">>,"EE-123456789"}]}, diff --git a/apps/epp_proxy/test/epp_router_SUITE.erl b/apps/epp_proxy/test/epp_router_SUITE.erl index c63e602..a49bd1b 100644 --- a/apps/epp_proxy/test/epp_router_SUITE.erl +++ b/apps/epp_proxy/test/epp_router_SUITE.erl @@ -25,61 +25,61 @@ request_method_test_case(_Config) -> %% TODO: Make less verbose and repetitive hello_url_test_case(_Config) -> - "http://localhost:9292/epp/session/hello" = epp_router:route_request("hello"), - "http://localhost:9292/epp/session/hello" = epp_router:route_request(<<"hello">>), + "http://localhost:9292/session/hello" = epp_router:route_request("hello"), + "http://localhost:9292/session/hello" = epp_router:route_request(<<"hello">>), ok. login_url_test_case(_Config) -> - "http://localhost:9292/epp/session/login" = epp_router:route_request("login"), - "http://localhost:9292/epp/session/login" = epp_router:route_request(<<"login">>), + "http://localhost:9292/session/login" = epp_router:route_request("login"), + "http://localhost:9292/session/login" = epp_router:route_request(<<"login">>), ok. logout_url_test_case(_Config) -> - "http://localhost:9292/epp/session/logout" = epp_router:route_request("logout"), - "http://localhost:9292/epp/session/logout" = epp_router:route_request(<<"logout">>), + "http://localhost:9292/session/logout" = epp_router:route_request("logout"), + "http://localhost:9292/session/logout" = epp_router:route_request(<<"logout">>), ok. check_url_test_case(_Config) -> - "http://localhost:9292/epp/command/check" = epp_router:route_request("check"), - "http://localhost:9292/epp/command/check" = epp_router:route_request(<<"check">>), + "http://localhost:9292/command/check" = epp_router:route_request("check"), + "http://localhost:9292/command/check" = epp_router:route_request(<<"check">>), ok. info_url_test_case(_Config) -> - "http://localhost:9292/epp/command/info" = epp_router:route_request("info"), - "http://localhost:9292/epp/command/info" = epp_router:route_request(<<"info">>), + "http://localhost:9292/command/info" = epp_router:route_request("info"), + "http://localhost:9292/command/info" = epp_router:route_request(<<"info">>), ok. poll_url_test_case(_Config) -> - "http://localhost:9292/epp/command/poll" = epp_router:route_request("poll"), - "http://localhost:9292/epp/command/poll" = epp_router:route_request(<<"poll">>), + "http://localhost:9292/command/poll" = epp_router:route_request("poll"), + "http://localhost:9292/command/poll" = epp_router:route_request(<<"poll">>), ok. create_url_test_case(_Config) -> - "http://localhost:9292/epp/command/create" = epp_router:route_request("create"), - "http://localhost:9292/epp/command/create" = epp_router:route_request(<<"create">>), + "http://localhost:9292/command/create" = epp_router:route_request("create"), + "http://localhost:9292/command/create" = epp_router:route_request(<<"create">>), ok. delete_url_test_case(_Config) -> - "http://localhost:9292/epp/command/delete" = epp_router:route_request("delete"), - "http://localhost:9292/epp/command/delete" = epp_router:route_request(<<"delete">>), + "http://localhost:9292/command/delete" = epp_router:route_request("delete"), + "http://localhost:9292/command/delete" = epp_router:route_request(<<"delete">>), ok. renew_url_test_case(_Config) -> - "http://localhost:9292/epp/command/renew" = epp_router:route_request("renew"), - "http://localhost:9292/epp/command/renew" = epp_router:route_request(<<"renew">>), + "http://localhost:9292/command/renew" = epp_router:route_request("renew"), + "http://localhost:9292/command/renew" = epp_router:route_request(<<"renew">>), ok. update_url_test_case(_Config) -> - "http://localhost:9292/epp/command/update" = epp_router:route_request("update"), - "http://localhost:9292/epp/command/update" = epp_router:route_request(<<"update">>), + "http://localhost:9292/command/update" = epp_router:route_request("update"), + "http://localhost:9292/command/update" = epp_router:route_request(<<"update">>), ok. transfer_url_test_case(_Config) -> - "http://localhost:9292/epp/command/transfer" = epp_router:route_request("transfer"), - "http://localhost:9292/epp/command/transfer" = epp_router:route_request(<<"transfer">>), + "http://localhost:9292/command/transfer" = epp_router:route_request("transfer"), + "http://localhost:9292/command/transfer" = epp_router:route_request(<<"transfer">>), ok. error_url_test_case(_Config) -> - "http://localhost:9292/epp/error" = epp_router:route_request("error"), - "http://localhost:9292/epp/error" = epp_router:route_request(<<"error">>), + "http://localhost:9292/error" = epp_router:route_request("error"), + "http://localhost:9292/error" = epp_router:route_request(<<"error">>), ok. diff --git a/apps/epp_proxy/test/tls_client_SUITE.erl b/apps/epp_proxy/test/tls_client_SUITE.erl index ae0ac6f..f550920 100644 --- a/apps/epp_proxy/test/tls_client_SUITE.erl +++ b/apps/epp_proxy/test/tls_client_SUITE.erl @@ -5,36 +5,62 @@ -export([all/0]). -export([init_per_suite/1, end_per_suite/1]). --export([frame_size_test_case/1]). +-export([frame_size_test_case/1, + greetings_test_case/1]). all() -> - [frame_size_test_case]. + [frame_size_test_case, + greetings_test_case]. init_per_suite(Config) -> application:ensure_all_started(epp_proxy), application:ensure_all_started(hackney), - [{my_key, <<"my value">>} | Config]. - -%% Test Cases -frame_size_test_case(_Config) -> CWD = code:priv_dir(epp_proxy), Options = [binary, {certfile, filename:join(CWD, "test_ca/certs/webclient.crt.pem")}, {keyfile, filename:join(CWD, "test_ca/private/webclient.key.pem")}, {active, false}], - {ok, Socket} = ssl:connect("localhost", 1443, Options, 2000), - {ok, Data} = ssl:recv(Socket, 0, 1200), - true = (byte_size(Data) =:= length_of_data(Data)), - ok. + [{ssl_options, Options} | Config]. end_per_suite(Config) -> application:stop(epp_proxy), application:stop(hackney), Config. +%% Test Cases +frame_size_test_case(Config) -> + Options = proplists:get_value(ssl_options, Config), + {ok, Socket} = ssl:connect("localhost", 1443, Options, 2000), + {ok, Data} = ssl:recv(Socket, 0, 1200), + true = (byte_size(Data) =:= length_of_data(Data)), + ok. + +greetings_test_case(Config) -> + Options = proplists:get_value(ssl_options, Config), + {ok, Socket} = ssl:connect("localhost", 1443, Options, 2000), + Data = receive_data(Socket), + match_data(Data, ""), + ok. + %% Helper functions: length_of_data(Data) -> EPPEnvelope = binary:part(Data, {0, 4}), ReportedLength = binary:decode_unsigned(EPPEnvelope, big), ReportedLength. + +send_data(Message, Socket) -> + Length = epp_util:frame_length_to_send(Message), + ByteSize = <>, + CompleteMessage = <>, + ok = ssl:send(Socket, CompleteMessage). + +receive_data(Socket) -> + {ok, Data} = ssl:recv(Socket, 0, 1200), + EppEnvelope = binary:part(Data, {0, 4}), + ReportedLength = binary:decode_unsigned(EppEnvelope, big), + binary:part(Data, {byte_size(Data), 4 - ReportedLength}). + +match_data(Data, Pattern) -> + {ok, MatchPattern} = re:compile(Pattern), + {match, _Captured} = re:run(Data, Pattern). diff --git a/config/test.config b/config/test.config index bb9982d..6b9b707 100644 --- a/config/test.config +++ b/config/test.config @@ -3,9 +3,9 @@ {tcp_port, 3333}, {tls_port, 1443}, - {epp_session_url, "http://localhost:9292/epp/session/"}, - {epp_command_url, "http://localhost:9292/epp/command/"}, - {epp_error_url, "http://localhost:9292/epp/error/"}, + {epp_session_url, "http://localhost:9292/session/"}, + {epp_command_url, "http://localhost:9292/command/"}, + {epp_error_url, "http://localhost:9292/error/"}, %% Path to root CA that should check the client certificates. {cacertfile_path, "test_ca/certs/ca.crt.pem"}, {certfile_path, "test_ca/certs/apache.crt"},