Ejemplo n.º 1
0
    def load_backends(self):
        """Initializes each manager and assigns them to an attribute."""

        # TODO(blk-u): Shouldn't need to clear the registry here, but some
        # tests call load_backends multiple times. These should be fixed to
        # only call load_backends once.
        dependency.reset()

        # TODO(morganfainberg): Shouldn't need to clear the registry here, but
        # some tests call load_backends multiple times.  Since it is not
        # possible to re-configure a backend, we need to clear the list.  This
        # should eventually be removed once testing has been cleaned up.
        kvs_core.KEY_VALUE_STORE_REGISTRY.clear()

        drivers = service.load_backends()

        # TODO(stevemar): currently, load oauth1 driver as well, eventually
        # we need to have this as optional.
        from keystone.contrib import oauth1
        drivers['oauth1_api'] = oauth1.Manager()

        from keystone.contrib import federation
        drivers['federation_api'] = federation.Manager()

        dependency.resolve_future_dependencies()

        for manager_name, manager in six.iteritems(drivers):
            setattr(self, manager_name, manager)
Ejemplo n.º 2
0
    def test_supported_token_providers(self):
        # test default config

        dependency.reset()
        self.assertIsInstance(token.provider.Manager().driver, uuid.Provider)

        dependency.reset()
        self.config_fixture.config(
            group='token', provider='keystone.token.providers.uuid.Provider')
        self.assertIsInstance(token.provider.Manager().driver, uuid.Provider)

        dependency.reset()
        self.config_fixture.config(
            group='token', provider='keystone.token.providers.pki.Provider')
        self.assertIsInstance(token.provider.Manager().driver, pki.Provider)

        dependency.reset()
        self.config_fixture.config(
            group='token', provider='keystone.token.providers.pkiz.Provider')
        self.assertIsInstance(token.provider.Manager().driver, pkiz.Provider)

        dependency.reset()
        self.config_fixture.config(
            group='token', provider='keystone.token.providers.fernet.Provider')
        self.assertIsInstance(token.provider.Manager().driver, fernet.Provider)
Ejemplo n.º 3
0
 def test_config_upload(self):
     dependency.reset()
     with mock.patch('__builtin__.print') as mock_print:
         self.assertRaises(SystemExit, cli.DomainConfigUpload.main)
         mock_print.assert_has_calls(
             [mock.call(_('The --all option cannot be used with '
                          'the --domain-name option'))])
Ejemplo n.º 4
0
    def load_backends(self):
        """Initializes each manager and assigns them to an attribute."""

        # TODO(blk-u): Shouldn't need to clear the registry here, but some
        # tests call load_backends multiple times. These should be fixed to
        # only call load_backends once.
        dependency.reset()

        # NOTE(blk-u): identity must be before assignment to ensure that the
        # identity driver is available to the assignment manager because the
        # assignment manager gets the default assignment driver from the
        # identity driver.
        for manager in [
                identity, assignment, catalog, credential, ec2, policy, token,
                token_provider, trust
        ]:
            # manager.__name__ is like keystone.xxx[.yyy],
            # converted to xxx[_yyy]
            manager_name = (
                '%s_api' %
                manager.__name__.replace('keystone.', '').replace('.', '_'))

            setattr(self, manager_name, manager.Manager())

        dependency.resolve_future_dependencies()
Ejemplo n.º 5
0
    def test_no_overwrite_config(self):
        # Create a config for the default domain
        default_config = {
            'ldap': {
                'url': uuid.uuid4().hex
            },
            'identity': {
                'driver': 'keystone.identity.backends.ldap.Identity'
            }
        }
        self.domain_config_api.create_config(CONF.identity.default_domain_id,
                                             default_config)

        # Now try and upload the settings in the configuration file for the
        # default domain
        dependency.reset()
        with mock.patch('__builtin__.print') as mock_print:
            self.assertRaises(SystemExit, cli.DomainConfigUpload.main)
            file_name = ('keystone.%s.conf' %
                         resource.calc_default_domain()['name'])
            error_msg = _(
                'Domain: %(domain)s already has a configuration defined - '
                'ignoring file: %(file)s.') % {
                    'domain': resource.calc_default_domain()['name'],
                    'file': os.path.join(CONF.identity.domain_config_dir,
                                         file_name)
                }
            mock_print.assert_has_calls([mock.call(error_msg)])

        res = self.domain_config_api.get_config(
            CONF.identity.default_domain_id)
        # The initial config should not have been overwritten
        self.assertEqual(default_config, res)
Ejemplo n.º 6
0
    def load_backends(self):
        """Initializes each manager and assigns them to an attribute."""

        # TODO(blk-u): Shouldn't need to clear the registry here, but some
        # tests call load_backends multiple times. These should be fixed to
        # only call load_backends once.
        dependency.reset()

        # TODO(morganfainberg): Shouldn't need to clear the registry here, but
        # some tests call load_backends multiple times.  Since it is not
        # possible to re-configure a backend, we need to clear the list.  This
        # should eventually be removed once testing has been cleaned up.
        kvs_core.KEY_VALUE_STORE_REGISTRY.clear()

        self.clear_auth_plugin_registry()
        drivers = service.load_backends()

        drivers.update(dependency.resolve_future_dependencies())

        for manager_name, manager in six.iteritems(drivers):
            setattr(self, manager_name, manager)
        self.addCleanup(self.cleanup_instance(*drivers.keys()))

        # The credential backend only supports SQL, so we always have to load
        # the tables.
        self.engine = sql.get_engine()
        self.addCleanup(sql.cleanup)
        self.addCleanup(self.cleanup_instance('engine'))

        sql.ModelBase.metadata.create_all(bind=self.engine)
        self.addCleanup(sql.ModelBase.metadata.drop_all, bind=self.engine)
Ejemplo n.º 7
0
 def test_config_upload(self):
     dependency.reset()
     with mock.patch("__builtin__.print") as mock_print:
         self.assertRaises(SystemExit, cli.DomainConfigUpload.main)
         mock_print.assert_has_calls(
             [mock.call(_("The --all option cannot be used with " "the --domain-name option"))]
         )
Ejemplo n.º 8
0
    def test_no_overwrite_config(self):
        # Create a config for the default domain
        default_config = {
            'ldap': {'url': uuid.uuid4().hex},
            'identity': {'driver': 'ldap'}
        }
        self.domain_config_api.create_config(
            CONF.identity.default_domain_id, default_config)

        # Now try and upload the settings in the configuration file for the
        # default domain
        dependency.reset()
        with mock.patch('six.moves.builtins.print') as mock_print:
            self.assertRaises(unit.UnexpectedExit, cli.DomainConfigUpload.main)
            file_name = ('keystone.%s.conf' % self.default_domain['name'])
            error_msg = _(
                'Domain: %(domain)s already has a configuration defined - '
                'ignoring file: %(file)s.') % {
                    'domain': self.default_domain['name'],
                    'file': os.path.join(CONF.identity.domain_config_dir,
                                         file_name)}
            mock_print.assert_has_calls([mock.call(error_msg)])

        res = self.domain_config_api.get_config(
            CONF.identity.default_domain_id)
        # The initial config should not have been overwritten
        self.assertEqual(default_config, res)
Ejemplo n.º 9
0
 def test_bad_domain_name(self):
     CONF(args=['mapping_populate', '--domain-name',
                uuid.uuid4().hex],
          project='keystone')
     dependency.reset()  # backends are loaded again in the command handler
     # NOTE: assertEqual is used on purpose. assertFalse passes with None.
     self.assertEqual(False, cli.MappingPopulate.main())
Ejemplo n.º 10
0
 def test_config_upload(self):
     dependency.reset()
     with mock.patch('six.moves.builtins.print') as mock_print:
         self.assertRaises(unit.UnexpectedExit, cli.DomainConfigUpload.main)
         mock_print.assert_has_calls(
             [mock.call(_('The --all option cannot be used with '
                          'the --domain-name option'))])
Ejemplo n.º 11
0
    def test_config_upload(self):
        # The values below are the same as in the domain_configs_multi_ldap
        # directory of test config_files.
        default_config = {
            'ldap': {
                'url': 'fake://memory',
                'user': '******',
                'password': '******',
                'suffix': 'cn=example,cn=com'
            },
            'identity': {
                'driver': 'keystone.identity.backends.ldap.Identity'
            }
        }

        # Clear backend dependencies, since cli loads these manually
        dependency.reset()
        cli.DomainConfigUpload.main()

        res = self.domain_config_api.get_config_with_sensitive_info(
            CONF.identity.default_domain_id)
        self.assertEqual(default_config, res)
        res = self.domain_config_api.get_config_with_sensitive_info(
            self.domains['domain1']['id'])
        self.assertEqual({}, res)
        res = self.domain_config_api.get_config_with_sensitive_info(
            self.domains['domain2']['id'])
        self.assertEqual({}, res)
Ejemplo n.º 12
0
    def load_backends(self):
        """Initializes each manager and assigns them to an attribute."""

        # TODO(blk-u): Shouldn't need to clear the registry here, but some
        # tests call load_backends multiple times. These should be fixed to
        # only call load_backends once.
        dependency.reset()

        # TODO(morganfainberg): Shouldn't need to clear the registry here, but
        # some tests call load_backends multiple times.  Since it is not
        # possible to re-configure a backend, we need to clear the list.  This
        # should eventually be removed once testing has been cleaned up.
        kvs_core.KEY_VALUE_STORE_REGISTRY.clear()

        self.clear_auth_plugin_registry()
        drivers = service.load_backends()

        drivers.update(dependency.resolve_future_dependencies())

        for manager_name, manager in six.iteritems(drivers):
            setattr(self, manager_name, manager)
        self.addCleanup(self.cleanup_instance(*drivers.keys()))

        # The credential backend only supports SQL, so we always have to load
        # the tables.
        self.engine = sql.get_engine()
        self.addCleanup(sql.cleanup)
        self.addCleanup(self.cleanup_instance('engine'))

        sql.ModelBase.metadata.create_all(bind=self.engine)
        self.addCleanup(sql.ModelBase.metadata.drop_all, bind=self.engine)
Ejemplo n.º 13
0
    def test_supported_token_providers(self):
        # test default config

        dependency.reset()
        self.assertIsInstance(token.provider.Manager().driver,
                              uuid.Provider)

        dependency.reset()
        self.config_fixture.config(
            group='token',
            provider='keystone.token.providers.uuid.Provider')
        self.assertIsInstance(token.provider.Manager().driver, uuid.Provider)

        dependency.reset()
        self.config_fixture.config(
            group='token',
            provider='keystone.token.providers.pki.Provider')
        self.assertIsInstance(token.provider.Manager().driver, pki.Provider)

        dependency.reset()
        self.config_fixture.config(
            group='token',
            provider='keystone.token.providers.pkiz.Provider')
        self.assertIsInstance(token.provider.Manager().driver, pkiz.Provider)

        dependency.reset()
        self.config_fixture.config(
            group='token',
            provider='keystone.token.providers.fernet.Provider')
        self.assertIsInstance(token.provider.Manager().driver, fernet.Provider)
Ejemplo n.º 14
0
    def test_mapping_populate(self):
        # mapping_populate should create id mappings. Test plan:
        # 0. Purge mappings
        # 1. Fetch user list directly via backend. It will not create any
        #    mappings because it bypasses identity manager
        # 2. Verify that users have no public_id yet
        # 3. Execute mapping_populate. It should create id mappings
        # 4. For the same users verify that they have public_id now
        purge_filter = {}
        self.id_mapping_api.purge_mappings(purge_filter)
        hints = None
        users = self.identity_api.driver.list_users(hints)
        for user in users:
            local_entity = {
                'domain_id': CONF.identity.default_domain_id,
                'local_id': user['id'],
                'entity_type': identity_mapping.EntityType.USER}
            self.assertIsNone(self.id_mapping_api.get_public_id(local_entity))

        dependency.reset()  # backends are loaded again in the command handler
        cli.MappingPopulate.main()

        for user in users:
            local_entity = {
                'domain_id': CONF.identity.default_domain_id,
                'local_id': user['id'],
                'entity_type': identity_mapping.EntityType.USER}
            self.assertIsNotNone(
                self.id_mapping_api.get_public_id(local_entity))
Ejemplo n.º 15
0
 def test_config_upload(self):
     dependency.reset()
     with mock.patch("six.moves.builtins.print") as mock_print:
         self.assertRaises(unit.UnexpectedExit, cli.DomainConfigUpload.main)
         mock_print.assert_has_calls(
             [mock.call(_("At least one option must be provided, use either " "--all or --domain-name"))]
         )
 def test_config_upload(self):
     dependency.reset()
     with mock.patch('six.moves.builtins.print') as mock_print:
         self.assertRaises(SystemExit, cli.DomainConfigUpload.main)
         mock_print.assert_has_calls(
             [mock.call(_('The --all option cannot be used with '
                          'the --domain-name option'))])
Ejemplo n.º 17
0
 def test_config_upload(self):
     dependency.reset()
     with mock.patch("six.moves.builtins.print") as mock_print:
         self.assertRaises(unit.UnexpectedExit, cli.DomainConfigUpload.main)
         mock_print.assert_has_calls(
             [mock.call(_("The --all option cannot be used with " "the --domain-name option"))]
         )
Ejemplo n.º 18
0
    def load_backends(self):
        """Initializes each manager and assigns them to an attribute."""

        # TODO(blk-u): Shouldn't need to clear the registry here, but some
        # tests call load_backends multiple times. These should be fixed to
        # only call load_backends once.
        dependency.reset()

        # TODO(morganfainberg): Shouldn't need to clear the registry here, but
        # some tests call load_backends multiple times.  Since it is not
        # possible to re-configure a backend, we need to clear the list.  This
        # should eventually be removed once testing has been cleaned up.
        kvs_core.KEY_VALUE_STORE_REGISTRY.clear()

        drivers = service.load_backends()

        # TODO(stevemar): currently, load oauth1 driver as well, eventually
        # we need to have this as optional.
        from keystone.contrib import oauth1
        drivers['oauth1_api'] = oauth1.Manager()

        dependency.resolve_future_dependencies()

        for manager_name, manager in drivers.iteritems():
            setattr(self, manager_name, manager)
Ejemplo n.º 19
0
 def test_config_upload(self):
     dependency.reset()
     with mock.patch('__builtin__.print') as mock_print:
         self.assertRaises(SystemExit, cli.DomainConfigUpload.main)
         mock_print.assert_has_calls(
             [mock.call(
                 _('At least one option must be provided, use either '
                   '--all or --domain-name'))])
 def test_config_upload(self):
     dependency.reset()
     with mock.patch('six.moves.builtins.print') as mock_print:
         self.assertRaises(SystemExit, cli.DomainConfigUpload.main)
         mock_print.assert_has_calls(
             [mock.call(
                 _('At least one option must be provided, use either '
                   '--all or --domain-name'))])
Ejemplo n.º 21
0
 def test_config_upload(self):
     dependency.reset()
     with mock.patch("six.moves.builtins.print") as mock_print:
         self.assertRaises(unit.UnexpectedExit, cli.DomainConfigUpload.main)
         file_name = "keystone.%s.conf" % self.invalid_domain_name
         error_msg = _(
             "Invalid domain name: %(domain)s found in config file name: " "%(file)s - ignoring this file."
         ) % {"domain": self.invalid_domain_name, "file": os.path.join(CONF.identity.domain_config_dir, file_name)}
         mock_print.assert_has_calls([mock.call(error_msg)])
Ejemplo n.º 22
0
 def test_config_upload(self):
     dependency.reset()
     with mock.patch('__builtin__.print') as mock_print:
         self.assertRaises(SystemExit, cli.DomainConfigUpload.main)
         file_name = 'keystone.%s.conf' % self.invalid_domain_name
         error_msg = (_(
             'Invalid domain name: %(domain)s found in config file name: '
             '%(file)s - ignoring this file.') % {
                 'domain': self.invalid_domain_name,
                 'file': os.path.join(CONF.identity.domain_config_dir,
                                      file_name)})
         mock_print.assert_has_calls([mock.call(error_msg)])
Ejemplo n.º 23
0
    def test_config_upload(self):
        # The values below are the same as in the domain_configs_multi_ldap
        # directory of test config_files.
        default_config = {
            'ldap': {
                'url': 'fake://memory',
                'user': '******',
                'password': '******',
                'suffix': 'cn=example,cn=com'
            },
            'identity': {
                'driver': 'ldap'
            }
        }
        domain1_config = {
            'ldap': {
                'url': 'fake://memory1',
                'user': '******',
                'password': '******',
                'suffix': 'cn=example,cn=com'
            },
            'identity': {
                'driver': 'ldap',
                'list_limit': '101'
            }
        }
        domain2_config = {
            'ldap': {
                'url': 'fake://memory',
                'user': '******',
                'password': '******',
                'suffix': 'cn=myroot,cn=com',
                'group_tree_dn': 'ou=UserGroups,dc=myroot,dc=org',
                'user_tree_dn': 'ou=Users,dc=myroot,dc=org'
            },
            'identity': {
                'driver': 'ldap'
            }
        }

        # Clear backend dependencies, since cli loads these manually
        dependency.reset()
        cli.DomainConfigUpload.main()

        res = self.domain_config_api.get_config_with_sensitive_info(
            CONF.identity.default_domain_id)
        self.assertEqual(default_config, res)
        res = self.domain_config_api.get_config_with_sensitive_info(
            self.domains['domain1']['id'])
        self.assertEqual(domain1_config, res)
        res = self.domain_config_api.get_config_with_sensitive_info(
            self.domains['domain2']['id'])
        self.assertEqual(domain2_config, res)
Ejemplo n.º 24
0
 def test_config_upload(self):
     dependency.reset()
     with mock.patch('six.moves.builtins.print') as mock_print:
         self.assertRaises(unit.UnexpectedExit, cli.DomainConfigUpload.main)
         file_name = 'keystone.%s.conf' % self.invalid_domain_name
         error_msg = (_(
             'Invalid domain name: %(domain)s found in config file name: '
             '%(file)s - ignoring this file.') % {
                 'domain': self.invalid_domain_name,
                 'file': os.path.join(CONF.identity.domain_config_dir,
                                      file_name)})
         mock_print.assert_has_calls([mock.call(error_msg)])
Ejemplo n.º 25
0
    def test_reset(self):
        # Can reset the registry of providers.

        p_id = uuid.uuid4().hex

        @dependency.provider(p_id)
        class P(object):
            pass

        p_inst = P()

        self.assertIs(dependency.get_provider(p_id), p_inst)

        dependency.reset()

        self.assertFalse(dependency._REGISTRY)
    def test_reset(self):
        # Can reset the registry of providers.

        p_id = uuid.uuid4().hex

        @dependency.provider(p_id)
        class P(object):
            pass

        p_inst = P()

        self.assertIs(dependency.get_provider(p_id), p_inst)

        dependency.reset()

        self.assertFalse(dependency._REGISTRY)
Ejemplo n.º 27
0
    def setUp(self):
        super(BackendLoader, self).setUp()

        # TODO(blk-u): Shouldn't need to clear the registry here, but some
        # tests call load_backends multiple times. These should be fixed to
        # only call load_backends once.
        dependency.reset()

        self.clear_auth_plugin_registry()
        drivers, _unused = common.setup_backends()

        for manager_name, manager in drivers.items():
            setattr(self._testcase, manager_name, manager)

        self.addCleanup(self._testcase.cleanup_instance(*list(drivers.keys())))

        del self._testcase  # break circular reference
Ejemplo n.º 28
0
    def setUp(self):
        super(BackendLoader, self).setUp()

        # TODO(blk-u): Shouldn't need to clear the registry here, but some
        # tests call load_backends multiple times. These should be fixed to
        # only call load_backends once.
        dependency.reset()

        self.clear_auth_plugin_registry()
        drivers, _unused = common.setup_backends()

        for manager_name, manager in drivers.items():
            setattr(self._testcase, manager_name, manager)

        self.addCleanup(self._testcase.cleanup_instance(*list(drivers.keys())))

        del self._testcase  # break circular reference
Ejemplo n.º 29
0
    def load_backends(self):
        """Initializes each manager and assigns them to an attribute."""

        # TODO(blk-u): Shouldn't need to clear the registry here, but some
        # tests call load_backends multiple times. These should be fixed to
        # only call load_backends once.
        dependency.reset()

        # TODO(morganfainberg): Shouldn't need to clear the registry here, but
        # some tests call load_backends multiple times.  Since it is not
        # possible to re-configure a backend, we need to clear the list.  This
        # should eventually be removed once testing has been cleaned up.
        kvs_core.KEY_VALUE_STORE_REGISTRY.clear()

        drivers = service.load_backends(include_oauth1=True)

        for manager_name, manager in drivers.iteritems():
            setattr(self, manager_name, manager)
Ejemplo n.º 30
0
    def load_backends(self):
        """Initializes each manager and assigns them to an attribute."""

        # TODO(blk-u): Shouldn't need to clear the registry here, but some
        # tests call load_backends multiple times. These should be fixed to
        # only call load_backends once.
        dependency.reset()

        # TODO(morganfainberg): Shouldn't need to clear the registry here, but
        # some tests call load_backends multiple times.  Since it is not
        # possible to re-configure a backend, we need to clear the list.  This
        # should eventually be removed once testing has been cleaned up.
        kvs_core.KEY_VALUE_STORE_REGISTRY.clear()

        drivers = service.load_backends(include_oauth1=True)

        for manager_name, manager in drivers.iteritems():
            setattr(self, manager_name, manager)
Ejemplo n.º 31
0
    def test_config_upload(self):
        # The values below are the same as in the domain_configs_multi_ldap
        # directory of test config_files.
        default_config = {
            "ldap": {"url": "fake://memory", "user": "******", "password": "******", "suffix": "cn=example,cn=com"},
            "identity": {"driver": "ldap"},
        }

        # Clear backend dependencies, since cli loads these manually
        dependency.reset()
        cli.DomainConfigUpload.main()

        res = self.domain_config_api.get_config_with_sensitive_info(CONF.identity.default_domain_id)
        self.assertEqual(default_config, res)
        res = self.domain_config_api.get_config_with_sensitive_info(self.domains["domain1"]["id"])
        self.assertEqual({}, res)
        res = self.domain_config_api.get_config_with_sensitive_info(self.domains["domain2"]["id"])
        self.assertEqual({}, res)
Ejemplo n.º 32
0
    def tearDown(self):
        try:
            timeutils.clear_time_override()
            # NOTE(morganfainberg):  The only way to reconfigure the
            # CacheRegion object on each setUp() call is to remove the
            # .backend property.
            del cache.REGION.backend
            super(TestCase, self).tearDown()
        finally:
            for path in self._paths:
                if path in sys.path:
                    sys.path.remove(path)

            # Clear the registry of providers so that providers from previous
            # tests aren't used.
            dependency.reset()

            kvs.INMEMDB.clear()
            CONF.reset()
Ejemplo n.º 33
0
    def tearDown(self):
        try:
            timeutils.clear_time_override()
            # NOTE(morganfainberg):  The only way to reconfigure the
            # CacheRegion object on each setUp() call is to remove the
            # .backend property.
            del cache.REGION.backend
            super(TestCase, self).tearDown()
        finally:
            for path in self._paths:
                if path in sys.path:
                    sys.path.remove(path)

            # Clear the registry of providers so that providers from previous
            # tests aren't used.
            dependency.reset()

            kvs.INMEMDB.clear()
            CONF.reset()
Ejemplo n.º 34
0
    def load_backends(self):
        """Initialize each manager and assigns them to an attribute."""
        # TODO(blk-u): Shouldn't need to clear the registry here, but some
        # tests call load_backends multiple times. These should be fixed to
        # only call load_backends once.
        dependency.reset()

        # TODO(morganfainberg): Shouldn't need to clear the registry here, but
        # some tests call load_backends multiple times.  Since it is not
        # possible to re-configure a backend, we need to clear the list.  This
        # should eventually be removed once testing has been cleaned up.
        kvs_core.KEY_VALUE_STORE_REGISTRY.clear()

        self.clear_auth_plugin_registry()
        drivers, _unused = common.setup_backends()

        for manager_name, manager in drivers.items():
            setattr(self, manager_name, manager)
        self.addCleanup(self.cleanup_instance(*list(drivers.keys())))
Ejemplo n.º 35
0
    def tearDown(self):
        try:
            timeutils.clear_time_override()
            self.mox.UnsetStubs()
            self.stubs.UnsetAll()
            self.stubs.SmartUnsetAll()
            self.mox.VerifyAll()
            super(TestCase, self).tearDown()
        finally:
            for path in self._paths:
                if path in sys.path:
                    sys.path.remove(path)

            # Clear the registry of providers so that providers from previous
            # tests aren't used.
            dependency.reset()

            kvs.INMEMDB.clear()
            CONF.reset()
Ejemplo n.º 36
0
    def tearDown(self):
        try:
            timeutils.clear_time_override()
            self.mox.UnsetStubs()
            self.stubs.UnsetAll()
            self.stubs.SmartUnsetAll()
            self.mox.VerifyAll()
            super(TestCase, self).tearDown()
        finally:
            for path in self._paths:
                if path in sys.path:
                    sys.path.remove(path)

            # Clear the registry of providers so that providers from previous
            # tests aren't used.
            dependency.reset()

            kvs.INMEMDB.clear()
            CONF.reset()
Ejemplo n.º 37
0
    def load_backends(self):
        """Initializes each manager and assigns them to an attribute."""
        # TODO(blk-u): Shouldn't need to clear the registry here, but some
        # tests call load_backends multiple times. These should be fixed to
        # only call load_backends once.
        dependency.reset()

        # TODO(morganfainberg): Shouldn't need to clear the registry here, but
        # some tests call load_backends multiple times.  Since it is not
        # possible to re-configure a backend, we need to clear the list.  This
        # should eventually be removed once testing has been cleaned up.
        kvs_core.KEY_VALUE_STORE_REGISTRY.clear()

        self.clear_auth_plugin_registry()
        drivers, _unused = common.setup_backends(
            load_extra_backends_fn=self.load_extra_backends)

        for manager_name, manager in drivers.items():
            setattr(self, manager_name, manager)
        self.addCleanup(self.cleanup_instance(*list(drivers.keys())))
Ejemplo n.º 38
0
    def test_no_overwrite_config(self):
        # Create a config for the default domain
        default_config = {"ldap": {"url": uuid.uuid4().hex}, "identity": {"driver": "ldap"}}
        self.domain_config_api.create_config(CONF.identity.default_domain_id, default_config)

        # Now try and upload the settings in the configuration file for the
        # default domain
        dependency.reset()
        with mock.patch("six.moves.builtins.print") as mock_print:
            self.assertRaises(unit.UnexpectedExit, cli.DomainConfigUpload.main)
            file_name = "keystone.%s.conf" % resource.calc_default_domain()["name"]
            error_msg = _("Domain: %(domain)s already has a configuration defined - " "ignoring file: %(file)s.") % {
                "domain": resource.calc_default_domain()["name"],
                "file": os.path.join(CONF.identity.domain_config_dir, file_name),
            }
            mock_print.assert_has_calls([mock.call(error_msg)])

        res = self.domain_config_api.get_config(CONF.identity.default_domain_id)
        # The initial config should not have been overwritten
        self.assertEqual(default_config, res)
Ejemplo n.º 39
0
    def test_config_upload(self):
        # The values below are the same as in the domain_configs_multi_ldap
        # directory of test config_files.
        default_config = {
            'ldap': {'url': 'fake://memory',
                     'user': '******',
                     'password': '******',
                     'suffix': 'cn=example,cn=com'},
            'identity': {'driver': 'ldap'}
        }
        domain1_config = {
            'ldap': {'url': 'fake://memory1',
                     'user': '******',
                     'password': '******',
                     'suffix': 'cn=example,cn=com'},
            'identity': {'driver': 'ldap',
                         'list_limit': '101'}
        }
        domain2_config = {
            'ldap': {'url': 'fake://memory',
                     'user': '******',
                     'password': '******',
                     'suffix': 'cn=myroot,cn=com',
                     'group_tree_dn': 'ou=UserGroups,dc=myroot,dc=org',
                     'user_tree_dn': 'ou=Users,dc=myroot,dc=org'},
            'identity': {'driver': 'ldap'}
        }

        # Clear backend dependencies, since cli loads these manually
        dependency.reset()
        cli.DomainConfigUpload.main()

        res = self.domain_config_api.get_config_with_sensitive_info(
            CONF.identity.default_domain_id)
        self.assertEqual(default_config, res)
        res = self.domain_config_api.get_config_with_sensitive_info(
            self.domains['domain1']['id'])
        self.assertEqual(domain1_config, res)
        res = self.domain_config_api.get_config_with_sensitive_info(
            self.domains['domain2']['id'])
        self.assertEqual(domain2_config, res)
Ejemplo n.º 40
0
    def setUp(self):
        super(BackendLoader, self).setUp()

        # TODO(blk-u): Shouldn't need to clear the registry here, but some
        # tests call load_backends multiple times. These should be fixed to
        # only call load_backends once.
        dependency.reset()

        # TODO(morganfainberg): Shouldn't need to clear the registry here, but
        # some tests call load_backends multiple times.  Since it is not
        # possible to re-configure a backend, we need to clear the list.  This
        # should eventually be removed once testing has been cleaned up.
        kvs_core.KEY_VALUE_STORE_REGISTRY.clear()

        self.clear_auth_plugin_registry()
        drivers, _unused = common.setup_backends()

        for manager_name, manager in drivers.items():
            setattr(self._testcase, manager_name, manager)

        self.addCleanup(self._testcase.cleanup_instance(*list(drivers.keys())))

        del self._testcase  # break circular reference
Ejemplo n.º 41
0
    def setUp(self):
        super(BackendLoader, self).setUp()

        # TODO(blk-u): Shouldn't need to clear the registry here, but some
        # tests call load_backends multiple times. These should be fixed to
        # only call load_backends once.
        dependency.reset()

        # TODO(morganfainberg): Shouldn't need to clear the registry here, but
        # some tests call load_backends multiple times.  Since it is not
        # possible to re-configure a backend, we need to clear the list.  This
        # should eventually be removed once testing has been cleaned up.
        kvs_core.KEY_VALUE_STORE_REGISTRY.clear()

        self.clear_auth_plugin_registry()
        drivers, _unused = common.setup_backends()

        for manager_name, manager in drivers.items():
            setattr(self._testcase, manager_name, manager)

        self.addCleanup(self._testcase.cleanup_instance(*list(drivers.keys())))

        del self._testcase  # break circular reference
Ejemplo n.º 42
0
    def load_backends(self):
        """Initializes each manager and assigns them to an attribute."""

        # TODO(blk-u): Shouldn't need to clear the registry here, but some
        # tests call load_backends multiple times. These should be fixed to
        # only call load_backends once.
        dependency.reset()

        # NOTE(blk-u): identity must be before assignment to ensure that the
        # identity driver is available to the assignment manager because the
        # assignment manager gets the default assignment driver from the
        # identity driver.
        for manager in [identity, assignment, catalog, credential, ec2, policy,
                        token, token_provider, trust, oauth1]:
            # manager.__name__ is like keystone.xxx[.yyy],
            # converted to xxx[_yyy]
            manager_name = ('%s_api' %
                            manager.__name__.replace('keystone.', '').
                            replace('.', '_'))

            setattr(self, manager_name, manager.Manager())

        dependency.resolve_future_dependencies()
Ejemplo n.º 43
0
    def load_backends(self):
        """Initializes each manager and assigns them to an attribute."""

        # TODO(blk-u): Shouldn't need to clear the registry here, but some
        # tests call load_backends multiple times. These should be fixed to
        # only call load_backends once.
        dependency.reset()

        # TODO(morganfainberg): Shouldn't need to clear the registry here, but
        # some tests call load_backends multiple times.  Since it is not
        # possible to re-configure a backend, we need to clear the list.  This
        # should eventually be removed once testing has been cleaned up.
        kvs_core.KEY_VALUE_STORE_REGISTRY.clear()

        self.clear_auth_plugin_registry()
        drivers = service.load_backends()

        # TODO(stevemar): currently, load oauth1 driver as well, eventually
        # we need to have this as optional.
        from keystone.contrib import oauth1
        drivers['oauth1_api'] = oauth1.Manager()

        from keystone.contrib import federation
        drivers['federation_api'] = federation.Manager()

        dependency.resolve_future_dependencies()

        for manager_name, manager in six.iteritems(drivers):
            setattr(self, manager_name, manager)

        # The credential backend only supports SQL, so we always have to load
        # the tables.
        self.engine = session.get_engine()
        self.addCleanup(session.cleanup)

        sql.ModelBase.metadata.create_all(bind=self.engine)
        self.addCleanup(sql.ModelBase.metadata.drop_all, bind=self.engine)
Ejemplo n.º 44
0
    def load_backends(self):
        """Initializes each manager and assigns them to an attribute."""

        # TODO(blk-u): Shouldn't need to clear the registry here, but some
        # tests call load_backends multiple times. These should be fixed to
        # only call load_backends once.
        dependency.reset()

        # TODO(morganfainberg): Shouldn't need to clear the registry here, but
        # some tests call load_backends multiple times.  Since it is not
        # possible to re-configure a backend, we need to clear the list.  This
        # should eventually be removed once testing has been cleaned up.
        kvs_core.KEY_VALUE_STORE_REGISTRY.clear()

        self.clear_auth_plugin_registry()
        drivers = service.load_backends()

        # TODO(stevemar): currently, load oauth1 driver as well, eventually
        # we need to have this as optional.
        from keystone.contrib import oauth1
        drivers['oauth1_api'] = oauth1.Manager()

        from keystone.contrib import federation
        drivers['federation_api'] = federation.Manager()

        dependency.resolve_future_dependencies()

        for manager_name, manager in six.iteritems(drivers):
            setattr(self, manager_name, manager)

        # The credential backend only supports SQL, so we always have to load
        # the tables.
        self.engine = session.get_engine()
        self.addCleanup(session.cleanup)

        sql.ModelBase.metadata.create_all(bind=self.engine)
        self.addCleanup(sql.ModelBase.metadata.drop_all, bind=self.engine)
Ejemplo n.º 45
0
    def test_config_upload(self):
        # The values below are the same as in the domain_configs_multi_ldap
        # directory of test config_files.
        default_config = {
            'ldap': {'url': 'fake://memory',
                     'user': '******',
                     'password': '******',
                     'suffix': 'cn=example,cn=com'},
            'identity': {'driver': 'keystone.identity.backends.ldap.Identity'}
        }

        # Clear backend dependencies, since cli loads these manually
        dependency.reset()
        cli.DomainConfigUpload.main()

        res = self.domain_config_api.get_config_with_sensitive_info(
            CONF.identity.default_domain_id)
        self.assertEqual(default_config, res)
        res = self.domain_config_api.get_config_with_sensitive_info(
            self.domains['domain1']['id'])
        self.assertEqual({}, res)
        res = self.domain_config_api.get_config_with_sensitive_info(
            self.domains['domain2']['id'])
        self.assertEqual({}, res)
Ejemplo n.º 46
0
 def tearDown(self):
     dependency.reset()
     super(TestDependencyInjection, self).tearDown()
Ejemplo n.º 47
0
 def tearDown(self):
     dependency.reset()
     super(TestDependencyInjection, self).tearDown()
Ejemplo n.º 48
0
 def setUp(self):
     super(TestDependencyInjection, self).setUp()
     dependency.reset()
     self.addCleanup(dependency.reset)
 def setUp(self):
     super(TestDependencyInjection, self).setUp()
     dependency.reset()
     self.addCleanup(dependency.reset)