mirror of
https://github.com/valitydev/capi-v2.git
synced 2024-11-06 01:55:20 +00:00
CAPI-59 Modify project to use the newest protocol (#23)
* CAPI-59 Modify project to use the newest protocol
This commit is contained in:
parent
1109497b62
commit
44f955d349
17
Makefile
17
Makefile
@ -3,7 +3,8 @@ SUBMODULES = schemes/swag apps/cp_proto/damsel build_utils
|
||||
SUBTARGETS = $(patsubst %,%/.git,$(SUBMODULES))
|
||||
|
||||
SWAGGER_CODEGEN ?= $(call which, swagger-codegen)
|
||||
SWAGGER_SCHEME = schemes/swag/swagger.yaml
|
||||
SWAGGER_SCHEME_PATH = schemes/swag
|
||||
SWAGGER_SCHEME = $(SWAGGER_SCHEME_PATH)/web_deploy/swagger.yaml
|
||||
SWAGGER_APP_PATH = apps/swagger
|
||||
|
||||
SWAGGER_APP_TARGET = $(SWAGGER_APP_PATH)/rebar.config
|
||||
@ -70,24 +71,26 @@ clean:
|
||||
$(REBAR) clean
|
||||
|
||||
distclean:
|
||||
$(REBAR) clean -a
|
||||
$(REBAR) clean
|
||||
rm -rfv _build apps/swagger
|
||||
|
||||
# CALL_W_CONTAINER
|
||||
test: submodules
|
||||
$(REBAR) ct
|
||||
|
||||
# Shitty generation. Will be replaced when a container with swagger-codegen appear
|
||||
define swagger_regenerate
|
||||
define swagger_generate
|
||||
rm -rf $(SWAGGER_APP_PATH)
|
||||
$(SWAGGER_CODEGEN) generate -i $(SWAGGER_SCHEME) -l erlang-server -o $(SWAGGER_APP_PATH)
|
||||
endef
|
||||
|
||||
$(SWAGGER_APP_TARGET): $(SWAGGER_SCHEME)
|
||||
$(call swagger_regenerate)
|
||||
$(call swagger_generate)
|
||||
|
||||
swagger_regenerate:
|
||||
$(call swagger_regenerate)
|
||||
$(SWAGGER_SCHEME):
|
||||
$(MAKE) -C $(SWAGGER_SCHEME_PATH)
|
||||
|
||||
swagger_generate: $(SWAGGER_SCHEME)
|
||||
$(call swagger_generate)
|
||||
|
||||
cover:
|
||||
$(REBAR) cover
|
||||
|
@ -10,21 +10,27 @@
|
||||
) -> {true, Context :: context()} | false.
|
||||
|
||||
auth_api_key(OperationID, ApiKey) ->
|
||||
{ok, Type, Credentials} = parse_auth_token(ApiKey),
|
||||
case process_auth(Type, Credentials, OperationID) of
|
||||
{ok, Context} ->
|
||||
{true, Context};
|
||||
{error, _Error} ->
|
||||
case parse_auth_token(ApiKey) of
|
||||
{ok, {Type, Credentials}} ->
|
||||
case process_auth(Type, Credentials, OperationID) of
|
||||
{ok, Context} ->
|
||||
{true, Context};
|
||||
{error, Error} ->
|
||||
_ = log_auth_error(OperationID, Error),
|
||||
false
|
||||
end;
|
||||
{error, Error} ->
|
||||
_ = log_auth_error(OperationID, Error),
|
||||
false
|
||||
end.
|
||||
|
||||
-spec parse_auth_token(ApiKey :: binary()) ->
|
||||
{ok, bearer, Credentials :: binary()} | {error, Reason :: atom()}.
|
||||
{ok, {bearer, Credentials :: binary()}} | {error, Reason :: atom()}.
|
||||
|
||||
parse_auth_token(ApiKey) ->
|
||||
case ApiKey of
|
||||
<<"Bearer ", Credentials/binary>> ->
|
||||
{ok, bearer, Credentials};
|
||||
{ok, {bearer, Credentials}};
|
||||
_ ->
|
||||
{error, unsupported_auth_scheme}
|
||||
end.
|
||||
@ -33,18 +39,18 @@ parse_auth_token(ApiKey) ->
|
||||
{ok, Context :: context()} | {error, Reason :: atom()}.
|
||||
|
||||
process_auth(bearer, AuthToken, OperationID) ->
|
||||
case verify_token(AuthToken) of
|
||||
case verify_token(AuthToken, OperationID) of
|
||||
{ok, Claims} ->
|
||||
authorize(Claims, OperationID);
|
||||
Error ->
|
||||
Error
|
||||
end.
|
||||
|
||||
verify_token(AuthToken) ->
|
||||
verify_token(AuthToken, OperationID) ->
|
||||
case verify_alg(AuthToken) of
|
||||
{ok, Payload} ->
|
||||
Claims = jsx:decode(Payload, [return_maps]), %% @FIXME deal with non json token
|
||||
case is_valid_exp(Claims) of
|
||||
case validate_claims(Claims, OperationID) of
|
||||
true ->
|
||||
{ok, Claims};
|
||||
false ->
|
||||
@ -91,7 +97,55 @@ authorize(
|
||||
authorize(_Claims, _OperationID) ->
|
||||
{error, unauthorized}.
|
||||
|
||||
is_valid_exp(Claims) ->
|
||||
validate_claims(Claims, OperationID) ->
|
||||
Validator = get_validator(OperationID),
|
||||
Validator(Claims).
|
||||
|
||||
get_actions() ->
|
||||
#{
|
||||
'CreateInvoice' => [<<"payments:create">>],
|
||||
'CreatePayment' => [<<"payments:create">>],
|
||||
'CreatePaymentToolToken' => [<<"payment_tool_tokens:create">>],
|
||||
'GetInvoiceByID' => [<<"payments:create">>],
|
||||
'FulfillInvoice' => [<<"payments:create">>],
|
||||
'RescindInvoice' => [<<"payments:create">>],
|
||||
'GetInvoiceEvents' => [<<"payments:create">>],
|
||||
'GetPaymentByID' => [<<"payments:create">>],
|
||||
'GetInvoices' => [<<"payments:create">>],
|
||||
'GetPaymentConversionStats' => [<<"party:create">>],
|
||||
'GetPaymentRevenueStats' => [<<"party:create">>],
|
||||
'GetPaymentGeoStats' => [<<"party:create">>],
|
||||
'GetPaymentRateStats' => [<<"party:create">>],
|
||||
'GetPaymentMethodStats' => [<<"party:create">>],
|
||||
'GetMyParty' => [<<"party:create">>],
|
||||
'ActivateShop' => [<<"party:create">>],
|
||||
'CreateShop' => [<<"party:create">>],
|
||||
'SuspendShop' => [<<"party:create">>],
|
||||
'UpdateShop' => [<<"party:create">>],
|
||||
'SuspendMyParty' => [<<"party:create">>],
|
||||
'ActivateMyParty' => [<<"party:create">>],
|
||||
'GetClaimByID' => [<<"party:create">>],
|
||||
'GetClaimsByStatus' => [<<"party:create">>],
|
||||
'RevokeClaimByID' => [<<"party:create">>],
|
||||
'GetCategories' => [<<"categories:get">>],
|
||||
'GetCategoryByRef' => [<<"categories:get">>],
|
||||
'GetAccountByID' => [<<"party:create">>],
|
||||
'GetShopByID' => [<<"party:create">>],
|
||||
'GetShops' => [<<"party:create">>],
|
||||
'GetPayoutTools' => [<<"party:create">>],
|
||||
'CreatePayoutTool' => [<<"party:create">>],
|
||||
'GetContracts' => [<<"party:create">>],
|
||||
'CreateContract' => [<<"party:create">>],
|
||||
'GetContractByID' => [<<"party:create">>],
|
||||
'GetLocationsNames' => [<<"party:create">>]
|
||||
}.
|
||||
|
||||
get_validator('CreatePaymentToolToken') ->
|
||||
fun (_Claims) -> true end;
|
||||
get_validator(_Any) ->
|
||||
fun check_expiration/1.
|
||||
|
||||
check_expiration(Claims) ->
|
||||
case genlib_map:get(<<"exp">>, Claims) of
|
||||
undefined ->
|
||||
false;
|
||||
@ -99,41 +153,7 @@ is_valid_exp(Claims) ->
|
||||
genlib_time:unow() =< I
|
||||
end.
|
||||
|
||||
get_actions() ->
|
||||
#{
|
||||
'CreateInvoice' => [<<"invoices:create">>],
|
||||
'CreatePayment' => [<<"payments:create">>],
|
||||
'CreatePaymentToolToken' => [<<"payment_tool_tokens:create">>],
|
||||
'GetInvoiceByID' => [<<"invoices:get">>],
|
||||
'FulfillInvoice' => [<<"invoices:fulfill">>],
|
||||
'RescindInvoice' => [<<"invoices:rescind">>],
|
||||
'GetInvoiceEvents' => [<<"invoices.events:get">>],
|
||||
'GetPaymentByID' => [<<"payments:get">>],
|
||||
'GetInvoices' => [<<"invoices_stats:get">>],
|
||||
'GetPaymentConversionStats' => [<<"payments_conversion_stats:get">>],
|
||||
'GetPaymentRevenueStats' => [<<"payments_revenue_stats:get">>],
|
||||
'GetPaymentGeoStats' => [<<"payments_geo_stats:get">>],
|
||||
'GetPaymentRateStats' => [<<"payments_rate_stats:get">>],
|
||||
'GetPaymentMethodStats' => [<<"payments_instrument_stats:get">>],
|
||||
'GetMyParty' => [<<"party:get">>, <<"party:create">>],
|
||||
'ActivateShop' => [<<"shops:activate">>, <<"party:create">>],
|
||||
'CreateShop' => [<<"shop:create">>, <<"party:create">>],
|
||||
'SuspendShop' => [<<"shops:suspend">>, <<"party:create">>],
|
||||
'UpdateShop' => [<<"shops:update">>, <<"party:create">>],
|
||||
'SuspendMyParty' => [<<"party:suspend">>, <<"party:create">>],
|
||||
'ActivateMyParty' => [<<"party:activate">>, <<"party:create">>],
|
||||
'GetClaimByID' => [<<"claims:get">>, <<"party:create">>],
|
||||
'GetClaimsByStatus' => [<<"claims:get">>, <<"party:create">>],
|
||||
'RevokeClaimByID' => [<<"claims:revoke">>, <<"party:create">>],
|
||||
'GetCategories' => [<<"categories:get">>],
|
||||
'GetCategoryByRef' => [<<"categories:get">>],
|
||||
'GetAccountByID' => [<<"party:get">>, <<"party:create">>],
|
||||
'GetShopByID' => [<<"party:get">>, <<"party:create">>],
|
||||
'GetShops' => [<<"party:get">>, <<"party:create">>],
|
||||
'GetPayoutTools' => [<<"party:get">>, <<"party:create">>],
|
||||
'CreatePayoutTool' => [<<"party:get">>, <<"party:create">>],
|
||||
'GetContracts' => [<<"party:get">>, <<"party:create">>],
|
||||
'CreateContract' => [<<"party:get">>, <<"party:create">>],
|
||||
'GetContractByID' => [<<"party:get">>, <<"party:create">>],
|
||||
'GetLocationsNames' => [<<"party:get">>, <<"party:create">>]
|
||||
}.
|
||||
|
||||
log_auth_error(OperationID, Error) ->
|
||||
lager:info("Auth for operation ~p failed due to ~p", [OperationID, Error]).
|
||||
|
||||
|
@ -47,8 +47,8 @@ handle_request(OperationID, Req, Context) ->
|
||||
{Code :: non_neg_integer(), Headers :: [], Response :: #{}}.
|
||||
|
||||
process_request(OperationID = 'CreateInvoice', Req, Context, ReqCtx) ->
|
||||
InvoiceParams = maps:get('CreateInvoiceArgs', Req),
|
||||
InvoiceContext = jsx:encode(genlib_map:get(<<"context">>, InvoiceParams)),
|
||||
InvoiceParams = maps:get('InvoiceParams', Req),
|
||||
InvoiceContext = jsx:encode(genlib_map:get(<<"metadata">>, InvoiceParams)),
|
||||
PartyID = get_party_id(Context),
|
||||
Params = #payproc_InvoiceParams{
|
||||
party_id = PartyID,
|
||||
@ -84,7 +84,7 @@ process_request(OperationID = 'CreateInvoice', Req, Context, ReqCtx) ->
|
||||
|
||||
process_request(OperationID = 'CreatePayment', Req, Context, ReqCtx) ->
|
||||
InvoiceID = maps:get('invoiceID', Req),
|
||||
PaymentParams = maps:get('CreatePaymentArgs', Req),
|
||||
PaymentParams = maps:get('PaymentParams', Req),
|
||||
Token = genlib_map:get(<<"paymentToolToken">>, PaymentParams),
|
||||
ContactInfo = genlib_map:get(<<"contactInfo">>, PaymentParams),
|
||||
PaymentTool = decode_bank_card(Token),
|
||||
@ -122,7 +122,7 @@ process_request(OperationID = 'CreatePayment', Req, Context, ReqCtx) ->
|
||||
end;
|
||||
|
||||
process_request(OperationID = 'CreatePaymentToolToken', Req, Context, ReqCtx) ->
|
||||
Params = maps:get('CreatePaymentToolTokenArgs', Req),
|
||||
Params = maps:get('PaymentToolTokenParams', Req),
|
||||
ClientInfo0 = maps:get(<<"clientInfo">>, Params),
|
||||
PaymentTool = maps:get(<<"paymentTool">>, Params),
|
||||
case PaymentTool of
|
||||
@ -369,7 +369,7 @@ process_request(OperationID = 'GetPaymentMethodStats', Req, Context, ReqCtx) ->
|
||||
|
||||
process_request(OperationID = 'GetLocationsNames', Req, _Context, ReqCtx) ->
|
||||
Language = maps:get('language', Req),
|
||||
GeoIDs = ordsets:from_list(maps:get('geoID', Req)),
|
||||
GeoIDs = ordsets:from_list(maps:get('geoIDs', Req)),
|
||||
|
||||
Result = service_call(
|
||||
geo_ip_service,
|
||||
@ -393,7 +393,7 @@ process_request(OperationID = 'GetLocationsNames', Req, _Context, ReqCtx) ->
|
||||
process_request(OperationID = 'CreateShop', Req, Context, ReqCtx) ->
|
||||
UserInfo = get_user_info(Context),
|
||||
PartyID = get_party_id(Context),
|
||||
Params = maps:get('CreateShopArgs', Req),
|
||||
Params = maps:get('ShopParams', Req),
|
||||
|
||||
Proxy = populate_proxy_options(genlib_map:get(<<"callbackUrl">>, Params), ReqCtx),
|
||||
|
||||
@ -444,8 +444,12 @@ process_request(OperationID = 'ActivateShop', Req, Context, ReqCtx) ->
|
||||
),
|
||||
|
||||
case Result of
|
||||
{ok, R} ->
|
||||
{202, [], decode_claim_result(R)};
|
||||
{ok, _R} ->
|
||||
{204, [], <<>>};
|
||||
{exception, #payproc_InvalidShopStatus{
|
||||
status = {suspension, {active, _}}
|
||||
}} ->
|
||||
{204, [], <<>>};
|
||||
{exception, Exception} ->
|
||||
process_exception(OperationID, Exception)
|
||||
end;
|
||||
@ -469,8 +473,12 @@ process_request(OperationID = 'SuspendShop', Req, Context, ReqCtx) ->
|
||||
),
|
||||
|
||||
case Result of
|
||||
{ok, R} ->
|
||||
{202, [], decode_claim_result(R)};
|
||||
{ok, _R} ->
|
||||
{204, [], <<>>};
|
||||
{exception, #payproc_InvalidShopStatus{
|
||||
status = {suspension, {suspended, _}}
|
||||
}} ->
|
||||
{204, [], <<>>};
|
||||
{exception, Exception} ->
|
||||
process_exception(OperationID, Exception)
|
||||
end;
|
||||
@ -479,7 +487,7 @@ process_request(OperationID = 'UpdateShop', Req, Context, ReqCtx) ->
|
||||
UserInfo = get_user_info(Context),
|
||||
PartyID = get_party_id(Context),
|
||||
ShopID = maps:get(shopID, Req),
|
||||
Params = maps:get('UpdateShopArgs', Req),
|
||||
Params = maps:get('UpdateShopParams', Req),
|
||||
|
||||
Proxy = populate_proxy_options(genlib_map:get(<<"callbackUrl">>, Params), ReqCtx),
|
||||
|
||||
@ -663,6 +671,8 @@ process_request(OperationID = 'GetClaimsByStatus', Req, Context, ReqCtx) ->
|
||||
end
|
||||
),
|
||||
case Result of
|
||||
{exception, #payproc_ClaimNotFound{}} ->
|
||||
{200, [], []};
|
||||
{ok, Claim} ->
|
||||
Resp = decode_claim(Claim, ReqCtx),
|
||||
{200, [], [Resp]}; %% pretending to have more than one pending claim at the same time
|
||||
@ -736,8 +746,12 @@ process_request(OperationID = 'SuspendMyParty', _Req, Context, ReqCtx) ->
|
||||
end
|
||||
),
|
||||
case Result of
|
||||
{ok, R} ->
|
||||
{202, [], decode_claim_result(R)};
|
||||
{ok, _R} ->
|
||||
{204, [], <<>>};
|
||||
{exception, #payproc_InvalidPartyStatus{
|
||||
status = {suspension, {suspended, _}}
|
||||
}} ->
|
||||
{204, [], <<>>};
|
||||
{exception, Exception} ->
|
||||
process_exception(OperationID, Exception)
|
||||
end;
|
||||
@ -758,8 +772,12 @@ process_request(OperationID = 'ActivateMyParty', _Req, Context, ReqCtx) ->
|
||||
end
|
||||
),
|
||||
case Result of
|
||||
{ok, R} ->
|
||||
{202, [], decode_claim_result(R)};
|
||||
{ok, _R} ->
|
||||
{204, [], <<>>};
|
||||
{exception, #payproc_InvalidPartyStatus{
|
||||
status = {suspension, {active, _}}
|
||||
}} ->
|
||||
{204, [], <<>>};
|
||||
{exception, Exception} ->
|
||||
process_exception(OperationID, Exception)
|
||||
end;
|
||||
@ -847,7 +865,7 @@ parse_exp_date(ExpDate) when is_binary(ExpDate) ->
|
||||
get_user_info(Context) ->
|
||||
#payproc_UserInfo{
|
||||
id = get_party_id(Context),
|
||||
type = {external_user, #payproc_ExternalUser{}} %%@FIXME do I have to guess?
|
||||
type = {external_user, #payproc_ExternalUser{}}
|
||||
}.
|
||||
|
||||
get_party_id(#{
|
||||
@ -1134,9 +1152,6 @@ decode_invoice(#domain_Invoice{
|
||||
context = RawContext,
|
||||
shop_id = ShopID
|
||||
}) ->
|
||||
Context = #{
|
||||
<<"context">> => decode_context(RawContext)
|
||||
},
|
||||
genlib_map:compact(maps:merge(#{
|
||||
<<"id">> => InvoiceID,
|
||||
<<"shopID">> => ShopID,
|
||||
@ -1144,7 +1159,7 @@ decode_invoice(#domain_Invoice{
|
||||
<<"dueDate">> => DueDate,
|
||||
<<"amount">> => Amount,
|
||||
<<"currency">> => decode_currency(Currency),
|
||||
<<"context">> => Context,
|
||||
<<"metadata">> => decode_context(RawContext),
|
||||
<<"product">> => Product,
|
||||
<<"description">> => Description
|
||||
}, decode_invoice_status(InvoiceStatus))).
|
||||
@ -1377,7 +1392,7 @@ decode_stat_response(payments_conversion_stat, Response) ->
|
||||
decode_stat_response(payments_geo_stat, Response) ->
|
||||
#{
|
||||
<<"offset">> => genlib:to_int(maps:get(<<"offset">>, Response)),
|
||||
<<"geoID">> => genlib:to_int(maps:get(<<"geoID">>, Response)),
|
||||
<<"geoID">> => genlib:to_int(maps:get(<<"city_id">>, Response)),
|
||||
<<"currency">> => maps:get(<<"currency_symbolic_code">>, Response),
|
||||
<<"profit">> => genlib:to_int(maps:get(<<"amount_with_fee">>, Response)),
|
||||
<<"revenue">> => genlib:to_int(maps:get(<<"amount_without_fee">>, Response))
|
||||
@ -1731,10 +1746,10 @@ parse_rfc3339_datetime(DateTime) ->
|
||||
{DateFrom, TimeFrom}.
|
||||
|
||||
process_exception(_, #payproc_InvalidUser{}) ->
|
||||
{400, [], logic_error(invalid_user, <<"Ivalid user">>)};
|
||||
{400, [], logic_error(invalidUser, <<"Ivalid user">>)};
|
||||
|
||||
process_exception(_, #'InvalidRequest'{errors = Errors}) ->
|
||||
{400, [], logic_error(invalid_request, format_request_errors(Errors))};
|
||||
{400, [], logic_error(invalidRequest, format_request_errors(Errors))};
|
||||
|
||||
process_exception(_, #payproc_UserInvoiceNotFound{}) ->
|
||||
{404, [], general_error(<<"Invoice not found">>)};
|
||||
@ -1742,20 +1757,29 @@ process_exception(_, #payproc_UserInvoiceNotFound{}) ->
|
||||
process_exception(_, #payproc_ClaimNotFound{}) ->
|
||||
{404, [], general_error(<<"Claim not found">>)};
|
||||
|
||||
process_exception(_, #payproc_ContractNotFound{}) ->
|
||||
{404, [], general_error(<<"Contract not found">>)};
|
||||
|
||||
process_exception(_, #payproc_InvalidInvoiceStatus{}) ->
|
||||
{400, [], logic_error(invalid_invoice_status, <<"Invalid invoice status">>)};
|
||||
{400, [], logic_error(invalidInvoiceStatus, <<"Invalid invoice status">>)};
|
||||
|
||||
process_exception(_, #payproc_InvalidPartyStatus{}) ->
|
||||
{400, [], logic_error(invalidPartyStatus, <<"Invalid party status">>)};
|
||||
|
||||
process_exception(_, #payproc_InvoicePaymentPending{}) ->
|
||||
{400, [], logic_error(invalid_payment_status, <<"Invalid payment status">>)};
|
||||
{400, [], logic_error(invalidPaymentStatus, <<"Invalid payment status">>)};
|
||||
|
||||
process_exception(_, #payproc_InvalidShopStatus{}) ->
|
||||
{400, [], logic_error(invalid_shop_status, <<"Invalid shop status">>)};
|
||||
{400, [], logic_error(invalidShopStatus, <<"Invalid shop status">>)};
|
||||
|
||||
process_exception(_, #payproc_InvalidContractStatus{}) ->
|
||||
{400, [], logic_error(invalidContractStatus, <<"Invalid contract status">>)};
|
||||
|
||||
process_exception(_, #payproc_PartyNotFound{}) ->
|
||||
{404, [], general_error(<<"Party not found">>)};
|
||||
|
||||
process_exception(_, #'InvalidCardData'{}) ->
|
||||
{400, [], logic_error(invalid_request, <<"Card data is invalid">>)};
|
||||
{400, [], logic_error(invalidRequest, <<"Card data is invalid">>)};
|
||||
|
||||
process_exception(_, #'KeyringLocked'{}) ->
|
||||
{503, [], <<"">>};
|
||||
|
@ -16,7 +16,7 @@ start_app(lager = AppName) ->
|
||||
{error_logger_hwm, 600},
|
||||
{suppress_application_start_stop, true},
|
||||
{handlers, [
|
||||
{lager_common_test_backend, debug}
|
||||
{lager_common_test_backend, info}
|
||||
]}
|
||||
]);
|
||||
|
||||
|
@ -20,6 +20,7 @@
|
||||
-export([
|
||||
authorization_error_no_header_test/1,
|
||||
authorization_error_expired_test/1,
|
||||
authorization_expired_ok_test/1,
|
||||
create_invoice_badard_test/1,
|
||||
create_invoice_ok_test/1,
|
||||
create_payment_ok_test/1,
|
||||
@ -38,8 +39,8 @@
|
||||
get_payment_method_stats_ok_test/1,
|
||||
%%%%
|
||||
get_my_party_ok_test/1,
|
||||
suspend_my_party_ok_test/1,
|
||||
activate_my_party_ok_test/1,
|
||||
suspend_my_party_idempotent_ok_test/1,
|
||||
activate_my_party_idempotent_ok_test/1,
|
||||
get_claim_by_id_ok_test/1,
|
||||
revoke_claim_ok_test/1,
|
||||
get_claims_by_status_ok_test/1,
|
||||
@ -50,7 +51,7 @@
|
||||
get_shops_ok_test/1,
|
||||
update_shop_ok_test/1,
|
||||
suspend_shop_ok_test/1,
|
||||
activate_shop_ok_test/1,
|
||||
activate_shop_idempotent_ok_test/1,
|
||||
%%%%
|
||||
get_account_by_id_ok_test/1,
|
||||
%%%%
|
||||
@ -99,6 +100,8 @@ init([]) ->
|
||||
|
||||
-type config() :: [{atom(), any()}].
|
||||
|
||||
-define(setconfig(K, V, C), lists:keystore(K, 1, C, {K, V})).
|
||||
|
||||
-spec all() -> [
|
||||
{group, GroupName :: atom()}
|
||||
].
|
||||
@ -130,7 +133,8 @@ groups() ->
|
||||
[
|
||||
{authorization, [parallel], [
|
||||
authorization_error_no_header_test,
|
||||
authorization_error_expired_test
|
||||
authorization_error_expired_test,
|
||||
authorization_expired_ok_test
|
||||
]},
|
||||
{invoice_management, [sequence], [
|
||||
create_invoice_badard_test,
|
||||
@ -162,8 +166,8 @@ groups() ->
|
||||
]},
|
||||
{party_management, [sequence], [
|
||||
get_my_party_ok_test,
|
||||
suspend_my_party_ok_test,
|
||||
activate_my_party_ok_test
|
||||
suspend_my_party_idempotent_ok_test,
|
||||
activate_my_party_idempotent_ok_test
|
||||
]},
|
||||
{contracts_management, [sequence], [
|
||||
create_contract_ok_test,
|
||||
@ -183,7 +187,7 @@ groups() ->
|
||||
create_shop_ok_test,
|
||||
get_shop_by_id_ok_test,
|
||||
get_shops_ok_test,
|
||||
activate_shop_ok_test,
|
||||
activate_shop_idempotent_ok_test,
|
||||
update_shop_ok_test,
|
||||
suspend_shop_ok_test
|
||||
]},
|
||||
@ -203,6 +207,9 @@ groups() ->
|
||||
-spec init_per_suite(config()) -> config().
|
||||
|
||||
init_per_suite(Config) ->
|
||||
% _ = dbg:tracer(),
|
||||
% _ = dbg:p(all, c),
|
||||
% _ = dbg:tpl({'capi_auth', '_', '_'}, x),
|
||||
Apps =
|
||||
capi_ct_helper:start_app(lager) ++
|
||||
capi_ct_helper:start_app(cowlib) ++
|
||||
@ -218,12 +225,6 @@ init_per_suite(Config) ->
|
||||
geo_ip_service => ?GEO_IP_URL,
|
||||
merchant_config => ?MERCHANT_CONFIG_URL
|
||||
}}
|
||||
]) ++
|
||||
capi_ct_helper:start_app(capi, [
|
||||
{ip, ?CAPI_IP},
|
||||
{port, ?CAPI_PORT},
|
||||
{service_type, ?CAPI_SERVICE_TYPE},
|
||||
{api_secret_path, filename:join(?config(data_dir, Config), "public_api_key.pem")}
|
||||
]),
|
||||
{ok, SupPid} = supervisor:start_link(?MODULE, []),
|
||||
_ = unlink(SupPid),
|
||||
@ -257,17 +258,33 @@ end_per_suite(C) ->
|
||||
|
||||
-spec init_per_group(Name :: atom(), config()) -> config().
|
||||
|
||||
init_per_group(statistics, Config) ->
|
||||
init_per_group(Group = statistics, Config) ->
|
||||
Apps = start_capi(Group, Config),
|
||||
ShopID = create_and_activate_shop(Config),
|
||||
[{shop_id, ShopID} | Config];
|
||||
[{capi_apps, Apps}, {shop_id, ShopID} | Config];
|
||||
|
||||
init_per_group(_, Config) ->
|
||||
Config.
|
||||
init_per_group(Group, Config) ->
|
||||
Apps = start_capi(Group, Config),
|
||||
[{capi_apps, Apps} | Config].
|
||||
|
||||
start_capi(Group, Config) ->
|
||||
capi_ct_helper:start_app(capi, [
|
||||
{ip, ?CAPI_IP},
|
||||
{port, ?CAPI_PORT},
|
||||
{service_type, ?CAPI_SERVICE_TYPE},
|
||||
{api_secret_path, filename:join(?config(data_dir, Config), get_pubkey_filepath(Group))}
|
||||
]).
|
||||
|
||||
get_pubkey_filepath(authorization) ->
|
||||
"keys/local/public.pem";
|
||||
get_pubkey_filepath(_) ->
|
||||
"keys/keycloak/public.pem".
|
||||
|
||||
-spec end_per_group(Name :: atom(), config()) -> config().
|
||||
|
||||
end_per_group(_, Config) ->
|
||||
Config.
|
||||
_ = [application:stop(App) || App <- ?config(capi_apps, Config)],
|
||||
lists:keydelete(capi_apps, 1, Config).
|
||||
|
||||
%% tests
|
||||
-spec authorization_error_no_header_test(config()) -> _.
|
||||
@ -278,10 +295,35 @@ authorization_error_no_header_test(_Config) ->
|
||||
-spec authorization_error_expired_test(config()) -> _.
|
||||
|
||||
authorization_error_expired_test(Config) ->
|
||||
Token = auth_token(#{}, genlib_time:unow() - 10, Config),
|
||||
ResourceAccess = #{<<"common-api">> => #{<<"roles">> => [<<"payments:get">>]}},
|
||||
Token = auth_token(ResourceAccess, genlib_time:unow() - 10, Config),
|
||||
AuthHeader = auth_header(Token),
|
||||
{ok, 401, _RespHeaders, _Body} = call(get, "/v1/processing/invoices/22?limit=22", #{}, [AuthHeader]).
|
||||
|
||||
-spec authorization_expired_ok_test(config()) -> _.
|
||||
|
||||
authorization_expired_ok_test(Config) ->
|
||||
ResourceAccess = #{<<"common-api">> => #{<<"roles">> => [<<"payment_tool_tokens:create">>]}},
|
||||
Token = auth_token(ResourceAccess, genlib_time:unow() - 10, Config),
|
||||
Headers = [
|
||||
auth_header(Token),
|
||||
{<<"Content-Type">>, <<"application/json; charset=utf-8">>},
|
||||
{<<"X-Request-ID">>, <<"BLARGH">>}
|
||||
],
|
||||
Body = #{
|
||||
<<"paymentTool">> => #{
|
||||
<<"paymentToolType">> => <<"CardData">>,
|
||||
<<"cardHolder">> => <<"Alexander Weinerschnitzel">>,
|
||||
<<"cardNumber">> => 4111111111111111,
|
||||
<<"expDate">> => <<"08/27">>,
|
||||
<<"cvv">> => <<"232">>
|
||||
},
|
||||
<<"clientInfo">> => #{
|
||||
<<"fingerprint">> => <<"test fingerprint">>
|
||||
}
|
||||
},
|
||||
{ok, 201, _RespHeaders, _Body} = call(post, "/v1/processing/payment_tools", Body, Headers).
|
||||
|
||||
-spec create_invoice_badard_test(config()) -> _.
|
||||
|
||||
create_invoice_badard_test(Config) ->
|
||||
@ -396,7 +438,8 @@ get_invoices_stats_ok_test(Config) ->
|
||||
{to_time, {{2020, 08, 11},{19, 42, 35}}},
|
||||
{status, unpaid}
|
||||
],
|
||||
{ok, _, _} = api_client_analytics:get_invoices(Context, ShopID, Query).
|
||||
|
||||
{ok, _, _} = api_client_searches:get_invoices(Context, ShopID, Query).
|
||||
|
||||
-spec get_payment_conversion_stats_ok_test(config()) -> _.
|
||||
|
||||
@ -479,24 +522,26 @@ get_payment_method_stats_ok_test(Config) ->
|
||||
|
||||
get_my_party_ok_test(Config) ->
|
||||
#{
|
||||
<<"isBlocked">> := false,
|
||||
<<"isSuspended">> := false,
|
||||
<<"isBlocked">> := _,
|
||||
<<"isSuspended">> := _,
|
||||
<<"id">> := ?MERCHANT_ID
|
||||
} = default_get_party(Config).
|
||||
|
||||
-spec suspend_my_party_ok_test(config()) -> _.
|
||||
-spec suspend_my_party_idempotent_ok_test(config()) -> _.
|
||||
|
||||
suspend_my_party_ok_test(Config) ->
|
||||
_ = default_suspend_my_party(Config),
|
||||
suspend_my_party_idempotent_ok_test(Config) ->
|
||||
ok = default_suspend_my_party(Config),
|
||||
ok = default_suspend_my_party(Config),
|
||||
#{
|
||||
<<"isSuspended">> := true
|
||||
} = default_get_party(Config),
|
||||
Config.
|
||||
|
||||
-spec activate_my_party_ok_test(config()) -> _.
|
||||
-spec activate_my_party_idempotent_ok_test(config()) -> _.
|
||||
|
||||
activate_my_party_ok_test(Config) ->
|
||||
_ = default_activate_my_party(Config),
|
||||
activate_my_party_idempotent_ok_test(Config) ->
|
||||
ok = default_activate_my_party(Config),
|
||||
ok = default_activate_my_party(Config),
|
||||
#{
|
||||
<<"isSuspended">> := false
|
||||
} = default_get_party(Config).
|
||||
@ -680,7 +725,7 @@ get_shops_ok_test(Config) ->
|
||||
-spec update_shop_ok_test(config()) -> _.
|
||||
|
||||
update_shop_ok_test(Config) ->
|
||||
{activate_shop_ok_test,
|
||||
{activate_shop_idempotent_ok_test,
|
||||
ShopID
|
||||
} = ?config(saved_config, Config),
|
||||
#{
|
||||
@ -709,21 +754,23 @@ suspend_shop_ok_test(Config) ->
|
||||
{update_shop_ok_test,
|
||||
ShopID
|
||||
} = ?config(saved_config, Config),
|
||||
_ = default_suspend_shop(ShopID, Config),
|
||||
ok = default_suspend_shop(ShopID, Config),
|
||||
ok = default_suspend_shop(ShopID, Config),
|
||||
#{
|
||||
<<"isSuspended">> := true
|
||||
} = default_get_shop_by_id(ShopID, Config),
|
||||
{save_config, ShopID}.
|
||||
|
||||
|
||||
-spec activate_shop_ok_test(config()) -> _.
|
||||
-spec activate_shop_idempotent_ok_test(config()) -> _.
|
||||
|
||||
activate_shop_ok_test(Config) ->
|
||||
activate_shop_idempotent_ok_test(Config) ->
|
||||
{get_shops_ok_test,
|
||||
ShopID
|
||||
} = ?config(saved_config, Config),
|
||||
|
||||
_ = default_activate_shop(ShopID, Config),
|
||||
ok = default_activate_shop(ShopID, Config),
|
||||
ok = default_activate_shop(ShopID, Config),
|
||||
#{
|
||||
<<"isSuspended">> := false
|
||||
} = default_get_shop_by_id(ShopID, Config),
|
||||
@ -817,8 +864,8 @@ auth_token(ResourseAccess, Exp, Config) ->
|
||||
<<"resource_access">> => ResourseAccess,
|
||||
<<"exp">> => Exp
|
||||
},
|
||||
RSAPrivateJWK = jose_jwk:from_pem_file(filename:join(?config(data_dir, Config), "private_api_key.pem")),
|
||||
Signed = jose_jwk:sign(jsx:encode(Message), #{ <<"alg">> => <<"RS256">> }, RSAPrivateJWK),
|
||||
RSAPrivateJWK = jose_jwk:from_pem_file(filename:join(?config(data_dir, Config), "keys/local/private.pem")),
|
||||
Signed = jose_jwt:sign(jose_jwk:from(RSAPrivateJWK), #{<<"alg">> => <<"RS256">>}, Message),
|
||||
{_Alg, Payload} = jose_jws:compact(Signed),
|
||||
Payload.
|
||||
|
||||
@ -830,8 +877,8 @@ default_create_invoice(Config) ->
|
||||
<<"shopID">> => ShopID,
|
||||
<<"amount">> => 100000,
|
||||
<<"currency">> => <<"RUB">>,
|
||||
<<"context">> => #{
|
||||
<<"invoice_dummy_context">> => <<"test_value">>
|
||||
<<"metadata">> => #{
|
||||
<<"invoice_dummy_metadata">> => <<"test_value">>
|
||||
},
|
||||
<<"dueDate">> => DueDate,
|
||||
<<"product">> => <<"test_product">>,
|
||||
@ -921,7 +968,7 @@ default_create_payout_tool(ContractID, Config) ->
|
||||
}
|
||||
},
|
||||
{Host, Port, PreparedParams} = api_client_lib:make_request(Context, Params),
|
||||
Response = swagger_payout_tools_api:create_payout_tool(Host, Port, PreparedParams),
|
||||
Response = swagger_payouts_api:create_payout_tool(Host, Port, PreparedParams),
|
||||
handle_response(Response).
|
||||
|
||||
get_payout_tools(ContractID, Config) ->
|
||||
@ -932,7 +979,7 @@ get_payout_tools(ContractID, Config) ->
|
||||
}
|
||||
},
|
||||
{Host, Port, PreparedParams} = api_client_lib:make_request(Context, Params),
|
||||
Response = swagger_payout_tools_api:get_payout_tools(Host, Port, PreparedParams),
|
||||
Response = swagger_payouts_api:get_payout_tools(Host, Port, PreparedParams),
|
||||
handle_response(Response).
|
||||
|
||||
default_tokenize_card(Config) ->
|
||||
@ -980,22 +1027,20 @@ default_get_claims_by_status(Status, Config) ->
|
||||
|
||||
default_suspend_my_party(Config) ->
|
||||
Context = ?config(context, Config),
|
||||
{ok, Body} = api_client_parties:suspend_my_party(Context),
|
||||
Body.
|
||||
Context = ?config(context, Config),
|
||||
api_client_parties:suspend_my_party(Context).
|
||||
|
||||
default_activate_my_party(Config) ->
|
||||
Context = ?config(context, Config),
|
||||
{ok, Body} = api_client_parties:activate_my_party(Context),
|
||||
Body.
|
||||
api_client_parties:activate_my_party(Context).
|
||||
|
||||
default_suspend_shop(ShopID, Config) ->
|
||||
Context = ?config(context, Config),
|
||||
{ok, Body} = api_client_shops:suspend_shop(Context, ShopID),
|
||||
Body.
|
||||
api_client_shops:suspend_shop(Context, ShopID).
|
||||
|
||||
default_activate_shop(ShopID, Config) ->
|
||||
Context = ?config(context, Config),
|
||||
api_client_shops:activate_shop(Context, ShopID).
|
||||
api_client_shops:activate_shop(Context,ShopID).
|
||||
|
||||
default_get_shop_by_id(ShopID, Config) ->
|
||||
Context = ?config(context, Config),
|
||||
@ -1077,7 +1122,7 @@ get_locations_names(GeoIDs, Lang, Config) ->
|
||||
PreparedGeo = genlib_string:join($,,[genlib:to_binary(I) || I <- GeoIDs]),
|
||||
Params = #{
|
||||
qs_val => #{
|
||||
<<"geoID">> => PreparedGeo,
|
||||
<<"geoIDs">> => PreparedGeo,
|
||||
<<"language">> => Lang
|
||||
}
|
||||
},
|
||||
@ -1593,7 +1638,7 @@ create_and_activate_shop(Config) ->
|
||||
} | _
|
||||
]
|
||||
} = default_get_claim_by_id(ClaimID, Config),
|
||||
_ = default_activate_shop(ShopID, Config),
|
||||
ok = default_activate_shop(ShopID, Config),
|
||||
ShopID.
|
||||
|
||||
get_any_category(Config) ->
|
||||
|
@ -0,0 +1,4 @@
|
||||
-----BEGIN PUBLIC KEY-----
|
||||
MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAK9fx7qOJT7Aoseu7KKgaLagBh3wvDzg
|
||||
7F/ZMtGbPFikJnnvRWvFB5oEGbMPblvtF0/fjqfu+eqjP3Z1tUSn7TkCAwEAAQ==
|
||||
-----END PUBLIC KEY-----
|
@ -65,6 +65,7 @@
|
||||
#{
|
||||
dirs => ["apps/*/src"],
|
||||
filter => "*.app.src",
|
||||
ignore => ["src/swagger*"],
|
||||
rules => [
|
||||
{elvis_style, line_length, #{limit => 120, skip_comments => false}},
|
||||
{elvis_style, no_tabs},
|
||||
|
@ -1,6 +1,6 @@
|
||||
[{<<"api_client">>,
|
||||
{git,"git@github.com:rbkmoney/api_client.git",
|
||||
{ref,"5855e6f7649fefa544599ee9660c3d8ab2532e27"}},
|
||||
{ref,"19fd71a4f90b78efe5878da93ee740d27fffee51"}},
|
||||
0},
|
||||
{<<"base64url">>,
|
||||
{git,"https://github.com/dvv/base64url.git",
|
||||
|
@ -1 +1 @@
|
||||
Subproject commit 9f0be4a32cca19902fc83d76b45ecb175e283b24
|
||||
Subproject commit cd65ecc96b6a11b13523bdc1bc668c2abc4b0e4a
|
Loading…
Reference in New Issue
Block a user