@@ -45,7 +45,10 @@ def setUp(self) -> None:
4545 "/order/5" , "Microservice call correct!!!" , methods = ("GET" , "PUT" , "PATCH" , "DELETE" ,)
4646 )
4747 self .microservice .add_json_response (
48- "/merchants/5" , "Microservice call correct!!!" , methods = ("GET" , "PUT" , "PATCH" , "DELETE" ,)
48+ "/autz-merchants/5" , "Microservice call correct!!!" , methods = ("GET" , "PUT" , "PATCH" , "DELETE" ,)
49+ )
50+ self .microservice .add_json_response (
51+ "/autz-merchants-2/5" , "Microservice call correct!!!" , methods = ("GET" , "PUT" , "PATCH" , "DELETE" ,)
4952 )
5053 self .microservice .add_json_response ("/categories/5" , "Microservice call correct!!!" , methods = ("GET" ,))
5154 self .microservice .add_json_response ("/order" , "Microservice call correct!!!" , methods = ("POST" ,))
@@ -94,22 +97,55 @@ async def get_application(self):
9497 async def test_auth_unauthorized (self ):
9598 await self .client .post (
9699 "/admin/rules" ,
97- data = json .dumps ({"service" : "merchants" , "rule" : "*://*/merchants/*" , "methods" : ["GET" , "POST" ]}),
100+ data = json .dumps (
101+ {"service" : "autz-merchants" , "rule" : "*://*/autz-merchants/*" , "methods" : ["GET" , "POST" ]}
102+ ),
98103 )
99104 await self .client .post (
100105 "/admin/autz-rules" ,
101106 data = json .dumps (
102- {"service" : "merchants" , "roles" : ["2" ], "rule" : "*://*/merchants/*" , "methods" : ["GET" , "POST" ]}
107+ {
108+ "service" : "autz-merchants" ,
109+ "roles" : [2 ],
110+ "rule" : "*://*/autz-merchants/*" ,
111+ "methods" : ["GET" , "POST" ],
112+ }
103113 ),
104114 )
105- url = "/merchants/5"
115+ url = "/autz- merchants/5"
106116 headers = {"Authorization" : "Bearer credential-token-test" }
107117
108118 response = await self .client .request ("POST" , url , headers = headers )
109119
110120 self .assertEqual (401 , response .status )
111121 self .assertIn ("401: Unauthorized" , await response .text ())
112122
123+ async def test_authorized (self ):
124+ await self .client .post (
125+ "/admin/rules" ,
126+ data = json .dumps (
127+ {"service" : "autz-merchants-2" , "rule" : "*://*/autz-merchants-2/*" , "methods" : ["GET" , "POST" ]}
128+ ),
129+ )
130+ await self .client .post (
131+ "/admin/autz-rules" ,
132+ data = json .dumps (
133+ {
134+ "service" : "autz-merchants-2" ,
135+ "roles" : [3 ],
136+ "rule" : "*://*/autz-merchants-2/*" ,
137+ "methods" : ["GET" , "POST" ],
138+ }
139+ ),
140+ )
141+ url = "/autz-merchants-2/5"
142+ headers = {"Authorization" : "Bearer credential-token-test" }
143+
144+ response = await self .client .request ("GET" , url , headers = headers )
145+
146+ self .assertEqual (200 , response .status )
147+ self .assertIn ("Microservice call correct!!!" , await response .text ())
148+
113149
114150class TestAutzFailed (AioHTTPTestCase ):
115151 CONFIG_FILE_PATH = BASE_PATH / "config.yml"
0 commit comments