Ejemplo n.º 1
0
 def setUp(self):
     super(PolicyFileTestCase, self).setUp()
     policy.reset()
     self.addCleanup(policy.reset)
     self.context = context.Context('fake', 'fake', is_admin=False)
     self.target = {}
     self.tempdir = self.useFixture(fixtures.TempDir())
Ejemplo n.º 2
0
    def setUp(self):
        super(TackerPolicyTestCase, self).setUp()
        self.skipTest("Not ready yet")
        policy.reset()
        policy.init()
        self.addCleanup(policy.reset)
        self.admin_only_legacy = "role:admin"
        self.admin_or_owner_legacy = "role:admin or tenant_id:%(tenant_id)s"
        # Add a Fake 'something' resource to RESOURCE_ATTRIBUTE_MAP
        attributes.RESOURCE_ATTRIBUTE_MAP.update(FAKE_RESOURCE)
        self.rules = dict((k, common_policy.parse_rule(v)) for k, v in {
            "context_is_admin": "role:admin",
            "admin_or_network_owner": "rule:context_is_admin or "
                                      "tenant_id:%(network:tenant_id)s",
            "admin_or_owner": ("rule:context_is_admin or "
                               "tenant_id:%(tenant_id)s"),
            "admin_only": "rule:context_is_admin",
            "regular_user": "******",
            "shared": "field:networks:shared=True",
            "external": "field:networks:router:external=True",
            "default": '@',

            "create_network": "rule:admin_or_owner",
            "create_network:shared": "rule:admin_only",
            "update_network": '@',
            "update_network:shared": "rule:admin_only",

            "get_network": "rule:admin_or_owner or "
                           "rule:shared or "
                           "rule:external",
            "create_port:mac": "rule:admin_or_network_owner",
            "create_something": "rule:admin_or_owner",
            "create_something:attr": "rule:admin_or_owner",
            "create_something:attr:sub_attr_1": "rule:admin_or_owner",
            "create_something:attr:sub_attr_2": "rule:admin_only",

            "get_firewall_policy": "rule:admin_or_owner or "
                            "rule:shared",
            "get_firewall_rule": "rule:admin_or_owner or "
                            "rule:shared"
        }.items())

        def fakepolicyinit():
            common_policy.set_rules(common_policy.Rules(self.rules))

        def remove_fake_resource():
            del attributes.RESOURCE_ATTRIBUTE_MAP["%ss" % FAKE_RESOURCE_NAME]

        self.patcher = mock.patch.object(tacker.policy,
                                         'init',
                                         new=fakepolicyinit)
        self.patcher.start()
        self.addCleanup(remove_fake_resource)
        self.context = context.Context('fake', 'fake', roles=['user'])
        plugin_klass = importutils.import_class(
            "tacker.db.db_base_plugin_v2.TackerDbPluginV2")
        self.manager_patcher = mock.patch('tacker.manager.TackerManager')
        fake_manager = self.manager_patcher.start()
        fake_manager_instance = fake_manager.return_value
        fake_manager_instance.plugin = plugin_klass()
Ejemplo n.º 3
0
    def setUp(self):
        super(DefaultPolicyTestCase, self).setUp()
        policy.reset()
        policy.init()
        self.addCleanup(policy.reset)

        self.rules = {"default": "", "example:exist": "!"}

        self._set_rules("default")

        self.context = context.Context("fake", "fake")
Ejemplo n.º 4
0
    def setUp(self):
        super(DefaultPolicyTestCase, self).setUp()
        policy.reset()
        policy.init()
        self.addCleanup(policy.reset)

        self.rules = {
            "default": '',
            "example:exist": '!',
        }

        self._set_rules('default')

        self.context = context.Context('fake', 'fake')
Ejemplo n.º 5
0
    def setUp(self):
        super(DefaultPolicyTestCase, self).setUp()
        self.skipTest("Not ready yet")
        policy.reset()
        policy.init()
        self.addCleanup(policy.reset)

        self.rules = {
            "default": '',
            "example:exist": '!',
        }

        self._set_rules('default')

        self.context = context.Context('fake', 'fake')
Ejemplo n.º 6
0
 def setUp(self):
     super(PolicyTestCase, self).setUp()
     policy.reset()
     self.addCleanup(policy.reset)
     # NOTE(vish): preload rules to circumvent reloading from file
     policy.init()
     rules = {
         "true": "@",
         "example:allowed": "@",
         "example:denied": "!",
         "example:get_http": "http:http://www.example.com",
         "example:my_file": "role:compute_admin or tenant_id:%(tenant_id)s",
         "example:early_and_fail": "! and @",
         "example:early_or_success": "@ or !",
         "example:lowercase_admin": "role:admin or role:sysadmin",
         "example:uppercase_admin": "role:ADMIN or role:sysadmin",
     }
     # NOTE(vish): then overload underlying rules
     common_policy.set_rules(common_policy.Rules(dict((k, common_policy.parse_rule(v)) for k, v in rules.items())))
     self.context = context.Context("fake", "fake", roles=["member"])
     self.target = {}
Ejemplo n.º 7
0
 def setUp(self):
     super(PolicyTestCase, self).setUp()
     policy.reset()
     self.addCleanup(policy.reset)
     # NOTE(vish): preload rules to circumvent reloading from file
     policy.init()
     rules = {
         "true": '@',
         "example:allowed": '@',
         "example:denied": '!',
         "example:get_http": "http:http://www.example.com",
         "example:my_file": "role:compute_admin or tenant_id:%(tenant_id)s",
         "example:early_and_fail": "! and @",
         "example:early_or_success": "@ or !",
         "example:lowercase_admin": "role:admin or role:sysadmin",
         "example:uppercase_admin": "role:ADMIN or role:sysadmin",
     }
     # NOTE(vish): then overload underlying rules
     common_policy.set_rules(common_policy.Rules(
         dict((k, common_policy.parse_rule(v))
              for k, v in rules.items())))
     self.context = context.Context('fake', 'fake', roles=['member'])
     self.target = {}
Ejemplo n.º 8
0
 def __init__(self, path):
     LOG.info(_('Initializing extension manager.'))
     self.path = path
     self.extensions = {}
     self._load_all_extensions()
     policy.reset()
Ejemplo n.º 9
0
    def setUp(self):
        super(TackerPolicyTestCase, self).setUp()
        self.skipTest("Not ready yet")
        policy.reset()
        policy.init()
        self.addCleanup(policy.reset)
        self.admin_only_legacy = "role:admin"
        self.admin_or_owner_legacy = "role:admin or tenant_id:%(tenant_id)s"
        # Add a Fake 'something' resource to RESOURCE_ATTRIBUTE_MAP
        attributes.RESOURCE_ATTRIBUTE_MAP.update(FAKE_RESOURCE)
        self.rules = dict(
            (k, common_policy.parse_rule(v)) for k, v in {
                "context_is_admin":
                "role:admin",
                "admin_or_network_owner":
                "rule:context_is_admin or "
                "tenant_id:%(network:tenant_id)s",
                "admin_or_owner": ("rule:context_is_admin or "
                                   "tenant_id:%(tenant_id)s"),
                "admin_only":
                "rule:context_is_admin",
                "regular_user":
                "******",
                "shared":
                "field:networks:shared=True",
                "external":
                "field:networks:router:external=True",
                "default":
                '@',
                "create_network":
                "rule:admin_or_owner",
                "create_network:shared":
                "rule:admin_only",
                "update_network":
                '@',
                "update_network:shared":
                "rule:admin_only",
                "get_network":
                "rule:admin_or_owner or "
                "rule:shared or "
                "rule:external",
                "create_port:mac":
                "rule:admin_or_network_owner",
                "create_something":
                "rule:admin_or_owner",
                "create_something:attr":
                "rule:admin_or_owner",
                "create_something:attr:sub_attr_1":
                "rule:admin_or_owner",
                "create_something:attr:sub_attr_2":
                "rule:admin_only",
                "get_firewall_policy":
                "rule:admin_or_owner or "
                "rule:shared",
                "get_firewall_rule":
                "rule:admin_or_owner or "
                "rule:shared"
            }.items())

        def fakepolicyinit():
            common_policy.set_rules(common_policy.Rules(self.rules))

        def remove_fake_resource():
            del attributes.RESOURCE_ATTRIBUTE_MAP["%ss" % FAKE_RESOURCE_NAME]

        self.patcher = mock.patch.object(tacker.policy,
                                         'init',
                                         new=fakepolicyinit)
        self.patcher.start()
        self.addCleanup(remove_fake_resource)
        self.context = context.Context('fake', 'fake', roles=['user'])
        plugin_klass = importutils.import_class(
            "tacker.db.db_base_plugin_v2.TackerDbPluginV2")
        self.manager_patcher = mock.patch('tacker.manager.TackerManager')
        fake_manager = self.manager_patcher.start()
        fake_manager_instance = fake_manager.return_value
        fake_manager_instance.plugin = plugin_klass()