Updated legacy profile support
This patch updates the logic that handles profiles in preparation
for deprecation. If no profile name is given then we use
"exculded_tests" and "included_tests" to read in the test filters
("exclude" and "include" were already used). If a profile name is
given then we will read in the filter as before.
In addition, this makes -s/-t/-p no longer mutually exclusive. If
-t/-s are used on the CLI then they will update the profile filter
read from the config (legacy or otherwise). This is handy for
adding in extra tests during a one-off manual run.
Eventually -p will be deprecated in favour of using -c to pick
from a set of new style config files.
This also adds -s/-t to the config gen tool.
Change-Id: Ibf701f68106195f0153a37303fb1bdf5a8c2df9c
This commit is contained in:
@@ -14,13 +14,15 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import importlib
|
||||
import logging
|
||||
|
||||
import mock
|
||||
from stevedore import extension
|
||||
import testtools
|
||||
import yaml
|
||||
|
||||
from bandit.cli import config_generator
|
||||
from bandit.core import extension_loader
|
||||
from bandit.core import test_properties as test
|
||||
|
||||
|
||||
@@ -57,21 +59,6 @@ class BanditConfigGeneratorLoggerTests(testtools.TestCase):
|
||||
|
||||
|
||||
class BanditConfigGeneratorTests(testtools.TestCase):
|
||||
def _make_test_manager(self, plugin):
|
||||
return extension.ExtensionManager.make_test_instance(
|
||||
[extension.Extension('test', None, _test_plugin, None)])
|
||||
|
||||
def setUp(self):
|
||||
mngr = self._make_test_manager(mock.MagicMock)
|
||||
self.patchExtMan = mock.patch('stevedore.extension.ExtensionManager')
|
||||
self.mockExtMan = self.patchExtMan.start()
|
||||
self.mockExtMan.return_value = mngr
|
||||
super(BanditConfigGeneratorTests, self).setUp()
|
||||
|
||||
def tearDown(self):
|
||||
super(BanditConfigGeneratorTests, self).tearDown()
|
||||
self.patchExtMan.stop()
|
||||
|
||||
@mock.patch('sys.argv', ['bandit-config-generator'])
|
||||
def test_parse_args_no_defaults(self):
|
||||
# Test that the config generator does not show default plugin settings
|
||||
@@ -91,8 +78,15 @@ class BanditConfigGeneratorTests(testtools.TestCase):
|
||||
self.assertEqual('dummyfile', return_value.output_file)
|
||||
|
||||
def test_get_config_settings(self):
|
||||
config = {}
|
||||
for plugin in extension_loader.MANAGER.plugins:
|
||||
function = plugin.plugin
|
||||
if hasattr(plugin.plugin, '_takes_config'):
|
||||
module = importlib.import_module(function.__module__)
|
||||
config[plugin.name] = module.gen_config(
|
||||
function._takes_config)
|
||||
settings = config_generator.get_config_settings()
|
||||
self.assertEqual(settings, "test: {test: test data}\n")
|
||||
self.assertEqual(yaml.safe_dump(config), settings)
|
||||
|
||||
@mock.patch('sys.argv', ['bandit-config-generator', '--show-defaults'])
|
||||
def test_main_show_defaults(self):
|
||||
|
||||
Reference in New Issue
Block a user