Move session_id function to util module

This commit is contained in:
Maciej Szlosarczyk 2019-05-28 09:44:09 +03:00
parent e7aa9b9770
commit 0c8cbaefc7
No known key found for this signature in database
GPG key ID: 41D62D42D3B0D765
6 changed files with 24 additions and 9 deletions

View file

@ -24,7 +24,8 @@ init(Port) ->
{ok, #state{socket=ListenSocket, port=Port, options=Options}}.
handle_cast(accept, State = #state{socket=ListenSocket, port=Port, options=Options}) ->
handle_cast(accept,
State = #state{socket=ListenSocket, port=Port, options=Options}) ->
{ok, AcceptSocket} = gen_tcp:accept(ListenSocket),
{ok, NewOwner} = create_worker(AcceptSocket),
ok = gen_tcp:controlling_process(AcceptSocket, NewOwner),

View file

@ -7,8 +7,6 @@
-export([init/1, handle_cast/2, handle_call/3, start_link/1]).
-export([code_change/3]).
-export([request/3]).
-record(state,{socket, length, session_id}).
-record(request,{method, url, body, cookies, headers}).

View file

@ -1,11 +1,19 @@
-module(epp_util).
-export([create_map/1, create_session_id/1, frame_length/1,
frame_length_to_receive/1, frame_length_to_send/1]).
frame_length_to_receive/1, frame_length_to_send/1,
session_id/1]).
-define(OFFSET, 4).
% Give me a process id, I'll create a random map for you.
%% Given a pid, return a sha512 hash of unique attributes.
-spec session_id(pid()) -> list(char()).
session_id(Pid) ->
UniqueMap = create_map(Pid),
BinaryHash = create_session_id(UniqueMap),
BinaryHash.
%% Give me a process id, I'll create a random map for you.
-spec create_map(pid()) -> #{string() => pid(), string() => float(),
string() => string()}.
create_map(Pid) when is_pid(Pid) ->

View file

@ -2,6 +2,12 @@
-include_lib("eunit/include/eunit.hrl").
session_id_test() ->
Pid = spawn(fun () -> ok end),
SessionId = epp_util:session_id(Pid),
?assert(is_list(SessionId)),
?assert(length(SessionId) > 0).
create_map_test() ->
Pid = spawn(fun () -> ok end),
Map = epp_util:create_map(Pid),

View file

@ -1,6 +1,9 @@
[
{epp_proxy, [{tcp_port, 1133},
{tls_port, 4444},
{epp_proxy, [{tcp_port, 17001,
{tls_port, 17002},
{epp_session_url, "https://registry.test/epp/session/"},
{epp_command_url, "https://registry.test/epp/command/"}]}
{epp_command_url, "https://registry.test/epp/command/"},
{cacertfile_path, "/opt/shared/ca/certs/ca.crt.pem"},
{certfile_path, "/opt/shared/ca/certs/ca.crt.pem"},
{keyfile_path, "/opt/shared/ca/certs/ca.crt.pem"}]}
].

View file

@ -5,7 +5,6 @@
[epp_proxy,
hackney,
sasl,
ssl,
xmerl]},
{sys_config, "./config/sys.config"},