Add policy enforcement unittest to magnum_service

Add policy enforcement unittest for magnum_service to imporve
test coverage and code quality.

Change-Id: I9377f99a361572e985717d950e2812bf69fefb92
Related-Bug: #1520311
houming-wang 2016-01-07 22:36:30 -05:00
parent fe8f435886
commit 05d9e75c03
1 changed files with 19 additions and 0 deletions

View File

@ -11,6 +11,8 @@
# limitations under the License.
import json
import mock
from magnum.api.controllers.v1 import magnum_services as mservice
@ -83,3 +85,20 @@ class TestMagnumServiceController(api_base.FunctionalTest):
for i in range(svc_num):
elem = response['mservices'][i]
self.assertEqual(i + 1, elem['id'])
class TestMagnumServiceEnforcement(api_base.FunctionalTest):
def _common_policy_check(self, rule, func, *arg, **kwarg):
self.policy.set_rules({rule: 'project:non_fake'})
response = func(*arg, **kwarg)
self.assertEqual(403, response.status_int)
self.assertEqual('application/json', response.content_type)
"Policy doesn't allow %s to be performed." % rule,
def test_policy_disallow_get_all(self):
'magnum-service:get_all', self.get_json,
'/mservices', expect_errors=True)