Ejemplo n.º 1
0
 def test_parse_cli_multiple_good_flags(self):
     args = ['sdir=.', 'tdir=test', '-g', '-u', '-v'] # currently -g, -t, -v have no real functionality. if these flags are added as actual functional flags, this test should be updated
     parser = CLIParser(args, check_assertions=True)
     parser.add_flag('-g', None)
     parser.add_flag('-u', None)
     parser.add_flag('-v', None)
     parser.parse_cli()
     flag_oracle = {'-g': True, '-g': True, '-u': True, '-v': True, '-h': False}
     for key in flag_oracle:
         self.assertEqual(parser.get_flag(key).get_value(), flag_oracle[key])
Ejemplo n.º 2
0
 def test_parse_cli_one_good_flag(self):
     args = ['sdir=.', 'tdir=test', '-g']
     parser = CLIParser(args, check_assertions=True)
     parser.add_flag('-g', None)
     parser.parse_cli()
     param_oracle = {'sdir': '.', 'tdir': 'test', 'lang': Languages.PYTHON, 'framework': Frameworks.UNITTEST}
     flag_oracle = {'-h': False, '-g': True, '-s': False, '-t': False}
     for key in param_oracle:
         self.assertEqual(parser.get_parameter(key).get_value(), param_oracle[key])
     for key in flag_oracle:
         self.assertEqual(parser.get_flag(key).get_value(), flag_oracle[key])
Ejemplo n.º 3
0
 def test_parse_cli_good_params(self):
     args = ['sdir=.', 'tdir=test', 'good_param=good_val2']
     parser = CLIParser(args, check_assertions=True)
     parser.add_param('good_param', {'good_val1', 'good_val2'})
     parser.parse_cli()
     oracle = {'sdir': '.', 'tdir': 'test', 'lang': Languages.PYTHON, 'framework': Frameworks.UNITTEST, 'good_param': 'good_val2'}
     for key in oracle:
         self.assertEqual(parser.get_parameter(key).get_value(), oracle[key])
Ejemplo n.º 4
0
 def test_parse_cli_multiple_good_params(self):
     args = ['sdir=.', 'tdir=test', 'good_param1=val1', 'good_param2=val3']
     parser = CLIParser(args, check_assertions=True)
     parser.add_param('good_param1', {'val1', 'val2'})
     parser.add_param('good_param2', {'val3', 'val4'})
     parser.parse_cli()
     param_oracle = {'sdir': '.', 'tdir': 'test', 'lang': Languages.PYTHON, 'good_param1': 'val1', 'good_param2': 'val3'}
     for key in param_oracle:
         self.assertEqual(parser.get_parameter(key).get_value(), param_oracle[key])
Ejemplo n.º 5
0
 def test_parse_cli_exits_with_good_flag_bad_param(self):
     args = ['-g', 'bad_param=bad_val']
     parser = CLIParser(args, check_assertions=True)
     parser.add_flag('-g', None) # add g to the parser as a valid command line flag
     with self.assertRaises(SystemExit) as sys_exit:
         parser.parse_cli()
     self.assertEqual(sys_exit.exception.code, 1)
Ejemplo n.º 6
0
 def test_parse_cli_exits_with_good_param_bad_flag(self):
     args = ['good_param=good_value', '-w']
     parser = CLIParser(args, check_assertions=True)
     parser.add_param('good_param', {'good_val'}) # add good_param to the parser as a valid command line flag with "good_val" as a valid value
     with self.assertRaises(SystemExit) as sys_exit:
         parser.parse_cli()
     self.assertEqual(sys_exit.exception.code, 1)
Ejemplo n.º 7
0
 def test_parse_cli_exits_with_no_args(self):
     args = []
     parser = CLIParser(args, check_assertions=True)
     with self.assertRaises(SystemExit) as sys_exit:
         parser.parse_cli()
     self.assertEqual(sys_exit.exception.code, 1)
Ejemplo n.º 8
0
import subprocess
import sys
import os
from crackn.parsing.cli_parser import CLIParser
from crackn.parsing.bandit_parser import BanditReport
from crackn.genetics.mutations import GeneticSimulator, Population, Chromosome
import crackn.settings as settings
import crackn.logging as Log

if __name__ == '__main__':
    cli_parser = CLIParser(sys.argv[1:])
    cli_parser.parse_cli()

    if cli_parser.get_flag('-h').get_value():
        cli_parser.print_help()
        exit(0)

    # check if the user requested to run in silent/suppressed mode
    silent_mode = cli_parser.get_flag('-s').get_value()

    # initialize the settings module and set the silent mode
    settings.init()
    settings.set_silent(silent_mode)

    # print a warning that Bandit output may look different when printed
    if not silent_mode:
        Log.INFO(
            'Running with silent mode turned OFF. Please note this may cause some output to lose formatting and/or coloring.\n'
        )

    repo_name = cli_parser.get_parameter('repo').get_value()