From 2445f446d630c9be8b84be0ac4379f225d1aa895 Mon Sep 17 00:00:00 2001 From: ndiezel0 Date: Thu, 3 Dec 2020 17:22:32 +0300 Subject: [PATCH] MSPF-591: Update bouncer_proto (#11) * MSPF-591: Update bouncer_proto * MSPF-591: Fix lint * MSPF-591: Update proto --- rebar.lock | 2 +- src/bouncer_arbiter_handler.erl | 10 ++++++++-- test/bouncer_tests_SUITE.erl | 13 +++++++------ 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/rebar.lock b/rebar.lock index e7b52ff..996fd51 100644 --- a/rebar.lock +++ b/rebar.lock @@ -2,7 +2,7 @@ [{<<"bear">>,{pkg,<<"bear">>,<<"0.8.7">>},2}, {<<"bouncer_proto">>, {git,"git@github.com:rbkmoney/bouncer-proto.git", - {ref,"ea44337686d65fa8e72cdb02c4b73dafd5cafc09"}}, + {ref,"aab9db7ecc0ff436acc81f3358ae52239559ce7b"}}, 0}, {<<"cache">>,{pkg,<<"cache">>,<<"2.2.0">>},1}, {<<"certifi">>,{pkg,<<"certifi">>,<<"2.5.1">>},2}, diff --git a/src/bouncer_arbiter_handler.erl b/src/bouncer_arbiter_handler.erl index af8c01a..0c67574 100644 --- a/src/bouncer_arbiter_handler.erl +++ b/src/bouncer_arbiter_handler.erl @@ -81,14 +81,20 @@ handle_network_error({unknown, Reason} = Error, St) -> thrift_judgement(). encode_judgement({Resolution, _Assertions}) -> #bdcs_Judgement{ + resolution_legacy = encode_resolution_legacy(Resolution), resolution = encode_resolution(Resolution) }. -encode_resolution(allowed) -> +encode_resolution_legacy(allowed) -> allowed; -encode_resolution(forbidden) -> +encode_resolution_legacy(forbidden) -> forbidden. +encode_resolution(allowed) -> + {allowed, #bdcs_ResolutionAllowed{}}; +encode_resolution(forbidden) -> + {forbidden, #bdcs_ResolutionForbidden{}}. + -spec decode_context(thrift_context(), st()) -> {bouncer_context:ctx(), st()}. decode_context(#bdcs_Context{fragments = FragmentsIn}, St0) -> diff --git a/test/bouncer_tests_SUITE.erl b/test/bouncer_tests_SUITE.erl index c7d0421..af4df98 100644 --- a/test/bouncer_tests_SUITE.erl +++ b/test/bouncer_tests_SUITE.erl @@ -167,7 +167,8 @@ end_per_testcase(_Name, _C) -> %% -define(CONTEXT(Fragments), #bdcs_Context{fragments = Fragments}). --define(JUDGEMENT(Resolution), #bdcs_Judgement{resolution = Resolution}). +-define(JUDGEMENT(Resolution, ResolutionLegacy), + #bdcs_Judgement{resolution = Resolution, resolution_legacy = ResolutionLegacy}). -spec missing_ruleset_notfound(config()) -> ok. -spec incorrect_ruleset_invalid1(config()) -> ok. @@ -361,7 +362,7 @@ allowed_create_invoice_shop_manager(C) -> ]), Context = ?CONTEXT(#{<<"root">> => mk_ctx_v1_fragment(Fragment)}), ?assertMatch( - ?JUDGEMENT(allowed), + ?JUDGEMENT({allowed, #bdcs_ResolutionAllowed{}}, allowed), call_judge(?API_RULESET_ID, Context, Client) ), ?assertMatch( @@ -380,7 +381,7 @@ forbidden_expired(C) -> }), Context = ?CONTEXT(#{<<"root">> => mk_ctx_v1_fragment(Fragment)}), ?assertMatch( - ?JUDGEMENT(forbidden), + ?JUDGEMENT({forbidden, #bdcs_ResolutionForbidden{}}, forbidden), call_judge(?API_RULESET_ID, Context, Client) ), ?assertMatch( @@ -398,7 +399,7 @@ forbidden_blacklisted_ip(C) -> ]), Context = ?CONTEXT(#{<<"root">> => mk_ctx_v1_fragment(Fragment)}), ?assertMatch( - ?JUDGEMENT(forbidden), + ?JUDGEMENT({forbidden, #bdcs_ResolutionForbidden{}}, forbidden), call_judge(?API_RULESET_ID, Context, Client) ), ?assertMatch( @@ -410,7 +411,7 @@ forbidden_w_empty_context(C) -> Client1 = mk_client(C), EmptyFragment = mk_ctx_v1_fragment(#{}), ?assertMatch( - ?JUDGEMENT(forbidden), + ?JUDGEMENT({forbidden, #bdcs_ResolutionForbidden{}}, forbidden), call_judge(?API_RULESET_ID, ?CONTEXT(#{}), Client1) ), ?assertMatch( @@ -419,7 +420,7 @@ forbidden_w_empty_context(C) -> ), Client2 = mk_client(C), ?assertMatch( - ?JUDGEMENT(forbidden), + ?JUDGEMENT({forbidden, #bdcs_ResolutionForbidden{}}, forbidden), call_judge(?API_RULESET_ID, ?CONTEXT(#{<<"empty">> => EmptyFragment}), Client2) ), ?assertMatch(