def test_detection_by_key(src, keys): args = parse_args([fixture_path(src)]) secrets = core.run(args) for key in keys: assert next(secrets).key == key with pytest.raises(StopIteration): next(secrets)
def test_exclude_files(): args = parse_args([fixture_path()]) args.config = core.load_config(config_path("exclude_files.yml"), FIXTURE_PATH) secrets = core.run(args) with pytest.raises(StopIteration): next(secrets)
def test_exclude_by_keys_and_values(configfile, src): args = parse_args([fixture_path(src)]) args.config = core.load_config(config_path(configfile), FIXTURE_PATH) secrets = core.run(args) assert next(secrets).key == "hardcoded_password" with pytest.raises(StopIteration): next(secrets)
def test_include_files(): args = parse_args([fixture_path()]) args.config = core.load_config(config_path("include_files.yml"), FIXTURE_PATH) secrets = core.run(args) assert next(secrets).value == "hardcoded" with pytest.raises(StopIteration): next(secrets)
def test_detection_by_value(src, count): args = parse_args([fixture_path(src)]) args.config = core.load_config( CONFIG_PATH.joinpath("detection_by_value.yml")) secrets = core.run(args) for _ in range(count): value = next(secrets).value.lower() if value.isnumeric(): continue assert "hardcoded" in value with pytest.raises(StopIteration): next(secrets)
def test_detection_by_filename(): expected = map( fixture_path, [ ".aws/credentials", ".htpasswd", ".npmrc", ".pypirc", "connection.config", "integration.conf", "pip.conf", "settings.cfg", "settings.conf", "settings.env", "settings.ini", ], ) args = parse_args([fixture_path()]) args.config = core.load_config( CONFIG_PATH.joinpath("detection_by_filename.yml")) secrets = core.run(args) result = [secret.value for secret in secrets] for exp in expected: assert exp in result
def test_run(filename, expectation): with expectation: args = parse_args([filename]) next(core.run(args))
def test_is_static(key, value, expectation): args = parse_args([fixture_path()]) args.config = core.load_config(CONFIG_PATH.joinpath("example.yml")) secrets = WhisperSecrets(args) assert secrets.is_static(key, value) == expectation
def test_parse_args(arguments, expectation, result): with expectation: args = parse_args(arguments) for key, value in result.items(): assert args.__dict__[key] == value
def test_parse_args(arguments, expectation): args = parse_args(arguments) assert args.config == expectation["config"] assert args.output == expectation["output"] assert args.rules == expectation["rules"] assert args.src == expectation["src"]
def test_find_line_number_all(src, linenumbers): args = parse_args([fixture_path(src)]) secrets = core.run(args) for number in linenumbers: assert next(secrets).line == number