Exemple #1
0
    def test_read_config_error(self):

        with self.assertRaisesRegex(
            (ValueError),
                'Make sure the file exists and you have correct access right'):
            Config.fromfiles(['/tmp/this_file_is_inexistent.conf'])

        WRONG_CONFIG = DEFAULT_CONFIG + '\nverbose=I dont know'

        with self.assertRaisesRegex(
                ValueError, 'Could not read boolean value in config file'):
            Config.fromstring(WRONG_CONFIG)

        WRONG_CONFIG = DEFAULT_CONFIG + '\nwpscan_args=["forgot", "a" "commas"]'

        with self.assertRaisesRegex(
                ValueError, 'Could not read JSON value in config file'):
            Config.fromstring(WRONG_CONFIG)
Exemple #2
0
    def test_init_config_from_file(self):

        # Test find config file, rename default file if already exist and restore after test
        paths_found = Config.find_config_files()
        existent_files = []
        if len(paths_found) == 0:
            paths_found = Config.find_config_files(create=True)
        else:
            existent_files = paths_found
            for p in paths_found:
                os.rename(p, '%s.temp' % p)
            paths_found = Config.find_config_files(create=True)

        # Init config and compare
        config_object = Config.fromenv()
        config_object2 = Config.fromfiles(paths_found)
        self.assertEqual(
            config_object, config_object2,
            "Config built with config path and without are different even if files are the same"
        )
        for f in paths_found:
            os.remove(f)
        for f in existent_files:
            os.rename('%s.temp' % f, f)