[ED-220] delete undefined client url (#130)

This commit is contained in:
Boris 2021-09-13 13:13:19 +03:00 committed by GitHub
parent 1ba6703578
commit 597a987f45
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 17 deletions

View File

@ -95,11 +95,11 @@ decode_deadline(Deadline) ->
decode_client_info(undefined) ->
undefined;
decode_client_info(ClientInfo) ->
#{
genlib_map:compact(#{
<<"fingerprint">> => ClientInfo#domain_ClientInfo.fingerprint,
<<"ip">> => ClientInfo#domain_ClientInfo.ip_address,
<<"url">> => ClientInfo#domain_ClientInfo.url
}.
}).
%%

View File

@ -81,10 +81,10 @@ process_request('CreatePaymentResource' = OperationID, Req, Context, Resolution)
end
end,
ClientInfo = maps:put(<<"ip">>, ClientIP, ClientInfo0),
ClientInfo1 = maps:put(<<"ip">>, ClientIP, ClientInfo0),
try
ClientUrl = get_client_url(ClientInfo),
ok = validate_url(ClientUrl),
ClientUrl = get_client_url(ClientInfo1),
ClientInfo = maps:put(<<"url">>, ClientUrl, ClientInfo1),
Data = maps:get(<<"paymentTool">>, Params),
PartyID = capi_handler_utils:get_party_id(Context),
ExternalID = maps:get(<<"externalID">>, Params, undefined),
@ -150,14 +150,17 @@ get_replacement_ip(ClientInfo) ->
maps:get(<<"ip">>, ClientInfo, undefined).
get_client_url(ClientInfo) ->
maps:get(<<"url">>, ClientInfo, undefined).
case maps:get(<<"url">>, ClientInfo, undefined) of
undefined ->
undefined;
Url ->
delete_query_params(Url)
end.
validate_url(undefined) ->
ok;
validate_url(Url) ->
case capi_utils:validate_url(Url) of
ok ->
ok;
delete_query_params(Url) ->
case capi_utils:delete_url_query_params(Url) of
{ok, UrlWithoutParams} ->
UrlWithoutParams;
{error, Error, Description} ->
_ = logger:notice("Unexpected client info url reason: ~p ~p", [Error, Description]),
throw({ok, logic_error(invalidRequest, <<"Client info url is invalid">>)})

View File

@ -11,7 +11,7 @@
-export([base64url_to_map/1]).
-export([map_to_base64url/1]).
-export([validate_url/1]).
-export([delete_url_query_params/1]).
-export([parse_deadline/1]).
-export([parse_lifetime/1]).
@ -52,13 +52,14 @@ base64url_to_map(Base64) when is_binary(Base64) ->
map_to_base64url(Map) when is_map(Map) ->
jose_base64url:encode(jsx:encode(Map)).
-spec validate_url(binary()) -> ok | uri_string:error().
validate_url(Url) ->
-spec delete_url_query_params(binary()) -> {ok, binary()} | uri_string:error().
delete_url_query_params(Url) ->
case uri_string:parse(Url) of
{error, _, _} = Error ->
Error;
UriMap when is_map(UriMap) ->
ok
UriMap1 when is_map(UriMap1) ->
UriMap2 = maps:without([query, fragment], UriMap1),
{ok, uri_string:recompose(UriMap2)}
end.
-spec to_universal_time(Timestamp :: binary()) -> TimestampUTC :: binary().