Add basic test case for greeting

This commit is contained in:
Maciej Szlosarczyk 2019-07-12 12:49:08 +03:00
parent 2c04020d16
commit c70d7c6bf2
No known key found for this signature in database
GPG key ID: 41D62D42D3B0D765
4 changed files with 66 additions and 40 deletions

View file

@ -19,7 +19,7 @@ hello_request_builder_test_case(_Config) ->
cl_trid => "EE-123456789", raw_frame => "", cl_trid => "EE-123456789", raw_frame => "",
headers => [{"User-Agent", <<"EPP proxy">>}]}, headers => [{"User-Agent", <<"EPP proxy">>}]},
Request = epp_http_client:request_builder(RequestMap), 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">>], [<<"session=Random; Version=1">>],
[{"User-Agent",<<"EPP proxy">>}], "hello"}, [{"User-Agent",<<"EPP proxy">>}], "hello"},
@ -32,7 +32,7 @@ error_request_builder_test_case(_Config) ->
message => <<"Expected better XML">>, message => <<"Expected better XML">>,
headers => [{"User-Agent", <<"EPP proxy">>}]}, headers => [{"User-Agent", <<"EPP proxy">>}]},
Request = epp_http_client:request_builder(RequestMap), 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">>}, [{<<"code">>,<<"2001">>},
{<<"msg">>,<<"Expected better XML">>}, {<<"msg">>,<<"Expected better XML">>},
{<<"clTRID">>,"EE-123456789"}], {<<"clTRID">>,"EE-123456789"}],
@ -48,7 +48,7 @@ command_request_builder_test_case(_Config) ->
headers => [{"User-Agent", <<"EPP proxy">>}]}, headers => [{"User-Agent", <<"EPP proxy">>}]},
Request = epp_http_client:request_builder(RequestMap), Request = epp_http_client:request_builder(RequestMap),
ExpectedTuple = {epp_request,post, ExpectedTuple = {epp_request,post,
"http://localhost:9292/epp/command/create", "http://localhost:9292/command/create",
{multipart, {multipart,
[{<<"raw_frame">>,"Some XML here"}, [{<<"raw_frame">>,"Some XML here"},
{<<"clTRID">>,"EE-123456789"}]}, {<<"clTRID">>,"EE-123456789"}]},

View file

@ -25,61 +25,61 @@ request_method_test_case(_Config) ->
%% TODO: Make less verbose and repetitive %% TODO: Make less verbose and repetitive
hello_url_test_case(_Config) -> hello_url_test_case(_Config) ->
"http://localhost:9292/epp/session/hello" = epp_router:route_request("hello"), "http://localhost:9292/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">>),
ok. ok.
login_url_test_case(_Config) -> login_url_test_case(_Config) ->
"http://localhost:9292/epp/session/login" = epp_router:route_request("login"), "http://localhost:9292/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">>),
ok. ok.
logout_url_test_case(_Config) -> logout_url_test_case(_Config) ->
"http://localhost:9292/epp/session/logout" = epp_router:route_request("logout"), "http://localhost:9292/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">>),
ok. ok.
check_url_test_case(_Config) -> check_url_test_case(_Config) ->
"http://localhost:9292/epp/command/check" = epp_router:route_request("check"), "http://localhost:9292/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">>),
ok. ok.
info_url_test_case(_Config) -> info_url_test_case(_Config) ->
"http://localhost:9292/epp/command/info" = epp_router:route_request("info"), "http://localhost:9292/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">>),
ok. ok.
poll_url_test_case(_Config) -> poll_url_test_case(_Config) ->
"http://localhost:9292/epp/command/poll" = epp_router:route_request("poll"), "http://localhost:9292/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">>),
ok. ok.
create_url_test_case(_Config) -> create_url_test_case(_Config) ->
"http://localhost:9292/epp/command/create" = epp_router:route_request("create"), "http://localhost:9292/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">>),
ok. ok.
delete_url_test_case(_Config) -> delete_url_test_case(_Config) ->
"http://localhost:9292/epp/command/delete" = epp_router:route_request("delete"), "http://localhost:9292/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">>),
ok. ok.
renew_url_test_case(_Config) -> renew_url_test_case(_Config) ->
"http://localhost:9292/epp/command/renew" = epp_router:route_request("renew"), "http://localhost:9292/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">>),
ok. ok.
update_url_test_case(_Config) -> update_url_test_case(_Config) ->
"http://localhost:9292/epp/command/update" = epp_router:route_request("update"), "http://localhost:9292/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">>),
ok. ok.
transfer_url_test_case(_Config) -> transfer_url_test_case(_Config) ->
"http://localhost:9292/epp/command/transfer" = epp_router:route_request("transfer"), "http://localhost:9292/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">>),
ok. ok.
error_url_test_case(_Config) -> error_url_test_case(_Config) ->
"http://localhost:9292/epp/error" = epp_router:route_request("error"), "http://localhost:9292/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">>),
ok. ok.

View file

@ -5,36 +5,62 @@
-export([all/0]). -export([all/0]).
-export([init_per_suite/1, end_per_suite/1]). -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() -> all() ->
[frame_size_test_case]. [frame_size_test_case,
greetings_test_case].
init_per_suite(Config) -> init_per_suite(Config) ->
application:ensure_all_started(epp_proxy), application:ensure_all_started(epp_proxy),
application:ensure_all_started(hackney), application:ensure_all_started(hackney),
[{my_key, <<"my value">>} | Config].
%% Test Cases
frame_size_test_case(_Config) ->
CWD = code:priv_dir(epp_proxy), CWD = code:priv_dir(epp_proxy),
Options = [binary, Options = [binary,
{certfile, filename:join(CWD, "test_ca/certs/webclient.crt.pem")}, {certfile, filename:join(CWD, "test_ca/certs/webclient.crt.pem")},
{keyfile, filename:join(CWD, "test_ca/private/webclient.key.pem")}, {keyfile, filename:join(CWD, "test_ca/private/webclient.key.pem")},
{active, false}], {active, false}],
{ok, Socket} = ssl:connect("localhost", 1443, Options, 2000), [{ssl_options, Options} | Config].
{ok, Data} = ssl:recv(Socket, 0, 1200),
true = (byte_size(Data) =:= length_of_data(Data)),
ok.
end_per_suite(Config) -> end_per_suite(Config) ->
application:stop(epp_proxy), application:stop(epp_proxy),
application:stop(hackney), application:stop(hackney),
Config. 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, "<greeting>"),
ok.
%% Helper functions: %% Helper functions:
length_of_data(Data) -> length_of_data(Data) ->
EPPEnvelope = binary:part(Data, {0, 4}), EPPEnvelope = binary:part(Data, {0, 4}),
ReportedLength = binary:decode_unsigned(EPPEnvelope, big), ReportedLength = binary:decode_unsigned(EPPEnvelope, big),
ReportedLength. ReportedLength.
send_data(Message, Socket) ->
Length = epp_util:frame_length_to_send(Message),
ByteSize = <<Length:32/big>>,
CompleteMessage = <<ByteSize/binary, Message/binary>>,
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).

View file

@ -3,9 +3,9 @@
{tcp_port, 3333}, {tcp_port, 3333},
{tls_port, 1443}, {tls_port, 1443},
{epp_session_url, "http://localhost:9292/epp/session/"}, {epp_session_url, "http://localhost:9292/session/"},
{epp_command_url, "http://localhost:9292/epp/command/"}, {epp_command_url, "http://localhost:9292/command/"},
{epp_error_url, "http://localhost:9292/epp/error/"}, {epp_error_url, "http://localhost:9292/error/"},
%% Path to root CA that should check the client certificates. %% Path to root CA that should check the client certificates.
{cacertfile_path, "test_ca/certs/ca.crt.pem"}, {cacertfile_path, "test_ca/certs/ca.crt.pem"},
{certfile_path, "test_ca/certs/apache.crt"}, {certfile_path, "test_ca/certs/apache.crt"},