diff --git a/Makefile b/Makefile index 30b5470c..d82b0dff 100644 --- a/Makefile +++ b/Makefile @@ -43,7 +43,11 @@ wc-shell: dev-image $(DOCKER_RUN) --interactive --tty $(DEV_IMAGE_TAG) wc-%: dev-image - $(DOCKER_RUN) $(DEV_IMAGE_TAG) make $* + $(DOCKER_RUN) $(DEV_IMAGE_TAG) make $(if $(MAKE_ARGS),$(MAKE_ARGS) $*,$*) + +# Pass CT_CASE through to container env +wc-common-test.%: MAKE_ARGS=$(if $(CT_CASE),CT_CASE=$(CT_CASE)) + # Rebar tasks @@ -74,6 +78,9 @@ eunit: common-test: $(REBAR) ct --cover +common-test.%: test/%.erl + $(REBAR) ct --cover --suite=$^ $(if $(CT_CASE),--case=$(strip $(CT_CASE))) + cover: $(REBAR) covertool generate diff --git a/rebar.config b/rebar.config index 6567275c..0d807f2c 100644 --- a/rebar.config +++ b/rebar.config @@ -77,8 +77,8 @@ {test, [ {deps, [ %% Libraries generated with swagger-codegen-erlang from valitydev/swag-wallets - {swag_server_wallet, {git, "https://github.com/valitydev/swag-wallets", {ref, "805f079"}}}, - {swag_client_wallet, {git, "https://github.com/valitydev/swag-wallets", {ref, "0ca43f1"}}}, + {swag_server_wallet, {git, "https://github.com/valitydev/swag-wallets", {ref, "96add0f"}}}, + {swag_client_wallet, {git, "https://github.com/valitydev/swag-wallets", {ref, "5fd60dd"}}}, {meck, "0.9.2"} ]}, {cover_enabled, true}, diff --git a/rebar.lock b/rebar.lock index 692caf32..886fe9cc 100644 --- a/rebar.lock +++ b/rebar.lock @@ -13,7 +13,7 @@ 0}, {<<"bouncer_proto">>, {git,"https://github.com/valitydev/bouncer-proto.git", - {ref,"07dcc7b9b4599923b20bcf5f84642c3a1d6570e2"}}, + {ref,"31866c36c049dc568d4bc795a641690db3cb20ab"}}, 0}, {<<"cache">>,{pkg,<<"cache">>,<<"2.3.3">>},1}, {<<"certifi">>,{pkg,<<"certifi">>,<<"2.8.0">>},2}, @@ -21,7 +21,7 @@ {<<"cowlib">>,{pkg,<<"cowlib">>,<<"2.11.0">>},2}, {<<"damsel">>, {git,"https://github.com/valitydev/damsel.git", - {ref,"24932cdc557a75bfb3a4aeb1738638366003aba4"}}, + {ref,"ab44b9db25a76a2c50545fd884e4cdf3d3e3b628"}}, 0}, {<<"dmt_client">>, {git,"https://github.com/valitydev/dmt-client.git", @@ -37,11 +37,11 @@ 0}, {<<"fistful_proto">>, {git,"https://github.com/valitydev/fistful-proto.git", - {ref,"54f1d580854d38429f56ce8cc14bac307eeb4ec7"}}, + {ref,"8b04c7faca7393b9a6a5509205be383d68039907"}}, 0}, {<<"fistful_reporter_proto">>, {git,"https://github.com/valitydev/fistful-reporter-proto.git", - {ref,"9e3e82424f905841b4f2cd66b38a7b0727667ab2"}}, + {ref,"6d5695d2e8aa13247f93451937adefa70c6edeca"}}, 0}, {<<"genlib">>, {git,"https://github.com/valitydev/genlib.git", diff --git a/src/wapi_backend_utils.erl b/src/wapi_backend_utils.erl index 96f3c90a..e5b3916a 100644 --- a/src/wapi_backend_utils.erl +++ b/src/wapi_backend_utils.erl @@ -1,10 +1,7 @@ -module(wapi_backend_utils). -include_lib("fistful_proto/include/fistful_fistful_base_thrift.hrl"). --include_lib("fistful_proto/include/fistful_identity_thrift.hrl"). --include_lib("fistful_proto/include/fistful_wallet_thrift.hrl"). -include_lib("fistful_proto/include/fistful_destination_thrift.hrl"). --include_lib("fistful_proto/include/fistful_w2w_transfer_thrift.hrl"). -include_lib("fistful_proto/include/fistful_wthd_thrift.hrl"). -define(EXTERNAL_ID, <<"externalID">>). @@ -33,23 +30,13 @@ -type hash() :: integer(). -type params() :: map(). -type gen_type() :: - identity - | identity_challenge - | wallet - | destination - | withdrawal - | w2w_transfer. + destination + | withdrawal. -type entity_type() :: - identity - | wallet - | destination - | withdrawal - | w2w_transfer. + destination + | withdrawal. -type entity_state() :: - fistful_identity_thrift:'IdentityState'() - | fistful_wallet_thrift:'WalletState'() - | fistful_destination_thrift:'DestinationState'() - | fistful_w2w_transfer_thrift:'W2WTransferState'() + fistful_destination_thrift:'DestinationState'() | fistful_wthd_thrift:'WithdrawalState'(). -export([gen_id/3]). @@ -59,7 +46,6 @@ -export([add_to_ctx/3]). -export([get_from_ctx/2]). -export([get_idempotent_key/3]). --export([issue_grant_token/3]). -export([create_params_hash/1]). -export([decode_resource/1]). -export([tokenize_resource/1]). @@ -112,7 +98,6 @@ gen_sequence_id(Type, IdempotentKey, Hash, #{woody_context := WoodyCtx}) -> make_ctx(Params) -> #{ ?CTX_NS => genlib_map:compact(#{ - <<"owner">> => maps:get(<<"partyID">>, Params), <<"metadata">> => maps:get(<<"metadata">>, Params, undefined) }) }. @@ -153,24 +138,6 @@ get_from_ctx(Key, Ctx) -> LegacyNSs ). --spec issue_grant_token(_, binary(), handler_context()) -> {ok, binary()} | {error, expired}. -issue_grant_token(TokenSpec, Expiration, Context) -> - case get_expiration_deadline(Expiration) of - {ok, Deadline} -> - {ok, wapi_tokens_legacy:issue_access_token(wapi_handler_utils:get_owner(Context), TokenSpec, Deadline)}; - Error = {error, _} -> - Error - end. - -get_expiration_deadline(Expiration) -> - Deadline = genlib_rfc3339:parse(Expiration, second), - case genlib_time:unow() - Deadline < 0 of - true -> - {ok, Deadline}; - false -> - {error, expired} - end. - -spec create_params_hash(term()) -> integer(). create_params_hash(Value) -> erlang:phash2(Value). @@ -213,19 +180,9 @@ tokenize_resource(Value) -> -spec get_entity_owner(entity_type(), entity_state()) -> {ok, id()}. get_entity_owner(Type, State) -> - {ok, get_context_owner(get_context_from_state(Type, State))}. - -get_context_from_state(identity, #identity_IdentityState{context = Context}) -> - Context; -get_context_from_state(wallet, #wallet_WalletState{context = Context}) -> - Context; -get_context_from_state(destination, #destination_DestinationState{context = Context}) -> - Context; -get_context_from_state(w2w_transfer, #w2w_transfer_W2WTransferState{context = Context}) -> - Context; -get_context_from_state(withdrawal, #wthd_WithdrawalState{context = Context}) -> - Context. + {ok, get_owner(Type, State)}. -get_context_owner(ContextThrift) -> - Context = wapi_codec:unmarshal(context, ContextThrift), - wapi_backend_utils:get_from_ctx(<<"owner">>, Context). +get_owner(destination, #destination_DestinationState{party_id = PartyID}) -> + PartyID; +get_owner(withdrawal, #wthd_WithdrawalState{party_id = PartyID}) -> + PartyID. diff --git a/src/wapi_bouncer_context.erl b/src/wapi_bouncer_context.erl index 92ef6f4d..430fd51b 100644 --- a/src/wapi_bouncer_context.erl +++ b/src/wapi_bouncer_context.erl @@ -21,11 +21,9 @@ -type prototype_operation() :: #{ id => operation_id(), party => maybe_undefined(entity_id()), - identity => maybe_undefined(entity_id()), wallet => maybe_undefined(entity_id()), withdrawal => maybe_undefined(entity_id()), deposit => maybe_undefined(entity_id()), - w2w_transfer => maybe_undefined(entity_id()), source => maybe_undefined(entity_id()), destination => maybe_undefined(entity_id()), report => maybe_undefined(entity_id()), @@ -36,22 +34,19 @@ -type prototype_wallet() :: [wallet_entity()]. -type wallet_entity() :: - {identity, identity_data()} - | {wallet, wallet_data()} + {wallet, wallet_data()} | {withdrawal, withdrawal_data()} | {deposit, deposit_data()} - | {w2w_transfer, w2w_transfer_data()} | {source, source_data()} | {destination, destination_data()} | {webhook, webhook_data()} | {report, report_data()}. -type wallet_entity_type() :: - identity + party | wallet | withdrawal | deposit - | w2w_transfer | source | destination | webhook @@ -59,10 +54,6 @@ | report | report_file. --type identity_data() :: #{ - id => entity_id() -}. - -type wallet_data() :: #{ id => entity_id(), party => entity_id(), @@ -79,11 +70,6 @@ party => entity_id() }. --type w2w_transfer_data() :: #{ - id => entity_id(), - party => entity_id() -}. - -type source_data() :: #{ id => entity_id(), party => entity_id() @@ -96,13 +82,13 @@ -type webhook_data() :: #{ id => entity_id(), - identity => entity_id(), + party => entity_id(), wallet => entity_id() }. -type report_data() :: #{ id => entity_id(), - identity => entity_id(), + party => entity_id(), files => [entity_id()] }. @@ -143,18 +129,15 @@ build(operation, #{id := OperationID} = Params, Acc) -> op = #ctx_v1_WalletAPIOperation{ id = operation_id_to_binary(OperationID), party = 'maybe'(party, Params), - identity = 'maybe'(identity, Params), wallet = 'maybe'(wallet, Params), withdrawal = 'maybe'(withdrawal, Params), deposit = 'maybe'(deposit, Params), - w2w_transfer = 'maybe'(w2w_transfer, Params), source = 'maybe'(source, Params), destination = 'maybe'(destination, Params), report = wapi_handler_utils:maybe_with(report, Params, fun genlib:to_binary/1), file = 'maybe'(file, Params), webhook = 'maybe'(webhook, Params) - }, - grants = wapi_handler_utils:maybe_with(grants, Params, fun build_grants/1) + } } }; build(wallet, Params, Acc) when is_list(Params) -> @@ -198,22 +181,23 @@ build_wallet_entity(Type, Params, {IDKey, ID}) -> build_wallet_entity_(deposit, #{<<"wallet">> := WalletID}) -> #{wallet => WalletID}; -build_wallet_entity_(webhook, #{<<"identityID">> := Identity} = Webhook) -> +build_wallet_entity_(webhook, #{<<"partyID">> := Party} = Webhook) -> Scope = 'maybe'(<<"scope">>, Webhook), WalletID = 'maybe'(<<"walletID">>, Scope), - #{identity => Identity, wallet => WalletID}; + #{party => Party, wallet => WalletID}; build_wallet_entity_(report, #{<<"files">> := Files}) -> #{files => lists:map(fun(#{<<"id">> := FileID}) -> FileID end, Files)}; -%% identity => IdentityID, +%% party => PartyID, build_wallet_entity_(_, _) -> #{}. %% -build_entity_ctx({identity, Data}) -> +build_entity_ctx({party, Data}) -> + %% TODO: fix after edit bouncer proto #base_Entity{ id = 'maybe'(id, Data), - type = <<"Identity">>, + type = <<"Party">>, party = 'maybe'(party, Data) }; build_entity_ctx({wallet, Data}) -> @@ -239,12 +223,6 @@ build_entity_ctx({deposit, Data}) -> wallet = 'maybe'(wallet, Data) } }; -build_entity_ctx({w2w_transfer, Data}) -> - #base_Entity{ - id = 'maybe'(id, Data), - type = <<"W2WTransfer">>, - party = 'maybe'(party, Data) - }; build_entity_ctx({source, Data}) -> #base_Entity{ id = 'maybe'(id, Data), @@ -261,8 +239,8 @@ build_entity_ctx({webhook, Data}) -> #base_Entity{ id = 'maybe'(id, Data), type = <<"WalletWebhook">>, + party = 'maybe'(party, Data), wallet = #base_WalletAttrs{ - identity = 'maybe'(identity, Data), wallet = 'maybe'(wallet, Data) } }; @@ -270,8 +248,8 @@ build_entity_ctx({report, Data}) -> #base_Entity{ id = 'maybe'(id, Data), type = <<"WalletReport">>, + party = 'maybe'(party, Data), wallet = #base_WalletAttrs{ - identity = 'maybe'(identity, Data), report = wapi_handler_utils:maybe_with(files, Data, fun build_report_attrs/1) } }. @@ -286,18 +264,6 @@ build_entity_ctx({report, Data}) -> operation_id_to_binary(V) -> erlang:atom_to_binary(V, utf8). -build_grants(Grants) when is_list(Grants) -> - build_set(lists:map(fun build_grant/1, Grants)). - -build_grant(Grant) -> - #ctx_v1_WalletGrant{ - wallet = 'maybe'(wallet, Grant), - destination = 'maybe'(destination, Grant), - body = wapi_handler_utils:maybe_with(body, Grant, fun build_cash/1), - created_at = 'maybe'(created_at, Grant), - expires_on = 'maybe'(expires_on, Grant) - }. - build_cash(Cash) -> #base_Cash{ amount = 'maybe'(amount, Cash), diff --git a/src/wapi_codec.erl b/src/wapi_codec.erl index 52ad9adb..c00043fe 100644 --- a/src/wapi_codec.erl +++ b/src/wapi_codec.erl @@ -62,23 +62,31 @@ marshal(provider_id, V) -> marshal(integer, V); marshal(terminal_id, V) -> marshal(integer, V); +marshal(realm, <<"test">>) -> + test; +marshal(realm, <<"live">>) -> + live; marshal(blocking, blocked) -> blocked; marshal(blocking, unblocked) -> unblocked; marshal(account_change, {created, Account}) -> {created, marshal(account, Account)}; -marshal(account, #{ - id := ID, - identity := IdentityID, - currency := CurrencyID, - accounter_account_id := AAID -}) -> +marshal(account_id, V) when is_integer(V) -> + V; +marshal( + account, + #{ + realm := Realm, + currency := CurrencyID, + account_id := AID + } = Account +) -> #'account_Account'{ - id = marshal(id, ID), - identity = marshal(id, IdentityID), + realm = Realm, + party_id = maybe_marshal(id, maps:get(party_id, Account, undefined)), currency = marshal(currency_ref, CurrencyID), - accounter_account_id = marshal(event_id, AAID) + account_id = marshal(integer, AID) }; marshal(resource, {bank_card, #{bank_card := BankCard} = ResourceBankCard}) -> {bank_card, #'fistful_base_ResourceBankCard'{ @@ -202,8 +210,6 @@ marshal(sub_failure, Failure) -> }; marshal(domain_revision, V) when is_integer(V) -> V; -marshal(party_revision, V) when is_integer(V) -> - V; marshal(string, V) when is_binary(V) -> V; marshal(integer, V) when is_integer(V) -> @@ -231,23 +237,29 @@ unmarshal(provider_id, V) -> unmarshal(integer, V); unmarshal(terminal_id, V) -> unmarshal(integer, V); +unmarshal(realm, test) -> + <<"test">>; +unmarshal(realm, live) -> + <<"live">>; unmarshal(blocking, blocked) -> blocked; unmarshal(blocking, unblocked) -> unblocked; unmarshal(account_change, {created, Account}) -> {created, unmarshal(account, Account)}; +unmarshal(account_id, V) when is_integer(V) -> + V; unmarshal(account, #'account_Account'{ - id = ID, - identity = IdentityID, + party_id = PartyID, + realm = Realm, currency = CurrencyRef, - accounter_account_id = AAID + account_id = AID }) -> #{ - id => unmarshal(id, ID), - identity => unmarshal(id, IdentityID), + realm => Realm, + party_id => maybe_unmarshal(id, PartyID), currency => unmarshal(currency_ref, CurrencyRef), - accounter_account_id => unmarshal(accounter_account_id, AAID) + account_id => unmarshal(account_id, AID) }; unmarshal(accounter_account_id, V) -> unmarshal(integer, V); @@ -348,7 +360,7 @@ unmarshal(digital_wallet, #'fistful_base_DigitalWallet'{ }) -> genlib_map:compact(#{ id => unmarshal(string, ID), - token => maybe_marshal(string, Token), + token => maybe_unmarshal(string, Token), payment_service => unmarshal(payment_service, PaymentService), account_name => unmarshal(string, AccountName), account_identity_number => unmarshal(string, AccountIdentityNumber) @@ -358,7 +370,7 @@ unmarshal(generic_resource, #'fistful_base_ResourceGenericData'{ data = Data }) -> genlib_map:compact(#{ - data => maybe_marshal(content, Data), + data => maybe_unmarshal(content, Data), payment_service => unmarshal(payment_service, PaymentService) }); unmarshal(payment_service, #'fistful_base_PaymentServiceRef'{id = Ref}) -> @@ -388,8 +400,6 @@ unmarshal(sub_failure, Failure) -> }); unmarshal(domain_revision, V) when is_integer(V) -> V; -unmarshal(party_revision, V) when is_integer(V) -> - V; unmarshal(string, V) when is_binary(V) -> V; unmarshal(integer, V) when is_integer(V) -> diff --git a/src/wapi_destination_backend.erl b/src/wapi_destination_backend.erl index 4257c42e..0d764f92 100644 --- a/src/wapi_destination_backend.erl +++ b/src/wapi_destination_backend.erl @@ -22,10 +22,9 @@ DestinationError :: {invalid_resource_token, binary()} | {invalid_generic_resource, {binary(), unknown_resource}} - | {identity, notfound} + | {party, notfound} | {currency, notfound} | inaccessible - | forbidden_withdrawal_method | {external_id_conflict, {id(), external_id()}}. create(Params, HandlerContext) -> do(fun() -> @@ -77,7 +76,7 @@ generate_id_legacy(Params, HandlerContext) -> is_id_unknown( ID, #{ - <<"identity">> := IdentityID, + <<"party">> := PartyID, <<"currency">> := CurrencyID, <<"name">> := Name }, @@ -89,7 +88,7 @@ is_id_unknown( {ok, #{ <<"id">> := ID, - <<"identity">> := IdentityID, + <<"party">> := PartyID, <<"currency">> := CurrencyID, <<"name">> := Name }, @@ -110,8 +109,8 @@ create_request(ID, Params, ResourceThrift, HandlerContext) -> case service_call(Request, HandlerContext) of {ok, Destination} -> {ok, unmarshal(destination, Destination)}; - {exception, #fistful_IdentityNotFound{}} -> - {error, {identity, notfound}}; + {exception, #fistful_PartyNotFound{}} -> + {error, {party, notfound}}; {exception, #fistful_CurrencyNotFound{}} -> {error, {currency, notfound}}; {exception, #fistful_PartyInaccessible{}} -> @@ -275,7 +274,8 @@ marshal( destination_params, #{ <<"id">> := ID, - <<"identity">> := IdentityID, + <<"party">> := PartyID, + <<"realm">> := Realm, <<"currency">> := CurrencyID, <<"name">> := Name, <<"resourceThrift">> := Resource @@ -285,7 +285,8 @@ marshal( AuthData = maps:get(<<"additionalAuthData">>, Params, undefined), #destination_DestinationParams{ id = marshal(id, ID), - identity = marshal(id, IdentityID), + party_id = marshal(id, PartyID), + realm = marshal(realm, Realm), name = marshal(string, Name), currency = marshal(string, CurrencyID), external_id = maybe_marshal(id, ExternalID), @@ -294,6 +295,10 @@ marshal( }; marshal(context, Context) -> wapi_codec:marshal(context, Context); +marshal(realm, <<"Test">>) -> + test; +marshal(realm, <<"Live">>) -> + live; marshal(auth_data, #{ <<"type">> := <<"SenderReceiverDestinationAuthData">>, <<"senderToken">> := SenderToken, @@ -313,40 +318,40 @@ maybe_marshal(T, V) -> unmarshal(destination, #destination_DestinationState{ id = DestinationID, + party_id = PartyID, + realm = Realm, name = Name, account = Account, external_id = ExternalID, created_at = CreatedAt, resource = Resource, - status = Status, blocking = Blocking, context = Context }) -> #{ - identity := Identity, currency := Currency } = unmarshal(account, Account), UnmarshaledContext = unmarshal(context, Context), genlib_map:compact(#{ <<"id">> => unmarshal(id, DestinationID), <<"name">> => unmarshal(string, Name), - <<"status">> => unmarshal(status, Status), + <<"realm">> => unmarshal(realm, Realm), <<"isBlocked">> => maybe_unmarshal(blocking, Blocking), - <<"identity">> => Identity, + <<"party">> => PartyID, <<"currency">> => Currency, <<"createdAt">> => CreatedAt, <<"resource">> => unmarshal(resource, Resource), <<"externalID">> => maybe_unmarshal(id, ExternalID), <<"metadata">> => wapi_backend_utils:get_from_ctx(<<"metadata">>, UnmarshaledContext) }); +unmarshal(realm, test) -> + <<"Test">>; +unmarshal(realm, live) -> + <<"Live">>; unmarshal(blocking, unblocked) -> false; unmarshal(blocking, blocked) -> true; -unmarshal(status, {authorized, #destination_Authorized{}}) -> - <<"Authorized">>; -unmarshal(status, {unauthorized, #destination_Unauthorized{}}) -> - <<"Unauthorized">>; unmarshal( resource, {bank_card, #'fistful_base_ResourceBankCard'{ diff --git a/src/wapi_domain_backend.erl b/src/wapi_domain_backend.erl index 4e0cf754..85ee4863 100644 --- a/src/wapi_domain_backend.erl +++ b/src/wapi_domain_backend.erl @@ -6,6 +6,8 @@ -type response_data() :: wapi_handler_utils:response_data(). -export([get_currency/1]). +-export([get_party_config/1]). +-export([get_wallet_config/1]). %% @@ -18,6 +20,26 @@ %% +-spec get_party_config(id()) -> {ok, {map(), id()}} | {error, notfound}. +get_party_config(PartyID) -> + do(fun() -> + Party = unwrap(object({party_config, #domain_PartyConfigRef{id = PartyID}})), + {#{<<"id">> => Party#domain_PartyConfig.id}, PartyID} + end). + +-spec get_wallet_config(id()) -> {ok, {map(), id()}} | {error, notfound}. +get_wallet_config(WalletID) -> + do(fun() -> + Wallet = unwrap(object({wallet_config, #domain_WalletConfigRef{id = WalletID}})), + { + #{ + <<"id">> => Wallet#domain_WalletConfig.id, + <<"partyID">> => Wallet#domain_WalletConfig.party_id + }, + Wallet#domain_WalletConfig.party_id + } + end). + -spec get_currency(id()) -> {ok, response_data()} | {error, notfound}. get_currency(ID) -> do(fun() -> diff --git a/src/wapi_identity_backend.erl b/src/wapi_identity_backend.erl deleted file mode 100644 index fba8c62b..00000000 --- a/src/wapi_identity_backend.erl +++ /dev/null @@ -1,228 +0,0 @@ --module(wapi_identity_backend). - --type handler_context() :: wapi_handler_utils:handler_context(). --type response_data() :: wapi_handler_utils:response_data(). --type params() :: map(). --type id() :: binary(). --type result(T, E) :: {ok, T} | {error, E}. --type identity_state() :: fistful_identity_thrift:'IdentityState'(). - --export_type([identity_state/0]). - --export([create/2]). --export([get/2]). - --export([get_thrift_identity/2]). --export([get_identity_withdrawal_methods/2]). - --include_lib("fistful_proto/include/fistful_fistful_thrift.hrl"). --include_lib("fistful_proto/include/fistful_identity_thrift.hrl"). --include_lib("fistful_proto/include/fistful_fistful_base_thrift.hrl"). - -%% Pipeline - --spec get(id(), handler_context()) -> - {ok, response_data(), id()} - | {error, {identity, notfound}}. -get(IdentityID, HandlerContext) -> - case get_thrift_identity(IdentityID, HandlerContext) of - {ok, IdentityThrift} -> - {ok, Owner} = wapi_backend_utils:get_entity_owner(identity, IdentityThrift), - {ok, unmarshal_identity(IdentityThrift), Owner}; - {error, _} = Error -> - Error - end. - --spec create(params(), handler_context()) -> - result( - map(), - {provider, notfound} - | {external_id_conflict, id()} - | inaccessible - | _Unexpected - ). -create(Params, HandlerContext) -> - case wapi_backend_utils:gen_id(identity, Params, HandlerContext) of - {ok, ID} -> - case is_id_unknown(ID, Params, HandlerContext) of - true -> - create_identity(ID, Params, HandlerContext); - false -> - create(Params, HandlerContext) - end; - {error, {external_id_conflict, _}} = Error -> - Error - end. - -is_id_unknown( - ID, - #{ - <<"name">> := Name, - <<"provider">> := Provider - }, - HandlerContext -) -> - case get(ID, HandlerContext) of - {error, {identity, notfound}} -> - true; - {ok, - #{ - <<"id">> := ID, - <<"name">> := Name, - <<"provider">> := Provider - }, - _Owner} -> - true; - {ok, _NonMatchingIdentity, _Owner} -> - false - end. - -create_identity(ID, Params, HandlerContext) -> - IdentityParams = marshal(identity_params, Params#{<<"id">> => ID}), - Request = {fistful_identity, 'Create', {IdentityParams, marshal(context, create_context(Params))}}, - - case service_call(Request, HandlerContext) of - {ok, Identity} -> - {ok, unmarshal_identity(Identity)}; - {exception, #fistful_PartyNotFound{}} -> - {error, {party, notfound}}; - {exception, #fistful_ProviderNotFound{}} -> - {error, {provider, notfound}}; - {exception, #fistful_PartyInaccessible{}} -> - {error, inaccessible}; - {exception, Details} -> - {error, Details} - end. - --spec get_thrift_identity(id(), handler_context()) -> - {ok, identity_state()} - | {error, {identity, notfound}}. -get_thrift_identity(IdentityID, HandlerContext) -> - Request = {fistful_identity, 'Get', {IdentityID, #'fistful_base_EventRange'{}}}, - case service_call(Request, HandlerContext) of - {ok, IdentityThrift} -> - {ok, IdentityThrift}; - {exception, #fistful_IdentityNotFound{}} -> - {error, {identity, notfound}} - end. - --spec get_identity_withdrawal_methods(id(), handler_context()) -> - {ok, response_data()} - | {error, {identity, notfound}}. -get_identity_withdrawal_methods(IdentityID, HandlerContext) -> - Request = {fistful_identity, 'GetWithdrawalMethods', {IdentityID}}, - case service_call(Request, HandlerContext) of - {ok, Methods} -> - {ok, unmarshal_withdrawal_methods(Methods)}; - {exception, #fistful_IdentityNotFound{}} -> - {error, {identity, notfound}} - end. - -%% -%% Internal -%% - -create_context(Params) -> - KV = {<<"name">>, maps:get(<<"name">>, Params, undefined)}, - wapi_backend_utils:add_to_ctx(KV, wapi_backend_utils:make_ctx(Params)). - -service_call(Params, Ctx) -> - wapi_handler_utils:service_call(Params, Ctx). - -%% Marshaling - -marshal( - identity_params, - #{ - <<"id">> := ID, - <<"name">> := Name, - <<"provider">> := Provider, - <<"partyID">> := PartyID - } = Params -) -> - ExternalID = maps:get(<<"externalID">>, Params, undefined), - #identity_IdentityParams{ - id = marshal(id, ID), - name = marshal(string, Name), - party = marshal(id, PartyID), - provider = marshal(string, Provider), - external_id = marshal(id, ExternalID) - }; -marshal(context, Ctx) -> - wapi_codec:marshal(context, Ctx); -marshal(T, V) -> - wapi_codec:marshal(T, V). - -%% - -unmarshal_withdrawal_methods(Methods) -> - MethodMap = ordsets:fold(fun unmarshal_withdrawal_method/2, #{}, Methods), - #{ - <<"methods">> => [ - #{ - <<"method">> => <<"WithdrawalMethodBankCard">>, - <<"paymentSystems">> => maps:get(bank_card, MethodMap, []) - }, - #{ - <<"method">> => <<"WithdrawalMethodDigitalWallet">>, - <<"providers">> => maps:get(digital_wallet, MethodMap, []) - }, - #{ - <<"method">> => <<"WithdrawalMethodGeneric">>, - <<"providers">> => maps:get(generic, MethodMap, []) - } - %% TODO: Need to add method type for crypto currency TD-250 - ] - }. - -unmarshal_withdrawal_method({bank_card, #'fistful_BankCardWithdrawalMethod'{payment_system = PaymentSystem}}, Acc0) -> - Methods = maps:get(bank_card, Acc0, []), - #{id := ID} = unmarshal(payment_system, PaymentSystem), - Acc0#{bank_card => [ID | Methods]}; -unmarshal_withdrawal_method({digital_wallet, PaymentServiceRef}, Acc0) -> - Methods = maps:get(digital_wallet, Acc0, []), - #{id := ID} = unmarshal(payment_service, PaymentServiceRef), - Acc0#{digital_wallet => [ID | Methods]}; -unmarshal_withdrawal_method({generic, PaymentServiceRef}, Acc0) -> - Methods = maps:get(generic, Acc0, []), - #{id := ID} = unmarshal(payment_service, PaymentServiceRef), - Acc0#{generic => [ID | Methods]}; -unmarshal_withdrawal_method({crypto_currency, CryptoCurrencyRef}, Acc0) -> - Methods = maps:get(crypto_currency, Acc0, []), - #{id := ID} = unmarshal(crypto_currency, CryptoCurrencyRef), - Acc0#{crypto_currency => [ID | Methods]}. - -unmarshal_identity(#identity_IdentityState{ - id = IdentityID, - name = Name, - blocking = Blocking, - provider_id = Provider, - external_id = ExternalID, - created_at = CreatedAt, - context = Ctx -}) -> - Context = unmarshal(context, Ctx), - genlib_map:compact(#{ - <<"id">> => unmarshal(id, IdentityID), - <<"name">> => unmarshal(string, Name), - <<"createdAt">> => maybe_unmarshal(string, CreatedAt), - <<"isBlocked">> => unmarshal_blocking(Blocking), - <<"provider">> => unmarshal(id, Provider), - <<"externalID">> => maybe_unmarshal(id, ExternalID), - <<"metadata">> => wapi_backend_utils:get_from_ctx(<<"metadata">>, Context) - }). - -unmarshal_blocking(undefined) -> - undefined; -unmarshal_blocking(unblocked) -> - false; -unmarshal_blocking(blocked) -> - true. - -unmarshal(T, V) -> - wapi_codec:unmarshal(T, V). - -maybe_unmarshal(_, undefined) -> - undefined; -maybe_unmarshal(T, V) -> - unmarshal(T, V). diff --git a/src/wapi_privdoc_backend.erl b/src/wapi_privdoc_backend.erl deleted file mode 100644 index 2abfd24a..00000000 --- a/src/wapi_privdoc_backend.erl +++ /dev/null @@ -1,92 +0,0 @@ -%% TODO -%% switch to wapi_privdoc_handler when wapi becomes a whole service. -%% Note -%% It's a bit dirty to call cds directly from a non-pcidss service -%% even though we get only presentaton data from cds here, not actual card data. - --module(wapi_privdoc_backend). - --include_lib("identdocstore_proto/include/identdocstore_identdoc_thrift.hrl"). - --export([get_proof/2]). - -%% Types - --type handler_context() :: wapi_handler_utils:handler_context(). - -%% API - --spec get_proof(binary(), handler_context()) -> map(). -get_proof(Token, Context) -> - {ok, DocData} = wapi_handler_utils:service_call({identdoc_storage, 'Get', {Token}}, Context), - to_swag(doc_data, {DocData, Token}). - -to_swag(doc_data, {{russian_domestic_passport, D}, Token}) -> - to_swag(doc, { - #{ - <<"type">> => <<"RUSDomesticPassportData">>, - <<"series">> => D#identdoc_RussianDomesticPassport.series, - <<"number">> => D#identdoc_RussianDomesticPassport.number, - <<"firstName">> => D#identdoc_RussianDomesticPassport.first_name, - <<"familyName">> => D#identdoc_RussianDomesticPassport.family_name, - <<"patronymic">> => D#identdoc_RussianDomesticPassport.patronymic - }, - Token - }); -to_swag(doc_data, {{russian_retiree_insurance_certificate, D}, Token}) -> - to_swag(doc, { - #{ - <<"type">> => <<"RUSRetireeInsuranceCertificateData">>, - <<"number">> => D#identdoc_RussianRetireeInsuranceCertificate.number - }, - Token - }); -to_swag(doc, {Params, Token}) -> - Doc = to_swag(raw_doc, {Params, Token}), - Doc#{<<"token">> => wapi_utils:map_to_base64url(Doc)}; -to_swag(raw_doc, {Params = #{<<"type">> := <<"RUSDomesticPassportData">>}, Token}) -> - #{ - <<"type">> => <<"RUSDomesticPassport">>, - <<"token">> => Token, - <<"seriesMasked">> => mask(pass_series, Params), - <<"numberMasked">> => mask(pass_number, Params), - <<"fullnameMasked">> => mask(pass_fullname, Params) - }; -to_swag(raw_doc, {Params = #{<<"type">> := <<"RUSRetireeInsuranceCertificateData">>}, Token}) -> - #{ - <<"type">> => <<"RUSRetireeInsuranceCertificate">>, - <<"token">> => Token, - <<"numberMasked">> => mask(retiree_insurance_cert_number, Params) - }. - --define(PATTERN_DIGIT, [<<"0">>, <<"1">>, <<"2">>, <<"3">>, <<"4">>, <<"5">>, <<"6">>, <<"7">>, <<"8">>, <<"9">>]). - -mask(pass_series, #{<<"series">> := V}) -> - wapi_utils:mask_and_keep(leading, 2, $*, V); -mask(pass_number, #{<<"number">> := V}) -> - wapi_utils:mask_and_keep(trailing, 1, $*, V); -mask(pass_fullname, Params) -> - MaskedFamilyName = mask(family_name, Params), - MaskedFirstName = mask(first_name, Params), - MaskedPatronymic = mask(patronymic, Params), - <>; -mask(family_name, #{<<"familyName">> := V}) -> - wapi_utils:mask_and_keep(leading, 1, $*, V); -mask(first_name, #{<<"firstName">> := V}) -> - <<(unicode:characters_to_binary(string:left(unicode:characters_to_list(V), 1)))/binary, "."/utf8>>; -mask(patronymic, #{<<"patronymic">> := V}) -> - <<(unicode:characters_to_binary(string:left(unicode:characters_to_list(V), 1)))/binary, "."/utf8>>; -mask(patronymic, _) -> - <<>>; -%% TODO rewrite this ugly shit -mask(retiree_insurance_cert_number, #{<<"number">> := Number}) -> - FirstPublicSymbols = 2, - LastPublicSymbols = 1, - V1 = binary:part(Number, {0, FirstPublicSymbols}), - Rest1 = binary:part(Number, {0 + FirstPublicSymbols, size(Number) - (0 + FirstPublicSymbols)}), - - V2 = binary:part(Rest1, {size(Rest1), -LastPublicSymbols}), - Rest2 = binary:part(Rest1, {0, size(Rest1) - LastPublicSymbols}), - - Mask = binary:replace(Rest2, ?PATTERN_DIGIT, <<"*">>, [global]), - <>. diff --git a/src/wapi_provider_backend.erl b/src/wapi_provider_backend.erl deleted file mode 100644 index 6fa47c68..00000000 --- a/src/wapi_provider_backend.erl +++ /dev/null @@ -1,61 +0,0 @@ --module(wapi_provider_backend). - --include_lib("fistful_proto/include/fistful_fistful_thrift.hrl"). --include_lib("fistful_proto/include/fistful_provider_thrift.hrl"). - --type handler_context() :: wapi_handler_utils:handler_context(). --type response_data() :: wapi_handler_utils:response_data(). --type id() :: binary(). - --export([get_providers/2]). --export([get_provider/2]). - --spec get_providers([binary()], handler_context()) -> [map()]. -get_providers(Residences, HandlerContext) -> - ResidenceSet = ordsets:from_list(Residences), - Request = {fistful_provider, 'ListProviders', {}}, - {ok, Providers} = wapi_handler_utils:service_call(Request, HandlerContext), - [ - P - || P <- unmarshal_providers(Providers), - ordsets:is_subset( - ResidenceSet, - ordsets:from_list(maps:get(<<"residences">>, P)) - ) - ]. - --spec get_provider(id(), handler_context()) -> {ok, response_data()} | {error, notfound}. -get_provider(ProviderID, HandlerContext) -> - case get_provider_thrift(ProviderID, HandlerContext) of - {ok, Provider} -> - {ok, unmarshal_provider(Provider)}; - {error, _} = Error -> - Error - end. - -%% Internal - -get_provider_thrift(ProviderID, HandlerContext) -> - Request = {fistful_provider, 'GetProvider', {ProviderID}}, - case wapi_handler_utils:service_call(Request, HandlerContext) of - {ok, _} = Result -> - Result; - {exception, #fistful_ProviderNotFound{}} -> - {error, notfound} - end. - -%% Marshaling - -unmarshal_providers(List) -> - lists:map(fun(Provider) -> unmarshal_provider(Provider) end, List). - -unmarshal_provider(#provider_Provider{ - id = ID, - name = Name, - residences = Residences -}) -> - genlib_map:compact(#{ - <<"id">> => ID, - <<"name">> => Name, - <<"residences">> => Residences - }). diff --git a/src/wapi_report_backend.erl b/src/wapi_report_backend.erl index c9109e8a..e112c5ee 100644 --- a/src/wapi_report_backend.erl +++ b/src/wapi_report_backend.erl @@ -2,68 +2,46 @@ -include_lib("fistful_reporter_proto/include/ffreport_reports_thrift.hrl"). -include_lib("file_storage_proto/include/filestore_storage_thrift.hrl"). --include_lib("fistful_proto/include/fistful_identity_thrift.hrl"). -export([create_report/2]). --export([get_report/4]). +-export([get_report/3]). -export([get_reports/2]). -export([download_file/3]). --type id() :: binary(). -type request_data() :: wapi_wallet_handler:request_data(). -type handler_context() :: wapi_handler_utils:handler_context(). -type response_data() :: wapi_handler_utils:response_data(). -spec create_report(request_data(), handler_context()) -> {ok, response_data()} | {error, Error} when Error :: - {identity, notfound} - | invalid_request - | invalid_contract. + {party, notfound} + | invalid_request. create_report( #{ - 'identityID' := IdentityID, 'partyID' := PartyID, 'ReportParams' := ReportParams }, HandlerContext ) -> - case get_contract_id_from_identity(IdentityID, HandlerContext) of - {ok, ContractID} -> - Req = create_report_request(#{ - party_id => PartyID, - contract_id => ContractID, - from_time => get_time(<<"fromTime">>, ReportParams), - to_time => get_time(<<"toTime">>, ReportParams) - }), - Call = {fistful_report, 'GenerateReport', {Req, maps:get(<<"reportType">>, ReportParams)}}, - case wapi_handler_utils:service_call(Call, HandlerContext) of - {ok, ReportID} -> - get_report('contractID', ReportID, ContractID, PartyID, HandlerContext); - {exception, #reports_InvalidRequest{}} -> - {error, invalid_request}; - {exception, #reports_ContractNotFound{}} -> - {error, invalid_contract} - end; - {error, _} = Error -> - Error + Req = create_report_request(#{ + party_id => PartyID, + from_time => get_time(<<"fromTime">>, ReportParams), + to_time => get_time(<<"toTime">>, ReportParams) + }), + Call = {fistful_report, 'GenerateReport', {Req, maps:get(<<"reportType">>, ReportParams)}}, + case wapi_handler_utils:service_call(Call, HandlerContext) of + {ok, ReportID} -> + get_report(ReportID, PartyID, HandlerContext); + {exception, #reports_InvalidRequest{}} -> + {error, invalid_request}; + {exception, #reports_PartyNotFound{}} -> + {error, {party, notfound}} end. --spec get_report(integer(), binary(), binary(), handler_context()) -> {ok, response_data()} | {error, Error} when - Error :: - {identity, notfound} - | notfound. -get_report(ReportID, IdentityID, PartyID, HandlerContext) -> - get_report('identityID', ReportID, IdentityID, PartyID, HandlerContext). - -get_report('identityID', ReportID, IdentityID, PartyID, HandlerContext) -> - case get_contract_id_from_identity(IdentityID, HandlerContext) of - {ok, ContractID} -> - get_report('contractID', ReportID, ContractID, PartyID, HandlerContext); - {error, _} = Error -> - Error - end; -get_report('contractID', ReportID, ContractID, PartyID, HandlerContext) -> - Call = {fistful_report, 'GetReport', {PartyID, ContractID, ReportID}}, +-spec get_report(binary(), binary(), handler_context()) -> {ok, response_data()} | {error, Error} when + Error :: notfound. +get_report(ReportID, PartyID, HandlerContext) -> + Call = {fistful_report, 'GetReport', {PartyID, ReportID}}, case wapi_handler_utils:service_call(Call, HandlerContext) of {ok, Report} -> {ok, unmarshal_report(Report)}; @@ -73,29 +51,23 @@ get_report('contractID', ReportID, ContractID, PartyID, HandlerContext) -> -spec get_reports(request_data(), handler_context()) -> {ok, response_data()} | {error, Error} when Error :: - {identity, notfound} + {party, notfound} | invalid_request | {dataset_too_big, integer()}. -get_reports(#{'identityID' := IdentityID, 'partyID' := PartyID} = Params, HandlerContext) -> - case get_contract_id_from_identity(IdentityID, HandlerContext) of - {ok, ContractID} -> - Req = create_report_request(#{ - party_id => PartyID, - contract_id => ContractID, - from_time => get_time('fromTime', Params), - to_time => get_time('toTime', Params) - }), - Call = {fistful_report, 'GetReports', {Req, [genlib:to_binary(maps:get(type, Params))]}}, - case wapi_handler_utils:service_call(Call, HandlerContext) of - {ok, ReportList} -> - {ok, unmarshal_reports(ReportList)}; - {exception, #reports_InvalidRequest{}} -> - {error, invalid_request}; - {exception, #reports_DatasetTooBig{limit = Limit}} -> - {error, {dataset_too_big, Limit}} - end; - {error, _} = Error -> - Error +get_reports(#{'partyID' := PartyID} = Params, HandlerContext) -> + Req = create_report_request(#{ + party_id => PartyID, + from_time => get_time('fromTime', Params), + to_time => get_time('toTime', Params) + }), + Call = {fistful_report, 'GetReports', {Req, [genlib:to_binary(maps:get(type, Params))]}}, + case wapi_handler_utils:service_call(Call, HandlerContext) of + {ok, ReportList} -> + {ok, unmarshal_reports(ReportList)}; + {exception, #reports_InvalidRequest{}} -> + {error, invalid_request}; + {exception, #reports_DatasetTooBig{limit = Limit}} -> + {error, {dataset_too_big, Limit}} end. -spec download_file(binary(), binary(), handler_context()) -> {ok, response_data()} | {error, Error} when @@ -113,25 +85,13 @@ download_file(FileID, ExpiresAt, HandlerContext) -> %% Internal --spec get_contract_id_from_identity(id(), handler_context()) -> {ok, id()} | {error, Error} when - Error :: {identity, notfound}. -get_contract_id_from_identity(IdentityID, HandlerContext) -> - case wapi_identity_backend:get_thrift_identity(IdentityID, HandlerContext) of - {ok, #identity_IdentityState{contract_id = ContractID}} -> - {ok, ContractID}; - {error, _} = Error -> - Error - end. - create_report_request(#{ party_id := PartyID, - contract_id := ContractID, from_time := FromTime, to_time := ToTime }) -> #reports_ReportRequest{ party_id = PartyID, - contract_id = ContractID, time_range = #reports_ReportTimeRange{ from_time = FromTime, to_time = ToTime diff --git a/src/wapi_stat_backend.erl b/src/wapi_stat_backend.erl index 3a29763f..b1976ca2 100644 --- a/src/wapi_stat_backend.erl +++ b/src/wapi_stat_backend.erl @@ -3,23 +3,14 @@ -include_lib("fistful_proto/include/fistful_fistful_base_thrift.hrl"). -include_lib("fistful_proto/include/fistful_stat_thrift.hrl"). --export([list_wallets/2]). -export([list_withdrawals/2]). -export([list_deposits/2]). -export([list_destinations/2]). --export([list_identities/2]). --export([list_deposit_reverts/2]). --export([list_deposit_adjustments/2]). -type request_data() :: wapi_wallet_handler:request_data(). -type handler_context() :: wapi_handler_utils:handler_context(). -type response_data() :: wapi_handler_utils:response_data(). --spec list_wallets(request_data(), handler_context()) -> {ok, response_data()} | {error, StatError} when - StatError :: {invalid | bad_token, binary()}. -list_wallets(Params, Context) -> - service_call(wallets, Params, Context). - -spec list_withdrawals(request_data(), handler_context()) -> {ok, response_data()} | {error, StatError} when StatError :: {invalid | bad_token, binary()}. list_withdrawals(Params, Context) -> @@ -35,21 +26,6 @@ list_deposits(Params, Context) -> list_destinations(Params, Context) -> service_call(destinations, Params, Context). --spec list_identities(request_data(), handler_context()) -> {ok, response_data()} | {error, StatError} when - StatError :: {invalid | bad_token, binary()}. -list_identities(Params, Context) -> - service_call(identities, Params, Context). - --spec list_deposit_reverts(request_data(), handler_context()) -> {ok, response_data()} | {error, StatError} when - StatError :: {invalid | bad_token, binary()}. -list_deposit_reverts(Params, Context) -> - service_call(deposit_reverts, Params, Context). - --spec list_deposit_adjustments(request_data(), handler_context()) -> {ok, response_data()} | {error, StatError} when - StatError :: {invalid | bad_token, binary()}. -list_deposit_adjustments(Params, Context) -> - service_call(deposit_adjustments, Params, Context). - service_call(StatTag, Params, Context) -> Req = create_request( create_dsl(StatTag, Params), @@ -59,13 +35,9 @@ service_call(StatTag, Params, Context) -> wapi_handler_utils:service_call({fistful_stat, method(StatTag), {Req}}, Context) ). -method(wallets) -> 'GetWallets'; method(withdrawals) -> 'GetWithdrawals'; method(deposits) -> 'GetDeposits'; -method(destinations) -> 'GetDestinations'; -method(identities) -> 'GetIdentities'; -method(deposit_reverts) -> 'GetDepositReverts'; -method(deposit_adjustments) -> 'GetDepositAdjustments'. +method(destinations) -> 'GetDestinations'. create_dsl(StatTag, Req) -> Query = create_query(StatTag, Req), @@ -79,9 +51,8 @@ create_dsl(StatTag, Req) -> create_query(withdrawals, Req) -> #{ - <<"party_id">> => maps:get('partyID', Req), <<"wallet_id">> => genlib_map:get('walletID', Req), - <<"identity_id">> => genlib_map:get('identityID', Req), + <<"party_id">> => genlib_map:get('partyID', Req), <<"withdrawal_id">> => genlib_map:get('withdrawalID', Req), <<"destination_id">> => genlib_map:get('destinationID', Req), <<"external_id">> => genlib_map:get('externalID', Req), @@ -94,9 +65,8 @@ create_query(withdrawals, Req) -> }; create_query(deposits, Req) -> #{ - <<"party_id">> => maps:get('partyID', Req), <<"wallet_id">> => genlib_map:get('walletID', Req), - <<"identity_id">> => genlib_map:get('identityID', Req), + <<"party_id">> => genlib_map:get('partyID', Req), <<"deposit_id">> => genlib_map:get('depositID', Req), <<"source_id">> => genlib_map:get('sourceID', Req), <<"status">> => genlib_map:get(status, Req), @@ -107,56 +77,10 @@ create_query(deposits, Req) -> <<"currency_code">> => genlib_map:get('currencyID', Req), <<"revert_status">> => genlib_map:get('revertStatus', Req) }; -create_query(wallets, Req) -> - #{ - <<"party_id">> => maps:get('partyID', Req), - <<"identity_id">> => genlib_map:get('identityID', Req), - <<"currency_code">> => genlib_map:get('currencyID', Req) - }; create_query(destinations, Req) -> #{ - <<"party_id">> => maps:get('partyID', Req), - <<"identity_id">> => genlib_map:get('identityID', Req), + <<"party_id">> => genlib_map:get('partyID', Req), <<"currency_code">> => genlib_map:get('currencyID', Req) - }; -create_query(identities, Req) -> - #{ - <<"party_id">> => maps:get('partyID', Req), - <<"provider_id">> => genlib_map:get('providerID', Req), - <<"class">> => genlib_map:get(class, Req), - <<"level">> => genlib_map:get(level, Req) - }; -create_query(deposit_reverts, Req) -> - #{ - <<"party_id">> => maps:get('partyID', Req), - <<"identity_id">> => genlib_map:get('identityID', Req), - <<"source_id">> => genlib_map:get('sourceID', Req), - <<"wallet_id">> => genlib_map:get('walletID', Req), - <<"deposit_id">> => genlib_map:get('depositID', Req), - <<"revert_id">> => genlib_map:get('revertID', Req), - <<"amount_from">> => genlib_map:get('amountFrom', Req), - <<"amount_to">> => genlib_map:get('amountTo', Req), - <<"currency_code">> => genlib_map:get('currencyID', Req), - <<"status">> => genlib_map:get(status, Req), - <<"deposit_status">> => genlib_map:get('depositStatus', Req), - <<"from_time">> => get_time('createdAtFrom', Req), - <<"to_time">> => get_time('createdAtTo', Req) - }; -create_query(deposit_adjustments, Req) -> - #{ - <<"party_id">> => maps:get('partyID', Req), - <<"identity_id">> => genlib_map:get('identityID', Req), - <<"source_id">> => genlib_map:get('sourceID', Req), - <<"wallet_id">> => genlib_map:get('walletID', Req), - <<"deposit_id">> => genlib_map:get('depositID', Req), - <<"adjustment_id">> => genlib_map:get('adjustmentID', Req), - <<"amount_from">> => genlib_map:get('amountFrom', Req), - <<"amount_to">> => genlib_map:get('amountTo', Req), - <<"currency_code">> => genlib_map:get('currencyID', Req), - <<"status">> => genlib_map:get(status, Req), - <<"deposit_status">> => genlib_map:get('depositStatus', Req), - <<"from_time">> => get_time('createdAtFrom', Req), - <<"to_time">> => get_time('createdAtTo', Req) }. create_request(Dsl, Token) -> @@ -200,17 +124,14 @@ format_request_errors(Errors) -> genlib_string:join(<<"\n">>, Errors). -spec unmarshal_response (withdrawals, fistful_stat_thrift:'StatWithdrawal'()) -> map(); (deposits, fistful_stat_thrift:'StatDeposit'()) -> map(); - (wallets, fistful_stat_thrift:'StatWallet'()) -> map(); - (destinations, fistful_stat_thrift:'StatDestination'()) -> map(); - (identities, fistful_stat_thrift:'StatIdentity'()) -> map(); - (deposit_reverts, fistful_stat_thrift:'StatDepositRevert'()) -> map(); - (deposit_adjustments, fistful_stat_thrift:'StatDepositAdjustment'()) -> map(). + (destinations, fistful_stat_thrift:'StatDestination'()) -> map(). unmarshal_response(withdrawals, Response) -> merge_and_compact( #{ <<"id">> => Response#stat_StatWithdrawal.id, <<"createdAt">> => Response#stat_StatWithdrawal.created_at, <<"wallet">> => Response#stat_StatWithdrawal.source_id, + <<"party">> => Response#stat_StatWithdrawal.party_id, <<"destination">> => Response#stat_StatWithdrawal.destination_id, <<"externalID">> => Response#stat_StatWithdrawal.external_id, <<"body">> => unmarshal_cash( @@ -230,6 +151,7 @@ unmarshal_response(deposits, Response) -> <<"id">> => Response#stat_StatDeposit.id, <<"createdAt">> => Response#stat_StatDeposit.created_at, <<"wallet">> => Response#stat_StatDeposit.destination_id, + <<"party">> => Response#stat_StatDeposit.party_id, <<"source">> => Response#stat_StatDeposit.source_id, <<"body">> => unmarshal_cash( Response#stat_StatDeposit.amount, @@ -239,120 +161,32 @@ unmarshal_response(deposits, Response) -> Response#stat_StatDeposit.fee, Response#stat_StatDeposit.currency_symbolic_code ), - <<"revertStatus">> => unmarshal_revert_status(Response#stat_StatDeposit.revert_status), <<"desc">> => Response#stat_StatDeposit.description }, unmarshal_deposit_stat_status(Response#stat_StatDeposit.status) ); -unmarshal_response(wallets, Response) -> - genlib_map:compact(#{ - <<"id">> => Response#stat_StatWallet.id, - <<"name">> => Response#stat_StatWallet.name, - <<"identity">> => Response#stat_StatWallet.identity_id, - <<"createdAt">> => Response#stat_StatWallet.created_at, - <<"currency">> => Response#stat_StatWallet.currency_symbolic_code - }); unmarshal_response(destinations, Response) -> genlib_map:compact(#{ <<"id">> => Response#stat_StatDestination.id, <<"name">> => Response#stat_StatDestination.name, <<"createdAt">> => Response#stat_StatDestination.created_at, <<"isBlocked">> => Response#stat_StatDestination.is_blocked, - <<"identity">> => Response#stat_StatDestination.identity, + <<"realm">> => unmarshal_realm(Response#stat_StatDestination.realm), + <<"party">> => Response#stat_StatDestination.party_id, <<"currency">> => Response#stat_StatDestination.currency_symbolic_code, <<"resource">> => unmarshal_resource(Response#stat_StatDestination.resource), - <<"status">> => unmarshal_destination_stat_status(Response#stat_StatDestination.status), <<"externalID">> => Response#stat_StatDestination.external_id - }); -unmarshal_response(identities, Response) -> - genlib_map:compact(#{ - <<"id">> => Response#stat_StatIdentity.id, - <<"name">> => Response#stat_StatIdentity.name, - <<"createdAt">> => Response#stat_StatIdentity.created_at, - <<"provider">> => Response#stat_StatIdentity.provider, - <<"isBlocked">> => Response#stat_StatIdentity.is_blocked, - <<"externalID">> => Response#stat_StatIdentity.external_id - }); -unmarshal_response(deposit_reverts, Response) -> - merge_and_compact( - #{ - <<"id">> => Response#stat_StatDepositRevert.id, - <<"depositId">> => Response#stat_StatDepositRevert.deposit_id, - <<"wallet">> => Response#stat_StatDepositRevert.wallet_id, - <<"source">> => Response#stat_StatDepositRevert.source_id, - <<"body">> => unmarshal_cash(Response#stat_StatDepositRevert.body), - <<"createdAt">> => Response#stat_StatDepositRevert.created_at, - <<"reason">> => Response#stat_StatDepositRevert.reason, - <<"externalId">> => Response#stat_StatDepositRevert.external_id - }, - unmarshal_status(Response#stat_StatDepositRevert.status) - ); -unmarshal_response(deposit_adjustments, Response) -> - merge_and_compact( - #{ - <<"id">> => Response#stat_StatDepositAdjustment.id, - <<"depositId">> => Response#stat_StatDepositAdjustment.deposit_id, - <<"changesPlan">> => unmarshal_changes_plan(Response#stat_StatDepositAdjustment.changes_plan), - <<"createdAt">> => Response#stat_StatDepositAdjustment.created_at, - <<"externalId">> => Response#stat_StatDepositAdjustment.external_id - }, - unmarshal_status(Response#stat_StatDepositAdjustment.status) - ). - -unmarshal_status({pending, _}) -> - #{<<"status">> => <<"Pending">>}; -unmarshal_status({succeeded, _}) -> - #{<<"status">> => <<"Succeeded">>}; -unmarshal_status({failed, _}) -> - #{ - <<"status">> => <<"Failed">>, - <<"failure">> => #{<<"code">> => <<"failed">>} - }. - -unmarshal_revert_status(undefined) -> - undefined; -unmarshal_revert_status(none) -> - <<"None"/utf8>>; -unmarshal_revert_status(partial) -> - <<"Partial"/utf8>>; -unmarshal_revert_status(full) -> - <<"Full"/utf8>>. - -unmarshal_changes_plan(#stat_DepositAdjustmentChangesPlan{new_cash = Cash, new_status = Status}) -> - maps:merge(#{<<"cash">> => unmarshal_cash_change_plan(Cash)}, unmarshal_status_change_plan(Status)). - -unmarshal_cash_change_plan(undefined) -> - #{}; -unmarshal_cash_change_plan(#stat_DepositAdjustmentCashChangePlan{ - amount = Amount, - fee = Fee, - provider_fee = ProviderFee -}) -> - #{ - <<"amount">> => unmarshal_cash(Amount), - <<"fee">> => unmarshal_cash(Fee), - <<"providerFee">> => unmarshal_cash(ProviderFee) - }. - -unmarshal_status_change_plan(undefined) -> - #{}; -unmarshal_status_change_plan(#stat_DepositAdjustmentStatusChangePlan{new_status = Status}) -> - unmarshal_status(Status). + }). -unmarshal_destination_stat_status(undefined) -> - undefined; -unmarshal_destination_stat_status({unauthorized, _}) -> - <<"Unauthorized">>; -unmarshal_destination_stat_status({authorized, _}) -> - <<"Authorized">>. +unmarshal_realm(test) -> + <<"Test">>; +unmarshal_realm(live) -> + <<"Live">>. unmarshal_cash(Amount, Currency) when is_bitstring(Currency) -> #{<<"amount">> => Amount, <<"currency">> => Currency}. -unmarshal_cash(#'fistful_base_Cash'{amount = Amount, currency = Currency}) -> - unmarshal_cash(Amount, Currency#'fistful_base_CurrencyRef'.symbolic_code). - -unmarshal_withdrawal_stat_status({failed, #stat_WithdrawalFailed{base_failure = BaseFailure}}) -> +unmarshal_withdrawal_stat_status({failed, #stat_WithdrawalFailed{failure = BaseFailure}}) -> wapi_codec:convert(withdrawal_status, {failed, BaseFailure}); unmarshal_withdrawal_stat_status(Status) -> wapi_codec:convert(withdrawal_status, Status). diff --git a/src/wapi_time.erl b/src/wapi_time.erl index 5ff8f239..443ff270 100644 --- a/src/wapi_time.erl +++ b/src/wapi_time.erl @@ -3,6 +3,7 @@ -module(wapi_time). +-export([rfc3339/0]). -export([now/0]). -export([to_rfc3339/1]). -export([from_rfc3339/1]). @@ -23,6 +24,10 @@ %% API +-spec rfc3339() -> binary(). +rfc3339() -> + to_rfc3339(erlang:system_time(millisecond)). + -spec now() -> timestamp_ms(). now() -> erlang:system_time(millisecond). diff --git a/src/wapi_w2w_transfer_backend.erl b/src/wapi_w2w_transfer_backend.erl deleted file mode 100644 index 71c0c0da..00000000 --- a/src/wapi_w2w_transfer_backend.erl +++ /dev/null @@ -1,184 +0,0 @@ --module(wapi_w2w_transfer_backend). - --type request_data() :: wapi_wallet_handler:request_data(). --type handler_context() :: wapi_handler_utils:handler_context(). --type response_data() :: wapi_handler_utils:response_data(). - --type id() :: binary(). --type external_id() :: id(). - --export([create/2]). --export([get/2]). - --include_lib("fistful_proto/include/fistful_fistful_base_thrift.hrl"). --include_lib("fistful_proto/include/fistful_fistful_thrift.hrl"). --include_lib("fistful_proto/include/fistful_w2w_transfer_thrift.hrl"). --include_lib("fistful_proto/include/fistful_w2w_status_thrift.hrl"). - --spec create(request_data(), handler_context()) -> {ok, response_data()} | {error, CreateError} when - CreateError :: - {external_id_conflict, external_id()} - | {wallet_from | wallet_to, notfound | inaccessible} - | bad_w2w_transfer_amount - | not_allowed_currency - | inconsistent_currency. -create(Params, HandlerContext) -> - case wapi_backend_utils:gen_id(w2w_transfer, Params, HandlerContext) of - {ok, ID} -> - case is_id_unknown(ID, Params, HandlerContext) of - true -> - Context = wapi_backend_utils:make_ctx(Params), - create(ID, Params, Context, HandlerContext); - false -> - create(Params, HandlerContext) - end; - {error, {external_id_conflict, _}} = Error -> - Error - end. - -is_id_unknown( - ID, - #{ - <<"sender">> := SenderID, - <<"receiver">> := ReceiverID, - <<"body">> := Body - }, - HandlerContext -) -> - case get(ID, HandlerContext) of - {error, {w2w_transfer, {unknown_w2w_transfer, ID}}} -> - true; - {ok, - #{ - <<"id">> := ID, - <<"sender">> := SenderID, - <<"receiver">> := ReceiverID, - <<"body">> := Body - }, - _Owner} -> - true; - {ok, _NonMatchingIdentity, _Owner} -> - false - end. - -create(ID, Params, Context, HandlerContext) -> - TransferParams = marshal(transfer_params, Params#{<<"id">> => ID}), - Request = {fistful_w2w_transfer, 'Create', {TransferParams, marshal(context, Context)}}, - case service_call(Request, HandlerContext) of - {ok, Transfer} -> - {ok, unmarshal(transfer, Transfer)}; - {exception, #fistful_WalletNotFound{id = ID}} -> - {error, wallet_not_found_error(unmarshal(id, ID), Params)}; - {exception, #fistful_WalletInaccessible{id = ID}} -> - {error, wallet_inaccessible_error(unmarshal(id, ID), Params)}; - {exception, #fistful_ForbiddenOperationCurrency{}} -> - {error, not_allowed_currency}; - {exception, #w2w_transfer_InconsistentW2WTransferCurrency{}} -> - {error, inconsistent_currency}; - {exception, #fistful_InvalidOperationAmount{}} -> - {error, bad_w2w_transfer_amount} - end. - --spec get(id(), handler_context()) -> {ok, response_data(), id()} | {error, GetError} when - GetError :: {w2w_transfer, {unknown_w2w_transfer, id()}}. -get(ID, HandlerContext) -> - EventRange = #'fistful_base_EventRange'{}, - Request = {fistful_w2w_transfer, 'Get', {ID, EventRange}}, - case service_call(Request, HandlerContext) of - {ok, TransferThrift} -> - {ok, Owner} = wapi_backend_utils:get_entity_owner(w2w_transfer, TransferThrift), - {ok, unmarshal(transfer, TransferThrift), Owner}; - {exception, #fistful_W2WNotFound{}} -> - {error, {w2w_transfer, {unknown_w2w_transfer, ID}}} - end. - -%% -%% Internal -%% - -service_call(Params, Ctx) -> - wapi_handler_utils:service_call(Params, Ctx). - -wallet_not_found_error(WalletID, #{<<"sender">> := WalletID}) -> - {wallet_from, notfound}; -wallet_not_found_error(WalletID, #{<<"receiver">> := WalletID}) -> - {wallet_to, notfound}. - -wallet_inaccessible_error(WalletID, #{<<"sender">> := WalletID}) -> - {wallet_from, inaccessible}; -wallet_inaccessible_error(WalletID, #{<<"receiver">> := WalletID}) -> - {wallet_to, inaccessible}. - -%% Marshaling - -marshal( - transfer_params, - #{ - <<"id">> := ID, - <<"sender">> := SenderID, - <<"receiver">> := ReceiverID, - <<"body">> := Body - } = Params -) -> - #w2w_transfer_W2WTransferParams{ - id = marshal(id, ID), - wallet_from_id = marshal(id, SenderID), - wallet_to_id = marshal(id, ReceiverID), - body = marshal(body, Body), - external_id = maps:get(<<"externalId">>, Params, undefined) - }; -marshal(body, #{ - <<"amount">> := Amount, - <<"currency">> := Currency -}) -> - #'fistful_base_Cash'{ - amount = marshal(amount, Amount), - currency = marshal(currency_ref, Currency) - }; -marshal(context, Ctx) -> - wapi_codec:marshal(context, Ctx); -marshal(T, V) -> - wapi_codec:marshal(T, V). - -unmarshal(transfer, #w2w_transfer_W2WTransferState{ - id = ID, - wallet_from_id = SenderID, - wallet_to_id = ReceiverID, - body = Body, - created_at = CreatedAt, - status = Status, - external_id = ExternalID -}) -> - genlib_map:compact(#{ - <<"id">> => unmarshal(id, ID), - <<"createdAt">> => CreatedAt, - <<"body">> => unmarshal(body, Body), - <<"sender">> => unmarshal(id, SenderID), - <<"receiver">> => unmarshal(id, ReceiverID), - <<"status">> => unmarshal(transfer_status, Status), - <<"externalID">> => maybe_unmarshal(id, ExternalID) - }); -unmarshal(body, #'fistful_base_Cash'{ - amount = Amount, - currency = Currency -}) -> - #{ - <<"amount">> => unmarshal(amount, Amount), - <<"currency">> => unmarshal(currency_ref, Currency) - }; -unmarshal(transfer_status, {pending, _}) -> - #{<<"status">> => <<"Pending">>}; -unmarshal(transfer_status, {succeeded, _}) -> - #{<<"status">> => <<"Succeeded">>}; -unmarshal(transfer_status, {failed, #w2w_status_Failed{failure = Failure}}) -> - #{ - <<"status">> => <<"Failed">>, - <<"failure">> => unmarshal(failure, Failure) - }; -unmarshal(T, V) -> - wapi_codec:unmarshal(T, V). - -maybe_unmarshal(_T, undefined) -> - undefined; -maybe_unmarshal(T, V) -> - unmarshal(T, V). diff --git a/src/wapi_wallet_backend.erl b/src/wapi_wallet_backend.erl deleted file mode 100644 index 3b319c64..00000000 --- a/src/wapi_wallet_backend.erl +++ /dev/null @@ -1,210 +0,0 @@ --module(wapi_wallet_backend). - --type request_data() :: wapi_wallet_handler:request_data(). --type handler_context() :: wapi_handler_utils:handler_context(). --type response_data() :: wapi_handler_utils:response_data(). --type id() :: binary(). --type external_id() :: binary(). - --export([create/2]). --export([get/2]). --export([get_by_external_id/2]). --export([get_account/2]). - --include_lib("fistful_proto/include/fistful_fistful_base_thrift.hrl"). --include_lib("fistful_proto/include/fistful_fistful_thrift.hrl"). --include_lib("fistful_proto/include/fistful_account_thrift.hrl"). --include_lib("fistful_proto/include/fistful_wallet_thrift.hrl"). - -%% Pipeline - --spec create(request_data(), handler_context()) -> {ok, response_data()} | {error, WalletError} when - WalletError :: - {identity, notfound} - | {currency, notfound} - | inaccessible - | {external_id_conflict, id()}. -create(Params, HandlerContext) -> - case wapi_backend_utils:gen_id(wallet, Params, HandlerContext) of - {ok, ID} -> - case is_id_unknown(ID, Params, HandlerContext) of - true -> - Context = wapi_backend_utils:make_ctx(Params), - create(ID, Params, Context, HandlerContext); - false -> - create(Params, HandlerContext) - end; - {error, {external_id_conflict, _}} = Error -> - Error - end. - -is_id_unknown( - ID, - #{ - <<"name">> := Name, - <<"identity">> := IdentityID, - <<"currency">> := CurrencyID - }, - HandlerContext -) -> - case get(ID, HandlerContext) of - {error, {wallet, notfound}} -> - true; - {ok, - #{ - <<"id">> := ID, - <<"name">> := Name, - <<"identity">> := IdentityID, - <<"currency">> := CurrencyID - }, - _Owner} -> - true; - {ok, _NonMatchingIdentity, _Owner} -> - false - end. - -create(WalletID, Params, Context, HandlerContext) -> - WalletParams = marshal(wallet_params, Params#{<<"id">> => WalletID}), - Request = {fistful_wallet, 'Create', {WalletParams, marshal(context, Context)}}, - case service_call(Request, HandlerContext) of - {ok, Wallet} -> - {ok, unmarshal(wallet, Wallet)}; - {exception, #fistful_IdentityNotFound{}} -> - {error, {identity, notfound}}; - {exception, #fistful_CurrencyNotFound{}} -> - {error, {currency, notfound}}; - {exception, #fistful_PartyInaccessible{}} -> - {error, inaccessible}; - {exception, Details} -> - {error, Details} - end. - --spec get_by_external_id(external_id(), handler_context()) -> - {ok, response_data(), id()} - | {error, {wallet, notfound}} - | {error, {external_id, {unknown_external_id, external_id()}}}. -get_by_external_id(ExternalID, #{woody_context := WoodyContext} = HandlerContext) -> - PartyID = wapi_handler_utils:get_owner(HandlerContext), - IdempotentKey = wapi_backend_utils:get_idempotent_key(wallet, PartyID, ExternalID), - case bender_client:get_internal_id(IdempotentKey, WoodyContext) of - {ok, WalletID, _} -> - get(WalletID, HandlerContext); - {error, internal_id_not_found} -> - {error, {external_id, {unknown_external_id, ExternalID}}} - end. - --spec get(id(), handler_context()) -> - {ok, response_data(), id()} - | {error, {wallet, notfound}}. -get(WalletID, HandlerContext) -> - Request = {fistful_wallet, 'Get', {WalletID, #'fistful_base_EventRange'{}}}, - case service_call(Request, HandlerContext) of - {ok, WalletThrift} -> - {ok, Owner} = wapi_backend_utils:get_entity_owner(wallet, WalletThrift), - {ok, unmarshal(wallet, WalletThrift), Owner}; - {exception, #fistful_WalletNotFound{}} -> - {error, {wallet, notfound}} - end. - --spec get_account(id(), handler_context()) -> - {ok, response_data()} - | {error, {wallet, notfound}}. -get_account(WalletID, HandlerContext) -> - Request = {fistful_wallet, 'GetAccountBalance', {WalletID}}, - case service_call(Request, HandlerContext) of - {ok, AccountBalanceThrift} -> - {ok, unmarshal(wallet_account_balance, AccountBalanceThrift)}; - {exception, #fistful_WalletNotFound{}} -> - {error, {wallet, notfound}} - end. - -%% -%% Internal -%% - -service_call(Params, Ctx) -> - wapi_handler_utils:service_call(Params, Ctx). - -%% Marshaling - -marshal( - wallet_params, - #{ - <<"id">> := ID, - <<"name">> := Name, - <<"identity">> := IdentityID, - <<"currency">> := CurrencyID - } = Params -) -> - ExternalID = maps:get(<<"externalID">>, Params, undefined), - #wallet_WalletParams{ - id = marshal(id, ID), - name = marshal(string, Name), - account_params = marshal(account_params, {IdentityID, CurrencyID}), - external_id = marshal(id, ExternalID) - }; -marshal(account_params, {IdentityID, CurrencyID}) -> - #account_AccountParams{ - identity_id = marshal(id, IdentityID), - symbolic_code = marshal(string, CurrencyID) - }; -marshal(context, Ctx) -> - wapi_codec:marshal(context, Ctx); -marshal(T, V) -> - wapi_codec:marshal(T, V). - -%% - -unmarshal(wallet, #wallet_WalletState{ - id = WalletID, - name = Name, - blocking = Blocking, - account = Account, - external_id = ExternalID, - created_at = CreatedAt, - context = Ctx -}) -> - #{ - identity := Identity, - currency := Currency - } = unmarshal(account, Account), - Context = unmarshal(context, Ctx), - genlib_map:compact(#{ - <<"id">> => unmarshal(id, WalletID), - <<"name">> => unmarshal(string, Name), - <<"isBlocked">> => unmarshal(blocking, Blocking), - <<"identity">> => Identity, - <<"currency">> => Currency, - <<"createdAt">> => CreatedAt, - <<"externalID">> => maybe_unmarshal(id, ExternalID), - <<"metadata">> => wapi_backend_utils:get_from_ctx(<<"metadata">>, Context) - }); -unmarshal(blocking, unblocked) -> - false; -unmarshal(blocking, blocked) -> - true; -unmarshal(wallet_account_balance, #account_AccountBalance{ - current = OwnAmount, - expected_min = AvailableAmount, - currency = Currency -}) -> - EncodedCurrency = unmarshal(currency_ref, Currency), - #{ - <<"own">> => #{ - <<"amount">> => OwnAmount, - <<"currency">> => EncodedCurrency - }, - <<"available">> => #{ - <<"amount">> => AvailableAmount, - <<"currency">> => EncodedCurrency - } - }; -unmarshal(context, Ctx) -> - wapi_codec:unmarshal(context, Ctx); -unmarshal(T, V) -> - wapi_codec:unmarshal(T, V). - -maybe_unmarshal(_, undefined) -> - undefined; -maybe_unmarshal(T, V) -> - unmarshal(T, V). diff --git a/src/wapi_wallet_handler.erl b/src/wapi_wallet_handler.erl index c57d733c..d8a52195 100644 --- a/src/wapi_wallet_handler.erl +++ b/src/wapi_wallet_handler.erl @@ -71,230 +71,7 @@ mask_notfound(Resolution) -> %% Providers -spec prepare(operation_id(), request_data(), handler_context(), handler_opts()) -> {ok, request_state()}. -prepare('ListProviders' = OperationID, #{'residence' := Residence}, Context, _Opts) -> - Authorize = fun() -> - Prototypes = [{operation, #{id => OperationID}}], - Resolution = wapi_auth:authorize_operation(Prototypes, Context), - {ok, Resolution} - end, - Process = fun() -> - Providers = wapi_provider_backend:get_providers(maybe_to_list(Residence), Context), - wapi_handler_utils:reply_ok(200, Providers) - end, - {ok, #{authorize => Authorize, process => Process}}; -prepare('GetProvider' = OperationID, #{'providerID' := ID}, Context, _Opts) -> - Authorize = fun() -> - Prototypes = [{operation, #{id => OperationID}}], - Resolution = wapi_auth:authorize_operation(Prototypes, Context), - {ok, Resolution} - end, - Process = fun() -> - case wapi_provider_backend:get_provider(ID, Context) of - {ok, Provider} -> wapi_handler_utils:reply_ok(200, Provider); - {error, notfound} -> wapi_handler_utils:reply_ok(404) - end - end, - {ok, #{authorize => Authorize, process => Process}}; -%% Identities -prepare('ListIdentities' = OperationID, Req0, Context, _Opts) -> - {Req, PartyID} = patch_party_req(Context, Req0), - Authorize = fun() -> - Prototypes = [{operation, #{party => PartyID, id => OperationID}}], - Resolution = wapi_auth:authorize_operation(Prototypes, Context), - {ok, Resolution} - end, - Process = fun() -> - case wapi_stat_backend:list_identities(Req, Context) of - {ok, List} -> - wapi_handler_utils:reply_ok(200, List); - {error, {invalid, Errors}} -> - wapi_handler_utils:reply_ok(400, #{ - <<"errorType">> => <<"NoMatch">>, - <<"description">> => Errors - }); - {error, {bad_token, Reason}} -> - wapi_handler_utils:reply_ok(400, #{ - <<"errorType">> => <<"InvalidToken">>, - <<"description">> => Reason - }) - end - end, - {ok, #{authorize => Authorize, process => Process}}; -prepare('GetWithdrawalMethods' = OperationID, #{'identityID' := IdentityID}, Context, _Opts) -> - {ResultIdentity, ResultOwner} = - case wapi_identity_backend:get(IdentityID, Context) of - {ok, Identity, Owner} -> {Identity, Owner}; - {error, {identity, notfound}} -> {undefined, undefined} - end, - Authorize = fun() -> - Prototypes = [ - {operation, #{identity => IdentityID, id => OperationID}}, - {wallet, [wapi_bouncer_context:build_wallet_entity(identity, ResultIdentity, {party, ResultOwner})]} - ], - Resolution = mask_notfound(wapi_auth:authorize_operation(Prototypes, Context)), - {ok, Resolution} - end, - Process = fun() -> - case wapi_identity_backend:get_identity_withdrawal_methods(IdentityID, Context) of - {ok, WithdrawalMethods} -> - wapi_handler_utils:reply_ok(200, WithdrawalMethods); - {error, {identity, notfound}} -> - wapi_handler_utils:reply_ok(422, wapi_handler_utils:get_error_msg(<<"No such identity">>)) - end - end, - {ok, #{authorize => Authorize, process => Process}}; -prepare('GetIdentity' = OperationID, #{'identityID' := IdentityID}, Context, _Opts) -> - {ResultIdentity, ResultOwner} = - case wapi_identity_backend:get(IdentityID, Context) of - {ok, Identity, Owner} -> {Identity, Owner}; - {error, {identity, notfound}} -> {undefined, undefined} - end, - Authorize = fun() -> - Prototypes = [ - {operation, #{identity => IdentityID, id => OperationID}}, - {wallet, [wapi_bouncer_context:build_wallet_entity(identity, ResultIdentity, {party, ResultOwner})]} - ], - Resolution = mask_notfound(wapi_auth:authorize_operation(Prototypes, Context)), - {ok, Resolution} - end, - Process = fun() -> - wapi_handler_utils:reply_ok(200, ResultIdentity) - end, - {ok, #{authorize => Authorize, process => Process}}; -prepare('CreateIdentity' = OperationID, #{'Identity' := Params}, Context, Opts) -> - PartyID = - case maps:get(<<"partyID">>, Params, undefined) of - undefined -> - wapi_handler_utils:get_owner(Context); - OwnerID -> - OwnerID - end, - Authorize = fun() -> - Prototypes = [ - { - operation, - #{party => PartyID, id => OperationID} - } - ], - Resolution = wapi_auth:authorize_operation(Prototypes, Context), - {ok, Resolution} - end, - Process = fun() -> - case wapi_identity_backend:create(Params#{<<"partyID">> => PartyID}, Context) of - {ok, Identity = #{<<"id">> := IdentityID}} -> - wapi_handler_utils:reply_ok(201, Identity, get_location('GetIdentity', [IdentityID], Context, Opts)); - {error, {inaccessible, _}} -> - wapi_handler_utils:reply_ok(422, wapi_handler_utils:get_error_msg(<<"Party inaccessible">>)); - {error, {party, notfound}} -> - wapi_handler_utils:reply_ok(422, wapi_handler_utils:get_error_msg(<<"Party does not exist">>)); - {error, {provider, notfound}} -> - wapi_handler_utils:reply_ok(422, wapi_handler_utils:get_error_msg(<<"No such provider">>)); - {error, inaccessible} -> - wapi_handler_utils:reply_ok(422, wapi_handler_utils:get_error_msg(<<"Identity inaccessible">>)); - {error, {external_id_conflict, ID}} -> - wapi_handler_utils:reply_ok(409, #{<<"id">> => ID}) - end - end, - {ok, #{authorize => Authorize, process => Process}}; -%% Wallets -prepare('ListWallets' = OperationID, Req0, Context, _Opts) -> - AuthContext = build_auth_context( - [wapi_handler_utils:maybe_with('identityID', Req0, fun(IdentityID) -> {identity, IdentityID} end)], - [], - Context - ), - {Req, PartyID} = patch_party_req(Context, Req0), - Authorize = fun() -> - Prototypes = [ - {operation, build_prototype_for(operation, #{party => PartyID, id => OperationID}, AuthContext)}, - {wallet, build_prototype_for(wallet, [], AuthContext)} - ], - Resolution = wapi_auth:authorize_operation(Prototypes, Context), - {ok, Resolution} - end, - Process = fun() -> - case wapi_stat_backend:list_wallets(Req, Context) of - {ok, List} -> - wapi_handler_utils:reply_ok(200, List); - {error, {invalid, Errors}} -> - wapi_handler_utils:reply_ok(400, #{ - <<"errorType">> => <<"NoMatch">>, - <<"description">> => Errors - }); - {error, {bad_token, Reason}} -> - wapi_handler_utils:reply_ok(400, #{ - <<"errorType">> => <<"InvalidToken">>, - <<"description">> => Reason - }) - end - end, - {ok, #{authorize => Authorize, process => Process}}; -prepare('GetWallet' = OperationID, #{'walletID' := WalletID}, Context, _Opts) -> - {ResultWallet, ResultWalletOwner} = - case wapi_wallet_backend:get(WalletID, Context) of - {ok, Wallet, Owner} -> {Wallet, Owner}; - {error, {wallet, notfound}} -> {undefined, undefined} - end, - Authorize = fun() -> - Prototypes = [ - {operation, #{wallet => WalletID, id => OperationID}}, - {wallet, [wapi_bouncer_context:build_wallet_entity(wallet, ResultWallet, {party, ResultWalletOwner})]} - ], - Resolution = mask_notfound(wapi_auth:authorize_operation(Prototypes, Context)), - {ok, Resolution} - end, - Process = fun() -> - wapi_handler_utils:reply_ok(200, ResultWallet) - end, - {ok, #{authorize => Authorize, process => Process}}; -prepare('GetWalletByExternalID' = OperationID, #{'externalID' := ExternalID}, Context, _Opts) -> - {ResultWallet, ResultWalletOwner, WalletID} = - case wapi_wallet_backend:get_by_external_id(ExternalID, Context) of - {ok, Wallet = #{<<"id">> := ID}, Owner} -> {Wallet, Owner, ID}; - {error, {wallet, notfound}} -> {undefined, undefined, undefined}; - {error, {external_id, {unknown_external_id, ExternalID}}} -> {undefined, undefined, undefined} - end, - Authorize = fun() -> - Prototypes = [ - { - operation, - #{wallet => WalletID, id => OperationID} - }, - {wallet, [wapi_bouncer_context:build_wallet_entity(wallet, ResultWallet, {party, ResultWalletOwner})]} - ], - Resolution = mask_notfound(wapi_auth:authorize_operation(Prototypes, Context)), - {ok, Resolution} - end, - Process = fun() -> - wapi_handler_utils:reply_ok(200, ResultWallet) - end, - {ok, #{authorize => Authorize, process => Process}}; -prepare('CreateWallet' = OperationID, #{'Wallet' := Params = #{<<"identity">> := IdentityID}}, Context, Opts) -> - AuthContext = [IdentityAuthContext] = build_auth_context([{identity, IdentityID}], [], Context), - PartyID = get_party_id_from_auth_context(IdentityAuthContext), - Authorize = fun() -> - Prototypes = [ - {operation, build_prototype_for(operation, #{id => OperationID}, AuthContext)}, - {wallet, build_prototype_for(wallet, [], AuthContext)} - ], - Resolution = wapi_auth:authorize_operation(Prototypes, Context), - {ok, Resolution} - end, - Process = fun() -> - case wapi_wallet_backend:create(add_party_id_to(PartyID, Params), Context) of - {ok, Wallet = #{<<"id">> := WalletID}} -> - wapi_handler_utils:reply_ok(201, Wallet, get_location('GetWallet', [WalletID], Context, Opts)); - {error, {identity, notfound}} -> - wapi_handler_utils:reply_ok(422, wapi_handler_utils:get_error_msg(<<"No such identity">>)); - {error, {currency, notfound}} -> - wapi_handler_utils:reply_ok(422, wapi_handler_utils:get_error_msg(<<"Currency not supported">>)); - {error, inaccessible} -> - wapi_handler_utils:reply_ok(422, wapi_handler_utils:get_error_msg(<<"Identity inaccessible">>)); - {error, {external_id_conflict, ID}} -> - wapi_handler_utils:reply_ok(409, #{<<"id">> => ID}) - end - end, - {ok, #{authorize => Authorize, process => Process}}; + prepare('GetWalletAccount' = OperationID, #{'walletID' := WalletID}, Context, _Opts) -> AuthContext = build_auth_context([{wallet, WalletID}], [], Context), Authorize = fun() -> @@ -306,50 +83,14 @@ prepare('GetWalletAccount' = OperationID, #{'walletID' := WalletID}, Context, _O {ok, Resolution} end, Process = fun() -> - case wapi_wallet_backend:get_account(WalletID, Context) of - {ok, WalletAccount} -> wapi_handler_utils:reply_ok(200, WalletAccount); - {error, {wallet, notfound}} -> wapi_handler_utils:reply_ok(404) - end - end, - {ok, #{authorize => Authorize, process => Process}}; -prepare( - 'IssueWalletGrant' = OperationID, - #{ - 'walletID' := WalletID, - 'WalletGrantRequest' := #{<<"validUntil">> := Expiration, <<"asset">> := Asset} - }, - Context, - _Opts -) -> - AuthContext = build_auth_context([{wallet, WalletID}], [], Context), - Authorize = fun() -> - Prototypes = [ - {operation, build_prototype_for(operation, #{id => OperationID}, AuthContext)}, - {wallet, build_prototype_for(wallet, [], AuthContext)} - ], - Resolution = wapi_auth:authorize_operation(Prototypes, Context), - {ok, Resolution} - end, - Process = fun() -> - case wapi_backend_utils:issue_grant_token({wallets, WalletID, Asset}, Expiration, Context) of - {ok, Token} -> - wapi_handler_utils:reply_ok(201, #{ - <<"token">> => Token, - <<"validUntil">> => Expiration, - <<"asset">> => Asset - }); - {error, expired} -> - wapi_handler_utils:reply_ok( - 422, - wapi_handler_utils:get_error_msg(<<"Invalid expiration: already expired">>) - ) - end + %% TODO: implement from new party service + wapi_handler_utils:reply_ok(404) end, {ok, #{authorize => Authorize, process => Process}}; %% Destinations prepare('ListDestinations' = OperationID, Req0, Context, _Opts) -> AuthContext = build_auth_context( - [wapi_handler_utils:maybe_with('identityID', Req0, fun(IdentityID) -> {identity, IdentityID} end)], + [wapi_handler_utils:maybe_with('partyID', Req0, fun(PartyID) -> {party, PartyID} end)], [], Context ), @@ -436,12 +177,11 @@ prepare('GetDestinationByExternalID' = OperationID, #{'externalID' := ExternalID {ok, #{authorize => Authorize, process => Process}}; prepare( 'CreateDestination' = OperationID, - #{'Destination' := Params = #{<<"identity">> := IdentityID}}, + #{'Destination' := Params = #{<<"party">> := PartyID}}, Context, Opts ) -> - AuthContext = [IdentityAuthContext] = build_auth_context([{identity, IdentityID}], [], Context), - PartyID = get_party_id_from_auth_context(IdentityAuthContext), + AuthContext = build_auth_context([{party, PartyID}], [], Context), Authorize = fun() -> Prototypes = [ {operation, build_prototype_for(operation, #{id => OperationID}, AuthContext)}, @@ -451,21 +191,17 @@ prepare( {ok, Resolution} end, Process = fun() -> - case wapi_destination_backend:create(add_party_id_to(PartyID, Params), Context) of + case wapi_destination_backend:create(Params, Context) of {ok, Destination = #{<<"id">> := DestinationID}} -> wapi_handler_utils:reply_ok( 201, Destination, get_location('GetDestination', [DestinationID], Context, Opts) ); - {error, {identity, notfound}} -> - wapi_handler_utils:reply_ok(422, wapi_handler_utils:get_error_msg(<<"No such identity">>)); + {error, {party, notfound}} -> + wapi_handler_utils:reply_ok(422, wapi_handler_utils:get_error_msg(<<"No such party">>)); {error, {currency, notfound}} -> wapi_handler_utils:reply_ok(422, wapi_handler_utils:get_error_msg(<<"Currency not supported">>)); {error, inaccessible} -> - wapi_handler_utils:reply_ok(422, wapi_handler_utils:get_error_msg(<<"Identity inaccessible">>)); - {error, forbidden_withdrawal_method} -> - wapi_handler_utils:reply_ok( - 422, wapi_handler_utils:get_error_msg(<<"Resource type not allowed">>) - ); + wapi_handler_utils:reply_ok(422, wapi_handler_utils:get_error_msg(<<"Party inaccessible">>)); {error, {external_id_conflict, {ID, ExternalID}}} -> wapi_handler_utils:logic_error(external_id_conflict, {ID, ExternalID}); {error, {invalid_resource_token, Type}} -> @@ -483,39 +219,6 @@ prepare( end end, {ok, #{authorize => Authorize, process => Process}}; -prepare( - 'IssueDestinationGrant' = OperationID, - #{ - 'destinationID' := DestinationID, - 'DestinationGrantRequest' := #{<<"validUntil">> := Expiration} - }, - Context, - _Opts -) -> - AuthContext = build_auth_context([{destination, DestinationID}], [], Context), - Authorize = fun() -> - Prototypes = [ - {operation, build_prototype_for(operation, #{id => OperationID}, AuthContext)}, - {wallet, build_prototype_for(wallet, [], AuthContext)} - ], - Resolution = wapi_auth:authorize_operation(Prototypes, Context), - {ok, Resolution} - end, - Process = fun() -> - case issue_grant_token({destinations, DestinationID}, Expiration, Context) of - {ok, Token} -> - wapi_handler_utils:reply_ok(201, #{ - <<"token">> => Token, - <<"validUntil">> => Expiration - }); - {error, expired} -> - wapi_handler_utils:reply_ok( - 422, - wapi_handler_utils:get_error_msg(<<"Invalid expiration: already expired">>) - ) - end - end, - {ok, #{authorize => Authorize, process => Process}}; %% Withdrawals prepare('CreateQuote' = OperationID, #{'WithdrawalQuoteParams' := Params}, Context, _Opts) -> AuthContext = build_auth_context( @@ -528,7 +231,6 @@ prepare('CreateQuote' = OperationID, #{'WithdrawalQuoteParams' := Params}, Conte [], Context ), - PartyID = find_party_id_for(wallet, AuthContext), Authorize = fun() -> Prototypes = [ {operation, build_prototype_for(operation, #{id => OperationID}, AuthContext)}, @@ -538,17 +240,13 @@ prepare('CreateQuote' = OperationID, #{'WithdrawalQuoteParams' := Params}, Conte {ok, Resolution} end, Process = fun() -> - case wapi_withdrawal_backend:create_quote(add_party_id_to(PartyID, Params), Context) of + case wapi_withdrawal_backend:create_quote(Params, Context) of {ok, Quote} -> wapi_handler_utils:reply_ok(202, Quote); {error, {destination, notfound}} -> wapi_handler_utils:reply_ok(422, wapi_handler_utils:get_error_msg(<<"No such destination">>)); - {error, {destination, unauthorized}} -> - wapi_handler_utils:reply_ok(422, wapi_handler_utils:get_error_msg(<<"Destination unauthorized">>)); - {error, {destination, forbidden_withdrawal_method}} -> - wapi_handler_utils:reply_ok( - 422, wapi_handler_utils:get_error_msg(<<"Destination uses resource no longer allowed">>) - ); + {error, {party, notfound}} -> + wapi_handler_utils:reply_ok(422, wapi_handler_utils:get_error_msg(<<"No such party">>)); {error, {wallet, notfound}} -> wapi_handler_utils:reply_ok(422, wapi_handler_utils:get_error_msg(<<"No such wallet">>)); {error, {forbidden_currency, _}} -> @@ -571,7 +269,7 @@ prepare('CreateQuote' = OperationID, #{'WithdrawalQuoteParams' := Params}, Conte 422, wapi_handler_utils:get_error_msg(<<"Invalid currency">>) ); - {error, {identity_providers_mismatch, _}} -> + {error, {realms_mismatch, _}} -> wapi_handler_utils:reply_ok( 422, wapi_handler_utils:get_error_msg( @@ -595,7 +293,6 @@ prepare('CreateWithdrawal' = OperationID, #{'WithdrawalParameters' := Params}, C [], Context ), - PartyID = find_party_id_for(wallet, AuthContext), Authorize = fun() -> Prototypes = [ {operation, build_prototype_for(operation, #{id => OperationID}, AuthContext)}, @@ -605,19 +302,15 @@ prepare('CreateWithdrawal' = OperationID, #{'WithdrawalParameters' := Params}, C {ok, Resolution} end, Process = fun() -> - case wapi_withdrawal_backend:create(add_party_id_to(PartyID, Params), Context) of + case wapi_withdrawal_backend:create(Params, Context) of {ok, Withdrawal = #{<<"id">> := WithdrawalID}} -> wapi_handler_utils:reply_ok( 202, Withdrawal, get_location('GetWithdrawal', [WithdrawalID], Context, Opts) ); {error, {destination, notfound}} -> wapi_handler_utils:reply_ok(422, wapi_handler_utils:get_error_msg(<<"No such destination">>)); - {error, {destination, unauthorized}} -> - wapi_handler_utils:reply_ok(422, wapi_handler_utils:get_error_msg(<<"Destination unauthorized">>)); - {error, {destination, forbidden_withdrawal_method}} -> - wapi_handler_utils:reply_ok( - 422, wapi_handler_utils:get_error_msg(<<"Destination uses resource no longer allowed">>) - ); + {error, {party, notfound}} -> + wapi_handler_utils:reply_ok(422, wapi_handler_utils:get_error_msg(<<"No such party">>)); {error, {external_id_conflict, ID}} -> ExternalID = maps:get(<<"externalID">>, Params, undefined), wapi_handler_utils:logic_error(external_id_conflict, {ID, ExternalID}); @@ -665,7 +358,7 @@ prepare('CreateWithdrawal' = OperationID, #{'WithdrawalParameters' := Params}, C 422, wapi_handler_utils:get_error_msg(<<"Invalid currency">>) ); - {error, {identity_providers_mismatch, _}} -> + {error, {realms_mismatch, _}} -> wapi_handler_utils:reply_ok( 422, wapi_handler_utils:get_error_msg( @@ -730,7 +423,7 @@ prepare('GetWithdrawalByExternalID' = OperationID, #{'externalID' := ExternalID} prepare('ListWithdrawals' = OperationID, Req0, Context, _Opts) -> AuthContext = build_auth_context( [ - wapi_handler_utils:maybe_with('identityID', Req0, fun(IdentityID) -> {identity, IdentityID} end), + wapi_handler_utils:maybe_with('partyID', Req0, fun(PartyID) -> {party, PartyID} end), wapi_handler_utils:maybe_with('walletID', Req0, fun(WalletID) -> {wallet, WalletID} end), wapi_handler_utils:maybe_with('withdrawalID', Req0, fun(WithdrawalID) -> {withdrawal, WithdrawalID} end), wapi_handler_utils:maybe_with('destinationID', Req0, fun(DestinationID) -> {destination, DestinationID} end) @@ -816,7 +509,7 @@ prepare( prepare('ListDeposits' = OperationID, Req0, Context, _Opts) -> AuthContext = build_auth_context( [ - wapi_handler_utils:maybe_with('identityID', Req0, fun(IdentityID) -> {identity, IdentityID} end), + wapi_handler_utils:maybe_with('partyID', Req0, fun(PartyID) -> {party, PartyID} end), wapi_handler_utils:maybe_with('walletID', Req0, fun(WalletID) -> {wallet, WalletID} end) ], [], @@ -848,172 +541,16 @@ prepare('ListDeposits' = OperationID, Req0, Context, _Opts) -> end end, {ok, #{authorize => Authorize, process => Process}}; -prepare('ListDepositReverts' = OperationID, Req0, Context, _Opts) -> - AuthContext = build_auth_context( - [ - wapi_handler_utils:maybe_with('identityID', Req0, fun(IdentityID) -> {identity, IdentityID} end), - wapi_handler_utils:maybe_with('walletID', Req0, fun(WalletID) -> {wallet, WalletID} end) - ], - [], - Context - ), - {Req, PartyID} = patch_party_req(Context, Req0), - Authorize = fun() -> - Prototypes = [ - {operation, build_prototype_for(operation, #{party => PartyID, id => OperationID}, AuthContext)}, - {wallet, build_prototype_for(wallet, [], AuthContext)} - ], - Resolution = wapi_auth:authorize_operation(Prototypes, Context), - {ok, Resolution} - end, - Process = fun() -> - case wapi_stat_backend:list_deposit_reverts(Req, Context) of - {ok, List} -> - wapi_handler_utils:reply_ok(200, List); - {error, {invalid, Errors}} -> - wapi_handler_utils:reply_ok(400, #{ - <<"errorType">> => <<"NoMatch">>, - <<"description">> => Errors - }); - {error, {bad_token, Reason}} -> - wapi_handler_utils:reply_ok(400, #{ - <<"errorType">> => <<"InvalidToken">>, - <<"description">> => Reason - }) - end - end, - {ok, #{authorize => Authorize, process => Process}}; -prepare('ListDepositAdjustments' = OperationID, Req0, Context, _Opts) -> - AuthContext = build_auth_context( - [ - wapi_handler_utils:maybe_with('identityID', Req0, fun(IdentityID) -> {identity, IdentityID} end), - wapi_handler_utils:maybe_with('walletID', Req0, fun(WalletID) -> {wallet, WalletID} end) - ], - [], - Context - ), - {Req, PartyID} = patch_party_req(Context, Req0), - Authorize = fun() -> - Prototypes = [ - {operation, build_prototype_for(operation, #{party => PartyID, id => OperationID}, AuthContext)}, - {wallet, build_prototype_for(wallet, [], AuthContext)} - ], - Resolution = wapi_auth:authorize_operation(Prototypes, Context), - {ok, Resolution} - end, - Process = fun() -> - case wapi_stat_backend:list_deposit_adjustments(Req, Context) of - {ok, List} -> - wapi_handler_utils:reply_ok(200, List); - {error, {invalid, Errors}} -> - wapi_handler_utils:reply_ok(400, #{ - <<"errorType">> => <<"NoMatch">>, - <<"description">> => Errors - }); - {error, {bad_token, Reason}} -> - wapi_handler_utils:reply_ok(400, #{ - <<"errorType">> => <<"InvalidToken">>, - <<"description">> => Reason - }) - end - end, - {ok, #{authorize => Authorize, process => Process}}; -%% W2W -prepare( - 'CreateW2WTransfer' = OperationID, - #{'W2WTransferParameters' := #{<<"sender">> := SenderID} = Params}, - Context, - _Opts -) -> - AuthContext = [WalletAuthContext] = build_auth_context([{wallet, SenderID}], [], Context), - PartyID = get_party_id_from_auth_context(WalletAuthContext), - Authorize = fun() -> - Prototypes = [ - {operation, build_prototype_for(operation, #{id => OperationID}, AuthContext)}, - {wallet, build_prototype_for(wallet, [], AuthContext)} - ], - Resolution = wapi_auth:authorize_operation(Prototypes, Context), - {ok, Resolution} - end, - Process = fun() -> - case wapi_w2w_transfer_backend:create(add_party_id_to(PartyID, Params), Context) of - {ok, W2WTransfer} -> - wapi_handler_utils:reply_ok(202, W2WTransfer); - {error, {wallet_from, notfound}} -> - wapi_handler_utils:reply_ok( - 422, - wapi_handler_utils:get_error_msg(<<"No such wallet sender">>) - ); - {error, {wallet_from, inaccessible}} -> - wapi_handler_utils:reply_ok( - 422, - wapi_handler_utils:get_error_msg(<<"Wallet inaccessible">>) - ); - {error, {wallet_to, notfound}} -> - wapi_handler_utils:reply_ok( - 422, - wapi_handler_utils:get_error_msg(<<"No such wallet receiver">>) - ); - {error, {wallet_to, inaccessible}} -> - wapi_handler_utils:reply_ok( - 422, - wapi_handler_utils:get_error_msg(<<"Wallet inaccessible">>) - ); - {error, not_allowed_currency} -> - wapi_handler_utils:reply_ok( - 422, - wapi_handler_utils:get_error_msg(<<"Currency not allowed">>) - ); - {error, bad_w2w_transfer_amount} -> - wapi_handler_utils:reply_ok( - 422, - wapi_handler_utils:get_error_msg(<<"Bad transfer amount">>) - ); - {error, inconsistent_currency} -> - wapi_handler_utils:reply_ok( - 422, - wapi_handler_utils:get_error_msg(<<"Inconsistent currency">>) - ) - end - end, - {ok, #{authorize => Authorize, process => Process}}; -prepare('GetW2WTransfer' = OperationID, #{'w2wTransferID' := W2WTransferId}, Context, _Opts) -> - {ResultW2WTransfer, ResultW2WTransferOwner} = - case wapi_w2w_transfer_backend:get(W2WTransferId, Context) of - {ok, W2WTransfer, Owner} -> {W2WTransfer, Owner}; - {error, {w2w_transfer, {unknown_w2w_transfer, _ID}}} -> {undefined, undefined} - end, - Authorize = fun() -> - Prototypes = [ - { - operation, - #{w2w_transfer => W2WTransferId, id => OperationID} - }, - {wallet, [ - wapi_bouncer_context:build_wallet_entity( - w2w_transfer, - ResultW2WTransfer, - {party, ResultW2WTransferOwner} - ) - ]} - ], - Resolution = mask_notfound(wapi_auth:authorize_operation(Prototypes, Context)), - {ok, Resolution} - end, - Process = fun() -> - wapi_handler_utils:reply_ok(200, ResultW2WTransfer) - end, - {ok, #{authorize => Authorize, process => Process}}; %% Webhooks prepare( 'CreateWebhook' = OperationID, - #{'Webhook' := #{<<"identityID">> := IdentityID, <<"scope">> := Scope}} = Req, + #{'Webhook' := #{<<"partyID">> := PartyID, <<"scope">> := Scope}} = Req, Context, _Opts ) -> AuthContext = build_auth_context( [ - {identity, IdentityID}, + {party, PartyID}, wapi_handler_utils:maybe_with(<<"walletID">>, Scope, fun(WalletID) -> {wallet, WalletID} end) ], [], @@ -1032,8 +569,8 @@ prepare( wapi_handler_utils:reply_ok(201, Webhook) end, {ok, #{authorize => Authorize, process => Process}}; -prepare('GetWebhooks' = OperationID, #{'identityID' := IdentityID}, Context, _Opts) -> - AuthContext = build_auth_context([{identity, IdentityID}], [], Context), +prepare('GetWebhooks' = OperationID, #{'partyID' := PartyID}, Context, _Opts) -> + AuthContext = build_auth_context([{party, PartyID}], [], Context), Authorize = fun() -> Prototypes = [ {operation, build_prototype_for(operation, #{id => OperationID}, AuthContext)}, @@ -1043,14 +580,14 @@ prepare('GetWebhooks' = OperationID, #{'identityID' := IdentityID}, Context, _Op {ok, Resolution} end, Process = fun() -> - {ok, Webhooks} = wapi_webhook_backend:get_webhooks(IdentityID, Context), + {ok, Webhooks} = wapi_webhook_backend:get_webhooks(PartyID, Context), wapi_handler_utils:reply_ok(200, Webhooks) end, {ok, #{authorize => Authorize, process => Process}}; -prepare('GetWebhookByID' = OperationID, #{'identityID' := IdentityID, 'webhookID' := WebhookID}, Context, _Opts) -> +prepare('GetWebhookByID' = OperationID, #{'partyID' := PartyID, 'webhookID' := WebhookID}, Context, _Opts) -> AuthContext = build_auth_context( [ - {identity, IdentityID}, + {party, PartyID}, {webhook, WebhookID} ], [], @@ -1075,13 +612,13 @@ prepare('GetWebhookByID' = OperationID, #{'identityID' := IdentityID, 'webhookID {ok, #{authorize => Authorize, process => Process}}; prepare( 'DeleteWebhookByID' = OperationID, - #{'identityID' := IdentityID, 'webhookID' := WebhookID}, + #{'partyID' := PartyID, 'webhookID' := WebhookID}, Context, _Opts ) -> AuthContext = build_auth_context( [ - {identity, IdentityID}, + {party, PartyID}, {webhook, WebhookID} ], [], @@ -1105,9 +642,8 @@ prepare( end, {ok, #{authorize => Authorize, process => Process}}; %% Reports -prepare('CreateReport' = OperationID, #{'identityID' := IdentityID} = Req0, Context, _Opts) -> - AuthContext = build_auth_context([{identity, IdentityID}], [], Context), - {Req, _PartyID} = patch_party_req(Context, Req0), +prepare('CreateReport' = OperationID, #{'partyID' := PartyID} = Req, Context, _Opts) -> + AuthContext = build_auth_context([{party, PartyID}], [], Context), Authorize = fun() -> Prototypes = [ {operation, build_prototype_for(operation, #{id => OperationID}, AuthContext)}, @@ -1120,23 +656,17 @@ prepare('CreateReport' = OperationID, #{'identityID' := IdentityID} = Req0, Cont case wapi_report_backend:create_report(Req, Context) of {ok, Report} -> wapi_handler_utils:reply_ok(201, Report); - {error, {identity, notfound}} -> - wapi_handler_utils:reply_ok(400, #{ - <<"errorType">> => <<"NotFound">>, - <<"name">> => <<"identity">>, - <<"description">> => <<"identity not found">> - }); {error, invalid_request} -> wapi_handler_utils:reply_ok(400, #{ <<"errorType">> => <<"NoMatch">>, <<"name">> => <<"timestamps">>, <<"description">> => <<"invalid time range">> }); - {error, invalid_contract} -> + {error, {party, notfound}} -> wapi_handler_utils:reply_ok(400, #{ <<"errorType">> => <<"NotFound">>, - <<"name">> => <<"contractID">>, - <<"description">> => <<"contract not found">> + <<"name">> => <<"partyID">>, + <<"description">> => <<"party not found">> }) end end, @@ -1144,30 +674,27 @@ prepare('CreateReport' = OperationID, #{'identityID' := IdentityID} = Req0, Cont prepare( 'GetReport' = OperationID, #{ - 'identityID' := IdentityID, - 'reportID' := ReportId - } = Req0, + 'partyID' := PartyID, + 'reportID' := ReportID + }, Context, _Opts ) -> - AuthContext = build_auth_context([{identity, IdentityID}], [], Context), - {_Req, PartyID} = patch_party_req(Context, Req0), + AuthContext = build_auth_context([{party, PartyID}], [], Context), ResultReport = - case wapi_report_backend:get_report(ReportId, IdentityID, PartyID, Context) of + case wapi_report_backend:get_report(ReportID, PartyID, Context) of {ok, Report} -> Report; - {error, {identity, notfound}} -> - undefined; {error, notfound} -> undefined end, Authorize = fun() -> Prototypes = [ - {operation, build_prototype_for(operation, #{report => ReportId, id => OperationID}, AuthContext)}, + {operation, build_prototype_for(operation, #{report => ReportID, id => OperationID}, AuthContext)}, {wallet, build_prototype_for( wallet, - [wapi_bouncer_context:build_wallet_entity(report, ResultReport, {identity, IdentityID})], + [wapi_bouncer_context:build_wallet_entity(report, ResultReport, {party, PartyID})], AuthContext )} ], @@ -1178,9 +705,8 @@ prepare( wapi_handler_utils:reply_ok(200, ResultReport) end, {ok, #{authorize => Authorize, process => Process}}; -prepare('GetReports' = OperationID, #{'identityID' := IdentityID} = Req0, Context, _Opts) -> - AuthContext = build_auth_context([{identity, IdentityID}], [], Context), - {Req, _PartyID} = patch_party_req(Context, Req0), +prepare('GetReports' = OperationID, #{'partyID' := PartyID} = Req, Context, _Opts) -> + AuthContext = build_auth_context([{party, PartyID}], [], Context), Authorize = fun() -> Prototypes = [ {operation, build_prototype_for(operation, #{id => OperationID}, AuthContext)}, @@ -1193,12 +719,6 @@ prepare('GetReports' = OperationID, #{'identityID' := IdentityID} = Req0, Contex case wapi_report_backend:get_reports(Req, Context) of {ok, ReportList} -> wapi_handler_utils:reply_ok(200, ReportList); - {error, {identity, notfound}} -> - wapi_handler_utils:reply_ok(400, #{ - <<"errorType">> => <<"NotFound">>, - <<"name">> => <<"identity">>, - <<"description">> => <<"identity not found">> - }); {error, invalid_request} -> wapi_handler_utils:reply_ok(400, #{ <<"errorType">> => <<"NoMatch">>, @@ -1264,24 +784,6 @@ get_location(OperationID, Params, #{swag_server_get_operation_fun := Get}, Opts) #{path := PathSpec} = Get(OperationID), wapi_handler_utils:get_location(PathSpec, Params, Opts). -issue_grant_token(TokenSpec, Expiration, Context) -> - case get_expiration_deadline(Expiration) of - {ok, Deadline} -> - {ok, wapi_tokens_legacy:issue_access_token(wapi_handler_utils:get_owner(Context), TokenSpec, Deadline)}; - Error = {error, _} -> - Error - end. - -get_expiration_deadline(Expiration) -> - {DateTime, MilliSec} = woody_deadline:from_binary(wapi_utils:to_universal_time(Expiration)), - Deadline = genlib_time:daytime_to_unixtime(DateTime) + MilliSec div 1000, - case genlib_time:unow() - Deadline < 0 of - true -> - {ok, Deadline}; - false -> - {error, expired} - end. - build_auth_context([], Acc, _Context) -> Acc; build_auth_context([undefined | T], Acc, Context) -> @@ -1290,18 +792,18 @@ build_auth_context([H | T], Acc, Context) -> AuthContext = build_auth_context(H, Context), build_auth_context(T, [AuthContext | Acc], Context). -build_auth_context({identity, IdentityID}, Context) -> - {ResultIdentity, ResultIdentityOwner} = - case wapi_identity_backend:get(IdentityID, Context) of - {ok, Identity, Owner} -> {Identity, Owner}; - {error, {identity, notfound}} -> {undefined, undefined} +build_auth_context({party, PartyID}, _Context) -> + {ResultParty, ResultPartyOwner} = + case wapi_domain_backend:get_party_config(PartyID) of + {ok, {PartyConfig, Owner}} -> {PartyConfig, Owner}; + {error, notfound} -> {undefined, undefined} end, - {identity, {IdentityID, ResultIdentity, ResultIdentityOwner}}; -build_auth_context({wallet, WalletID}, Context) -> + {party, {PartyID, ResultParty, ResultPartyOwner}}; +build_auth_context({wallet, WalletID}, _Context) -> {ResultWallet, ResultWalletOwner} = - case wapi_wallet_backend:get(WalletID, Context) of - {ok, Wallet, Owner} -> {Wallet, Owner}; - {error, {wallet, notfound}} -> {undefined, undefined} + case wapi_domain_backend:get_wallet_config(WalletID) of + {ok, {WalletConfig, Owner}} -> {WalletConfig, Owner}; + {error, notfound} -> {undefined, undefined} end, {wallet, {WalletID, ResultWallet, ResultWalletOwner}}; build_auth_context({destination, DestinationID}, Context) -> @@ -1329,8 +831,8 @@ build_auth_context({webhook, WebhookID}, Context) -> build_prototype_for(operation, OpContext, AuthContext) -> lists:foldl( fun - ({identity, {IdentityID, _Identity, _Owner}}, Acc) -> - Acc#{identity => IdentityID}; + ({party, {PartyID, _Identity, _Owner}}, Acc) -> + Acc#{party => PartyID}; ({wallet, {WalletID, _Wallet, _Owner}}, Acc) -> Acc#{wallet => WalletID}; ({destination, {DestinationID, _Destination, _Owner}}, Acc) -> @@ -1346,8 +848,8 @@ build_prototype_for(operation, OpContext, AuthContext) -> build_prototype_for(wallet, Entities, AuthContext) -> lists:foldl( fun - ({identity, {_IdentityID, Identity, Owner}}, Acc) -> - [wapi_bouncer_context:build_wallet_entity(identity, Identity, {party, Owner}) | Acc]; + ({party, {_IdentityID, Party, Owner}}, Acc) -> + [wapi_bouncer_context:build_wallet_entity(party, Party, {party, Owner}) | Acc]; ({wallet, {_WalletID, Wallet, Owner}}, Acc) -> [wapi_bouncer_context:build_wallet_entity(wallet, Wallet, {party, Owner}) | Acc]; ({destination, {_DestinationID, Destination, Owner}}, Acc) -> @@ -1361,17 +863,6 @@ build_prototype_for(wallet, Entities, AuthContext) -> AuthContext ). -find_party_id_for(Tag, [Context = {Tag, _} | _Rest]) -> get_party_id_from_auth_context(Context); -find_party_id_for(Tag, [_H | Rest]) -> find_party_id_for(Tag, Rest). - -get_party_id_from_auth_context({identity, {_, _, PartyID}}) -> PartyID; -get_party_id_from_auth_context({wallet, {_, _, PartyID}}) -> PartyID. - -add_party_id_to(undefined, Params) -> - Params; -add_party_id_to(PartyID, Params) when is_map(Params) -> - Params#{<<"partyID">> => PartyID}. - patch_party_req(_Context, #{'partyID' := PartyID} = Req) when PartyID =/= undefined -> {Req, PartyID}; patch_party_req(Context, Req) -> @@ -1385,8 +876,3 @@ get_default_url_lifetime() -> Now = erlang:system_time(second), Lifetime = application:get_env(wapi_lib, file_storage_url_lifetime, ?DEFAULT_URL_LIFETIME), genlib_rfc3339:format(Now + Lifetime, second). - -maybe_to_list(undefined) -> - []; -maybe_to_list(T) -> - [T]. diff --git a/src/wapi_webhook_backend.erl b/src/wapi_webhook_backend.erl index 79857854..2715a838 100644 --- a/src/wapi_webhook_backend.erl +++ b/src/wapi_webhook_backend.erl @@ -21,8 +21,8 @@ create_webhook(#{'Webhook' := Params}, HandlerContext) -> process_create_webhook_result(Result). -spec get_webhooks(id(), ctx()) -> {ok, response_data()}. -get_webhooks(IdentityID, HandlerContext) -> - Call = {webhook_manager, 'GetList', {IdentityID}}, +get_webhooks(PartyID, HandlerContext) -> + Call = {webhook_manager, 'GetList', {PartyID}}, Result = wapi_handler_utils:service_call(Call, HandlerContext), process_get_webhooks_result(Result). @@ -79,13 +79,13 @@ encode_webhook_id(WebhookID) -> %% marshaling marshal_webhook_params(#{ - <<"identityID">> := IdentityID, + <<"partyID">> := PartyID, <<"scope">> := Scope, <<"url">> := URL }) -> WalletID = maps:get(<<"walletID">>, Scope, undefined), #webhooker_WebhookParams{ - identity_id = IdentityID, + party_id = PartyID, wallet_id = WalletID, event_filter = marshal_webhook_scope(Scope), url = URL @@ -106,18 +106,14 @@ marshal_webhook_event_type(<<"WithdrawalSucceeded">>) -> marshal_webhook_event_type(<<"WithdrawalFailed">>) -> {withdrawal, {failed, #webhooker_WithdrawalFailed{}}}; marshal_webhook_event_type(<<"DestinationCreated">>) -> - {destination, {created, #webhooker_DestinationCreated{}}}; -marshal_webhook_event_type(<<"DestinationUnauthorized">>) -> - {destination, {unauthorized, #webhooker_DestinationUnauthorized{}}}; -marshal_webhook_event_type(<<"DestinationAuthorized">>) -> - {destination, {authorized, #webhooker_DestinationAuthorized{}}}. + {destination, {created, #webhooker_DestinationCreated{}}}. unmarshal_webhooks(Webhooks) when is_list(Webhooks) -> lists:map(fun(Webhook) -> unmarshal_webhook(Webhook) end, Webhooks). unmarshal_webhook(#webhooker_Webhook{ id = ID, - identity_id = IdentityID, + party_id = PartyID, wallet_id = WalletID, event_filter = EventFilter, url = URL, @@ -126,7 +122,7 @@ unmarshal_webhook(#webhooker_Webhook{ }) -> genlib_map:compact(#{ <<"id">> => integer_to_binary(ID), - <<"identityID">> => IdentityID, + <<"partyID">> => PartyID, <<"active">> => wapi_codec:unmarshal(bool, Enabled), <<"scope">> => unmarshal_webhook_scope(EventFilter, WalletID), <<"url">> => URL, diff --git a/src/wapi_withdrawal_backend.erl b/src/wapi_withdrawal_backend.erl index 0a812cf8..989b1072 100644 --- a/src/wapi_withdrawal_backend.erl +++ b/src/wapi_withdrawal_backend.erl @@ -12,10 +12,13 @@ -type handler_context() :: wapi_handler_utils:handler_context(). -type response_data() :: wapi_handler_utils:response_data(). -type id() :: binary(). +-type realm() :: binary(). -type external_id() :: binary(). -type create_error() :: - {destination, notfound | unauthorized | forbidden_withdrawal_method} + {destination, notfound} + | forbidden_withdrawal_method + | {party, notfound} | {wallet, notfound} | {external_id_conflict, id()} | {quote_invalid_party, _} @@ -27,17 +30,18 @@ | {invalid_amount, _} | {inconsistent_currency, _} | {quote, token_expired} - | {identity_providers_mismatch, {id(), id()}} + | {realms_mismatch, {realm(), realm()}} | {destination_resource, {bin_data, not_found}}. -type create_quote_error() :: {destination, notfound | unauthorized | forbidden_withdrawal_method} | {wallet, notfound} + | {party, notfound} | {forbidden_currency, _} | {forbidden_amount, _} | {invalid_amount, _} | {inconsistent_currency, _} - | {identity_providers_mismatch, {id(), id()}} + | {realms_mismatch, {realm(), realm()}} | {destination_resource, {bin_data, not_found}}. -export([create/2]). @@ -73,12 +77,12 @@ create(Params, Context, HandlerContext) -> case service_call(Request, HandlerContext) of {ok, Withdrawal} -> {ok, unmarshal(withdrawal, Withdrawal)}; + {exception, #fistful_PartyNotFound{}} -> + {error, {party, notfound}}; {exception, #fistful_WalletNotFound{}} -> {error, {wallet, notfound}}; {exception, #fistful_DestinationNotFound{}} -> {error, {destination, notfound}}; - {exception, #fistful_DestinationUnauthorized{}} -> - {error, {destination, unauthorized}}; {exception, #fistful_ForbiddenOperationCurrency{currency = Currency}} -> {error, {forbidden_currency, unmarshal_currency_ref(Currency)}}; {exception, #fistful_ForbiddenOperationAmount{amount = Amount}} -> @@ -96,17 +100,17 @@ create(Params, Context, HandlerContext) -> unmarshal_currency_ref(DestinationCurrency), unmarshal_currency_ref(WalletCurrency) }}}; - {exception, #wthd_IdentityProvidersMismatch{ - wallet_provider = WalletProvider, - destination_provider = DestinationProvider + {exception, #fistful_RealmsMismatch{ + wallet_realm = WalletRealm, + destination_realm = DestinationRealm }} -> - {error, {identity_providers_mismatch, {WalletProvider, DestinationProvider}}}; + {error, {realms_mismatch, {unmarshal(realm, WalletRealm), unmarshal(realm, DestinationRealm)}}}; {exception, #wthd_NoDestinationResourceInfo{}} -> {error, {destination_resource, {bin_data, not_found}}}; {exception, #fistful_WalletInaccessible{id = WalletID}} -> {error, {wallet, {inaccessible, WalletID}}}; {exception, #fistful_ForbiddenWithdrawalMethod{}} -> - {error, {destination, forbidden_withdrawal_method}} + {error, forbidden_withdrawal_method} end. -spec get(id(), handler_context()) -> @@ -152,10 +156,10 @@ create_quote(Params, HandlerContext) -> {ok, UnmarshaledQuote#{<<"quoteToken">> => Token}}; {exception, #fistful_WalletNotFound{}} -> {error, {wallet, notfound}}; + {exception, #fistful_PartyNotFound{}} -> + {error, {party, notfound}}; {exception, #fistful_DestinationNotFound{}} -> {error, {destination, notfound}}; - {exception, #fistful_DestinationUnauthorized{}} -> - {error, {destination, unauthorized}}; {exception, #fistful_ForbiddenOperationCurrency{currency = Currency}} -> {error, {forbidden_currency, unmarshal_currency_ref(Currency)}}; {exception, #fistful_ForbiddenOperationAmount{amount = Amount}} -> @@ -173,15 +177,15 @@ create_quote(Params, HandlerContext) -> unmarshal_currency_ref(DestinationCurrency), unmarshal_currency_ref(WalletCurrency) }}}; - {exception, #wthd_IdentityProvidersMismatch{ - wallet_provider = WalletProvider, - destination_provider = DestinationProvider + {exception, #fistful_RealmsMismatch{ + wallet_realm = WalletRealm, + destination_realm = DestinationRealm }} -> - {error, {identity_providers_mismatch, {WalletProvider, DestinationProvider}}}; + {error, {realms_mismatch, {unmarshal(realm, WalletRealm), unmarshal(realm, DestinationRealm)}}}; {exception, #wthd_NoDestinationResourceInfo{}} -> {error, {destination_resource, {bin_data, not_found}}}; {exception, #fistful_ForbiddenWithdrawalMethod{}} -> - {error, {destination, forbidden_withdrawal_method}} + {error, forbidden_withdrawal_method} end. -spec get_events(request_data(), handler_context()) -> @@ -367,6 +371,7 @@ marshal( ExternalID = maps:get(<<"externalID">>, Params, undefined), Metadata = maps:get(<<"metadata">>, Params, undefined), Quote = maps:get(<<"quote">>, Params, undefined), + PartyID = maps:get(<<"party">>, Params, <<>>), #wthd_WithdrawalParams{ id = marshal(id, ID), wallet_id = marshal(id, WalletID), @@ -374,7 +379,8 @@ marshal( body = marshal_body(Body), quote = Quote, external_id = maybe_marshal(id, ExternalID), - metadata = maybe_marshal(context, Metadata) + metadata = maybe_marshal(context, Metadata), + party_id = PartyID }; marshal( create_quote_params, @@ -387,13 +393,15 @@ marshal( ) -> ExternalID = maps:get(<<"externalID">>, Params, undefined), DestinationID = maps:get(<<"destinationID">>, Params, undefined), + PartyID = maps:get(<<"partyID">>, Params, <<>>), #wthd_QuoteParams{ wallet_id = marshal(id, WalletID), body = marshal_body(Body), currency_from = marshal_currency_ref(CurrencyFrom), currency_to = marshal_currency_ref(CurrencyTo), destination_id = maybe_marshal(id, DestinationID), - external_id = maybe_marshal(id, ExternalID) + external_id = maybe_marshal(id, ExternalID), + party_id = PartyID }; marshal(context, Context) -> wapi_codec:marshal(context, Context); @@ -430,6 +438,7 @@ unmarshal({list, Type}, List) -> unmarshal(withdrawal, #wthd_WithdrawalState{ id = ID, wallet_id = WalletID, + party_id = PartyID, destination_id = DestinationID, body = Body, external_id = ExternalID, @@ -444,6 +453,7 @@ unmarshal(withdrawal, #wthd_WithdrawalState{ #{ <<"id">> => ID, <<"wallet">> => WalletID, + <<"party">> => PartyID, <<"destination">> => DestinationID, <<"body">> => unmarshal_body(Body), <<"createdAt">> => CreatedAt, diff --git a/src/wapi_withdrawal_quote.erl b/src/wapi_withdrawal_quote.erl index 22787cf5..2d675d24 100644 --- a/src/wapi_withdrawal_quote.erl +++ b/src/wapi_withdrawal_quote.erl @@ -102,8 +102,7 @@ payload_symmetry_test() -> bin_data_id = {obj, #{{arr, [{nl, {'msgp_Nil'}}]} => {arr, [{nl, {'msgp_Nil'}}]}}} }}, operation_timestamp = <<"1970-01-01T00:00:00.234Z">>, - domain_revision = 1, - party_revision = 2 + domain_revision = 1 }, Payload = create_token_payload(ThriftQuote, WalletID, DestinationID, PartyID), {ok, {Decoded, WalletID, DestinationID, PartyID}} = decode_token_payload(Payload), @@ -140,8 +139,7 @@ payload_v2_decoding_test() -> bin_data_id = {obj, #{{arr, [{nl, {'msgp_Nil'}}]} => {arr, [{nl, {'msgp_Nil'}}]}}} }}, operation_timestamp = <<"1970-01-01T00:00:00.234Z">>, - domain_revision = 1, - party_revision = 2 + domain_revision = 1 }, Payload = #{ <<"version">> => 2, @@ -183,8 +181,7 @@ payload_v1_decoding_test() -> <<"terminal_id">> => 2, <<"resource_id">> => #{<<"bank_card">> => 5}, <<"timestamp">> => 234, - <<"domain_revision">> => 1, - <<"party_revision">> => 2 + <<"domain_revision">> => 1 } }, ?assertEqual( diff --git a/src/wapi_woody_client.erl b/src/wapi_woody_client.erl index cb32cb5c..0bd2c401 100644 --- a/src/wapi_woody_client.erl +++ b/src/wapi_woody_client.erl @@ -68,8 +68,6 @@ get_service_url(ServiceName) -> maps:get(ServiceName, genlib_app:env(?APP, service_urls)). -spec get_service_modname(service_name()) -> woody:service(). -get_service_modname(identdoc_storage) -> - {identdocstore_identity_document_storage_thrift, 'IdentityDocumentStorage'}; get_service_modname(token_storage) -> {tds_storage_thrift, 'TokenStorage'}; get_service_modname(fistful_stat) -> @@ -78,18 +76,10 @@ get_service_modname(fistful_report) -> {ffreport_reports_thrift, 'Reporting'}; get_service_modname(file_storage) -> {filestore_storage_thrift, 'FileStorage'}; -get_service_modname(fistful_provider) -> - {fistful_provider_thrift, 'Management'}; -get_service_modname(fistful_identity) -> - {fistful_identity_thrift, 'Management'}; -get_service_modname(fistful_wallet) -> - {fistful_wallet_thrift, 'Management'}; get_service_modname(fistful_destination) -> {fistful_destination_thrift, 'Management'}; get_service_modname(fistful_withdrawal) -> {fistful_wthd_thrift, 'Management'}; -get_service_modname(fistful_w2w_transfer) -> - {fistful_w2w_transfer_thrift, 'Management'}; get_service_modname(webhook_manager) -> {fistful_webhooker_thrift, 'WebhookManager'}. diff --git a/test/wapi_bouncer_data.hrl b/test/wapi_bouncer_data.hrl index 6ea79012..a2a593f6 100644 --- a/test/wapi_bouncer_data.hrl +++ b/test/wapi_bouncer_data.hrl @@ -23,9 +23,9 @@ party = PartyID }). --define(CTX_IDENTITY_OP(ID, IdentityID), #ctx_v1_WalletAPIOperation{ +-define(CTX_IDENTITY_OP(ID, PartyID), #ctx_v1_WalletAPIOperation{ id = ID, - identity = IdentityID + party = PartyID }). -define(CTX_DESTINAION_OP(ID, DestinaionID), #ctx_v1_WalletAPIOperation{ diff --git a/test/wapi_ct_helper.erl b/test/wapi_ct_helper.erl index 6c1dc94f..8307e568 100644 --- a/test/wapi_ct_helper.erl +++ b/test/wapi_ct_helper.erl @@ -2,6 +2,7 @@ -include_lib("common_test/include/ct.hrl"). -include_lib("damsel/include/dmsl_domain_conf_thrift.hrl"). +-include_lib("damsel/include/dmsl_domain_thrift.hrl"). -include_lib("wapi_wallet_dummy_data.hrl"). -include_lib("wapi_token_keeper_data.hrl"). @@ -132,11 +133,66 @@ start_app(woody = AppName) -> {acceptors_pool_size, 4} ]); start_app({dmt_client = AppName, SupPid}) -> + WalletConfig = #domain_WalletConfig{ + id = ?STRING, + created_at = wapi_time:rfc3339(), + blocking = + {unblocked, #domain_Unblocked{ + reason = <<"">>, + since = wapi_time:rfc3339() + }}, + suspension = + {active, #domain_Active{ + since = wapi_time:rfc3339() + }}, + details = #domain_Details{ + name = <<"Test Wallet">>, + description = <<"Test description">> + }, + currency_configs = #{ + #domain_CurrencyRef{symbolic_code = <<"RUB">>} => #domain_WalletCurrencyConfig{ + currency = #domain_CurrencyRef{symbolic_code = <<"RUB">>}, + settlement = ?INTEGER + } + }, + payment_institution = #domain_PaymentInstitutionRef{id = 1}, + terms = #domain_TermSetHierarchyRef{id = 1}, + party_id = ?STRING + }, + WalletConfigObject = #domain_WalletConfigObject{ref = #domain_WalletConfigRef{id = ?STRING}, data = WalletConfig}, + PartyConfig = #domain_PartyConfig{ + id = ?STRING, + contact_info = #domain_PartyContactInfo{ + registration_email = <<"test@test.ru">> + }, + created_at = wapi_time:rfc3339(), + blocking = + {unblocked, #domain_Unblocked{ + reason = <<"">>, + since = wapi_time:rfc3339() + }}, + suspension = + {active, #domain_Active{ + since = wapi_time:rfc3339() + }}, + shops = [], + wallets = [#domain_WalletConfigRef{id = ?STRING}] + }, + PartyConfigObject = #domain_PartyConfigObject{ref = #domain_PartyConfigRef{id = ?STRING}, data = PartyConfig}, Urls = mock_services_( [ {domain_config, fun - ('Checkout', _) -> {ok, #domain_conf_Snapshot{version = 1, domain = #{}}}; - ('PullRange', _) -> {ok, #{}} + ('Checkout', _) -> + {ok, #domain_conf_Snapshot{ + version = 1, + domain = #{ + {wallet_config, #domain_WalletConfigRef{id = ?STRING}} => + {wallet_config, WalletConfigObject}, + {party_config, #domain_PartyConfigRef{id = ?STRING}} => {party_config, PartyConfigObject} + } + }}; + ('PullRange', _) -> + {ok, #{}} end} ], SupPid diff --git a/test/wapi_ct_helper_bouncer.erl b/test/wapi_ct_helper_bouncer.erl index 9cced67b..fa8e0911 100644 --- a/test/wapi_ct_helper_bouncer.erl +++ b/test/wapi_ct_helper_bouncer.erl @@ -5,11 +5,9 @@ -export([mock_assert_op_ctx/2]). -export([mock_assert_party_op_ctx/3]). --export([mock_assert_identity_op_ctx/4]). -export([mock_assert_destination_op_ctx/4]). -export([mock_assert_wallet_op_ctx/4]). -export([mock_assert_withdrawal_op_ctx/4]). --export([mock_assert_w2w_transfer_op_ctx/4]). -export([mock_assert_generic_op_ctx/3]). -export([mock_client/1]). @@ -41,14 +39,6 @@ mock_assert_party_op_ctx(Op, PartyID, Config) -> Config ). --spec mock_assert_identity_op_ctx(_, _, _, _) -> _. -mock_assert_identity_op_ctx(Op, IdentityID, PartyID, Config) -> - mock_assert_generic_op_ctx( - [{identity, IdentityID, PartyID}], - ?CTX_WAPI(?CTX_IDENTITY_OP(Op, IdentityID)), - Config - ). - -spec mock_assert_destination_op_ctx(_, _, _, _) -> _. mock_assert_destination_op_ctx(Op, DestinationID, PartyID, Config) -> mock_assert_generic_op_ctx( @@ -73,14 +63,6 @@ mock_assert_withdrawal_op_ctx(Op, WithdrawalID, PartyID, Config) -> Config ). --spec mock_assert_w2w_transfer_op_ctx(_, _, _, _) -> _. -mock_assert_w2w_transfer_op_ctx(Op, W2WTransferID, PartyID, Config) -> - mock_assert_generic_op_ctx( - [{w2w_transfer, W2WTransferID, PartyID}], - ?CTX_WAPI(?CTX_W2W_TRANSFER_OP(Op, W2WTransferID)), - Config - ). - -spec mock_assert_generic_op_ctx(_, _, _) -> _. mock_assert_generic_op_ctx(Entities, WapiContext, Config) -> List = lists:map(fun make_entity/1, Entities), @@ -96,10 +78,10 @@ mock_assert_generic_op_ctx(Entities, WapiContext, Config) -> %% -make_entity({identity, ID, OwnerID}) -> +make_entity({party, ID, OwnerID}) -> #base_Entity{ id = ID, - type = <<"Identity">>, + type = <<"Party">>, party = OwnerID }; make_entity({wallet, ID, OwnerID}) -> @@ -127,21 +109,21 @@ make_entity({destination, ID, OwnerID}) -> type = <<"Destination">>, party = OwnerID }; -make_entity({report, ID, Data = #{identity := IdentityID}}) -> +make_entity({report, ID, Data = #{party := PartyID}}) -> #base_Entity{ id = ID, type = <<"WalletReport">>, + party = PartyID, wallet = #base_WalletAttrs{ - identity = IdentityID, report = wapi_handler_utils:maybe_with(files, Data, fun build_report_attrs/1) } }; -make_entity({webhook, ID, Data = #{identity := IdentityID}}) -> +make_entity({webhook, ID, Data = #{party := PartyID}}) -> #base_Entity{ id = ID, type = <<"WalletWebhook">>, + party = PartyID, wallet = #base_WalletAttrs{ - identity = IdentityID, wallet = maps:get(wallet, Data, undefined) } }. diff --git a/test/wapi_destination_tests_SUITE.erl b/test/wapi_destination_tests_SUITE.erl index 77d7dda2..d8f8912d 100644 --- a/test/wapi_destination_tests_SUITE.erl +++ b/test/wapi_destination_tests_SUITE.erl @@ -7,7 +7,6 @@ -include_lib("fistful_proto/include/fistful_fistful_base_thrift.hrl"). -include_lib("fistful_proto/include/fistful_fistful_thrift.hrl"). --include_lib("fistful_proto/include/fistful_identity_thrift.hrl"). -include_lib("fistful_proto/include/fistful_account_thrift.hrl"). -include_lib("fistful_proto/include/fistful_destination_thrift.hrl"). -include_lib("tds_proto/include/tds_storage_thrift.hrl"). @@ -28,10 +27,9 @@ -export([create_destination_ok_test/1]). -export([create_destination_fail_resource_token_invalid_test/1]). -export([create_destination_fail_resource_token_expire_test/1]). --export([create_destination_fail_identity_notfound_test/1]). +-export([create_destination_fail_party_notfound_test/1]). -export([create_destination_fail_currency_notfound_test/1]). -export([create_destination_fail_party_inaccessible_test/1]). --export([create_destination_fail_withdrawal_method_test/1]). -export([get_destination_ok_test/1]). -export([get_destination_fail_notfound_test/1]). -export([bank_card_resource_test/1]). @@ -68,10 +66,9 @@ groups() -> create_destination_ok_test, create_destination_fail_resource_token_invalid_test, create_destination_fail_resource_token_expire_test, - create_destination_fail_identity_notfound_test, + create_destination_fail_party_notfound_test, create_destination_fail_currency_notfound_test, create_destination_fail_party_inaccessible_test, - create_destination_fail_withdrawal_method_test, get_destination_ok_test, get_destination_fail_notfound_test, bank_card_resource_test, @@ -250,12 +247,12 @@ create_destination_fail_resource_token_expire_test(C) -> create_destination_call_api(C, Destination, InvalidResourceToken) ). --spec create_destination_fail_identity_notfound_test(config()) -> _. -create_destination_fail_identity_notfound_test(C) -> +-spec create_destination_fail_party_notfound_test(config()) -> _. +create_destination_fail_party_notfound_test(C) -> Destination = make_destination(C, bank_card), - _ = create_destination_start_mocks(C, {throwing, #fistful_IdentityNotFound{}}), + _ = create_destination_start_mocks(C, {throwing, #fistful_PartyNotFound{}}), ?assertEqual( - {error, {422, #{<<"message">> => <<"No such identity">>}}}, + {error, {422, #{<<"message">> => <<"No such party">>}}}, create_destination_call_api(C, Destination) ). @@ -273,16 +270,7 @@ create_destination_fail_party_inaccessible_test(C) -> Destination = make_destination(C, bank_card), _ = create_destination_start_mocks(C, {throwing, #fistful_PartyInaccessible{}}), ?assertEqual( - {error, {422, #{<<"message">> => <<"Identity inaccessible">>}}}, - create_destination_call_api(C, Destination) - ). - --spec create_destination_fail_withdrawal_method_test(config()) -> _. -create_destination_fail_withdrawal_method_test(C) -> - Destination = make_destination(C, bank_card), - _ = create_destination_start_mocks(C, {throwing, #fistful_ForbiddenWithdrawalMethod{}}), - ?assertEqual( - {error, {422, #{<<"message">> => <<"Resource type not allowed">>}}}, + {error, {422, #{<<"message">> => <<"Party inaccessible">>}}}, create_destination_call_api(C, Destination) ). @@ -351,8 +339,9 @@ digital_wallet_w_token_resource_test(C) -> }, Destination = #{ <<"name">> => ?STRING, - <<"identity">> => ?STRING, + <<"party">> => PartyID, <<"currency">> => ?RUB, + <<"realm">> => <<"Live">>, <<"resource">> => Resource }, _ = wapi_ct_helper:mock_services( @@ -365,10 +354,6 @@ digital_wallet_w_token_resource_test(C) -> ('GenerateID', _) -> {ok, ?GENERATE_ID_RESULT}; ('GetInternalID', _) -> {ok, ?GET_INTERNAL_ID_RESULT} end}, - {fistful_identity, fun - ('GetContext', _) -> {ok, ?DEFAULT_CONTEXT(PartyID)}; - ('Get', _) -> {ok, ?IDENTITY(PartyID)} - end}, {fistful_destination, fun ('Create', _) -> {ok, ?DESTINATION(PartyID, ?RESOURCE_DIGITAL_WALLET)}; @@ -378,7 +363,7 @@ digital_wallet_w_token_resource_test(C) -> ], C ), - _ = wapi_ct_helper_bouncer:mock_assert_identity_op_ctx(<<"CreateDestination">>, ?STRING, PartyID, C), + _ = wapi_ct_helper_bouncer:mock_assert_party_op_ctx(<<"CreateDestination">>, PartyID, C), {ok, #{<<"resource">> := ResourceOut}} = call_api( fun swag_client_wallet_withdrawals_api:create_destination/3, #{body => Destination}, @@ -397,7 +382,7 @@ digital_wallet_w_token_resource_test(C) -> check_unknown_destination_id(C) -> PartyID = ?config(party, C), - _ = wapi_ct_helper_bouncer:mock_assert_identity_op_ctx(<<"CreateDestination">>, ?STRING, PartyID, C), + _ = wapi_ct_helper_bouncer:mock_assert_party_op_ctx(<<"CreateDestination">>, PartyID, C), CounterRef = counters:new(1, []), ID0 = <<"Test0">>, @@ -413,10 +398,6 @@ check_unknown_destination_id(C) -> ok = counters:add(CounterRef, 1, 1), {ok, ?GENERATE_ID_RESULT(<<"Test", BinaryCID/binary>>)} end}, - {fistful_identity, fun - ('GetContext', _) -> {ok, ?DEFAULT_CONTEXT(PartyID)}; - ('Get', _) -> {ok, ?IDENTITY(PartyID)} - end}, {fistful_destination, fun ('Create', _) -> {ok, Destination1}; @@ -437,20 +418,15 @@ check_unknown_destination_id(C) -> do_destination_lifecycle(ResourceType, C) -> PartyID = wapi_ct_helper:cfg(party, C), - Identity = generate_identity(PartyID), Resource = generate_resource(ResourceType), Context = generate_context(PartyID), - Destination = generate_destination(Identity#identity_IdentityState.id, Resource, Context), + Destination = generate_destination(PartyID, Resource, Context), _ = wapi_ct_helper:mock_services( [ {bender, fun ('GenerateID', _) -> {ok, ?GENERATE_ID_RESULT}; ('GetInternalID', _) -> {ok, ?GET_INTERNAL_ID_RESULT} end}, - {fistful_identity, fun - ('GetContext', _) -> {ok, ?DEFAULT_CONTEXT(PartyID)}; - ('Get', _) -> {ok, ?IDENTITY(PartyID)} - end}, {fistful_destination, fun ('Create', _) -> {ok, Destination}; ('GetContext', _) -> {ok, ?DEFAULT_CONTEXT(PartyID)}; @@ -460,7 +436,7 @@ do_destination_lifecycle(ResourceType, C) -> C ), Sup0 = wapi_ct_helper:start_mocked_service_sup(?MODULE), - _ = wapi_ct_helper_bouncer:mock_assert_identity_op_ctx(<<"CreateDestination">>, ?STRING, PartyID, Sup0), + _ = wapi_ct_helper_bouncer:mock_assert_party_op_ctx(<<"CreateDestination">>, PartyID, Sup0), {ok, CreateResult} = call_api( fun swag_client_wallet_withdrawals_api:create_destination/3, #{ @@ -500,13 +476,12 @@ do_destination_lifecycle(ResourceType, C) -> ?assertEqual(GetResult, GetByIDResult), ?assertEqual(Destination#destination_DestinationState.id, maps:get(<<"id">>, CreateResult)), ?assertEqual(Destination#destination_DestinationState.external_id, maps:get(<<"externalID">>, CreateResult)), - ?assertEqual(Identity#identity_IdentityState.id, maps:get(<<"identity">>, CreateResult)), + ?assertEqual(PartyID, maps:get(<<"party">>, CreateResult)), Account = Destination#destination_DestinationState.account, ?assertEqual( Account#account_Account.currency#fistful_base_CurrencyRef.symbolic_code, maps:get(<<"currency">>, CreateResult) ), - ?assertEqual(<<"Authorized">>, maps:get(<<"status">>, CreateResult)), ?assertEqual(false, maps:get(<<"isBlocked">>, CreateResult)), ?assertEqual(Destination#destination_DestinationState.created_at, maps:get(<<"createdAt">>, CreateResult)), ?assertEqual(#{<<"key">> => <<"val">>}, maps:get(<<"metadata">>, CreateResult)), @@ -523,7 +498,8 @@ build_destination_spec(D, undefined) -> build_destination_spec(D, Resource) -> #{ <<"name">> => D#destination_DestinationState.name, - <<"identity">> => (D#destination_DestinationState.account)#account_Account.identity, + <<"party">> => D#destination_DestinationState.party_id, + <<"realm">> => <<"Test">>, <<"currency">> => D#destination_DestinationState.account#account_Account.currency#fistful_base_CurrencyRef.symbolic_code, <<"externalID">> => D#destination_DestinationState.external_id, @@ -569,15 +545,6 @@ build_resource_spec(Token) -> uniq() -> genlib:bsuuid(). -generate_identity(PartyID) -> - #identity_IdentityState{ - id = ?STRING, - name = uniq(), - party_id = PartyID, - provider_id = uniq(), - context = generate_context(PartyID) - }. - generate_context(PartyID) -> #{ ?CTX_NS => @@ -588,19 +555,17 @@ generate_context(PartyID) -> }} }. -generate_destination(IdentityID, Resource, Context) -> - ID = ?STRING, +generate_destination(PartyID, Resource, Context) -> #destination_DestinationState{ - id = ID, + id = ?STRING, name = uniq(), - status = {authorized, #destination_Authorized{}}, account = #account_Account{ - id = ID, - identity = IdentityID, + account_id = ?INTEGER, + party_id = PartyID, currency = #'fistful_base_CurrencyRef'{ symbolic_code = <<"RUB">> }, - accounter_account_id = 123 + realm = test }, resource = Resource, external_id = ?STRING, @@ -608,6 +573,8 @@ generate_destination(IdentityID, Resource, Context) -> blocking = unblocked, metadata = #{<<"key">> => {str, <<"val">>}}, context = Context, + party_id = PartyID, + realm = test, auth_data = {sender_receiver, #destination_SenderReceiverAuthData{ sender = <<"SenderToken">>, @@ -666,22 +633,17 @@ generate_digital_wallet_provider() -> make_destination(C, ResourceType) -> PartyID = ?config(party, C), - Identity = generate_identity(PartyID), Resource = generate_resource(ResourceType), Context = generate_context(PartyID), - generate_destination(Identity#identity_IdentityState.id, Resource, Context). + generate_destination(PartyID, Resource, Context). create_destination_start_mocks(C, CreateDestinationResult) -> PartyID = ?config(party, C), - _ = wapi_ct_helper_bouncer:mock_assert_identity_op_ctx(<<"CreateDestination">>, ?STRING, PartyID, C), + _ = wapi_ct_helper_bouncer:mock_assert_party_op_ctx(<<"CreateDestination">>, PartyID, C), wapi_ct_helper:mock_services( [ {bender, fun('GenerateID', _) -> {ok, ?GENERATE_ID_RESULT} end}, - {fistful_identity, fun - ('GetContext', _) -> {ok, ?DEFAULT_CONTEXT(PartyID)}; - ('Get', _) -> {ok, ?IDENTITY(PartyID)} - end}, {fistful_destination, fun ('Create', _) -> CreateDestinationResult; ('Get', _) -> {throwing, #fistful_DestinationNotFound{}} diff --git a/test/wapi_identity_tests_SUITE.erl b/test/wapi_identity_tests_SUITE.erl deleted file mode 100644 index 775489ce..00000000 --- a/test/wapi_identity_tests_SUITE.erl +++ /dev/null @@ -1,357 +0,0 @@ --module(wapi_identity_tests_SUITE). - --include_lib("common_test/include/ct.hrl"). --include_lib("stdlib/include/assert.hrl"). - --include_lib("wapi_wallet_dummy_data.hrl"). - --include_lib("fistful_proto/include/fistful_fistful_base_thrift.hrl"). --include_lib("fistful_proto/include/fistful_fistful_thrift.hrl"). --include_lib("fistful_proto/include/fistful_identity_thrift.hrl"). - --export([all/0]). --export([groups/0]). --export([init_per_suite/1]). --export([end_per_suite/1]). --export([init_per_group/2]). --export([end_per_group/2]). --export([init_per_testcase/2]). --export([end_per_testcase/2]). - --export([init/1]). - --export([ - create_identity/1, - create_identity_with_party_id/1, - create_identity_provider_notfound/1, - create_identity_party_notfound/1, - create_identity_party_inaccessible/1, - create_identity_thrift_name/1, - get_identity/1, - get_identity_notfound/1, - get_identity_withdrawal_methods/1, - get_identity_withdrawal_methods_notfound/1, - check_unknown_identity_id/1 -]). - --type test_case_name() :: atom(). --type config() :: [{atom(), any()}]. --type group_name() :: atom(). - --behaviour(supervisor). - --spec init([]) -> {ok, {supervisor:sup_flags(), [supervisor:child_spec()]}}. -init([]) -> - {ok, {#{strategy => one_for_all, intensity => 1, period => 1}, []}}. - --spec all() -> [{group, test_case_name()}]. -all() -> - [ - {group, base} - ]. - --spec groups() -> [{group_name(), list(), [test_case_name()]}]. -groups() -> - [ - {base, [], [ - create_identity, - create_identity_with_party_id, - create_identity_provider_notfound, - create_identity_party_notfound, - create_identity_party_inaccessible, - create_identity_thrift_name, - get_identity, - get_identity_notfound, - get_identity_withdrawal_methods, - get_identity_withdrawal_methods_notfound, - check_unknown_identity_id - ]} - ]. - -%% -%% starting/stopping -%% --spec init_per_suite(config()) -> config(). -init_per_suite(C) -> - wapi_ct_helper:init_suite(?MODULE, C). - --spec end_per_suite(config()) -> _. -end_per_suite(C) -> - _ = wapi_ct_helper:stop_mocked_service_sup(?config(suite_test_sup, C)), - _ = [application:stop(App) || App <- ?config(apps, C)], - ok. - --spec init_per_group(group_name(), config()) -> config(). -init_per_group(Group, Config) when Group =:= base -> - Party = genlib:bsuuid(), - Config1 = [{party, Party} | Config], - GroupSup = wapi_ct_helper:start_mocked_service_sup(?MODULE), - _ = wapi_ct_helper_token_keeper:mock_user_session_token(Party, GroupSup), - [{group_test_sup, GroupSup}, {context, wapi_ct_helper:get_context(?API_TOKEN)} | Config1]; -init_per_group(_, Config) -> - Config. - --spec end_per_group(group_name(), config()) -> _. -end_per_group(_Group, C) -> - _ = wapi_ct_helper:stop_mocked_service_sup(?config(group_test_sup, C)), - ok. - --spec init_per_testcase(test_case_name(), config()) -> config(). -init_per_testcase(Name, C) -> - C1 = wapi_ct_helper:makeup_cfg([wapi_ct_helper:test_case_name(Name), wapi_ct_helper:woody_ctx()], C), - [{test_sup, wapi_ct_helper:start_mocked_service_sup(?MODULE)} | C1]. - --spec end_per_testcase(test_case_name(), config()) -> ok. -end_per_testcase(_Name, C) -> - wapi_ct_helper:stop_mocked_service_sup(?config(test_sup, C)), - ok. - -%%% Tests --spec create_identity(config()) -> _. -create_identity(C) -> - PartyID = ?config(party, C), - _ = wapi_ct_helper_bouncer:mock_assert_party_op_ctx(<<"CreateIdentity">>, PartyID, C), - _ = wapi_ct_helper:mock_services( - [ - {bender, fun('GenerateID', _) -> {ok, ?GENERATE_ID_RESULT} end}, - {fistful_identity, fun - ('Create', _) -> {ok, ?IDENTITY(PartyID)}; - ('Get', _) -> {throwing, #fistful_IdentityNotFound{}} - end} - ], - C - ), - {ok, _} = create_identity_call_api(C). - --spec create_identity_with_party_id(config()) -> _. -create_identity_with_party_id(C) -> - %% this works because party existence check is in fistful - PartyID = <<"Test">>, - _ = wapi_ct_helper_bouncer:mock_assert_party_op_ctx(<<"CreateIdentity">>, PartyID, C), - _ = wapi_ct_helper:mock_services( - [ - {bender, fun('GenerateID', _) -> {ok, ?GENERATE_ID_RESULT} end}, - {fistful_identity, fun - ('Create', _) -> {ok, ?IDENTITY(PartyID)}; - ('Get', _) -> {throwing, #fistful_IdentityNotFound{}} - end} - ], - C - ), - {ok, _} = create_identity_call_api(PartyID, C). - --spec create_identity_provider_notfound(config()) -> _. -create_identity_provider_notfound(C) -> - PartyID = ?config(party, C), - _ = wapi_ct_helper_bouncer:mock_assert_party_op_ctx(<<"CreateIdentity">>, PartyID, C), - _ = wapi_ct_helper:mock_services( - [ - {bender, fun('GenerateID', _) -> {ok, ?GENERATE_ID_RESULT} end}, - {fistful_identity, fun - ('Create', _) -> {throwing, #fistful_ProviderNotFound{}}; - ('Get', _) -> {throwing, #fistful_IdentityNotFound{}} - end} - ], - C - ), - ?assertEqual( - {error, {422, #{<<"message">> => <<"No such provider">>}}}, - create_identity_call_api(C) - ). - --spec create_identity_party_notfound(config()) -> _. -create_identity_party_notfound(C) -> - PartyID = ?config(party, C), - _ = wapi_ct_helper_bouncer:mock_assert_party_op_ctx(<<"CreateIdentity">>, PartyID, C), - _ = wapi_ct_helper:mock_services( - [ - {bender, fun('GenerateID', _) -> {ok, ?GENERATE_ID_RESULT} end}, - {fistful_identity, fun - ('Create', _) -> {throwing, #fistful_PartyNotFound{}}; - ('Get', _) -> {throwing, #fistful_IdentityNotFound{}} - end} - ], - C - ), - ?assertEqual( - {error, {422, #{<<"message">> => <<"Party does not exist">>}}}, - create_identity_call_api(C) - ). - --spec create_identity_party_inaccessible(config()) -> _. -create_identity_party_inaccessible(C) -> - PartyID = ?config(party, C), - _ = wapi_ct_helper_bouncer:mock_assert_party_op_ctx(<<"CreateIdentity">>, PartyID, C), - _ = wapi_ct_helper:mock_services( - [ - {bender, fun('GenerateID', _) -> {ok, ?GENERATE_ID_RESULT} end}, - {fistful_identity, fun - ('Create', _) -> {throwing, #fistful_PartyInaccessible{}}; - ('Get', _) -> {throwing, #fistful_IdentityNotFound{}} - end} - ], - C - ), - ?assertEqual( - {error, {422, #{<<"message">> => <<"Identity inaccessible">>}}}, - create_identity_call_api(C) - ). - --spec create_identity_thrift_name(config()) -> _. -create_identity_thrift_name(C) -> - PartyID = ?config(party, C), - _ = wapi_ct_helper_bouncer:mock_assert_party_op_ctx(<<"CreateIdentity">>, PartyID, C), - _ = wapi_ct_helper:mock_services( - [ - {bender, fun('GenerateID', _) -> {ok, ?GENERATE_ID_RESULT} end}, - {fistful_identity, fun - ('Create', _) -> {ok, ?IDENTITY(PartyID, ?DEFAULT_CONTEXT_NO_NAME(PartyID))}; - ('Get', _) -> {throwing, #fistful_IdentityNotFound{}} - end} - ], - C - ), - {ok, #{<<"name">> := ?STRING}} = create_identity_call_api(C). - --spec get_identity(config()) -> _. -get_identity(C) -> - PartyID = ?config(party, C), - _ = wapi_ct_helper_bouncer:mock_assert_identity_op_ctx(<<"GetIdentity">>, ?STRING, PartyID, C), - _ = wapi_ct_helper:mock_services( - [ - {fistful_identity, fun('Get', _) -> {ok, ?IDENTITY(PartyID)} end} - ], - C - ), - {ok, _} = get_identity_call_api(C). - --spec get_identity_notfound(config()) -> _. -get_identity_notfound(C) -> - _ = wapi_ct_helper_bouncer:mock_arbiter(_ = wapi_ct_helper_bouncer:judge_always_forbidden(), C), - _ = wapi_ct_helper:mock_services( - [ - {fistful_identity, fun('Get', _) -> {throwing, #fistful_IdentityNotFound{}} end} - ], - C - ), - ?assertEqual( - {error, {404, #{}}}, - get_identity_call_api(C) - ). - --spec get_identity_withdrawal_methods(config()) -> _. -get_identity_withdrawal_methods(C) -> - PartyID = ?config(party, C), - _ = wapi_ct_helper_bouncer:mock_assert_identity_op_ctx(<<"GetWithdrawalMethods">>, ?STRING, PartyID, C), - _ = wapi_ct_helper:mock_services( - [ - {fistful_identity, fun - ('GetWithdrawalMethods', _) -> {ok, ?WITHDRAWAL_METHODS}; - ('Get', _) -> {ok, ?IDENTITY(PartyID)} - end} - ], - C - ), - {ok, _} = get_identity_withdrawal_methods_call_api(C). - --spec get_identity_withdrawal_methods_notfound(config()) -> _. -get_identity_withdrawal_methods_notfound(C) -> - PartyID = ?config(party, C), - _ = wapi_ct_helper_bouncer:mock_arbiter(_ = wapi_ct_helper_bouncer:judge_always_forbidden(), C), - _ = wapi_ct_helper:mock_services( - [ - {fistful_identity, fun - ('GetWithdrawalMethods', _) -> {throwing, #fistful_IdentityNotFound{}}; - ('Get', _) -> {ok, ?IDENTITY(PartyID)} - end} - ], - C - ), - ?assertEqual( - {error, {404, #{}}}, - get_identity_call_api(C) - ). - --spec check_unknown_identity_id(config()) -> _. -check_unknown_identity_id(C) -> - PartyID = ?config(party, C), - _ = wapi_ct_helper_bouncer:mock_assert_party_op_ctx(<<"CreateIdentity">>, PartyID, C), - CounterRef = counters:new(1, []), - ID0 = <<"Test0">>, - ID1 = <<"Test1">>, - Identity0 = ?IDENTITY(PartyID), - Identity1 = Identity0#identity_IdentityState{id = ID1}, - Identity2 = Identity1#identity_IdentityState{id = ID0, name = ?STRING2}, - _ = wapi_ct_helper:mock_services( - [ - {bender, fun('GenerateID', _) -> - CID = counters:get(CounterRef, 1), - BinaryCID = erlang:integer_to_binary(CID), - ok = counters:add(CounterRef, 1, 1), - {ok, ?GENERATE_ID_RESULT(<<"Test", BinaryCID/binary>>)} - end}, - {fistful_identity, fun - ('Create', _) -> - {ok, Identity1}; - ('Get', {WID, _}) when WID =:= ID0 -> - {ok, Identity2}; - ('Get', {WID, _}) when WID =:= ID1 -> - {throwing, #fistful_IdentityNotFound{}} - end} - ], - C - ), - {ok, #{ - <<"id">> := ID1 - }} = create_identity_call_api(C). - -%% - -create_identity_call_api(C) -> - create_identity_call_api(undefined, C). - -create_identity_call_api(PartyID, C) -> - call_api( - fun swag_client_wallet_identities_api:create_identity/3, - #{ - body => genlib_map:compact(#{ - <<"name">> => ?STRING, - <<"provider">> => ?STRING, - <<"partyID">> => PartyID, - <<"metadata">> => #{ - <<"somedata">> => ?STRING - } - }) - }, - wapi_ct_helper:cfg(context, C) - ). - -get_identity_call_api(C) -> - call_api( - fun swag_client_wallet_identities_api:get_identity/3, - #{ - binding => #{ - <<"identityID">> => ?STRING - } - }, - wapi_ct_helper:cfg(context, C) - ). - -get_identity_withdrawal_methods_call_api(C) -> - call_api( - fun swag_client_wallet_identities_api:get_withdrawal_methods/3, - #{ - binding => #{ - <<"identityID">> => ?STRING - } - }, - wapi_ct_helper:cfg(context, C) - ). - -%% - --spec call_api(function(), map(), wapi_client_lib:context()) -> {ok, term()} | {error, term()}. -call_api(F, Params, Context) -> - {Url, PreparedParams, Opts} = wapi_client_lib:make_request(Context, Params), - Response = F(Url, PreparedParams, Opts), - wapi_client_lib:handle_response(Response). diff --git a/test/wapi_identity_tests_SUITE_data/jwk.json b/test/wapi_identity_tests_SUITE_data/jwk.json deleted file mode 100644 index d3804153..00000000 --- a/test/wapi_identity_tests_SUITE_data/jwk.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "use": "enc", - "kty": "oct", - "kid": "1", - "alg": "dir", - "k": "M3VKOExvQVdhWUtXekduVGt1eDdrUmtwTTNBSko1a2M" -} \ No newline at end of file diff --git a/test/wapi_identity_tests_SUITE_data/jwk.priv.json b/test/wapi_identity_tests_SUITE_data/jwk.priv.json deleted file mode 100644 index e7d65575..00000000 --- a/test/wapi_identity_tests_SUITE_data/jwk.priv.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "use": "enc", - "kty": "EC", - "kid": "kxdD0orVPGoAxWrqAMTeQ0U5MRoK47uZxWiSJdgo0t0", - "crv": "P-256", - "alg": "ECDH-ES", - "x": "nHi7TCgBwfrPuNTf49bGvJMczk6WZOI-mCKAghbrOlM", - "y": "_8kiXGOIWkfz57m8K5dmTfbYzCJVYHZZZisCfbYicr0", - "d": "i45qDiARZ5qbS_uzeT-CiKnPUe64qHitKaVdAvcN6TI" -} \ No newline at end of file diff --git a/test/wapi_identity_tests_SUITE_data/jwk.publ.json b/test/wapi_identity_tests_SUITE_data/jwk.publ.json deleted file mode 100644 index 00b7002d..00000000 --- a/test/wapi_identity_tests_SUITE_data/jwk.publ.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "use": "enc", - "kty": "EC", - "kid": "kxdD0orVPGoAxWrqAMTeQ0U5MRoK47uZxWiSJdgo0t0", - "crv": "P-256", - "alg": "ECDH-ES", - "x": "nHi7TCgBwfrPuNTf49bGvJMczk6WZOI-mCKAghbrOlM", - "y": "_8kiXGOIWkfz57m8K5dmTfbYzCJVYHZZZisCfbYicr0" -} \ No newline at end of file diff --git a/test/wapi_identity_tests_SUITE_data/private.pem b/test/wapi_identity_tests_SUITE_data/private.pem deleted file mode 100644 index 4e6d12c9..00000000 --- a/test/wapi_identity_tests_SUITE_data/private.pem +++ /dev/null @@ -1,9 +0,0 @@ ------BEGIN RSA PRIVATE KEY----- -MIIBOwIBAAJBAK9fx7qOJT7Aoseu7KKgaLagBh3wvDzg7F/ZMtGbPFikJnnvRWvF -B5oEGbMPblvtF0/fjqfu+eqjP3Z1tUSn7TkCAwEAAQJABUY5KIgr4JZEjwLYxQ9T -9uIbLP1Xe/E7yqoqmBk2GGhSrPY0OeRkYnUVLcP96UPQhF63iuG8VF6uZ7oAPsq+ -gQIhANZy3jSCzPjXYHRU1kRqQzpt2S+OqoEiqQ6YG1HrC/VxAiEA0Vq6JlQK2tOX -37SS00dK0Qog4Qi8dN73GliFQNP18EkCIQC4epSA48zkfJMzQBAbRraSuxDNApPX -BzQbo+pMrEDbYQIgY4AncQgIkLB4Qk5kah48JNYXglzQlQtTjiX8Ty9ueGECIQCM -GD3UbQKiA0gf5plBA24I4wFVKxxa4wXbW/7SfP6XmQ== ------END RSA PRIVATE KEY----- diff --git a/test/wapi_provider_tests_SUITE.erl b/test/wapi_provider_tests_SUITE.erl deleted file mode 100644 index 96e5f398..00000000 --- a/test/wapi_provider_tests_SUITE.erl +++ /dev/null @@ -1,156 +0,0 @@ --module(wapi_provider_tests_SUITE). - --include_lib("common_test/include/ct.hrl"). - --include_lib("wapi_wallet_dummy_data.hrl"). - --include_lib("fistful_proto/include/fistful_fistful_thrift.hrl"). --include_lib("fistful_proto/include/fistful_provider_thrift.hrl"). - --export([all/0]). --export([groups/0]). --export([init_per_suite/1]). --export([end_per_suite/1]). --export([init_per_group/2]). --export([end_per_group/2]). --export([init_per_testcase/2]). --export([end_per_testcase/2]). - --export([init/1]). - --export([ - get_provider_ok/1, - get_provider_fail_notfound/1, - list_providers/1 -]). - --type test_case_name() :: atom(). --type config() :: [{atom(), any()}]. --type group_name() :: atom(). - --behaviour(supervisor). - --spec init([]) -> {ok, {supervisor:sup_flags(), [supervisor:child_spec()]}}. -init([]) -> - {ok, {#{strategy => one_for_all, intensity => 1, period => 1}, []}}. - --spec all() -> [{group, test_case_name()}]. -all() -> - [ - {group, base} - ]. - --spec groups() -> [{group_name(), list(), [test_case_name()]}]. -groups() -> - [ - {base, [], [ - get_provider_ok, - get_provider_fail_notfound, - list_providers - ]} - ]. - -%% -%% starting/stopping -%% --spec init_per_suite(config()) -> config(). -init_per_suite(C) -> - wapi_ct_helper:init_suite(?MODULE, C). - --spec end_per_suite(config()) -> _. -end_per_suite(C) -> - _ = wapi_ct_helper:stop_mocked_service_sup(?config(suite_test_sup, C)), - _ = [application:stop(App) || App <- ?config(apps, C)], - ok. - --spec init_per_group(group_name(), config()) -> config(). -init_per_group(Group, Config) when Group =:= base -> - Party = genlib:bsuuid(), - Config1 = [{party, Party} | Config], - GroupSup = wapi_ct_helper:start_mocked_service_sup(?MODULE), - _ = wapi_ct_helper_token_keeper:mock_user_session_token(Party, GroupSup), - [{group_test_sup, GroupSup}, {context, wapi_ct_helper:get_context(?API_TOKEN)} | Config1]; -init_per_group(_, Config) -> - Config. - --spec end_per_group(group_name(), config()) -> _. -end_per_group(_Group, C) -> - _ = wapi_ct_helper:stop_mocked_service_sup(?config(group_test_sup, C)), - ok. - --spec init_per_testcase(test_case_name(), config()) -> config(). -init_per_testcase(Name, C) -> - C1 = wapi_ct_helper:makeup_cfg([wapi_ct_helper:test_case_name(Name), wapi_ct_helper:woody_ctx()], C), - [{test_sup, wapi_ct_helper:start_mocked_service_sup(?MODULE)} | C1]. - --spec end_per_testcase(test_case_name(), config()) -> ok. -end_per_testcase(_Name, C) -> - _ = wapi_ct_helper:stop_mocked_service_sup(?config(test_sup, C)), - ok. - -%%% Tests - --spec get_provider_ok(config()) -> _. -get_provider_ok(C) -> - _ = wapi_ct_helper_bouncer:mock_assert_op_ctx(<<"GetProvider">>, C), - _ = wapi_ct_helper:mock_services( - [ - {fistful_provider, fun('GetProvider', _) -> {ok, ?PROVIDER} end} - ], - C - ), - {ok, _} = call_api( - fun swag_client_wallet_providers_api:get_provider/3, - #{ - binding => #{ - <<"providerID">> => ?STRING - } - }, - wapi_ct_helper:cfg(context, C) - ). - --spec get_provider_fail_notfound(config()) -> _. -get_provider_fail_notfound(C) -> - _ = wapi_ct_helper_bouncer:mock_assert_op_ctx(<<"GetProvider">>, C), - _ = wapi_ct_helper:mock_services( - [ - {fistful_provider, fun('GetProvider', _) -> {throwing, #fistful_ProviderNotFound{}} end} - ], - C - ), - {error, {404, #{}}} = call_api( - fun swag_client_wallet_providers_api:get_provider/3, - #{ - binding => #{ - <<"providerID">> => ?STRING - } - }, - wapi_ct_helper:cfg(context, C) - ). - --spec list_providers(config()) -> _. -list_providers(C) -> - _ = wapi_ct_helper_bouncer:mock_assert_op_ctx(<<"ListProviders">>, C), - _ = wapi_ct_helper:mock_services( - [ - {fistful_provider, fun('ListProviders', _) -> {ok, [?PROVIDER, ?PROVIDER]} end} - ], - C - ), - {ok, _} = call_api( - fun swag_client_wallet_providers_api:list_providers/3, - #{ - qs_val => #{ - <<"residence">> => ?RESIDENCE_RUS - } - }, - wapi_ct_helper:cfg(context, C) - ). - -%% - --spec call_api(function(), map(), wapi_client_lib:context()) -> {ok, term()} | {error, term()}. -call_api(F, Params, Context) -> - {Url, PreparedParams, Opts} = wapi_client_lib:make_request(Context, Params), - Response = F(Url, PreparedParams, Opts), - wapi_client_lib:handle_response(Response). diff --git a/test/wapi_provider_tests_SUITE_data/jwk.json b/test/wapi_provider_tests_SUITE_data/jwk.json deleted file mode 100644 index d3804153..00000000 --- a/test/wapi_provider_tests_SUITE_data/jwk.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "use": "enc", - "kty": "oct", - "kid": "1", - "alg": "dir", - "k": "M3VKOExvQVdhWUtXekduVGt1eDdrUmtwTTNBSko1a2M" -} \ No newline at end of file diff --git a/test/wapi_provider_tests_SUITE_data/jwk.priv.json b/test/wapi_provider_tests_SUITE_data/jwk.priv.json deleted file mode 100644 index e7d65575..00000000 --- a/test/wapi_provider_tests_SUITE_data/jwk.priv.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "use": "enc", - "kty": "EC", - "kid": "kxdD0orVPGoAxWrqAMTeQ0U5MRoK47uZxWiSJdgo0t0", - "crv": "P-256", - "alg": "ECDH-ES", - "x": "nHi7TCgBwfrPuNTf49bGvJMczk6WZOI-mCKAghbrOlM", - "y": "_8kiXGOIWkfz57m8K5dmTfbYzCJVYHZZZisCfbYicr0", - "d": "i45qDiARZ5qbS_uzeT-CiKnPUe64qHitKaVdAvcN6TI" -} \ No newline at end of file diff --git a/test/wapi_provider_tests_SUITE_data/jwk.publ.json b/test/wapi_provider_tests_SUITE_data/jwk.publ.json deleted file mode 100644 index 00b7002d..00000000 --- a/test/wapi_provider_tests_SUITE_data/jwk.publ.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "use": "enc", - "kty": "EC", - "kid": "kxdD0orVPGoAxWrqAMTeQ0U5MRoK47uZxWiSJdgo0t0", - "crv": "P-256", - "alg": "ECDH-ES", - "x": "nHi7TCgBwfrPuNTf49bGvJMczk6WZOI-mCKAghbrOlM", - "y": "_8kiXGOIWkfz57m8K5dmTfbYzCJVYHZZZisCfbYicr0" -} \ No newline at end of file diff --git a/test/wapi_provider_tests_SUITE_data/private.pem b/test/wapi_provider_tests_SUITE_data/private.pem deleted file mode 100644 index 4e6d12c9..00000000 --- a/test/wapi_provider_tests_SUITE_data/private.pem +++ /dev/null @@ -1,9 +0,0 @@ ------BEGIN RSA PRIVATE KEY----- -MIIBOwIBAAJBAK9fx7qOJT7Aoseu7KKgaLagBh3wvDzg7F/ZMtGbPFikJnnvRWvF -B5oEGbMPblvtF0/fjqfu+eqjP3Z1tUSn7TkCAwEAAQJABUY5KIgr4JZEjwLYxQ9T -9uIbLP1Xe/E7yqoqmBk2GGhSrPY0OeRkYnUVLcP96UPQhF63iuG8VF6uZ7oAPsq+ -gQIhANZy3jSCzPjXYHRU1kRqQzpt2S+OqoEiqQ6YG1HrC/VxAiEA0Vq6JlQK2tOX -37SS00dK0Qog4Qi8dN73GliFQNP18EkCIQC4epSA48zkfJMzQBAbRraSuxDNApPX -BzQbo+pMrEDbYQIgY4AncQgIkLB4Qk5kah48JNYXglzQlQtTjiX8Ty9ueGECIQCM -GD3UbQKiA0gf5plBA24I4wFVKxxa4wXbW/7SfP6XmQ== ------END RSA PRIVATE KEY----- diff --git a/test/wapi_report_tests_SUITE.erl b/test/wapi_report_tests_SUITE.erl index dce95321..3ab3e049 100644 --- a/test/wapi_report_tests_SUITE.erl +++ b/test/wapi_report_tests_SUITE.erl @@ -5,7 +5,6 @@ -include_lib("fistful_reporter_proto/include/ffreport_reports_thrift.hrl"). -include_lib("wapi_wallet_dummy_data.hrl"). -include_lib("fistful_proto/include/fistful_fistful_thrift.hrl"). --include_lib("fistful_proto/include/fistful_identity_thrift.hrl"). -include_lib("wapi_bouncer_data.hrl"). -export([all/0]). @@ -23,7 +22,7 @@ create_report_ok_test/1, get_report_ok_test/1, get_reports_ok_test/1, - reports_with_wrong_identity_ok_test/1, + reports_with_wrong_party_ok_test/1, download_file_ok_test/1 ]). @@ -52,7 +51,7 @@ groups() -> create_report_ok_test, get_report_ok_test, get_reports_ok_test, - reports_with_wrong_identity_ok_test, + reports_with_wrong_party_ok_test, download_file_ok_test ]} ]. @@ -98,35 +97,29 @@ end_per_testcase(_Name, C) -> %%% Tests -spec create_report_ok_test(config()) -> _. create_report_ok_test(C) -> - PartyID = ?config(party, C), - ParamPartyID = genlib:bsuuid(), - _ = wapi_ct_helper_bouncer:mock_assert_identity_op_ctx(<<"CreateReport">>, ?STRING, PartyID, C), + _ = wapi_ct_helper_bouncer:mock_assert_party_op_ctx(<<"CreateReport">>, ?STRING, C), _ = wapi_ct_helper:mock_services( [ {fistful_report, fun ('GenerateReport', {#reports_ReportRequest{party_id = ExpectedPartyID}, _}) when - ExpectedPartyID =:= ParamPartyID + ExpectedPartyID =:= ?STRING -> {ok, ?REPORT_ID}; ('GenerateReport', _) -> erlang:throw("Unexpected party id"); - ('GetReport', {ExpectedPartyID, _, _}) when ExpectedPartyID =:= ParamPartyID -> + ('GetReport', {ExpectedPartyID, _}) when ExpectedPartyID =:= ?STRING -> {ok, ?REPORT}; ('GetReport', _) -> erlang:throw("Unexpected party id") - end}, - {fistful_identity, fun('Get', _) -> {ok, ?IDENTITY(PartyID)} end} + end} ], C ), {ok, _} = call_api( fun swag_client_wallet_reports_api:create_report/3, #{ - binding => #{ - <<"identityID">> => ?STRING - }, qs_val => #{ - <<"partyID">> => ParamPartyID + <<"partyID">> => ?STRING }, body => #{ <<"reportType">> => <<"withdrawalRegistry">>, @@ -139,16 +132,14 @@ create_report_ok_test(C) -> -spec get_report_ok_test(config()) -> _. get_report_ok_test(C) -> - PartyID = ?config(party, C), - ParamPartyID = genlib:bsuuid(), _ = wapi_ct_helper_bouncer:mock_assert_generic_op_ctx( [ - {report, genlib:to_binary(?INTEGER), #{identity => ?STRING, files => [?STRING, ?STRING, ?STRING]}}, - {identity, ?STRING, PartyID} + {report, genlib:to_binary(?INTEGER), #{party => ?STRING, files => [?STRING, ?STRING, ?STRING]}}, + {party, ?STRING, ?STRING} ], ?CTX_WAPI(#ctx_v1_WalletAPIOperation{ id = <<"GetReport">>, - identity = ?STRING, + party = ?STRING, report = genlib:to_binary(?INTEGER) }), C @@ -156,12 +147,11 @@ get_report_ok_test(C) -> _ = wapi_ct_helper:mock_services( [ {fistful_report, fun - ('GetReport', {ExpectedPartyID, _, _}) when ExpectedPartyID =:= ParamPartyID -> + ('GetReport', {ExpectedPartyID, _}) when ExpectedPartyID =:= ?STRING -> {ok, ?REPORT}; - ('GetReport', _) -> - erlang:throw("Unexpected party id") - end}, - {fistful_identity, fun('Get', _) -> {ok, ?IDENTITY(PartyID)} end} + ('GetReport', {ExpectedPartyID, _}) -> + erlang:throw({"Unexpected party id", ExpectedPartyID, ?STRING}) + end} ], C ), @@ -169,11 +159,10 @@ get_report_ok_test(C) -> fun swag_client_wallet_reports_api:get_report/3, #{ binding => #{ - <<"identityID">> => ?STRING, <<"reportID">> => ?INTEGER }, qs_val => #{ - <<"partyID">> => ParamPartyID + <<"partyID">> => ?STRING } }, wapi_ct_helper:cfg(context, C) @@ -181,9 +170,8 @@ get_report_ok_test(C) -> -spec get_reports_ok_test(config()) -> _. get_reports_ok_test(C) -> - PartyID = ?config(party, C), ParamPartyID = genlib:bsuuid(), - _ = wapi_ct_helper_bouncer:mock_assert_identity_op_ctx(<<"GetReports">>, ?STRING, PartyID, C), + _ = wapi_ct_helper_bouncer:mock_assert_party_op_ctx(<<"GetReports">>, ParamPartyID, C), _ = wapi_ct_helper:mock_services( [ {fistful_report, fun @@ -197,17 +185,13 @@ get_reports_ok_test(C) -> ]}; ('GetReports', _) -> erlang:throw("Unexpected party id") - end}, - {fistful_identity, fun('Get', _) -> {ok, ?IDENTITY(PartyID)} end} + end} ], C ), {ok, _} = call_api( fun swag_client_wallet_reports_api:get_reports/3, #{ - binding => #{ - <<"identityID">> => ?STRING - }, qs_val => #{ <<"partyID">> => ParamPartyID, <<"fromTime">> => ?TIMESTAMP, @@ -218,9 +202,9 @@ get_reports_ok_test(C) -> wapi_ct_helper:cfg(context, C) ). --spec reports_with_wrong_identity_ok_test(config()) -> _. -reports_with_wrong_identity_ok_test(C) -> - IdentityID = <<"WrongIdentity">>, +-spec reports_with_wrong_party_ok_test(config()) -> _. +reports_with_wrong_party_ok_test(C) -> + PartyID = <<"WrongPartyID">>, _ = wapi_ct_helper_bouncer:mock_arbiter(_ = wapi_ct_helper_bouncer:judge_always_forbidden(), C), _ = wapi_ct_helper:mock_services( [ @@ -228,16 +212,15 @@ reports_with_wrong_identity_ok_test(C) -> ('GenerateReport', _) -> {ok, ?REPORT_ID}; ('GetReport', _) -> {ok, ?REPORT}; ('GetReports', _) -> {ok, [?REPORT, ?REPORT, ?REPORT]} - end}, - {fistful_identity, fun('Get', _) -> {throwing, #fistful_IdentityNotFound{}} end} + end} ], C ), ?EMPTY_RESP(401) = call_api( fun swag_client_wallet_reports_api:create_report/3, #{ - binding => #{ - <<"identityID">> => IdentityID + qs_val => #{ + <<"partyID">> => PartyID }, body => #{ <<"reportType">> => <<"withdrawalRegistry">>, @@ -251,8 +234,10 @@ reports_with_wrong_identity_ok_test(C) -> fun swag_client_wallet_reports_api:get_report/3, #{ binding => #{ - <<"identityID">> => IdentityID, <<"reportID">> => ?INTEGER + }, + qs_val => #{ + <<"partyID">> => PartyID } }, wapi_ct_helper:cfg(context, C) @@ -260,10 +245,8 @@ reports_with_wrong_identity_ok_test(C) -> ?EMPTY_RESP(401) = call_api( fun swag_client_wallet_reports_api:get_reports/3, #{ - binding => #{ - <<"identityID">> => IdentityID - }, qs_val => #{ + <<"partyID">> => PartyID, <<"fromTime">> => ?TIMESTAMP, <<"toTime">> => ?TIMESTAMP, <<"type">> => <<"withdrawalRegistry">> diff --git a/test/wapi_stat_tests_SUITE.erl b/test/wapi_stat_tests_SUITE.erl index 8ae43317..4ac9d64d 100644 --- a/test/wapi_stat_tests_SUITE.erl +++ b/test/wapi_stat_tests_SUITE.erl @@ -19,10 +19,6 @@ -export([init/1]). -export([ - list_wallets/1, - list_wallets_party_id_passed/1, - list_wallets_invalid_error/1, - list_wallets_bad_token_error/1, list_withdrawals/1, list_withdrawals_invalid_error/1, list_withdrawals_bad_token_error/1, @@ -31,17 +27,7 @@ list_deposits_bad_token_error/1, list_destinations/1, list_destinations_invalid_error/1, - list_destinations_bad_token_error/1, - list_identities/1, - list_identities_invalid_error/1, - list_identities_bad_token_error/1, - list_deposit_revert/1, - list_deposit_revert_invalid_error/1, - list_deposit_revert_bad_token_error/1, - list_deposit_adjustment_wo_changes_plan/1, - list_deposit_adjustment_with_changes_plan/1, - list_deposit_adjustment_invalid_error/1, - list_deposit_adjustment_bad_token_error/1 + list_destinations_bad_token_error/1 ]). -type test_case_name() :: atom(). @@ -64,10 +50,6 @@ all() -> groups() -> [ {base, [], [ - list_wallets, - list_wallets_party_id_passed, - list_wallets_invalid_error, - list_wallets_bad_token_error, list_withdrawals, list_withdrawals_invalid_error, list_withdrawals_bad_token_error, @@ -76,17 +58,7 @@ groups() -> list_deposits_bad_token_error, list_destinations, list_destinations_invalid_error, - list_destinations_bad_token_error, - list_identities, - list_identities_invalid_error, - list_identities_bad_token_error, - list_deposit_revert, - list_deposit_revert_invalid_error, - list_deposit_revert_bad_token_error, - list_deposit_adjustment_wo_changes_plan, - list_deposit_adjustment_with_changes_plan, - list_deposit_adjustment_invalid_error, - list_deposit_adjustment_bad_token_error + list_destinations_bad_token_error ]} ]. @@ -130,53 +102,6 @@ end_per_testcase(_Name, C) -> %%% Tests --spec list_wallets(config()) -> _. -list_wallets(C) -> - PartyID = wapi_ct_helper:cfg(party, C), - Params = #{ - qs_val => #{ - <<"limit">> => <<"123">> - } - }, - _ = assert_list_wallets_party_id(PartyID, Params, C). - --spec list_wallets_party_id_passed(config()) -> _. -list_wallets_party_id_passed(C) -> - PartyID = genlib:bsuuid(), - Params = #{ - qs_val => #{ - <<"partyID">> => PartyID, - <<"limit">> => <<"123">> - } - }, - _ = assert_list_wallets_party_id(PartyID, Params, C). - -assert_list_wallets_party_id(PartyID, Params, C) -> - _ = wapi_ct_helper_bouncer:mock_assert_party_op_ctx(<<"ListWallets">>, PartyID, C), - _ = wapi_ct_helper:mock_services( - [ - {fistful_stat, fun('GetWallets', _) -> {ok, ?STAT_RESPONSE(?STAT_WALLETS)} end} - ], - C - ), - {ok, _} = call_api( - fun swag_client_wallet_wallets_api:list_wallets/3, - Params, - wapi_ct_helper:cfg(context, C) - ). - --spec list_wallets_invalid_error(config()) -> _. -list_wallets_invalid_error(C) -> - MockFunc = fun('GetWallets', _) -> {throwing, ?STAT_INVALID_EXCEPTION([<<"Error 1">>, <<"Error 2">>])} end, - SwagFunc = fun swag_client_wallet_wallets_api:list_wallets/3, - check_invalid_error(<<"ListWallets">>, MockFunc, SwagFunc, C). - --spec list_wallets_bad_token_error(config()) -> _. -list_wallets_bad_token_error(C) -> - MockFunc = fun('GetWallets', _) -> {throwing, ?STAT_BADTOKEN_EXCEPTION} end, - SwagFunc = fun swag_client_wallet_wallets_api:list_wallets/3, - check_bad_token_error(<<"ListWallets">>, MockFunc, SwagFunc, C). - -spec list_withdrawals(config()) -> _. list_withdrawals(C) -> _ = wapi_ct_helper_bouncer:mock_assert_op_ctx(<<"ListWithdrawals">>, C), @@ -271,124 +196,6 @@ list_destinations_bad_token_error(C) -> SwagFunc = fun swag_client_wallet_withdrawals_api:list_destinations/3, check_bad_token_error(<<"ListDestinations">>, MockFunc, SwagFunc, C). --spec list_identities(config()) -> _. -list_identities(C) -> - _ = wapi_ct_helper_bouncer:mock_assert_op_ctx(<<"ListIdentities">>, C), - _ = wapi_ct_helper:mock_services( - [ - {fistful_stat, fun('GetIdentities', _) -> {ok, ?STAT_RESPONSE(?STAT_IDENTITIES)} end} - ], - C - ), - {ok, _} = call_api( - fun swag_client_wallet_identities_api:list_identities/3, - #{ - qs_val => #{ - <<"limit">> => <<"123">> - } - }, - wapi_ct_helper:cfg(context, C) - ). - --spec list_identities_invalid_error(config()) -> _. -list_identities_invalid_error(C) -> - MockFunc = fun('GetIdentities', _) -> {throwing, ?STAT_INVALID_EXCEPTION([<<"Error 1">>, <<"Error 2">>])} end, - SwagFunc = fun swag_client_wallet_identities_api:list_identities/3, - check_invalid_error(<<"ListIdentities">>, MockFunc, SwagFunc, C). - --spec list_identities_bad_token_error(config()) -> _. -list_identities_bad_token_error(C) -> - MockFunc = fun('GetIdentities', _) -> {throwing, ?STAT_BADTOKEN_EXCEPTION} end, - SwagFunc = fun swag_client_wallet_identities_api:list_identities/3, - check_bad_token_error(<<"ListIdentities">>, MockFunc, SwagFunc, C). - --spec list_deposit_revert(config()) -> _. -list_deposit_revert(Cfg) -> - _ = wapi_ct_helper_bouncer:mock_assert_op_ctx(<<"ListDepositReverts">>, Cfg), - _ = wapi_ct_helper:mock_services( - [ - {fistful_stat, fun('GetDepositReverts', _) -> {ok, ?STAT_RESPONSE(?STAT_DEPOSIT_REVERTS)} end} - ], - Cfg - ), - {ok, _} = call_api( - fun swag_client_wallet_deposits_api:list_deposit_reverts/3, - #{ - qs_val => #{ - <<"limit">> => <<"123">> - } - }, - wapi_ct_helper:cfg(context, Cfg) - ). - --spec list_deposit_revert_invalid_error(config()) -> _. -list_deposit_revert_invalid_error(Cfg) -> - MockFunc = fun('GetDepositReverts', _) -> {throwing, ?STAT_INVALID_EXCEPTION([<<"Error 1">>, <<"Error 2">>])} end, - SwagFunc = fun swag_client_wallet_deposits_api:list_deposit_reverts/3, - check_invalid_error(<<"ListDepositReverts">>, MockFunc, SwagFunc, Cfg). - --spec list_deposit_revert_bad_token_error(config()) -> _. -list_deposit_revert_bad_token_error(Cfg) -> - MockFunc = fun('GetDepositReverts', _) -> {throwing, ?STAT_BADTOKEN_EXCEPTION} end, - SwagFunc = fun swag_client_wallet_deposits_api:list_deposit_reverts/3, - check_bad_token_error(<<"ListDepositReverts">>, MockFunc, SwagFunc, Cfg). - --spec list_deposit_adjustment_wo_changes_plan(config()) -> _. -list_deposit_adjustment_wo_changes_plan(Cfg) -> - _ = wapi_ct_helper_bouncer:mock_assert_op_ctx(<<"ListDepositAdjustments">>, Cfg), - _ = wapi_ct_helper:mock_services( - [ - {fistful_stat, fun('GetDepositAdjustments', _) -> - {ok, ?STAT_RESPONSE(?STAT_DEPOSIT_ADJUSTMENTS_WO_CANGES_PLAN)} - end} - ], - Cfg - ), - {ok, _} = call_api( - fun swag_client_wallet_deposits_api:list_deposit_adjustments/3, - #{ - qs_val => #{ - <<"limit">> => <<"123">> - } - }, - wapi_ct_helper:cfg(context, Cfg) - ). - --spec list_deposit_adjustment_with_changes_plan(config()) -> _. -list_deposit_adjustment_with_changes_plan(Cfg) -> - _ = wapi_ct_helper_bouncer:mock_assert_op_ctx(<<"ListDepositAdjustments">>, Cfg), - _ = wapi_ct_helper:mock_services( - [ - {fistful_stat, fun('GetDepositAdjustments', _) -> - {ok, ?STAT_RESPONSE(?STAT_DEPOSIT_ADJUSTMENTS_WITH_CANGES_PLAN)} - end} - ], - Cfg - ), - {ok, _} = call_api( - fun swag_client_wallet_deposits_api:list_deposit_adjustments/3, - #{ - qs_val => #{ - <<"limit">> => <<"123">> - } - }, - wapi_ct_helper:cfg(context, Cfg) - ). - --spec list_deposit_adjustment_invalid_error(config()) -> _. -list_deposit_adjustment_invalid_error(Cfg) -> - MockFunc = fun('GetDepositAdjustments', _) -> - {throwing, ?STAT_INVALID_EXCEPTION([<<"Error 1">>, <<"Error 2">>])} - end, - SwagFunc = fun swag_client_wallet_deposits_api:list_deposit_adjustments/3, - check_invalid_error(<<"ListDepositAdjustments">>, MockFunc, SwagFunc, Cfg). - --spec list_deposit_adjustment_bad_token_error(config()) -> _. -list_deposit_adjustment_bad_token_error(Cfg) -> - MockFunc = fun('GetDepositAdjustments', _) -> {throwing, ?STAT_BADTOKEN_EXCEPTION} end, - SwagFunc = fun swag_client_wallet_deposits_api:list_deposit_adjustments/3, - check_bad_token_error(<<"ListDepositAdjustments">>, MockFunc, SwagFunc, Cfg). - %% check_invalid_error(OpName, MockFunc, SwagFunc, C) -> diff --git a/test/wapi_tests_SUITE.erl b/test/wapi_tests_SUITE.erl deleted file mode 100644 index 63f93d9d..00000000 --- a/test/wapi_tests_SUITE.erl +++ /dev/null @@ -1,139 +0,0 @@ --module(wapi_tests_SUITE). - --include_lib("common_test/include/ct.hrl"). --include_lib("stdlib/include/assert.hrl"). - --include_lib("wapi_wallet_dummy_data.hrl"). - --export([all/0]). --export([groups/0]). --export([init_per_suite/1]). --export([end_per_suite/1]). --export([init_per_group/2]). --export([end_per_group/2]). --export([init_per_testcase/2]). --export([end_per_testcase/2]). - --export([init/1]). - --export([ - map_schema_violated_error_ok/1, - map_wrong_body_error_ok/1 -]). - --type test_case_name() :: atom(). --type config() :: [{atom(), any()}]. --type group_name() :: atom(). - --behaviour(supervisor). - --spec init([]) -> {ok, {supervisor:sup_flags(), [supervisor:child_spec()]}}. -init([]) -> - {ok, {#{strategy => one_for_all, intensity => 1, period => 1}, []}}. - --spec all() -> [{group, test_case_name()}]. -all() -> - [ - {group, base} - ]. - --spec groups() -> [{group_name(), list(), [test_case_name()]}]. -groups() -> - [ - {base, [], [ - map_schema_violated_error_ok, - map_wrong_body_error_ok - ]} - ]. - -%% -%% starting/stopping -%% --spec init_per_suite(config()) -> config(). -init_per_suite(C) -> - wapi_ct_helper:init_suite(?MODULE, C). - --spec end_per_suite(config()) -> _. -end_per_suite(C) -> - _ = wapi_ct_helper:stop_mocked_service_sup(?config(suite_test_sup, C)), - _ = [application:stop(App) || App <- ?config(apps, C)], - ok. - --spec init_per_group(group_name(), config()) -> config(). -init_per_group(Group, Config) when Group =:= base -> - Party = genlib:bsuuid(), - Config1 = [{party, Party} | Config], - [{context, wapi_ct_helper:get_context(?API_TOKEN)} | Config1]; -init_per_group(_, Config) -> - Config. - --spec end_per_group(group_name(), config()) -> _. -end_per_group(_Group, _C) -> - ok. - --spec init_per_testcase(test_case_name(), config()) -> config(). -init_per_testcase(Name, C) -> - C1 = wapi_ct_helper:makeup_cfg([wapi_ct_helper:test_case_name(Name), wapi_ct_helper:woody_ctx()], C), - [{test_sup, wapi_ct_helper:start_mocked_service_sup(?MODULE)} | C1]. - --spec end_per_testcase(test_case_name(), config()) -> ok. -end_per_testcase(_Name, C) -> - _ = wapi_ct_helper:stop_mocked_service_sup(?config(test_sup, C)), - ok. - -%%% Tests - --spec map_schema_violated_error_ok(config()) -> _. -map_schema_violated_error_ok(C) -> - Context = wapi_ct_helper:cfg(context, C), - Params = #{}, - {Endpoint, PreparedParams, Opts0} = wapi_client_lib:make_request(Context, Params), - Url = swag_client_wallet_utils:get_url(Endpoint, "/wallet/v0/w2w/transfers"), - Headers = maps:to_list(maps:get(header, PreparedParams)), - Body = <<"{}">>, - Opts = Opts0 ++ [with_body], - {ok, 400, _, Error} = hackney:request( - post, - Url, - Headers, - Body, - Opts - ), - ExpectedError = make_mapped_error( - "W2WTransferParameters", "SchemaViolated", ", description: Missing required property: body." - ), - ?assertEqual( - ExpectedError, - Error - ). - --spec map_wrong_body_error_ok(config()) -> _. -map_wrong_body_error_ok(C) -> - Context = wapi_ct_helper:cfg(context, C), - Params = #{}, - {Endpoint, PreparedParams, Opts0} = wapi_client_lib:make_request(Context, Params), - Url = swag_client_wallet_utils:get_url(Endpoint, "/wallet/v0/w2w/transfers"), - Headers = maps:to_list(maps:get(header, PreparedParams)), - LongBinary = - << - "LongBinaryLongBinaryLongBinaryLongBinaryLongBinaryLong\n" - " BinaryLongBinaryLongBinaryLongBinaryLongBinaryLongBinary" - >>, - Body = <<"{", LongBinary/binary, LongBinary/binary, LongBinary/binary, LongBinary/binary, LongBinary/binary, "}">>, - Opts = Opts0 ++ [with_body], - {ok, 400, _, Error} = hackney:request( - post, - Url, - Headers, - Body, - Opts - ), - ExpectedError = make_mapped_error("W2WTransferParameters", "WrongBody", ", description: Invalid json"), - ?assertEqual( - ExpectedError, - Error - ). - -make_mapped_error(Name, Type, Desc) -> - Format = <<"{\"description\":\"Request parameter: ~s, error type: ~s~s\",\"errorType\":\"~s\",\"name\":\"~s\"}">>, - genlib:to_binary(io_lib:format(Format, [Name, Type, Desc, Type, Name])). diff --git a/test/wapi_tests_SUITE_data/jwk.json b/test/wapi_tests_SUITE_data/jwk.json deleted file mode 100644 index d3804153..00000000 --- a/test/wapi_tests_SUITE_data/jwk.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "use": "enc", - "kty": "oct", - "kid": "1", - "alg": "dir", - "k": "M3VKOExvQVdhWUtXekduVGt1eDdrUmtwTTNBSko1a2M" -} \ No newline at end of file diff --git a/test/wapi_tests_SUITE_data/jwk.priv.json b/test/wapi_tests_SUITE_data/jwk.priv.json deleted file mode 100644 index e7d65575..00000000 --- a/test/wapi_tests_SUITE_data/jwk.priv.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "use": "enc", - "kty": "EC", - "kid": "kxdD0orVPGoAxWrqAMTeQ0U5MRoK47uZxWiSJdgo0t0", - "crv": "P-256", - "alg": "ECDH-ES", - "x": "nHi7TCgBwfrPuNTf49bGvJMczk6WZOI-mCKAghbrOlM", - "y": "_8kiXGOIWkfz57m8K5dmTfbYzCJVYHZZZisCfbYicr0", - "d": "i45qDiARZ5qbS_uzeT-CiKnPUe64qHitKaVdAvcN6TI" -} \ No newline at end of file diff --git a/test/wapi_tests_SUITE_data/jwk.publ.json b/test/wapi_tests_SUITE_data/jwk.publ.json deleted file mode 100644 index 00b7002d..00000000 --- a/test/wapi_tests_SUITE_data/jwk.publ.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "use": "enc", - "kty": "EC", - "kid": "kxdD0orVPGoAxWrqAMTeQ0U5MRoK47uZxWiSJdgo0t0", - "crv": "P-256", - "alg": "ECDH-ES", - "x": "nHi7TCgBwfrPuNTf49bGvJMczk6WZOI-mCKAghbrOlM", - "y": "_8kiXGOIWkfz57m8K5dmTfbYzCJVYHZZZisCfbYicr0" -} \ No newline at end of file diff --git a/test/wapi_tests_SUITE_data/private.pem b/test/wapi_tests_SUITE_data/private.pem deleted file mode 100644 index 4e6d12c9..00000000 --- a/test/wapi_tests_SUITE_data/private.pem +++ /dev/null @@ -1,9 +0,0 @@ ------BEGIN RSA PRIVATE KEY----- -MIIBOwIBAAJBAK9fx7qOJT7Aoseu7KKgaLagBh3wvDzg7F/ZMtGbPFikJnnvRWvF -B5oEGbMPblvtF0/fjqfu+eqjP3Z1tUSn7TkCAwEAAQJABUY5KIgr4JZEjwLYxQ9T -9uIbLP1Xe/E7yqoqmBk2GGhSrPY0OeRkYnUVLcP96UPQhF63iuG8VF6uZ7oAPsq+ -gQIhANZy3jSCzPjXYHRU1kRqQzpt2S+OqoEiqQ6YG1HrC/VxAiEA0Vq6JlQK2tOX -37SS00dK0Qog4Qi8dN73GliFQNP18EkCIQC4epSA48zkfJMzQBAbRraSuxDNApPX -BzQbo+pMrEDbYQIgY4AncQgIkLB4Qk5kah48JNYXglzQlQtTjiX8Ty9ueGECIQCM -GD3UbQKiA0gf5plBA24I4wFVKxxa4wXbW/7SfP6XmQ== ------END RSA PRIVATE KEY----- diff --git a/test/wapi_w2w_tests_SUITE.erl b/test/wapi_w2w_tests_SUITE.erl deleted file mode 100644 index 87a05c0b..00000000 --- a/test/wapi_w2w_tests_SUITE.erl +++ /dev/null @@ -1,323 +0,0 @@ --module(wapi_w2w_tests_SUITE). - --include_lib("stdlib/include/assert.hrl"). --include_lib("common_test/include/ct.hrl"). - --include_lib("wapi_wallet_dummy_data.hrl"). - --include_lib("fistful_proto/include/fistful_fistful_base_thrift.hrl"). --include_lib("fistful_proto/include/fistful_fistful_thrift.hrl"). --include_lib("fistful_proto/include/fistful_account_thrift.hrl"). --include_lib("fistful_proto/include/fistful_cashflow_thrift.hrl"). --include_lib("fistful_proto/include/fistful_w2w_transfer_thrift.hrl"). --include_lib("fistful_proto/include/fistful_w2w_status_thrift.hrl"). --include_lib("fistful_proto/include/fistful_wallet_thrift.hrl"). - --export([all/0]). --export([groups/0]). --export([init_per_suite/1]). --export([end_per_suite/1]). --export([init_per_group/2]). --export([end_per_group/2]). --export([init_per_testcase/2]). --export([end_per_testcase/2]). - --export([init/1]). - --export([ - create_ok_test/1, - create_fail_unauthorized_wallet_test/1, - create_fail_wallet_notfound_test/1, - create_fail_invalid_operation_amount_test/1, - create_fail_forbidden_operation_currency_test/1, - create_fail_inconsistent_w2w_transfer_currency_test/1, - create_fail_wallet_inaccessible_test/1, - get_ok_test/1, - get_fail_w2w_notfound_test/1, - check_unknown_w2w_id/1 -]). - --define(EMPTY_RESP(Code), {error, {Code, #{}}}). - --type test_case_name() :: atom(). --type config() :: [{atom(), any()}]. --type group_name() :: atom(). - --behaviour(supervisor). - --spec init([]) -> {ok, {supervisor:sup_flags(), [supervisor:child_spec()]}}. -init([]) -> - {ok, {#{strategy => one_for_all, intensity => 1, period => 1}, []}}. - --spec all() -> [{group, test_case_name()}]. -all() -> - [ - {group, base} - ]. - --spec groups() -> [{group_name(), list(), [test_case_name()]}]. -groups() -> - [ - {base, [], [ - create_ok_test, - create_fail_unauthorized_wallet_test, - create_fail_wallet_notfound_test, - create_fail_invalid_operation_amount_test, - create_fail_forbidden_operation_currency_test, - create_fail_inconsistent_w2w_transfer_currency_test, - create_fail_wallet_inaccessible_test, - get_ok_test, - get_fail_w2w_notfound_test, - check_unknown_w2w_id - ]} - ]. - -%% -%% starting/stopping -%% --spec init_per_suite(config()) -> config(). -init_per_suite(C) -> - wapi_ct_helper:init_suite(?MODULE, C). - --spec end_per_suite(config()) -> _. -end_per_suite(C) -> - _ = wapi_ct_helper:stop_mocked_service_sup(?config(suite_test_sup, C)), - _ = [application:stop(App) || App <- ?config(apps, C)], - ok. - --spec init_per_group(group_name(), config()) -> config(). -init_per_group(Group, Config) when Group =:= base -> - Party = genlib:bsuuid(), - Config1 = [{party, Party} | Config], - GroupSup = wapi_ct_helper:start_mocked_service_sup(?MODULE), - _ = wapi_ct_helper_token_keeper:mock_user_session_token(Party, GroupSup), - [{group_test_sup, GroupSup}, {context, wapi_ct_helper:get_context(?API_TOKEN)} | Config1]; -init_per_group(_, Config) -> - Config. - --spec end_per_group(group_name(), config()) -> _. -end_per_group(_Group, C) -> - _ = wapi_ct_helper:stop_mocked_service_sup(?config(group_test_sup, C)), - ok. - --spec init_per_testcase(test_case_name(), config()) -> config(). -init_per_testcase(Name, C) -> - C1 = wapi_ct_helper:makeup_cfg([wapi_ct_helper:test_case_name(Name), wapi_ct_helper:woody_ctx()], C), - [{test_sup, wapi_ct_helper:start_mocked_service_sup(?MODULE)} | C1]. - --spec end_per_testcase(test_case_name(), config()) -> ok. -end_per_testcase(_Name, C) -> - _ = wapi_ct_helper:stop_mocked_service_sup(?config(test_sup, C)), - ok. - -%%% Tests - --spec create_ok_test(config()) -> _. -create_ok_test(C) -> - PartyID = ?config(party, C), - _ = create_w2_w_transfer_start_mocks(C, fun() -> {ok, ?W2W_TRANSFER(PartyID)} end), - {ok, _} = create_w2_w_transfer_call_api(C). - --spec create_fail_unauthorized_wallet_test(config()) -> _. -create_fail_unauthorized_wallet_test(C) -> - PartyID = ?config(party, C), - _ = wapi_ct_helper_bouncer:mock_arbiter(wapi_ct_helper_bouncer:judge_always_forbidden(), C), - _ = wapi_ct_helper:mock_services( - [ - {bender, fun('GenerateID', _) -> {ok, ?GENERATE_ID_RESULT} end}, - {fistful_wallet, fun - ('GetContext', _) -> {ok, ?DEFAULT_CONTEXT(<<"someotherparty">>)}; - ('Get', _) -> {ok, ?WALLET(<<"someotherparty">>)} - end}, - {fistful_w2w_transfer, fun('Create', _) -> {ok, ?W2W_TRANSFER(PartyID)} end} - ], - C - ), - ?assertEqual( - ?EMPTY_RESP(401), - create_w2_w_transfer_call_api(C) - ). - --spec create_fail_wallet_notfound_test(config()) -> _. -create_fail_wallet_notfound_test(C) -> - WalletNotFoundException = #fistful_WalletNotFound{ - id = ?STRING - }, - _ = create_w2_w_transfer_start_mocks(C, fun() -> {throwing, WalletNotFoundException} end), - ?assertEqual( - {error, {422, #{<<"message">> => <<"No such wallet sender">>}}}, - create_w2_w_transfer_call_api(C) - ). - --spec create_fail_invalid_operation_amount_test(config()) -> _. -create_fail_invalid_operation_amount_test(C) -> - InvalidOperationAmountException = #fistful_InvalidOperationAmount{ - amount = ?CASH - }, - _ = create_w2_w_transfer_start_mocks(C, fun() -> {throwing, InvalidOperationAmountException} end), - ?assertEqual( - {error, {422, #{<<"message">> => <<"Bad transfer amount">>}}}, - create_w2_w_transfer_call_api(C) - ). - --spec create_fail_forbidden_operation_currency_test(config()) -> _. -create_fail_forbidden_operation_currency_test(C) -> - ForbiddenOperationCurrencyException = #fistful_ForbiddenOperationCurrency{ - currency = #'fistful_base_CurrencyRef'{symbolic_code = ?USD}, - allowed_currencies = [ - #'fistful_base_CurrencyRef'{symbolic_code = ?RUB} - ] - }, - _ = create_w2_w_transfer_start_mocks(C, fun() -> {throwing, ForbiddenOperationCurrencyException} end), - ?assertEqual( - {error, {422, #{<<"message">> => <<"Currency not allowed">>}}}, - create_w2_w_transfer_call_api(C) - ). - --spec create_fail_inconsistent_w2w_transfer_currency_test(config()) -> _. -create_fail_inconsistent_w2w_transfer_currency_test(C) -> - InconsistentW2WCurrencyException = #w2w_transfer_InconsistentW2WTransferCurrency{ - w2w_transfer_currency = #'fistful_base_CurrencyRef'{ - symbolic_code = ?USD - }, - wallet_from_currency = #'fistful_base_CurrencyRef'{ - symbolic_code = ?RUB - }, - wallet_to_currency = #'fistful_base_CurrencyRef'{ - symbolic_code = ?RUB - } - }, - _ = create_w2_w_transfer_start_mocks(C, fun() -> {throwing, InconsistentW2WCurrencyException} end), - ?assertEqual( - {error, {422, #{<<"message">> => <<"Inconsistent currency">>}}}, - create_w2_w_transfer_call_api(C) - ). - --spec create_fail_wallet_inaccessible_test(config()) -> _. -create_fail_wallet_inaccessible_test(C) -> - WalletInaccessibleException = #fistful_WalletInaccessible{ - id = ?STRING - }, - _ = create_w2_w_transfer_start_mocks(C, fun() -> {throwing, WalletInaccessibleException} end), - ?assertEqual( - {error, {422, #{<<"message">> => <<"Wallet inaccessible">>}}}, - create_w2_w_transfer_call_api(C) - ). - --spec get_ok_test(config()) -> _. -get_ok_test(C) -> - PartyID = ?config(party, C), - _ = wapi_ct_helper_bouncer:mock_assert_w2w_transfer_op_ctx(<<"GetW2WTransfer">>, ?STRING, PartyID, C), - _ = get_w2_w_transfer_start_mocks(C, fun() -> {ok, ?W2W_TRANSFER(PartyID)} end), - {ok, _} = get_w2_w_transfer_call_api(C). - --spec get_fail_w2w_notfound_test(config()) -> _. -get_fail_w2w_notfound_test(C) -> - _ = wapi_ct_helper_bouncer:mock_arbiter(wapi_ct_helper_bouncer:judge_always_forbidden(), C), - _ = get_w2_w_transfer_start_mocks(C, fun() -> {throwing, #fistful_W2WNotFound{}} end), - ?assertMatch( - {error, {404, #{}}}, - get_w2_w_transfer_call_api(C) - ). - --spec check_unknown_w2w_id(config()) -> _. -check_unknown_w2w_id(C) -> - PartyID = ?config(party, C), - _ = wapi_ct_helper_bouncer:mock_assert_wallet_op_ctx(<<"CreateW2WTransfer">>, ?STRING, PartyID, C), - CounterRef = counters:new(1, []), - ID0 = <<"Test0">>, - ID1 = <<"Test1">>, - W2WTransfer0 = ?W2W_TRANSFER(PartyID), - W2WTransfer1 = W2WTransfer0#w2w_transfer_W2WTransferState{id = ID1}, - W2WTransfer2 = W2WTransfer1#w2w_transfer_W2WTransferState{id = ID0, wallet_from_id = ?STRING2}, - _ = wapi_ct_helper:mock_services( - [ - {bender, fun('GenerateID', _) -> - CID = counters:get(CounterRef, 1), - BinaryCID = erlang:integer_to_binary(CID), - ok = counters:add(CounterRef, 1, 1), - {ok, ?GENERATE_ID_RESULT(<<"Test", BinaryCID/binary>>)} - end}, - {fistful_wallet, fun - ('GetContext', _) -> {ok, ?DEFAULT_CONTEXT(PartyID)}; - ('Get', _) -> {ok, ?WALLET(PartyID)} - end}, - {fistful_w2w_transfer, fun - ('Create', _) -> - {ok, W2WTransfer1}; - ('Get', {WID, _}) when WID =:= ID0 -> - {ok, W2WTransfer2}; - ('Get', {WID, _}) when WID =:= ID1 -> - {throwing, #fistful_W2WNotFound{}} - end} - ], - C - ), - {ok, #{ - <<"id">> := ID1 - }} = create_w2_w_transfer_call_api(C). - -%% - --spec call_api(function(), map(), wapi_client_lib:context()) -> {ok, term()} | {error, term()}. -call_api(F, Params, Context) -> - {Url, PreparedParams, Opts} = wapi_client_lib:make_request(Context, Params), - Response = F(Url, PreparedParams, Opts), - wapi_client_lib:handle_response(Response). - -create_w2_w_transfer_call_api(C) -> - call_api( - fun swag_client_wallet_w2_w_api:create_w2_w_transfer/3, - #{ - body => #{ - <<"sender">> => ?STRING, - <<"receiver">> => ?STRING, - <<"body">> => #{ - <<"amount">> => ?INTEGER, - <<"currency">> => ?RUB - } - } - }, - wapi_ct_helper:cfg(context, C) - ). - -get_w2_w_transfer_call_api(C) -> - call_api( - fun swag_client_wallet_w2_w_api:get_w2_w_transfer/3, - #{ - binding => #{ - <<"w2wTransferID">> => ?STRING - } - }, - wapi_ct_helper:cfg(context, C) - ). - -create_w2_w_transfer_start_mocks(C, CreateResultFun) -> - PartyID = ?config(party, C), - _ = wapi_ct_helper_bouncer:mock_assert_wallet_op_ctx(<<"CreateW2WTransfer">>, ?STRING, PartyID, C), - wapi_ct_helper:mock_services( - [ - {bender, fun('GenerateID', _) -> {ok, ?GENERATE_ID_RESULT} end}, - {fistful_wallet, fun - ('GetContext', _) -> {ok, ?DEFAULT_CONTEXT(PartyID)}; - ('Get', _) -> {ok, ?WALLET(PartyID)} - end}, - {fistful_w2w_transfer, fun - ('Create', _) -> CreateResultFun(); - ('Get', _) -> {throwing, #fistful_W2WNotFound{}} - end} - ], - C - ). - -get_w2_w_transfer_start_mocks(C, GetResultFun) -> - PartyID = ?config(party, C), - wapi_ct_helper:mock_services( - [ - {fistful_w2w_transfer, fun - ('GetContext', _) -> {ok, ?DEFAULT_CONTEXT(PartyID)}; - ('Get', _) -> GetResultFun() - end} - ], - C - ). diff --git a/test/wapi_w2w_tests_SUITE_data/jwk.json b/test/wapi_w2w_tests_SUITE_data/jwk.json deleted file mode 100644 index d3804153..00000000 --- a/test/wapi_w2w_tests_SUITE_data/jwk.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "use": "enc", - "kty": "oct", - "kid": "1", - "alg": "dir", - "k": "M3VKOExvQVdhWUtXekduVGt1eDdrUmtwTTNBSko1a2M" -} \ No newline at end of file diff --git a/test/wapi_w2w_tests_SUITE_data/jwk.priv.json b/test/wapi_w2w_tests_SUITE_data/jwk.priv.json deleted file mode 100644 index e7d65575..00000000 --- a/test/wapi_w2w_tests_SUITE_data/jwk.priv.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "use": "enc", - "kty": "EC", - "kid": "kxdD0orVPGoAxWrqAMTeQ0U5MRoK47uZxWiSJdgo0t0", - "crv": "P-256", - "alg": "ECDH-ES", - "x": "nHi7TCgBwfrPuNTf49bGvJMczk6WZOI-mCKAghbrOlM", - "y": "_8kiXGOIWkfz57m8K5dmTfbYzCJVYHZZZisCfbYicr0", - "d": "i45qDiARZ5qbS_uzeT-CiKnPUe64qHitKaVdAvcN6TI" -} \ No newline at end of file diff --git a/test/wapi_w2w_tests_SUITE_data/jwk.publ.json b/test/wapi_w2w_tests_SUITE_data/jwk.publ.json deleted file mode 100644 index 00b7002d..00000000 --- a/test/wapi_w2w_tests_SUITE_data/jwk.publ.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "use": "enc", - "kty": "EC", - "kid": "kxdD0orVPGoAxWrqAMTeQ0U5MRoK47uZxWiSJdgo0t0", - "crv": "P-256", - "alg": "ECDH-ES", - "x": "nHi7TCgBwfrPuNTf49bGvJMczk6WZOI-mCKAghbrOlM", - "y": "_8kiXGOIWkfz57m8K5dmTfbYzCJVYHZZZisCfbYicr0" -} \ No newline at end of file diff --git a/test/wapi_w2w_tests_SUITE_data/private.pem b/test/wapi_w2w_tests_SUITE_data/private.pem deleted file mode 100644 index 4e6d12c9..00000000 --- a/test/wapi_w2w_tests_SUITE_data/private.pem +++ /dev/null @@ -1,9 +0,0 @@ ------BEGIN RSA PRIVATE KEY----- -MIIBOwIBAAJBAK9fx7qOJT7Aoseu7KKgaLagBh3wvDzg7F/ZMtGbPFikJnnvRWvF -B5oEGbMPblvtF0/fjqfu+eqjP3Z1tUSn7TkCAwEAAQJABUY5KIgr4JZEjwLYxQ9T -9uIbLP1Xe/E7yqoqmBk2GGhSrPY0OeRkYnUVLcP96UPQhF63iuG8VF6uZ7oAPsq+ -gQIhANZy3jSCzPjXYHRU1kRqQzpt2S+OqoEiqQ6YG1HrC/VxAiEA0Vq6JlQK2tOX -37SS00dK0Qog4Qi8dN73GliFQNP18EkCIQC4epSA48zkfJMzQBAbRraSuxDNApPX -BzQbo+pMrEDbYQIgY4AncQgIkLB4Qk5kah48JNYXglzQlQtTjiX8Ty9ueGECIQCM -GD3UbQKiA0gf5plBA24I4wFVKxxa4wXbW/7SfP6XmQ== ------END RSA PRIVATE KEY----- diff --git a/test/wapi_wallet_dummy_data.hrl b/test/wapi_wallet_dummy_data.hrl index b6c0a496..d767bfb4 100644 --- a/test/wapi_wallet_dummy_data.hrl +++ b/test/wapi_wallet_dummy_data.hrl @@ -48,12 +48,6 @@ } }). --define(PROVIDER, #provider_Provider{ - id = ?STRING, - name = ?STRING, - residences = [?RESIDENCE_RUS, ?RESIDENCE_DEU] -}). - -define(GET_INTERNAL_ID_RESULT, { 'bender_GetInternalIDResult', ?STRING, @@ -104,7 +98,9 @@ adjustments = [], metadata = ?DEFAULT_METADATA(), context = ?DEFAULT_CONTEXT(PartyID), - quote = ?WITHDRAWAL_QUOTE_STATE + quote = ?WITHDRAWAL_QUOTE_STATE, + party_id = PartyID, + domain_revision = 123 }). -define(WITHDRAWAL_QUOTE_STATE, #wthd_QuoteState{ @@ -121,7 +117,6 @@ expires_on = ?TIMESTAMP, operation_timestamp = ?TIMESTAMP, domain_revision = 123, - party_revision = 123, route = #wthd_Route{ provider_id = 123, terminal_id = 123 @@ -140,12 +135,12 @@ -define(BLOCKING, unblocked). -define(ACCOUNT, #account_Account{ - id = ?STRING, - identity = ?STRING, + party_id = ?STRING, + realm = live, currency = #'fistful_base_CurrencyRef'{ symbolic_code = ?RUB }, - accounter_account_id = ?INTEGER + account_id = ?INTEGER }). -define(ACCOUNT_BALANCE, #account_AccountBalance{ @@ -204,37 +199,13 @@ -define(DESTINATION(PartyID, Resource), #destination_DestinationState{ id = ?STRING, name = ?STRING, - status = ?DESTINATION_STATUS, account = ?ACCOUNT, resource = Resource, external_id = ?STRING, created_at = ?TIMESTAMP, - context = ?DEFAULT_CONTEXT(PartyID) -}). - --define(WALLET(PartyID), #wallet_WalletState{ - id = ?STRING, - name = ?STRING, - blocking = ?BLOCKING, - account = ?ACCOUNT, - external_id = ?STRING, - created_at = ?TIMESTAMP, - metadata = ?DEFAULT_METADATA(), - context = ?DEFAULT_CONTEXT(PartyID) -}). - --define(IDENTITY(PartyID), - ?IDENTITY(PartyID, ?DEFAULT_CONTEXT(PartyID)) -). - --define(IDENTITY(PartyID, Context), #identity_IdentityState{ - id = ?STRING, - name = ?STRING, - party_id = ?STRING, - provider_id = ?STRING, - contract_id = ?STRING, - metadata = ?DEFAULT_METADATA(), - context = Context + context = ?DEFAULT_CONTEXT(PartyID), + party_id = PartyID, + realm = live }). -define(WITHDRAWAL_METHOD_BANK_CARD(ID), @@ -261,24 +232,12 @@ -define(STAT_RESPONSE(Data), #stat_StatResponse{data = Data}). --define(STAT_WALLETS, - {wallets, [ - #stat_StatWallet{ - id = ?STRING, - identity_id = ?STRING, - name = ?STRING, - created_at = ?TIMESTAMP, - currency_symbolic_code = ?RUB - } - ]} -). - -define(STAT_WITHDRAWALS, {withdrawals, [ #stat_StatWithdrawal{ id = ?STRING, created_at = ?TIMESTAMP, - identity_id = ?STRING, + party_id = ?STRING, source_id = ?STRING, destination_id = ?STRING, external_id = ?STRING, @@ -295,7 +254,7 @@ #stat_StatDeposit{ id = ?STRING, created_at = ?TIMESTAMP, - identity_id = ?STRING, + party_id = ?STRING, source_id = ?STRING, destination_id = ?STRING, amount = ?INTEGER, @@ -311,106 +270,29 @@ {destinations, [ #stat_StatDestination{ id = ?STRING, + party_id = ?STRING, + realm = live, name = ?STRING, created_at = ?TIMESTAMP, is_blocked = ?BOOLEAN, - identity = ?STRING, currency_symbolic_code = ?RUB, resource = {bank_card, ?BANK_CARD}, - external_id = ?STRING, - status = {unauthorized, #stat_Unauthorized{}} + external_id = ?STRING }, #stat_StatDestination{ id = ?STRING, + party_id = ?STRING, + realm = live, name = ?STRING, created_at = ?TIMESTAMP, is_blocked = ?BOOLEAN, - identity = ?STRING, currency_symbolic_code = ?RUB, resource = {digital_wallet, ?DIGITAL_WALLET}, - external_id = ?STRING, - status = {unauthorized, #stat_Unauthorized{}} - } - ]} -). - --define(STAT_IDENTITIES, - {identities, [ - #stat_StatIdentity{ - id = ?STRING, - name = ?STRING, - created_at = ?TIMESTAMP, - provider = ?STRING, - is_blocked = ?BOOLEAN, external_id = ?STRING } ]} ). --define(STAT_DEPOSIT_REVERTS, - {deposit_reverts, [ - #stat_StatDepositRevert{ - id = ?STRING, - wallet_id = ?STRING, - source_id = ?STRING, - status = {succeeded, #stat_DepositRevertSucceeded{}}, - body = ?CASH, - created_at = ?TIMESTAMP, - domain_revision = ?INTEGER, - party_revision = ?INTEGER, - reason = ?STRING, - external_id = ?STRING, - deposit_id = ?STRING - } - ]} -). - --define(STAT_DEPOSIT_ADJUSTMENTS_WO_CANGES_PLAN, - ?STAT_DEPOSIT_ADJUSTMENTS(#stat_DepositAdjustmentChangesPlan{}) -). - --define(STAT_DEPOSIT_ADJUSTMENTS_WITH_CANGES_PLAN, - ?STAT_DEPOSIT_ADJUSTMENTS( - #stat_DepositAdjustmentChangesPlan{ - new_cash = #stat_DepositAdjustmentCashChangePlan{amount = ?CASH, fee = ?CASH, provider_fee = ?CASH}, - new_status = #stat_DepositAdjustmentStatusChangePlan{ - new_status = {succeeded, #stat_DepositAdjustmentStatusChangePlanSucceeded{}} - } - } - ) -). - --define(STAT_DEPOSIT_ADJUSTMENTS(ChangesPlan), - {deposit_adjustments, [ - #stat_StatDepositAdjustment{ - id = ?STRING, - status = {succeeded, #stat_DepositAdjustmentSucceeded{}}, - changes_plan = ChangesPlan, - created_at = ?TIMESTAMP, - domain_revision = ?INTEGER, - party_revision = ?INTEGER, - external_id = ?STRING, - operation_timestamp = ?TIMESTAMP, - deposit_id = ?STRING - } - ]} -). - --define(IDENT_DOC, - {russian_domestic_passport, #'identdocstore_RussianDomesticPassport'{ - issuer = ?STRING, - issuer_code = ?STRING, - issued_at = ?TIMESTAMP, - birth_date = ?TIMESTAMP, - birth_place = ?STRING, - series = ?STRING, - number = ?STRING, - first_name = ?STRING, - family_name = ?STRING, - patronymic = ?STRING - }} -). - -define(REPORT_ID, ?INTEGER). -define(REPORT_EXT(Status, FilesList), #reports_Report{ @@ -439,15 +321,13 @@ -define(DESTINATION_EVENT_FILTER, #webhooker_EventFilter{ types = ordsets:from_list([ - {destination, {created, #webhooker_DestinationCreated{}}}, - {destination, {unauthorized, #webhooker_DestinationUnauthorized{}}}, - {destination, {authorized, #webhooker_DestinationAuthorized{}}} + {destination, {created, #webhooker_DestinationCreated{}}} ]) }). -define(WEBHOOK_WITH_WALLET(EventFilter, WalletID), #webhooker_Webhook{ id = ?INTEGER, - identity_id = ?STRING, + party_id = ?STRING, wallet_id = WalletID, event_filter = EventFilter, url = ?URL, @@ -457,22 +337,4 @@ -define(WEBHOOK(EventFilter), ?WEBHOOK_WITH_WALLET(EventFilter, undefined)). --define(W2W_TRANSFER(PartyID), #w2w_transfer_W2WTransferState{ - id = ?STRING, - wallet_from_id = ?STRING, - wallet_to_id = ?STRING, - body = ?CASH, - created_at = ?TIMESTAMP, - domain_revision = ?INTEGER, - party_revision = ?INTEGER, - status = {pending, #w2w_status_Pending{}}, - external_id = ?STRING, - metadata = ?DEFAULT_METADATA(), - context = ?DEFAULT_CONTEXT(PartyID), - effective_final_cash_flow = #cashflow_FinalCashFlow{ - postings = [] - }, - adjustments = [] -}). - -define(FEES, #'fistful_base_Fees'{fees = #{operation_amount => ?CASH}}). diff --git a/test/wapi_wallet_tests_SUITE.erl b/test/wapi_wallet_tests_SUITE.erl deleted file mode 100644 index 311eabcb..00000000 --- a/test/wapi_wallet_tests_SUITE.erl +++ /dev/null @@ -1,359 +0,0 @@ --module(wapi_wallet_tests_SUITE). - --include_lib("stdlib/include/assert.hrl"). --include_lib("common_test/include/ct.hrl"). - --include_lib("wapi_wallet_dummy_data.hrl"). - --include_lib("fistful_proto/include/fistful_fistful_base_thrift.hrl"). --include_lib("fistful_proto/include/fistful_fistful_thrift.hrl"). --include_lib("fistful_proto/include/fistful_account_thrift.hrl"). --include_lib("fistful_proto/include/fistful_identity_thrift.hrl"). --include_lib("fistful_proto/include/fistful_wallet_thrift.hrl"). - --export([all/0]). --export([groups/0]). --export([init_per_suite/1]). --export([end_per_suite/1]). --export([init_per_group/2]). --export([end_per_group/2]). --export([init_per_testcase/2]). --export([end_per_testcase/2]). - --export([init/1]). - --export([ - create_ok/1, - create_fail_identity_notfound/1, - create_fail_currency_notfound/1, - create_fail_party_inaccessible/1, - get_ok/1, - get_fail_wallet_notfound/1, - get_by_external_id_ok/1, - get_account_ok/1, - get_account_fail_get_context_wallet_notfound/1, - get_account_fail_get_accountbalance_wallet_notfound/1, - check_unknown_wallet_id/1 -]). - --define(EMPTY_RESP(Code), {error, {Code, #{}}}). - --type test_case_name() :: atom(). --type config() :: [{atom(), any()}]. --type group_name() :: atom(). - --behaviour(supervisor). - --spec init([]) -> {ok, {supervisor:sup_flags(), [supervisor:child_spec()]}}. -init([]) -> - {ok, {#{strategy => one_for_all, intensity => 1, period => 1}, []}}. - --spec all() -> [{group, test_case_name()}]. -all() -> - [ - {group, base} - ]. - --spec groups() -> [{group_name(), list(), [test_case_name()]}]. -groups() -> - [ - {base, [], [ - create_ok, - create_fail_identity_notfound, - create_fail_currency_notfound, - create_fail_party_inaccessible, - get_ok, - get_fail_wallet_notfound, - get_by_external_id_ok, - get_account_ok, - get_account_fail_get_context_wallet_notfound, - get_account_fail_get_accountbalance_wallet_notfound, - check_unknown_wallet_id - ]} - ]. - -%% -%% starting/stopping -%% --spec init_per_suite(config()) -> config(). -init_per_suite(C) -> - wapi_ct_helper:init_suite(?MODULE, C). - --spec end_per_suite(config()) -> _. -end_per_suite(C) -> - _ = wapi_ct_helper:stop_mocked_service_sup(?config(suite_test_sup, C)), - _ = [application:stop(App) || App <- ?config(apps, C)], - ok. - --spec init_per_group(group_name(), config()) -> config(). -init_per_group(Group, Config) when Group =:= base -> - Party = genlib:bsuuid(), - Config1 = [{party, Party} | Config], - GroupSup = wapi_ct_helper:start_mocked_service_sup(?MODULE), - _ = wapi_ct_helper_token_keeper:mock_user_session_token(Party, GroupSup), - [{group_test_sup, GroupSup}, {context, wapi_ct_helper:get_context(?API_TOKEN)} | Config1]; -init_per_group(_, Config) -> - Config. - --spec end_per_group(group_name(), config()) -> _. -end_per_group(_Group, C) -> - _ = wapi_ct_helper:stop_mocked_service_sup(?config(group_test_sup, C)), - ok. - --spec init_per_testcase(test_case_name(), config()) -> config(). -init_per_testcase(Name, C) -> - C1 = wapi_ct_helper:makeup_cfg([wapi_ct_helper:test_case_name(Name), wapi_ct_helper:woody_ctx()], C), - [{test_sup, wapi_ct_helper:start_mocked_service_sup(?MODULE)} | C1]. - --spec end_per_testcase(test_case_name(), config()) -> ok. -end_per_testcase(_Name, C) -> - _ = wapi_ct_helper:stop_mocked_service_sup(?config(test_sup, C)), - ok. - -%%% Tests - --spec create_ok(config()) -> _. -create_ok(C) -> - PartyID = ?config(party, C), - _ = create_wallet_start_mocks(C, fun() -> {ok, ?WALLET(PartyID)} end), - {ok, _} = create_wallet_call_api(C). - --spec create_fail_identity_notfound(config()) -> _. -create_fail_identity_notfound(C) -> - _ = create_wallet_start_mocks(C, fun() -> {throwing, #fistful_IdentityNotFound{}} end), - ?assertEqual( - {error, {422, #{<<"message">> => <<"No such identity">>}}}, - create_wallet_call_api(C) - ). - --spec create_fail_currency_notfound(config()) -> _. -create_fail_currency_notfound(C) -> - _ = create_wallet_start_mocks(C, fun() -> {throwing, #fistful_CurrencyNotFound{}} end), - ?assertEqual( - {error, {422, #{<<"message">> => <<"Currency not supported">>}}}, - create_wallet_call_api(C) - ). - --spec create_fail_party_inaccessible(config()) -> _. -create_fail_party_inaccessible(C) -> - _ = create_wallet_start_mocks(C, fun() -> {throwing, #fistful_PartyInaccessible{}} end), - ?assertEqual( - {error, {422, #{<<"message">> => <<"Identity inaccessible">>}}}, - create_wallet_call_api(C) - ). - --spec get_ok(config()) -> _. -get_ok(C) -> - PartyID = ?config(party, C), - _ = get_wallet_start_mocks(C, fun() -> {ok, ?WALLET(PartyID)} end), - {ok, _} = get_wallet_call_api(C). - --spec get_fail_wallet_notfound(config()) -> _. -get_fail_wallet_notfound(C) -> - _ = wapi_ct_helper:mock_services( - [ - {fistful_wallet, fun - % Чтобы тест не упал на авторизации нужно, чтобы были оба мока - ('GetContext', _) -> {throwing, #fistful_WalletNotFound{}}; - ('Get', _) -> {throwing, #fistful_WalletNotFound{}} - end} - ], - C - ), - _ = wapi_ct_helper_bouncer:mock_arbiter(wapi_ct_helper_bouncer:judge_always_forbidden(), C), - ?assertEqual( - {error, {404, #{}}}, - get_wallet_call_api(C) - ). - --spec get_by_external_id_ok(config()) -> _. -get_by_external_id_ok(C) -> - PartyID = ?config(party, C), - _ = wapi_ct_helper_bouncer:mock_assert_wallet_op_ctx(<<"GetWalletByExternalID">>, ?STRING, PartyID, C), - _ = wapi_ct_helper:mock_services( - [ - {bender, fun('GetInternalID', _) -> {ok, ?GET_INTERNAL_ID_RESULT} end}, - {fistful_wallet, fun - ('GetContext', _) -> {ok, ?DEFAULT_CONTEXT(PartyID)}; - ('Get', _) -> {ok, ?WALLET(PartyID)} - end} - ], - C - ), - {ok, _} = call_api( - fun swag_client_wallet_wallets_api:get_wallet_by_external_id/3, - #{ - qs_val => #{ - <<"externalID">> => ?STRING - } - }, - wapi_ct_helper:cfg(context, C) - ). - --spec get_account_ok(config()) -> _. -get_account_ok(C) -> - PartyID = ?config(party, C), - _ = wapi_ct_helper_bouncer:mock_assert_wallet_op_ctx(<<"GetWalletAccount">>, ?STRING, PartyID, C), - _ = wapi_ct_helper:mock_services( - [ - {fistful_wallet, fun - ('GetContext', _) -> {ok, ?DEFAULT_CONTEXT(PartyID)}; - ('Get', _) -> {ok, ?WALLET(PartyID)}; - ('GetAccountBalance', _) -> {ok, ?ACCOUNT_BALANCE} - end} - ], - C - ), - {ok, _} = get_account_call_api(C). - --spec get_account_fail_get_context_wallet_notfound(config()) -> _. -get_account_fail_get_context_wallet_notfound(C) -> - _ = wapi_ct_helper_bouncer:mock_arbiter(wapi_ct_helper_bouncer:judge_always_forbidden(), C), - _ = wapi_ct_helper:mock_services( - [ - {fistful_wallet, fun - % Чтобы тест не упал на авторизации нужно, чтобы были оба мока - ('GetContext', _) -> {throwing, #fistful_WalletNotFound{}}; - ('Get', _) -> {throwing, #fistful_WalletNotFound{}}; - ('GetAccountBalance', _) -> {ok, ?ACCOUNT_BALANCE} - end} - ], - C - ), - ?assertEqual( - ?EMPTY_RESP(401), - get_account_call_api(C) - ). - --spec get_account_fail_get_accountbalance_wallet_notfound(config()) -> _. -get_account_fail_get_accountbalance_wallet_notfound(C) -> - PartyID = ?config(party, C), - _ = wapi_ct_helper_bouncer:mock_assert_wallet_op_ctx(<<"GetWalletAccount">>, ?STRING, PartyID, C), - _ = wapi_ct_helper:mock_services( - [ - {fistful_wallet, fun - ('GetContext', _) -> {ok, ?DEFAULT_CONTEXT(PartyID)}; - ('Get', _) -> {ok, ?WALLET(PartyID)}; - ('GetAccountBalance', _) -> {throwing, #fistful_WalletNotFound{}} - end} - ], - C - ), - ?assertEqual( - {error, {404, #{}}}, - get_account_call_api(C) - ). - --spec check_unknown_wallet_id(config()) -> _. -check_unknown_wallet_id(C) -> - PartyID = ?config(party, C), - _ = wapi_ct_helper_bouncer:mock_assert_identity_op_ctx(<<"CreateWallet">>, ?STRING, PartyID, C), - CounterRef = counters:new(1, []), - ID0 = <<"Test0">>, - ID1 = <<"Test1">>, - Wallet0 = ?WALLET(PartyID), - Wallet1 = Wallet0#wallet_WalletState{id = ID1}, - Wallet2 = Wallet1#wallet_WalletState{id = ID0, name = ?STRING2}, - _ = wapi_ct_helper:mock_services( - [ - {bender, fun('GenerateID', _) -> - CID = counters:get(CounterRef, 1), - BinaryCID = erlang:integer_to_binary(CID), - ok = counters:add(CounterRef, 1, 1), - {ok, ?GENERATE_ID_RESULT(<<"Test", BinaryCID/binary>>)} - end}, - {fistful_identity, fun - ('GetContext', _) -> {ok, ?DEFAULT_CONTEXT(PartyID)}; - ('Get', _) -> {ok, ?IDENTITY(PartyID)} - end}, - {fistful_wallet, fun - ('Create', _) -> - {ok, Wallet1}; - ('Get', {WID, _}) when WID =:= ID0 -> - {ok, Wallet2}; - ('Get', {WID, _}) when WID =:= ID1 -> - {throwing, #fistful_WalletNotFound{}} - end} - ], - C - ), - {ok, #{ - <<"id">> := ID1 - }} = create_wallet_call_api(C). - -%% - --spec call_api(function(), map(), wapi_client_lib:context()) -> {ok, term()} | {error, term()}. -call_api(F, Params, Context) -> - {Url, PreparedParams, Opts} = wapi_client_lib:make_request(Context, Params), - Response = F(Url, PreparedParams, Opts), - wapi_client_lib:handle_response(Response). - -create_wallet_call_api(C) -> - call_api( - fun swag_client_wallet_wallets_api:create_wallet/3, - #{ - body => #{ - <<"name">> => ?STRING, - <<"identity">> => ?STRING, - <<"currency">> => ?RUB, - <<"metadata">> => #{ - <<"somedata">> => ?STRING - } - } - }, - wapi_ct_helper:cfg(context, C) - ). - -get_wallet_call_api(C) -> - call_api( - fun swag_client_wallet_wallets_api:get_wallet/3, - #{ - binding => #{ - <<"walletID">> => ?STRING - } - }, - wapi_ct_helper:cfg(context, C) - ). - -get_account_call_api(C) -> - call_api( - fun swag_client_wallet_wallets_api:get_wallet_account/3, - #{ - binding => #{ - <<"walletID">> => ?STRING - } - }, - wapi_ct_helper:cfg(context, C) - ). - -create_wallet_start_mocks(C, CreateResultFun) -> - PartyID = ?config(party, C), - _ = wapi_ct_helper_bouncer:mock_assert_identity_op_ctx(<<"CreateWallet">>, ?STRING, PartyID, C), - wapi_ct_helper:mock_services( - [ - {bender, fun('GenerateID', _) -> {ok, ?GENERATE_ID_RESULT} end}, - {fistful_identity, fun - ('GetContext', _) -> {ok, ?DEFAULT_CONTEXT(PartyID)}; - ('Get', _) -> {ok, ?IDENTITY(PartyID)} - end}, - {fistful_wallet, fun - ('Create', _) -> CreateResultFun(); - ('Get', _) -> {throwing, #fistful_WalletNotFound{}} - end} - ], - C - ). - -get_wallet_start_mocks(C, GetResultFun) -> - PartyID = ?config(party, C), - _ = wapi_ct_helper_bouncer:mock_assert_wallet_op_ctx(<<"GetWallet">>, ?STRING, PartyID, C), - wapi_ct_helper:mock_services( - [ - {fistful_wallet, fun - ('GetContext', _) -> {ok, ?DEFAULT_CONTEXT(PartyID)}; - ('Get', _) -> GetResultFun() - end} - ], - C - ). diff --git a/test/wapi_wallet_tests_SUITE_data/jwk.json b/test/wapi_wallet_tests_SUITE_data/jwk.json deleted file mode 100644 index d3804153..00000000 --- a/test/wapi_wallet_tests_SUITE_data/jwk.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "use": "enc", - "kty": "oct", - "kid": "1", - "alg": "dir", - "k": "M3VKOExvQVdhWUtXekduVGt1eDdrUmtwTTNBSko1a2M" -} \ No newline at end of file diff --git a/test/wapi_wallet_tests_SUITE_data/jwk.priv.json b/test/wapi_wallet_tests_SUITE_data/jwk.priv.json deleted file mode 100644 index e7d65575..00000000 --- a/test/wapi_wallet_tests_SUITE_data/jwk.priv.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "use": "enc", - "kty": "EC", - "kid": "kxdD0orVPGoAxWrqAMTeQ0U5MRoK47uZxWiSJdgo0t0", - "crv": "P-256", - "alg": "ECDH-ES", - "x": "nHi7TCgBwfrPuNTf49bGvJMczk6WZOI-mCKAghbrOlM", - "y": "_8kiXGOIWkfz57m8K5dmTfbYzCJVYHZZZisCfbYicr0", - "d": "i45qDiARZ5qbS_uzeT-CiKnPUe64qHitKaVdAvcN6TI" -} \ No newline at end of file diff --git a/test/wapi_wallet_tests_SUITE_data/jwk.publ.json b/test/wapi_wallet_tests_SUITE_data/jwk.publ.json deleted file mode 100644 index 00b7002d..00000000 --- a/test/wapi_wallet_tests_SUITE_data/jwk.publ.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "use": "enc", - "kty": "EC", - "kid": "kxdD0orVPGoAxWrqAMTeQ0U5MRoK47uZxWiSJdgo0t0", - "crv": "P-256", - "alg": "ECDH-ES", - "x": "nHi7TCgBwfrPuNTf49bGvJMczk6WZOI-mCKAghbrOlM", - "y": "_8kiXGOIWkfz57m8K5dmTfbYzCJVYHZZZisCfbYicr0" -} \ No newline at end of file diff --git a/test/wapi_wallet_tests_SUITE_data/private.pem b/test/wapi_wallet_tests_SUITE_data/private.pem deleted file mode 100644 index 4e6d12c9..00000000 --- a/test/wapi_wallet_tests_SUITE_data/private.pem +++ /dev/null @@ -1,9 +0,0 @@ ------BEGIN RSA PRIVATE KEY----- -MIIBOwIBAAJBAK9fx7qOJT7Aoseu7KKgaLagBh3wvDzg7F/ZMtGbPFikJnnvRWvF -B5oEGbMPblvtF0/fjqfu+eqjP3Z1tUSn7TkCAwEAAQJABUY5KIgr4JZEjwLYxQ9T -9uIbLP1Xe/E7yqoqmBk2GGhSrPY0OeRkYnUVLcP96UPQhF63iuG8VF6uZ7oAPsq+ -gQIhANZy3jSCzPjXYHRU1kRqQzpt2S+OqoEiqQ6YG1HrC/VxAiEA0Vq6JlQK2tOX -37SS00dK0Qog4Qi8dN73GliFQNP18EkCIQC4epSA48zkfJMzQBAbRraSuxDNApPX -BzQbo+pMrEDbYQIgY4AncQgIkLB4Qk5kah48JNYXglzQlQtTjiX8Ty9ueGECIQCM -GD3UbQKiA0gf5plBA24I4wFVKxxa4wXbW/7SfP6XmQ== ------END RSA PRIVATE KEY----- diff --git a/test/wapi_webhook_tests_SUITE.erl b/test/wapi_webhook_tests_SUITE.erl index d3580a72..835bf968 100644 --- a/test/wapi_webhook_tests_SUITE.erl +++ b/test/wapi_webhook_tests_SUITE.erl @@ -8,8 +8,6 @@ -include_lib("fistful_proto/include/fistful_fistful_base_thrift.hrl"). -include_lib("fistful_proto/include/fistful_fistful_thrift.hrl"). -include_lib("fistful_proto/include/fistful_account_thrift.hrl"). --include_lib("fistful_proto/include/fistful_identity_thrift.hrl"). --include_lib("fistful_proto/include/fistful_wallet_thrift.hrl"). -include_lib("fistful_proto/include/fistful_webhooker_thrift.hrl"). -export([all/0]). @@ -101,24 +99,19 @@ end_per_testcase(_Name, C) -> -spec create_webhook_ok_test(config()) -> _. create_webhook_ok_test(C) -> - PartyID = ?config(party, C), _ = wapi_ct_helper_bouncer:mock_assert_generic_op_ctx( [ - {identity, ?STRING, PartyID} + {party, ?STRING, ?STRING} ], ?CTX_WAPI(#ctx_v1_WalletAPIOperation{ id = <<"CreateWebhook">>, - identity = ?STRING + party = ?STRING }), C ), _ = wapi_ct_helper:mock_services( [ - {webhook_manager, fun('Create', _) -> {ok, ?WEBHOOK(?DESTINATION_EVENT_FILTER)} end}, - {fistful_identity, fun - ('GetContext', _) -> {ok, ?DEFAULT_CONTEXT(PartyID)}; - ('Get', _) -> {ok, ?IDENTITY(PartyID)} - end} + {webhook_manager, fun('Create', _) -> {ok, ?WEBHOOK(?DESTINATION_EVENT_FILTER)} end} ], C ), @@ -126,7 +119,7 @@ create_webhook_ok_test(C) -> fun swag_client_wallet_webhooks_api:create_webhook/3, #{ body => #{ - <<"identityID">> => ?STRING, + <<"partyID">> => ?STRING, <<"url">> => ?URL, <<"scope">> => #{ <<"topic">> => <<"DestinationsTopic">>, @@ -139,31 +132,22 @@ create_webhook_ok_test(C) -> -spec create_withdrawal_webhook_ok_test(config()) -> _. create_withdrawal_webhook_ok_test(C) -> - PartyID = ?config(party, C), WalletID = ?STRING, _ = wapi_ct_helper_bouncer:mock_assert_generic_op_ctx( [ - {identity, ?STRING, PartyID}, - {wallet, ?STRING, PartyID} + {party, ?STRING, ?STRING}, + {wallet, ?STRING, ?STRING} ], ?CTX_WAPI(#ctx_v1_WalletAPIOperation{ id = <<"CreateWebhook">>, - identity = ?STRING, + party = ?STRING, wallet = ?STRING }), C ), _ = wapi_ct_helper:mock_services( [ - {webhook_manager, fun('Create', _) -> {ok, ?WEBHOOK_WITH_WALLET(?WITHDRAWAL_EVENT_FILTER, WalletID)} end}, - {fistful_identity, fun - ('GetContext', _) -> {ok, ?DEFAULT_CONTEXT(PartyID)}; - ('Get', _) -> {ok, ?IDENTITY(PartyID)} - end}, - {fistful_wallet, fun - ('GetContext', _) -> {ok, ?DEFAULT_CONTEXT(PartyID)}; - ('Get', _) -> {ok, ?WALLET(PartyID)} - end} + {webhook_manager, fun('Create', _) -> {ok, ?WEBHOOK_WITH_WALLET(?WITHDRAWAL_EVENT_FILTER, WalletID)} end} ], C ), @@ -171,7 +155,7 @@ create_withdrawal_webhook_ok_test(C) -> fun swag_client_wallet_webhooks_api:create_webhook/3, #{ body => #{ - <<"identityID">> => ?STRING, + <<"partyID">> => ?STRING, <<"url">> => ?URL, <<"scope">> => #{ <<"topic">> => <<"WithdrawalsTopic">>, @@ -185,16 +169,11 @@ create_withdrawal_webhook_ok_test(C) -> -spec get_webhooks_ok_test(config()) -> _. get_webhooks_ok_test(C) -> - PartyID = ?config(party, C), - _ = wapi_ct_helper_bouncer:mock_assert_identity_op_ctx(<<"GetWebhooks">>, ?STRING, PartyID, C), + _ = wapi_ct_helper_bouncer:mock_assert_party_op_ctx(<<"GetWebhooks">>, ?STRING, C), _ = wapi_ct_helper:mock_services( [ {webhook_manager, fun('GetList', _) -> {ok, [?WEBHOOK(?WITHDRAWAL_EVENT_FILTER), ?WEBHOOK(?DESTINATION_EVENT_FILTER)]} - end}, - {fistful_identity, fun - ('GetContext', _) -> {ok, ?DEFAULT_CONTEXT(PartyID)}; - ('Get', _) -> {ok, ?IDENTITY(PartyID)} end} ], C @@ -203,7 +182,7 @@ get_webhooks_ok_test(C) -> fun swag_client_wallet_webhooks_api:get_webhooks/3, #{ qs_val => #{ - <<"identityID">> => ?STRING + <<"partyID">> => ?STRING } }, wapi_ct_helper:cfg(context, C) @@ -211,26 +190,21 @@ get_webhooks_ok_test(C) -> -spec get_webhook_ok_test(config()) -> _. get_webhook_ok_test(C) -> - PartyID = ?config(party, C), _ = wapi_ct_helper_bouncer:mock_assert_generic_op_ctx( [ - {webhook, integer_to_binary(?INTEGER), #{identity => ?STRING}}, - {identity, ?STRING, PartyID} + {webhook, integer_to_binary(?INTEGER), #{party => ?STRING}}, + {party, ?STRING, ?STRING} ], ?CTX_WAPI(#ctx_v1_WalletAPIOperation{ id = <<"GetWebhookByID">>, - identity = ?STRING, + party = ?STRING, webhook = integer_to_binary(?INTEGER) }), C ), _ = wapi_ct_helper:mock_services( [ - {webhook_manager, fun('Get', _) -> {ok, ?WEBHOOK(?WITHDRAWAL_EVENT_FILTER)} end}, - {fistful_identity, fun - ('GetContext', _) -> {ok, ?DEFAULT_CONTEXT(PartyID)}; - ('Get', _) -> {ok, ?IDENTITY(PartyID)} - end} + {webhook_manager, fun('Get', _) -> {ok, ?WEBHOOK(?WITHDRAWAL_EVENT_FILTER)} end} ], C ), @@ -241,7 +215,7 @@ get_webhook_ok_test(C) -> <<"webhookID">> => integer_to_binary(?INTEGER) }, qs_val => #{ - <<"identityID">> => ?STRING + <<"partyID">> => ?STRING } }, wapi_ct_helper:cfg(context, C) @@ -249,15 +223,14 @@ get_webhook_ok_test(C) -> -spec delete_webhook_ok_test(config()) -> _. delete_webhook_ok_test(C) -> - PartyID = ?config(party, C), _ = wapi_ct_helper_bouncer:mock_assert_generic_op_ctx( [ - {webhook, integer_to_binary(?INTEGER), #{identity => ?STRING}}, - {identity, ?STRING, PartyID} + {webhook, integer_to_binary(?INTEGER), #{party => ?STRING}}, + {party, ?STRING, ?STRING} ], ?CTX_WAPI(#ctx_v1_WalletAPIOperation{ id = <<"DeleteWebhookByID">>, - identity = ?STRING, + party = ?STRING, webhook = integer_to_binary(?INTEGER) }), C @@ -267,10 +240,6 @@ delete_webhook_ok_test(C) -> {webhook_manager, fun ('Get', _) -> {ok, ?WEBHOOK(?WITHDRAWAL_EVENT_FILTER)}; ('Delete', _) -> {ok, ok} - end}, - {fistful_identity, fun - ('GetContext', _) -> {ok, ?DEFAULT_CONTEXT(PartyID)}; - ('Get', _) -> {ok, ?IDENTITY(PartyID)} end} ], C @@ -282,7 +251,7 @@ delete_webhook_ok_test(C) -> <<"webhookID">> => integer_to_binary(?INTEGER) }, qs_val => #{ - <<"identityID">> => ?STRING + <<"partyID">> => ?STRING } }, wapi_ct_helper:cfg(context, C) diff --git a/test/wapi_withdrawal_tests_SUITE.erl b/test/wapi_withdrawal_tests_SUITE.erl index 78eb470b..4f13526e 100644 --- a/test/wapi_withdrawal_tests_SUITE.erl +++ b/test/wapi_withdrawal_tests_SUITE.erl @@ -10,7 +10,6 @@ -include_lib("fistful_proto/include/fistful_fistful_thrift.hrl"). -include_lib("fistful_proto/include/fistful_account_thrift.hrl"). -include_lib("fistful_proto/include/fistful_cashflow_thrift.hrl"). --include_lib("fistful_proto/include/fistful_wallet_thrift.hrl"). -include_lib("fistful_proto/include/fistful_wthd_thrift.hrl"). -include_lib("fistful_proto/include/fistful_wthd_status_thrift.hrl"). -include_lib("fistful_proto/include/fistful_destination_thrift.hrl"). @@ -30,8 +29,6 @@ create_ok/1, create_fail_wallet_notfound/1, create_fail_destination_notfound/1, - create_fail_destination_unauthorized/1, - create_fail_destination_withdrawal_method/1, create_fail_forbidden_operation_currency/1, create_fail_forbidden_operation_amount/1, create_fail_invalid_operation_amount/1, @@ -47,8 +44,6 @@ create_quote_ok/1, get_quote_fail_wallet_notfound/1, get_quote_fail_destination_notfound/1, - get_quote_fail_destination_unauthorized/1, - get_quote_fail_destination_withdrawal_method/1, get_quote_fail_forbidden_operation_currency/1, get_quote_fail_forbidden_operation_amount/1, get_quote_fail_invalid_operation_amount/1, @@ -83,8 +78,6 @@ groups() -> create_ok, create_fail_wallet_notfound, create_fail_destination_notfound, - create_fail_destination_unauthorized, - create_fail_destination_withdrawal_method, create_fail_forbidden_operation_currency, create_fail_forbidden_operation_amount, create_fail_invalid_operation_amount, @@ -100,8 +93,6 @@ groups() -> create_quote_ok, get_quote_fail_wallet_notfound, get_quote_fail_destination_notfound, - get_quote_fail_destination_unauthorized, - get_quote_fail_destination_withdrawal_method, get_quote_fail_forbidden_operation_currency, get_quote_fail_forbidden_operation_amount, get_quote_fail_invalid_operation_amount, @@ -176,22 +167,6 @@ create_fail_destination_notfound(C) -> create_withdrawal_call_api(C) ). --spec create_fail_destination_unauthorized(config()) -> _. -create_fail_destination_unauthorized(C) -> - _ = create_withdrawal_start_mocks(C, fun() -> {throwing, #fistful_DestinationUnauthorized{}} end), - ?assertEqual( - {error, {422, #{<<"message">> => <<"Destination unauthorized">>}}}, - create_withdrawal_call_api(C) - ). - --spec create_fail_destination_withdrawal_method(config()) -> _. -create_fail_destination_withdrawal_method(C) -> - _ = create_withdrawal_start_mocks(C, fun() -> {throwing, #fistful_ForbiddenWithdrawalMethod{}} end), - ?assertEqual( - {error, {422, #{<<"message">> => <<"Destination uses resource no longer allowed">>}}}, - create_withdrawal_call_api(C) - ). - -spec create_fail_forbidden_operation_currency(config()) -> _. create_fail_forbidden_operation_currency(C) -> ForbiddenOperationCurrencyException = #fistful_ForbiddenOperationCurrency{ @@ -261,11 +236,11 @@ create_fail_no_destination_resource_info(C) -> -spec create_fail_identity_providers_mismatch(config()) -> _. create_fail_identity_providers_mismatch(C) -> - IdentityProviderMismatchException = #wthd_IdentityProvidersMismatch{ - wallet_provider = ?INTEGER, - destination_provider = ?INTEGER + RealmsMismatch = #fistful_RealmsMismatch{ + wallet_realm = test, + destination_realm = live }, - _ = create_withdrawal_start_mocks(C, fun() -> {throwing, IdentityProviderMismatchException} end), + _ = create_withdrawal_start_mocks(C, fun() -> {throwing, RealmsMismatch} end), ?assertEqual( {error, {422, #{<<"message">> => <<"This wallet and destination cannot be used together">>}}}, create_withdrawal_call_api(C) @@ -454,22 +429,6 @@ get_quote_fail_destination_notfound(C) -> create_qoute_call_api(C) ). --spec get_quote_fail_destination_unauthorized(config()) -> _. -get_quote_fail_destination_unauthorized(C) -> - _ = get_quote_start_mocks(C, fun() -> {throwing, #fistful_DestinationUnauthorized{}} end), - ?assertEqual( - {error, {422, #{<<"message">> => <<"Destination unauthorized">>}}}, - create_qoute_call_api(C) - ). - --spec get_quote_fail_destination_withdrawal_method(config()) -> _. -get_quote_fail_destination_withdrawal_method(C) -> - _ = get_quote_start_mocks(C, fun() -> {throwing, #fistful_ForbiddenWithdrawalMethod{}} end), - ?assertEqual( - {error, {422, #{<<"message">> => <<"Destination uses resource no longer allowed">>}}}, - create_qoute_call_api(C) - ). - -spec get_quote_fail_forbidden_operation_currency(config()) -> _. get_quote_fail_forbidden_operation_currency(C) -> ForbiddenOperationCurrencyException = #fistful_ForbiddenOperationCurrency{ @@ -531,11 +490,11 @@ get_quote_fail_inconsistent_withdrawal_currency(C) -> -spec get_quote_fail_identity_provider_mismatch(config()) -> _. get_quote_fail_identity_provider_mismatch(C) -> - IdentityProviderMismatchException = #wthd_IdentityProvidersMismatch{ - wallet_provider = ?INTEGER, - destination_provider = ?INTEGER + RealmsMismatch = #fistful_RealmsMismatch{ + wallet_realm = test, + destination_realm = live }, - _ = get_quote_start_mocks(C, fun() -> {throwing, IdentityProviderMismatchException} end), + _ = get_quote_start_mocks(C, fun() -> {throwing, RealmsMismatch} end), ?assertEqual( {error, {422, #{<<"message">> => <<"This wallet and destination cannot be used together">>}}}, create_qoute_call_api(C) @@ -596,7 +555,7 @@ check_unknown_withdrawal_id(C) -> _ = wapi_ct_helper_bouncer:mock_assert_generic_op_ctx( [ {destination, ?STRING, PartyID}, - {wallet, ?STRING, PartyID} + {wallet, ?STRING, ?STRING} ], ?CTX_WAPI(#ctx_v1_WalletAPIOperation{ id = <<"CreateWithdrawal">>, @@ -619,10 +578,6 @@ check_unknown_withdrawal_id(C) -> ok = counters:add(CounterRef, 1, 1), {ok, ?GENERATE_ID_RESULT(<<"Test", BinaryCID/binary>>)} end}, - {fistful_wallet, fun - ('Get', _) -> {ok, ?WALLET(PartyID)}; - ('GetContext', _) -> {ok, ?DEFAULT_CONTEXT(PartyID)} - end}, {fistful_destination, fun ('Get', _) -> {ok, ?DESTINATION(PartyID)}; ('GetContext', _) -> {ok, ?DEFAULT_CONTEXT(PartyID)} @@ -651,11 +606,13 @@ call_api(F, Params, Context) -> wapi_client_lib:handle_response(Response). create_withdrawal_call_api(C) -> + PartyID = ?config(party, C), call_api( fun swag_client_wallet_withdrawals_api:create_withdrawal/3, #{ body => genlib_map:compact(#{ <<"wallet">> => ?STRING, + <<"party">> => PartyID, <<"destination">> => ?STRING, <<"body">> => #{ <<"amount">> => ?INTEGER, @@ -667,11 +624,13 @@ create_withdrawal_call_api(C) -> ). create_qoute_call_api(C) -> + PartyID = ?config(party, C), call_api( fun swag_client_wallet_withdrawals_api:create_quote/3, #{ body => genlib_map:compact(#{ <<"walletID">> => ?STRING, + <<"partyID">> => PartyID, <<"destinationID">> => ?STRING, <<"currencyFrom">> => ?RUB, <<"currencyTo">> => ?USD, @@ -689,7 +648,7 @@ create_withdrawal_start_mocks(C, CreateWithdrawalResultFun) -> _ = wapi_ct_helper_bouncer:mock_assert_generic_op_ctx( [ {destination, ?STRING, PartyID}, - {wallet, ?STRING, PartyID} + {wallet, ?STRING, ?STRING} ], ?CTX_WAPI(#ctx_v1_WalletAPIOperation{ id = <<"CreateWithdrawal">>, @@ -701,10 +660,6 @@ create_withdrawal_start_mocks(C, CreateWithdrawalResultFun) -> wapi_ct_helper:mock_services( [ {bender, fun('GenerateID', _) -> {ok, ?GENERATE_ID_RESULT} end}, - {fistful_wallet, fun - ('Get', _) -> {ok, ?WALLET(PartyID)}; - ('GetContext', _) -> {ok, ?DEFAULT_CONTEXT(PartyID)} - end}, {fistful_destination, fun ('Get', _) -> {ok, ?DESTINATION(PartyID)}; ('GetContext', _) -> {ok, ?DEFAULT_CONTEXT(PartyID)} @@ -737,7 +692,7 @@ get_quote_start_mocks(C, GetQuoteResultFun) -> _ = wapi_ct_helper_bouncer:mock_assert_generic_op_ctx( [ {destination, ?STRING, PartyID}, - {wallet, ?STRING, PartyID} + {wallet, ?STRING, ?STRING} ], ?CTX_WAPI(#ctx_v1_WalletAPIOperation{ id = <<"CreateQuote">>, @@ -748,10 +703,6 @@ get_quote_start_mocks(C, GetQuoteResultFun) -> ), wapi_ct_helper:mock_services( [ - {fistful_wallet, fun - ('Get', _) -> {ok, ?WALLET(PartyID)}; - ('GetContext', _) -> {ok, ?DEFAULT_CONTEXT(PartyID)} - end}, {fistful_destination, fun ('Get', _) -> {ok, ?DESTINATION(PartyID)}; ('GetContext', _) -> {ok, ?DEFAULT_CONTEXT(PartyID)}