示例#1
0
    def setUp(self):
        super(ProjectAdminTests, self).setUp()
        self.loadapp()

        self.policy_file = self.useFixture(temporaryfile.SecureTempFile())
        self.policy_file_name = self.policy_file.file_name
        self.useFixture(
            ksfixtures.Policy(
                self.config_fixture, policy_file=self.policy_file_name
            )
        )
        self.config_fixture.config(group='oslo_policy', enforce_scope=True)

        # Reuse the system administrator account created during
        # ``keystone-manage bootstrap``
        self.user_id = self.bootstrapper.admin_user_id
        self.project_id = self.bootstrapper.project_id
        auth = self.build_authentication_request(
            user_id=self.user_id,
            password=self.bootstrapper.admin_password,
            project_id=self.project_id
        )

        # Grab a token using the persona we're testing and prepare headers
        # for requests we'll be making in the tests.
        with self.test_client() as c:
            r = c.post('/v3/auth/tokens', json=auth)
            self.token_id = r.headers['X-Subject-Token']
            self.headers = {'X-Auth-Token': self.token_id}
示例#2
0
    def setUp(self):
        super(DomainAdminTests, self).setUp()
        self.loadapp()
        self.policy_file = self.useFixture(temporaryfile.SecureTempFile())
        self.policy_file_name = self.policy_file.file_name
        self.useFixture(
            ksfixtures.Policy(self.config_fixture,
                              policy_file=self.policy_file_name))
        self._override_policy()
        self.config_fixture.config(group='oslo_policy', enforce_scope=True)

        domain = PROVIDERS.resource_api.create_domain(uuid.uuid4().hex,
                                                      unit.new_domain_ref())
        self.domain_id = domain['id']
        domain_admin = unit.new_user_ref(domain_id=self.domain_id)
        self.user_id = PROVIDERS.identity_api.create_user(domain_admin)['id']
        PROVIDERS.assignment_api.create_grant(self.bootstrapper.admin_role_id,
                                              user_id=self.user_id,
                                              domain_id=self.domain_id)

        auth = self.build_authentication_request(
            user_id=self.user_id,
            password=domain_admin['password'],
            domain_id=self.domain_id)

        # Grab a token using the persona we're testing and prepare headers
        # for requests we'll be making in the tests.
        with self.test_client() as c:
            r = c.post('/v3/auth/tokens', json=auth)
            self.token_id = r.headers['X-Subject-Token']
            self.headers = {'X-Auth-Token': self.token_id}
示例#3
0
 def _set_policy(self, new_policy):
     self.tempfile = self.useFixture(temporaryfile.SecureTempFile())
     self.tmpfilename = self.tempfile.file_name
     self.config_fixture.config(group='oslo_policy',
                                policy_file=self.tmpfilename)
     with open(self.tmpfilename, "w") as policyfile:
         policyfile.write(jsonutils.dumps(new_policy))
示例#4
0
 def setUp(self):
     """Setup for Identity Filter Test Cases."""
     super(IdentityTestFilteredCase, self).setUp()
     self.tempfile = self.useFixture(temporaryfile.SecureTempFile())
     self.tmpfilename = self.tempfile.file_name
     self.config_fixture.config(group='oslo_policy',
                                policy_file=self.tmpfilename)
示例#5
0
    def setUp(self):
        super(ProjectAdminTests, self).setUp()
        self.loadapp()

        self.policy_file = self.useFixture(temporaryfile.SecureTempFile())
        self.policy_file_name = self.policy_file.file_name
        self.useFixture(
            ksfixtures.Policy(
                self.config_fixture, policy_file=self.policy_file_name
            )
        )
        _override_policy(self.policy_file_name)
        self.config_fixture.config(group='oslo_policy', enforce_scope=True)

        self.user_id = self.bootstrapper.admin_user_id
        PROVIDERS.assignment_api.create_grant(
            self.bootstrapper.admin_role_id, user_id=self.user_id,
            project_id=self.bootstrapper.project_id
        )
        self.project_id = self.bootstrapper.project_id

        auth = self.build_authentication_request(
            user_id=self.user_id, password=self.bootstrapper.admin_password,
            project_id=self.bootstrapper.project_id
        )

        # Grab a token using the persona we're testing and prepare headers
        # for requests we'll be making in the tests.
        with self.test_client() as c:
            r = c.post('/v3/auth/tokens', json=auth)
            self.token_id = r.headers['X-Subject-Token']
            self.headers = {'X-Auth-Token': self.token_id}
示例#6
0
    def setUp(self):
        """Setup for Identity Protection Test Cases.

        As well as the usual housekeeping, create a set of domains,
        users, roles and projects for the subsequent tests:

        - Three domains: A,B & C.  C is disabled.
        - DomainA has user1, DomainB has user2 and user3
        - DomainA has group1 and group2, DomainB has group3
        - User1 has two roles on DomainA
        - User2 has one role on DomainA

        Remember that there will also be a fourth domain in existence,
        the default domain.

        """
        # Ensure that test_v3.RestfulTestCase doesn't load its own
        # sample data, which would make checking the results of our
        # tests harder
        super(IdentityTestProtectedCase, self).setUp()
        self.tempfile = self.useFixture(temporaryfile.SecureTempFile())
        self.tmpfilename = self.tempfile.file_name
        self.config_fixture.config(group='oslo_policy',
                                   policy_file=self.tmpfilename)

        # A default auth request we can use - un-scoped user token
        self.auth = self.build_authentication_request(
            user_id=self.user1['id'], password=self.user1['password'])
示例#7
0
    def setUp(self):
        super(OwnerTests, self).setUp()
        self.loadapp()

        self.policy_file = self.useFixture(temporaryfile.SecureTempFile())
        self.policy_file_name = self.policy_file.file_name
        self.useFixture(
            ksfixtures.Policy(
                self.config_fixture, policy_file=self.policy_file_name
            )
        )

        self._override_policy()
        self.config_fixture.config(group='oslo_policy', enforce_scope=True)

        # in this case app_cred_user_id and user_id are the same since we
        # are testing the owner
        self.user_id = self.app_cred_user_id
        auth = self.build_authentication_request(
            user_id=self.user_id,
            password=self.app_cred_user_password,
            project_id=self.app_cred_project_id
        )

        # Grab a token using the persona we're testing and prepare headers
        # for requests we'll be making in the tests.
        with self.test_client() as c:
            r = c.post('/v3/auth/tokens', json=auth)
            self.token_id = r.headers['X-Subject-Token']
            self.headers = {'X-Auth-Token': self.token_id}
示例#8
0
 def setUp(self):
     # self.tmpfilename should exist before setUp super is called
     # this is to ensure it is available for the config_fixture in
     # the config_overrides call.
     self.tempfile = self.useFixture(temporaryfile.SecureTempFile())
     self.tmpfilename = self.tempfile.file_name
     super(PolicyFileTestCase, self).setUp()
     self.target = {}
示例#9
0
 def test_invalid_json_raises_error(self):
     tmpfile = self.useFixture(temporaryfile.SecureTempFile())
     invalid_access_rules = tmpfile.file_name
     with open(invalid_access_rules, 'w') as f:
         f.write("This is an invalid data")
     self.useFixture(
         access_rules_config.AccessRulesConfig(
             self.config_fixture, rules_file=invalid_access_rules))
     self.assertRaises(exception.AccessRulesConfigFileError,
                       json_driver.AccessRulesConfig)
示例#10
0
    def setUp(self):
        """Setup for Identity Filter Test Cases."""

        super(IdentityTestFilteredCase, self).setUp()

        # Initialize the policy engine and allow us to write to a temp
        # file in each test to create the policies
        self.orig_policy_file = CONF.policy_file
        rules.reset()
        self.tempfile = self.useFixture(temporaryfile.SecureTempFile())
        self.tmpfilename = self.tempfile.file_name
        self.config_fixture.config(policy_file=self.tmpfilename)

        # drop the policy rules
        self.addCleanup(rules.reset)
示例#11
0
    def setUp(self):
        super(ProjectUserTestsWithoutEnforceScope, self).setUp()
        self.loadapp()
        self.policy_file = self.useFixture(temporaryfile.SecureTempFile())
        self.policy_file_name = self.policy_file.file_name
        self.useFixture(
            ksfixtures.Policy(
                self.config_fixture, policy_file=self.policy_file_name
            )
        )
        self._override_policy()
        # Explicity set enforce_scope to False to make sure we maintain
        # backwards compatibility with project users.
        self.config_fixture.config(group='oslo_policy', enforce_scope=False)

        domain = PROVIDERS.resource_api.create_domain(
            uuid.uuid4().hex, unit.new_domain_ref()
        )
        user = unit.new_user_ref(domain_id=domain['id'])
        self.user_id = PROVIDERS.identity_api.create_user(user)['id']

        self.project_id = PROVIDERS.resource_api.create_project(
            uuid.uuid4().hex, unit.new_project_ref(domain_id=domain['id'])
        )['id']

        PROVIDERS.assignment_api.create_grant(
            self.bootstrapper.admin_role_id, user_id=self.user_id,
            project_id=self.project_id
        )

        auth = self.build_authentication_request(
            user_id=self.user_id,
            password=user['password'],
            project_id=self.project_id
        )

        # Grab a token using the persona we're testing and prepare headers
        # for requests we'll be making in the tests.
        with self.test_client() as c:
            r = c.post('/v3/auth/tokens', json=auth)
            self.token_id = r.headers['X-Subject-Token']
            self.headers = {'X-Auth-Token': self.token_id}
示例#12
0
    def setUp(self):
        super(ProjectMemberTests, self).setUp()
        self.loadapp()

        self.policy_file = self.useFixture(temporaryfile.SecureTempFile())
        self.policy_file_name = self.policy_file.file_name
        self.useFixture(
            ksfixtures.Policy(
                self.config_fixture, policy_file=self.policy_file_name
            )
        )

        self._override_policy()
        self.config_fixture.config(group='oslo_policy', enforce_scope=True)

        project_admin = unit.new_user_ref(
            domain_id=CONF.identity.default_domain_id)
        self.user_id = PROVIDERS.identity_api.create_user(project_admin)['id']
        # even project admin of project where the app credential
        # is intended for cannot perform app credential operations
        PROVIDERS.assignment_api.create_grant(
            self.bootstrapper.member_role_id,
            user_id=self.user_id,
            project_id=self.app_cred_project_id
        )
        auth = self.build_authentication_request(
            user_id=self.user_id, password=project_admin['password'],
            project_id=self.app_cred_project_id
        )

        # Grab a token using the persona we're testing and prepare headers
        # for requests we'll be making in the tests.
        with self.test_client() as c:
            r = c.post('/v3/auth/tokens', json=auth)
            self.token_id = r.headers['X-Subject-Token']
            self.headers = {'X-Auth-Token': self.token_id}
示例#13
0
 def setUp(self):
     """Setup for Identity Filter Test Cases."""
     self.tempfile = self.useFixture(temporaryfile.SecureTempFile())
     self.tmpfilename = self.tempfile.file_name
     super(IdentityTestFilteredCase, self).setUp()
示例#14
0
    def setUp(self):
        super(TrustTests, self).setUp()
        self.loadapp()
        self.policy_file = self.useFixture(temporaryfile.SecureTempFile())
        self.policy_file_name = self.policy_file.file_name
        self.useFixture(
            ksfixtures.Policy(self.config_fixture,
                              policy_file=self.policy_file_name))

        domain = PROVIDERS.resource_api.create_domain(uuid.uuid4().hex,
                                                      unit.new_domain_ref())
        self.domain_id = domain['id']

        trustor_user = unit.new_user_ref(domain_id=self.domain_id)
        self.trustor_user_id = PROVIDERS.identity_api.create_user(
            trustor_user)['id']
        trustee_user = unit.new_user_ref(domain_id=self.domain_id)
        self.trustee_user_id = PROVIDERS.identity_api.create_user(
            trustee_user)['id']
        project = PROVIDERS.resource_api.create_project(
            uuid.uuid4().hex, unit.new_project_ref(domain_id=self.domain_id))
        self.project_id = project['id']
        PROVIDERS.assignment_api.create_grant(self.bootstrapper.member_role_id,
                                              user_id=self.trustor_user_id,
                                              project_id=self.project_id)
        PROVIDERS.assignment_api.create_grant(self.bootstrapper.member_role_id,
                                              user_id=self.trustee_user_id,
                                              project_id=project['id'])
        self.trust_id = uuid.uuid4().hex
        self.trust_data = {
            'trust': {
                'trustor_user_id': self.trustor_user_id,
                'trustee_user_id': self.trustee_user_id,
                'project_id': self.project_id,
                'impersonation': False
            },
            'roles': [{
                "id": self.bootstrapper.member_role_id
            }]
        }
        auth = self.build_authentication_request(
            user_id=self.trustor_user_id,
            password=trustor_user['password'],
            project_id=project['id'])
        # Grab a token using the trustor persona we're testing and prepare
        # headers for requests we'll be making in the tests.
        with self.test_client() as c:
            r = c.post('/v3/auth/tokens', json=auth)
            self.token_id = r.headers['X-Subject-Token']
            self.trustor_headers = {'X-Auth-Token': self.token_id}

        auth = self.build_authentication_request(
            user_id=self.trustee_user_id,
            password=trustee_user['password'],
            project_id=project['id'])
        # Grab a token using the trustee persona we're testing and prepare
        # headers for requests we'll be making in the tests.
        with self.test_client() as c:
            r = c.post('/v3/auth/tokens', json=auth)
            self.token_id = r.headers['X-Subject-Token']
            self.trustee_headers = {'X-Auth-Token': self.token_id}