コード例 #1
0
 def _set_policy_rules(self):
     rules = {'compute:get': common_policy.parse_rule(''),
              'compute_extension:instance_actions':
                  common_policy.parse_rule(''),
              'compute_extension:instance_actions:events':
                  common_policy.parse_rule('is_admin:True')}
     policy.set_rules(rules)
コード例 #2
0
 def _set_policy_rules(self):
     rules = {
         "compute:get": common_policy.parse_rule(""),
         "os_compute_api:os-instance-actions": common_policy.parse_rule(""),
         "os_compute_api:os-instance-actions:events": common_policy.parse_rule("is_admin:True"),
     }
     policy.set_rules(rules)
コード例 #3
0
 def _set_policy_rules(self):
     rules = {'compute:get': common_policy.parse_rule(''),
              'os_compute_api:os-instance-actions':
                  common_policy.parse_rule(''),
              'os_compute_api:os-instance-actions:events':
                  common_policy.parse_rule('is_admin:True')}
     policy.set_rules(rules)
コード例 #4
0
 def _set_policy_rules(self):
     rules = {
         "compute:get": common_policy.parse_rule(""),
         "compute_extension:instance_actions": common_policy.parse_rule(""),
         "compute_extension:instance_actions:events": common_policy.parse_rule("is_admin:True"),
     }
     policy.set_rules(rules)
コード例 #5
0
 def test_shelve_allowed(self):
     rules = {'compute:get': common_policy.parse_rule(''),
              'compute_extension:%sshelve' % self.prefix:
                  common_policy.parse_rule('')}
     policy.set_rules(rules)
     self.stubs.Set(db, 'instance_get_by_uuid', fake_instance_get_by_uuid)
     self.assertRaises(exception.Forbidden, self.controller._shelve,
             self.req, str(uuid.uuid4()), {})
コード例 #6
0
ファイル: test_shelve.py プロジェクト: AsherBond/nova
    def test_unshelve_allowed(self):
        rules = {'compute:get': common_policy.parse_rule(''),
                 'compute_extension:unshelve': common_policy.parse_rule('')}
        policy.set_rules(rules)

        self.stubs.Set(db, 'instance_get_by_uuid', fake_instance_get_by_uuid)
        req = fakes.HTTPRequest.blank('/v2/123/servers/12/os-shelve')
        self.assertRaises(exception.Forbidden, self.controller._unshelve,
                req, str(uuid.uuid4()), {})
コード例 #7
0
ファイル: test_shelve.py プロジェクト: B-Rich/nova-1
    def test_shelve_offload_allowed(self):
        rules = policy.Rules({'compute:get': policy.parse_rule(''),
                              'compute_extension:v3:shelve_offload':
                              policy.parse_rule('')})
        policy.set_rules(rules)

        self.stubs.Set(db, 'instance_get_by_uuid', fake_instance_get_by_uuid)
        req = fakes.HTTPRequestV3.blank('/servers/12/os-shelve')
        self.assertRaises(exception.Forbidden,
                self.controller._shelve_offload, req, str(uuid.uuid4()), {})
コード例 #8
0
ファイル: test_shelve.py プロジェクト: Cisco-OCPChina/nova
    def test_shelve_allowed(self):
        rules = policy.Rules({'compute:get': policy.parse_rule(''),
                              'compute_extension:shelve':
                              policy.parse_rule('')})
        policy.set_rules(rules)

        self.stubs.Set(db, 'instance_get_by_uuid', fake_instance_get_by_uuid)
        req = fakes.HTTPRequest.blank('/v2/123/servers/12/os-shelve')
        self.assertRaises(exception.NotAuthorized, self.controller._shelve,
                req, str(uuid.uuid4()), {})
コード例 #9
0
 def test_create_vol_backed_img_snapshotting_policy_blocks_role(self):
     """Don't permit a snapshot of a volume backed instance if configured
     not to based on role
     """
     body = {"createImage": {"name": "Snapshot 1"}}
     rule_name = "compute:snapshot_volume_backed"
     rules = {rule_name: common_policy.parse_rule("role:no_role"), "compute:get": common_policy.parse_rule("")}
     policy.set_rules(rules)
     with mock.patch.object(compute_api.API, "is_volume_backed_instance", return_value=True):
         exc = self.assertRaises(
             exception.PolicyNotAuthorized, self.controller._action_create_image, self.req, FAKE_UUID, body=body
         )
         self.assertEqual("Policy doesn't allow %s to be performed." % rule_name, exc.format_message())
コード例 #10
0
ファイル: test_instance_actions.py プロジェクト: NetApp/nova
    def test_list_actions_restricted_by_project(self):
        rules = policy.Rules({'compute:get': policy.parse_rule(''),
                              'compute_extension:instance_actions':
                               policy.parse_rule('project_id:%(project_id)s')})
        policy.set_rules(rules)

        def fake_instance_get_by_uuid(context, instance_id):
            return {'name': 'fake', 'project_id': '%s_unequal' %
                                                            context.project_id}

        self.stubs.Set(db, 'instance_get_by_uuid', fake_instance_get_by_uuid)
        req = fakes.HTTPRequest.blank('/v2/123/servers/12/os-instance-actions')
        self.assertRaises(exception.NotAuthorized, self.controller.index, req,
                          str(uuid.uuid4()))
コード例 #11
0
ファイル: test_instance_actions.py プロジェクト: jziub/nova
    def test_get_action_restricted_by_project(self):
        rules = policy.Rules(
            {
                "compute:get": policy.parse_rule(""),
                "compute_extension:instance_actions": policy.parse_rule("project_id:%(project_id)s"),
            }
        )
        policy.set_rules(rules)

        def fake_instance_get_by_uuid(context, instance_id, columns_to_join=None):
            return fake_instance.fake_db_instance(**{"name": "fake", "project_id": "%s_unequal" % context.project_id})

        self.stubs.Set(db, "instance_get_by_uuid", fake_instance_get_by_uuid)
        req = fakes.HTTPRequest.blank("/v2/123/servers/12/os-instance-actions/1")
        self.assertRaises(exception.NotAuthorized, self.controller.show, req, str(uuid.uuid4()), "1")
コード例 #12
0
ファイル: test_keypairs.py プロジェクト: zinic/nova
 def test_keypair_list_pass_policy(self):
     rules = {'compute_extension:v3:keypairs:index':
                  common_policy.parse_rule('')}
     policy.set_rules(rules)
     req = fakes.HTTPRequestV3.blank('/keypairs')
     res = self.KeyPairController.index(req)
     self.assertIn('keypairs', res)
コード例 #13
0
    def test_unshelve_restricted_by_role(self):
        rules = {'compute_extension:%sunshelve' % self.prefix:
                     common_policy.parse_rule('role:admin')}
        policy.set_rules(rules)

        self.assertRaises(exception.Forbidden, self.controller._unshelve,
                self.req, str(uuid.uuid4()), {})
コード例 #14
0
ファイル: test_keypairs.py プロジェクト: Dynavisor/nova
 def test_keypair_delete_fail_policy(self):
     rules = {self.policy_path + ':delete':
                  common_policy.parse_rule('role:admin')}
     policy.set_rules(rules)
     self.assertRaises(exception.Forbidden,
                       self.KeyPairController.delete,
                       self.req, 'FAKE')
コード例 #15
0
ファイル: test_keypairs.py プロジェクト: imsplitbit/nova
 def test_keypair_delete_pass_policy(self):
     rules = policy.Rules({"compute_extension:v3:keypairs:delete": policy.parse_rule("")})
     policy.set_rules(rules)
     req = fakes.HTTPRequest.blank("/v3/keypairs/FAKE")
     req.method = "DELETE"
     res = self.KeyPairController.delete(req, "FAKE")
     self.assertEqual(res.status_int, 202)
コード例 #16
0
ファイル: test_keypairs.py プロジェクト: zinic/nova
 def test_keypair_show_pass_policy(self):
     rules = {'compute_extension:v3:keypairs:show':
                 common_policy.parse_rule('')}
     policy.set_rules(rules)
     req = fakes.HTTPRequestV3.blank('/keypairs/FAKE')
     res = self.KeyPairController.show(req, 'FAKE')
     self.assertIn('keypair', res)
コード例 #17
0
ファイル: test_keypairs.py プロジェクト: zinic/nova
 def test_keypair_delete_pass_policy(self):
     rules = {'compute_extension:v3:keypairs:delete':
                  common_policy.parse_rule('')}
     policy.set_rules(rules)
     req = fakes.HTTPRequestV3.blank('/keypairs/FAKE')
     req.method = 'DELETE'
     self.assertIsNone(self.KeyPairController.delete(req, 'FAKE'))
コード例 #18
0
ファイル: test_keypairs.py プロジェクト: Dynavisor/nova
 def test_keypair_list_fail_policy(self):
     rules = {self.policy_path + ':index':
                  common_policy.parse_rule('role:admin')}
     policy.set_rules(rules)
     self.assertRaises(exception.Forbidden,
                       self.KeyPairController.index,
                       self.req)
コード例 #19
0
ファイル: test_keypairs.py プロジェクト: Dynavisor/nova
 def test_keypair_create_pass_policy(self):
     body = {'keypair': {'name': 'create_test'}}
     rules = {self.policy_path + ':create':
                  common_policy.parse_rule('')}
     policy.set_rules(rules)
     res = self.KeyPairController.create(self.req, body=body)
     self.assertIn('keypair', res)
コード例 #20
0
ファイル: test_shelve.py プロジェクト: 674009287/nova
    def test_shelve_offload_allowed(self):
        rules = policy.Rules({'compute:get': policy.parse_rule(''),
                              'compute_extension:v3:shelve_offload':
                              policy.parse_rule('')})
        policy.set_rules(rules)

        def fake_instance_get_by_uuid(context, instance_id,
                                      columns_to_join=None):
            return fake_instance.fake_db_instance(
                **{'name': 'fake', 'project_id': '%s_unequal' %
                       context.project_id})

        self.stubs.Set(db, 'instance_get_by_uuid', fake_instance_get_by_uuid)
        req = fakes.HTTPRequest.blank('/v3/servers/12/os-shelve')
        self.assertRaises(exception.NotAuthorized,
                self.controller._shelve_offload, req, str(uuid.uuid4()), {})
コード例 #21
0
 def test_keypair_create_fail_policy(self):
     body = {"keypair": {"name": "create_test"}}
     rules = {"compute_extension:keypairs:create": common_policy.parse_rule("role:admin")}
     policy.set_rules(rules)
     req = fakes.HTTPRequest.blank("/v2/fake/os-keypairs")
     req.method = "POST"
     self.assertRaises(exception.Forbidden, self.KeyPairController.create, req, body)
コード例 #22
0
 def test_keypair_list_pass_policy(self):
     rules = policy.Rules({'compute_extension:v3:os-keypairs:index':
                          policy.parse_rule('')})
     policy.set_rules(rules)
     req = fakes.HTTPRequest.blank('/v3/fake/os-keypairs')
     res = self.KeyPairController.index(req)
     self.assertTrue('keypairs' in res)
コード例 #23
0
    def test_list_actions_restricted_by_project(self):
        rules = policy.Rules({'compute:get': policy.parse_rule(''),
                              'compute_extension:v3:os-server-actions':
                               policy.parse_rule('project_id:%(project_id)s')})
        policy.set_rules(rules)

        def fake_instance_get_by_uuid(context, instance_id,
                                      columns_to_join=None, use_slave=False):
            return fake_instance.fake_db_instance(
                **{'name': 'fake', 'project_id': '%s_unequal' %
                       context.project_id})

        self.stubs.Set(db, 'instance_get_by_uuid', fake_instance_get_by_uuid)
        req = fakes.HTTPRequestV3.blank('/servers/12/os-server-actions')
        self.assertRaises(exception.Forbidden, self.controller.index, req,
                          str(uuid.uuid4()))
コード例 #24
0
ファイル: test_keypairs.py プロジェクト: FengYang/nova
 def test_keypair_show_pass_policy(self):
     rules = {self.policy_path + ':show':
                  common_policy.parse_rule('')}
     policy.set_rules(rules)
     req = fakes.HTTPRequest.blank(self.base_url + '/os-keypairs/FAKE')
     res = self.KeyPairController.show(req, 'FAKE')
     self.assertIn('keypair', res)
コード例 #25
0
ファイル: test_keypairs.py プロジェクト: FengYang/nova
 def test_keypair_list_pass_policy(self):
     rules = {self.policy_path + ':index':
                  common_policy.parse_rule('')}
     policy.set_rules(rules)
     req = fakes.HTTPRequest.blank(self.base_url + '/os-keypairs')
     res = self.KeyPairController.index(req)
     self.assertIn('keypairs', res)
コード例 #26
0
 def test_keypair_show_pass_policy(self):
     rules = policy.Rules({'compute_extension:v3:os-keypairs:show':
                          policy.parse_rule('')})
     policy.set_rules(rules)
     req = fakes.HTTPRequest.blank('/v3/fake/os-keypairs/FAKE')
     res = self.KeyPairController.show(req, 'FAKE')
     self.assertTrue('keypair' in res)
コード例 #27
0
 def test_keypair_show_fail_policy(self):
     rules = policy.Rules({'compute_extension:v3:os-keypairs:show':
                          policy.parse_rule('role:admin')})
     policy.set_rules(rules)
     req = fakes.HTTPRequest.blank('/v3/fake/os-keypairs/FAKE')
     self.assertRaises(exception.NotAuthorized,
                       self.KeyPairController.show,
                       req, 'FAKE')
コード例 #28
0
 def test_keypair_delete_pass_policy(self):
     rules = policy.Rules({'compute_extension:v3:os-keypairs:delete':
                          policy.parse_rule('')})
     policy.set_rules(rules)
     req = fakes.HTTPRequest.blank('/v3/fake/os-keypairs/FAKE')
     req.method = 'DELETE'
     res = self.KeyPairController.delete(req, 'FAKE')
     self.assertEqual(res.status_int, 202)
コード例 #29
0
 def test_keypair_list_fail_policy(self):
     rules = policy.Rules({'compute_extension:keypairs:index':
                          policy.parse_rule('role:admin')})
     policy.set_rules(rules)
     req = fakes.HTTPRequest.blank('/v2/fake/os-keypairs')
     self.assertRaises(exception.NotAuthorized,
                       self.KeyPairController.index,
                       req)
コード例 #30
0
ファイル: test_shelve.py プロジェクト: 674009287/nova
    def test_shelve_offload_restricted_by_role(self):
        rules = policy.Rules({'compute_extension:v3:os-shelve:shelve_offload':
                              policy.parse_rule('role:admin')})
        policy.set_rules(rules)

        req = fakes.HTTPRequest.blank('/v3/servers/12/os-shelve')
        self.assertRaises(exception.NotAuthorized,
                self.controller._shelve_offload, req, str(uuid.uuid4()), {})
コード例 #31
0
 def test_keypair_list_pass_policy(self):
     rules = {self.policy_path + ':index': common_policy.parse_rule('')}
     policy.set_rules(rules)
     res = self.KeyPairController.index(self.req)
     self.assertIn('keypairs', res)
コード例 #32
0
ファイル: test_keypairs.py プロジェクト: XiaoDongZhi/nova
 def test_keypair_list_pass_policy(self):
     rules = {self.policy_path + ':index': common_policy.parse_rule('')}
     policy.set_rules(rules)
     req = fakes.HTTPRequest.blank(self.base_url + '/os-keypairs')
     res = self.KeyPairController.index(req)
     self.assertIn('keypairs', res)
コード例 #33
0
 def _set_policy_rules(self):
     rules = {'compute:get': common_policy.parse_rule(''),
              'compute_extension:v3:os-instance-actions':
                  common_policy.parse_rule('project_id:%(project_id)s')}
     policy.set_rules(rules)
コード例 #34
0
 def set_rules(self, rules):
     common_policy.set_rules(common_policy.Rules(
             dict((k, common_policy.parse_rule(v))
                  for k, v in rules.items())))
コード例 #35
0
 def test_keypair_delete_pass_policy(self):
     rules = {self.policy_path + ':delete': common_policy.parse_rule('')}
     policy.set_rules(rules)
     self.KeyPairController.delete(self.req, 'FAKE')
コード例 #36
0
ファイル: policy_fixture.py プロジェクト: bopopescu/nova-24
 def set_rules(self, rules):
     policy = nova.policy._ENFORCER
     policy.set_rules(
         dict((k, common_policy.parse_rule(v)) for k, v in rules.items()))
コード例 #37
0
ファイル: test_policy.py プロジェクト: SUSE-Cloud/nova
 def _set_rules(self, default_rule):
     rules = common_policy.Rules(
         dict((k, common_policy.parse_rule(v))
              for k, v in self.rules.items()), default_rule)
     common_policy.set_rules(rules)
コード例 #38
0
 def _set_rules(self, default_rule):
     policy.reset()
     rules = {k: common_policy.parse_rule(v) for k, v in self.rules.items()}
     policy.init(rules=rules, default_rule=default_rule, use_conf=False)
コード例 #39
0
 def test_keypair_show_pass_policy(self):
     rules = {self.policy_path + ':show': common_policy.parse_rule('')}
     policy.set_rules(rules)
     res = self.KeyPairController.show(self.req, 'FAKE')
     self.assertIn('keypair', res)
コード例 #40
0
 def test_keypair_create_pass_policy(self):
     body = {'keypair': {'name': 'create_test'}}
     rules = {self.policy_path + ':create': common_policy.parse_rule('')}
     policy.set_rules(rules)
     res = self.KeyPairController.create(self.req, body=body)
     self.assertIn('keypair', res)
コード例 #41
0
 def set_rules(self, rules):
     policy = nova.policy._ENFORCER
     policy.set_rules(
         {k: common_policy.parse_rule(v)
          for k, v in rules.items()})
コード例 #42
0
ファイル: test_keypairs.py プロジェクト: XiaoDongZhi/nova
 def test_keypair_show_pass_policy(self):
     rules = {self.policy_path + ':show': common_policy.parse_rule('')}
     policy.set_rules(rules)
     req = fakes.HTTPRequest.blank(self.base_url + '/os-keypairs/FAKE')
     res = self.KeyPairController.show(req, 'FAKE')
     self.assertIn('keypair', res)