def test_console_notifier(self):
        config_path = Path(__file__).parent.parent / 'config.toml'
        config = Config.load_file(config_path)

        notifier = Registry.get("console")(config)
        findings = [
            Finding("testfile.py", 123, "test_secret_type",
                    "https://www.example.com")
        ]
        notifier.process(findings, 'test-detector')
Exemplo n.º 2
0
 def _json_to_findings(self, parsed_output, filename, commit_link):
     results = parsed_output["results"]
     findings = []
     for _, file_results in results.items():
         for file_result in file_results:
             findings.append(
                 Finding(filename,
                         file_result["type"],
                         file_result["hashed_secret"],
                         link=commit_link))
     return findings
Exemplo n.º 3
0
    def _output_json_findings(self, output, commit_link):
        findings = []
        if isinstance(output, bytes):
            output = output.decode()

        for line in output.splitlines():
            json_line = json.loads(line)

            reason = json_line['reason']
            results = json_line['stringsFound']
            filename = json_line['path']
            findings.append(
                Finding(filename, reason, str(results), link=commit_link))
        return findings
Exemplo n.º 4
0
    def _output_to_findings(self, output, commit_link):
        if isinstance(output, bytes):
            output = output.decode()

        findings = []
        for line in output.splitlines():
            # the first non-blank lines of git-secrets output will
            # be findings, so parse those, but ignore empty output
            # and ignore everything after the findings
            if line == '':
                break
            parts = line.split(':')
            findings.append(Finding(parts[0], "generic", parts[2], line_number=parts[1], link=commit_link))
        return findings
Exemplo n.º 5
0
 def test_webhook_url(self, mock_post):
     environ['GITHUB_WATCHER_TOKEN'] = 'abcdef'
     # sorta hacky -- we get more than one notifier loaded with the default
     # config and we can't get it by name, so loop through all of them
     notifier = None
     for n in Config.notifiers:
         if isinstance(n, SlackWebhookNotifier):
             notifier = n
             break
     findings = [
         Finding("testfile.py", 123, "test_secret_type",
                 "https://www.example.com")
     ]
     notifier.process(findings, 'test-detector')