2222#include < olp/authentication/AuthorizeResult.h>
2323
2424namespace {
25- using namespace olp ::authentication;
25+ namespace auth = olp::authentication;
2626
2727TEST (DecisionApiClientTest, AuthorizeRequestTest) {
28- EXPECT_EQ (AuthorizeRequest ().WithServiceId (" ServiceId" ).GetServiceId (),
28+ EXPECT_EQ (auth:: AuthorizeRequest ().WithServiceId (" ServiceId" ).GetServiceId (),
2929 " ServiceId" );
30- EXPECT_EQ (
31- AuthorizeRequest ().WithContractId (" ContractId" ).GetContractId ().get (),
32- " ContractId" );
33- auto request = AuthorizeRequest ().WithAction (" action1" ).WithAction (
30+ EXPECT_EQ (auth::AuthorizeRequest ()
31+ .WithContractId (" ContractId" )
32+ .GetContractId ()
33+ .get (),
34+ " ContractId" );
35+ auto request = auth::AuthorizeRequest ().WithAction (" action1" ).WithAction (
3436 " action2" , std::string (" hrn::test" ));
35- EXPECT_EQ (AuthorizeRequest ().GetDiagnostics (), false );
36- EXPECT_EQ (AuthorizeRequest ().WithDiagnostics (true ).GetDiagnostics (), true );
37+ EXPECT_EQ (auth::AuthorizeRequest ().GetDiagnostics (), false );
38+ EXPECT_EQ (auth::AuthorizeRequest ().WithDiagnostics (true ).GetDiagnostics (),
39+ true );
3740 EXPECT_EQ (request.GetActions ().size (), 2 );
3841 auto actions_it = request.GetActions ().begin ();
3942 EXPECT_EQ (actions_it->first , " action1" );
@@ -42,29 +45,44 @@ TEST(DecisionApiClientTest, AuthorizeRequestTest) {
4245 EXPECT_EQ (actions_it->first , " action2" );
4346 EXPECT_EQ (actions_it->second , " hrn::test" );
4447 EXPECT_EQ (request.GetOperatorType (),
45- AuthorizeRequest::DecisionOperatorType::kAnd );
46- request.WithOperatorType (AuthorizeRequest::DecisionOperatorType::kOr );
48+ auth:: AuthorizeRequest::DecisionOperatorType::kAnd );
49+ request.WithOperatorType (auth:: AuthorizeRequest::DecisionOperatorType::kOr );
4750 EXPECT_EQ (request.GetOperatorType (),
48- AuthorizeRequest::DecisionOperatorType::kOr );
51+ auth:: AuthorizeRequest::DecisionOperatorType::kOr );
4952 request.WithServiceId (" service" );
5053 EXPECT_EQ (request.CreateKey (), " service" );
5154 request.WithContractId (" contract" );
5255 EXPECT_EQ (request.CreateKey (), " service[contract]" );
5356}
5457
5558TEST (DecisionApiClientTest, AuthorizeResponceTest) {
56- EXPECT_EQ (AuthorizeResult ().GetDecision (), DecisionType::kDeny );
57- EXPECT_EQ (ActionResult ().GetDecision (), DecisionType::kDeny );
58- EXPECT_EQ (AuthorizeResult ().GetClientId (), " " );
59- ActionResult action;
60- action.SetDecision (DecisionType::kAllow );
61- action.SetPermissions ({{" read" , DecisionType::kAllow }});
62- AuthorizeResult decision;
59+ EXPECT_EQ (auth::AuthorizeResult ().GetDecision (), auth::DecisionType::kDeny );
60+ EXPECT_EQ (auth::ActionResult ().GetDecision (), auth::DecisionType::kDeny );
61+ EXPECT_EQ (auth::AuthorizeResult ().GetClientId (), " " );
62+ auth::ActionResult action;
63+ action.SetDecision (auth::DecisionType::kAllow );
64+ auth::Permission permission;
65+ permission.SetAction (" read" );
66+ permission.SetResource (" hrn:test" );
67+ permission.SetDecision (auth::DecisionType::kAllow );
68+ action.SetPermissions ({permission});
69+ auth::AuthorizeResult decision;
6370 decision.SetActionResults ({action});
64- EXPECT_EQ (decision.GetActionResults ().front ().GetPermissions ().front ().first ,
65- " read" );
66- EXPECT_EQ (decision.GetActionResults ().front ().GetPermissions ().front ().second ,
67- DecisionType::kAllow );
71+ EXPECT_EQ (
72+ decision.GetActionResults ().front ().GetPermissions ().front ().GetAction (),
73+ " read" );
74+ EXPECT_EQ (decision.GetActionResults ()
75+ .front ()
76+ .GetPermissions ()
77+ .front ()
78+ .GetDecision (),
79+ auth::DecisionType::kAllow );
80+ EXPECT_EQ (decision.GetActionResults ()
81+ .front ()
82+ .GetPermissions ()
83+ .front ()
84+ .GetResource (),
85+ " hrn:test" );
6886}
6987
7088} // namespace
0 commit comments