mirror of
https://github.com/internetee/epp_proxy.git
synced 2025-08-16 12:33:48 +02:00
Move router to epp_router
This commit is contained in:
parent
eac669cbd3
commit
7e6273091b
6 changed files with 67 additions and 66 deletions
|
@ -1,4 +1,4 @@
|
|||
-module(pool_supervisor).
|
||||
-module(epp_pool_supervisor).
|
||||
|
||||
-behaviour(supervisor).
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
-module(router).
|
||||
-module(epp_router).
|
||||
|
||||
-export([route_request/1, is_valid_epp_command/1]).
|
||||
|
|
@ -10,7 +10,7 @@
|
|||
-record(state,{socket, length, session_id}).
|
||||
|
||||
init(Socket) ->
|
||||
logger:info("Created a test process"),
|
||||
logger:info("Created a worker process"),
|
||||
{ok, #state{socket=Socket}}.
|
||||
|
||||
start_link(Socket) ->
|
||||
|
@ -20,12 +20,13 @@ handle_cast(serve, State = #state{socket=Socket}) ->
|
|||
{noreply, State#state{socket=Socket}};
|
||||
handle_cast(greeting, State = #state{socket=Socket}) ->
|
||||
SessionId = session_id(),
|
||||
Cookie = hackney_cookie:setcookie("session", SessionId, []),
|
||||
|
||||
{Status, StatusCode, Headers, ClientRef} =
|
||||
hackney:request(get, router:route_request("hello"), [], "",
|
||||
[{cookie, [<<"session=">>, SessionId]}, insecure]),
|
||||
{_Status, _StatusCode, _Headers, ClientRef} =
|
||||
hackney:request(get, epp_router:route_request("hello"), [], "",
|
||||
[{cookie, Cookie}, insecure]),
|
||||
|
||||
Body = <<"Some BODY">>,
|
||||
{ok, Body} = hackney:body(ClientRef),
|
||||
|
||||
Length = byte_size(Body) + 4,
|
||||
ByteSize = << Length:32/big >>,
|
||||
|
@ -33,7 +34,7 @@ handle_cast(greeting, State = #state{socket=Socket}) ->
|
|||
write_line(Socket, ByteSize),
|
||||
write_line(Socket, Body),
|
||||
gen_server:cast(self(), read_length),
|
||||
{noreply, State#state{socket=Socket}};
|
||||
{noreply, State#state{socket=Socket, session_id=SessionId}};
|
||||
handle_cast(read_length, State = #state{socket=Socket}) ->
|
||||
case read_length(Socket) of
|
||||
{ok, Data} ->
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
-module(router_SUITE).
|
||||
-module(epp_router_SUITE).
|
||||
|
||||
-include_lib("common_test/include/ct.hrl").
|
||||
|
||||
|
@ -9,4 +9,4 @@ all() -> [run_eunit].
|
|||
|
||||
%% Run Unit tests
|
||||
run_eunit(_Config) ->
|
||||
ok = eunit:test(router_tests).
|
||||
ok = eunit:test(epp_router_tests).
|
56
apps/epp_proxy/test/epp_router_tests.erl
Normal file
56
apps/epp_proxy/test/epp_router_tests.erl
Normal file
|
@ -0,0 +1,56 @@
|
|||
-module(epp_router_tests).
|
||||
|
||||
-include_lib("eunit/include/eunit.hrl").
|
||||
|
||||
is_valid_epp_command_test() ->
|
||||
Commands = ["hello", "login", "logout", "check", "info", "poll",
|
||||
"create", "delete", "renew", "update", "transfer"],
|
||||
lists:foreach(fun (N) ->
|
||||
?assert(epp_router:is_valid_epp_command(N))
|
||||
end,
|
||||
Commands).
|
||||
|
||||
%% TODO: Make less verbose and repetitive
|
||||
hello_url_test() ->
|
||||
?assertEqual("https://registry.test/epp/session/hello", epp_router:route_request("hello")),
|
||||
?assertEqual("https://registry.test/epp/session/hello", epp_router:route_request(<<"hello">>)).
|
||||
|
||||
login_url_test() ->
|
||||
?assertEqual("https://registry.test/epp/session/login", epp_router:route_request("login")),
|
||||
?assertEqual("https://registry.test/epp/session/login", epp_router:route_request(<<"login">>)).
|
||||
|
||||
logout_url_test() ->
|
||||
?assertEqual("https://registry.test/epp/session/logout", epp_router:route_request("logout")),
|
||||
?assertEqual("https://registry.test/epp/session/logout", epp_router:route_request(<<"logout">>)).
|
||||
|
||||
check_url_test() ->
|
||||
?assertEqual("https://registry.test/epp/command/check", epp_router:route_request("check")),
|
||||
?assertEqual("https://registry.test/epp/command/check", epp_router:route_request(<<"check">>)).
|
||||
|
||||
info_url_test() ->
|
||||
?assertEqual("https://registry.test/epp/command/info", epp_router:route_request("info")),
|
||||
?assertEqual("https://registry.test/epp/command/info", epp_router:route_request(<<"info">>)).
|
||||
|
||||
poll_url_test() ->
|
||||
?assertEqual("https://registry.test/epp/command/poll", epp_router:route_request("poll")),
|
||||
?assertEqual("https://registry.test/epp/command/poll", epp_router:route_request(<<"poll">>)).
|
||||
|
||||
create_url_test() ->
|
||||
?assertEqual("https://registry.test/epp/command/create", epp_router:route_request("create")),
|
||||
?assertEqual("https://registry.test/epp/command/create", epp_router:route_request(<<"create">>)).
|
||||
|
||||
delete_url_test() ->
|
||||
?assertEqual("https://registry.test/epp/command/delete", epp_router:route_request("delete")),
|
||||
?assertEqual("https://registry.test/epp/command/delete", epp_router:route_request(<<"delete">>)).
|
||||
|
||||
renew_url_test() ->
|
||||
?assertEqual("https://registry.test/epp/command/renew", epp_router:route_request("renew")),
|
||||
?assertEqual("https://registry.test/epp/command/renew", epp_router:route_request(<<"renew">>)).
|
||||
|
||||
update_url_test() ->
|
||||
?assertEqual("https://registry.test/epp/command/update", epp_router:route_request("update")),
|
||||
?assertEqual("https://registry.test/epp/command/update", epp_router:route_request(<<"update">>)).
|
||||
|
||||
transfer_url_test() ->
|
||||
?assertEqual("https://registry.test/epp/command/transfer", epp_router:route_request("transfer")),
|
||||
?assertEqual("https://registry.test/epp/command/transfer", epp_router:route_request(<<"transfer">>)).
|
|
@ -1,56 +0,0 @@
|
|||
-module(router_tests).
|
||||
|
||||
-include_lib("eunit/include/eunit.hrl").
|
||||
|
||||
is_valid_epp_command_test() ->
|
||||
Commands = ["hello", "login", "logout", "check", "info", "poll",
|
||||
"create", "delete", "renew", "update", "transfer"],
|
||||
lists:foreach(fun (N) ->
|
||||
?assert(router:is_valid_epp_command(N))
|
||||
end,
|
||||
Commands).
|
||||
|
||||
%% TODO: Make less verbose and repetitive
|
||||
hello_url_test() ->
|
||||
?assertEqual("https://registry.test/epp/session/hello", router:route_request("hello")),
|
||||
?assertEqual("https://registry.test/epp/session/hello", router:route_request(<<"hello">>)).
|
||||
|
||||
login_url_test() ->
|
||||
?assertEqual("https://registry.test/epp/session/login", router:route_request("login")),
|
||||
?assertEqual("https://registry.test/epp/session/login", router:route_request(<<"login">>)).
|
||||
|
||||
logout_url_test() ->
|
||||
?assertEqual("https://registry.test/epp/session/logout", router:route_request("logout")),
|
||||
?assertEqual("https://registry.test/epp/session/logout", router:route_request(<<"logout">>)).
|
||||
|
||||
check_url_test() ->
|
||||
?assertEqual("https://registry.test/epp/command/check", router:route_request("check")),
|
||||
?assertEqual("https://registry.test/epp/command/check", router:route_request(<<"check">>)).
|
||||
|
||||
info_url_test() ->
|
||||
?assertEqual("https://registry.test/epp/command/info", router:route_request("info")),
|
||||
?assertEqual("https://registry.test/epp/command/info", router:route_request(<<"info">>)).
|
||||
|
||||
poll_url_test() ->
|
||||
?assertEqual("https://registry.test/epp/command/poll", router:route_request("poll")),
|
||||
?assertEqual("https://registry.test/epp/command/poll", router:route_request(<<"poll">>)).
|
||||
|
||||
create_url_test() ->
|
||||
?assertEqual("https://registry.test/epp/command/create", router:route_request("create")),
|
||||
?assertEqual("https://registry.test/epp/command/create", router:route_request(<<"create">>)).
|
||||
|
||||
delete_url_test() ->
|
||||
?assertEqual("https://registry.test/epp/command/delete", router:route_request("delete")),
|
||||
?assertEqual("https://registry.test/epp/command/delete", router:route_request(<<"delete">>)).
|
||||
|
||||
renew_url_test() ->
|
||||
?assertEqual("https://registry.test/epp/command/renew", router:route_request("renew")),
|
||||
?assertEqual("https://registry.test/epp/command/renew", router:route_request(<<"renew">>)).
|
||||
|
||||
update_url_test() ->
|
||||
?assertEqual("https://registry.test/epp/command/update", router:route_request("update")),
|
||||
?assertEqual("https://registry.test/epp/command/update", router:route_request(<<"update">>)).
|
||||
|
||||
transfer_url_test() ->
|
||||
?assertEqual("https://registry.test/epp/command/transfer", router:route_request("transfer")),
|
||||
?assertEqual("https://registry.test/epp/command/transfer", router:route_request(<<"transfer">>)).
|
Loading…
Add table
Add a link
Reference in a new issue