Skip to content

Commit

Permalink
Merge pull request #29 from Ostorlab/fixit/usless-logs-info-to-debug
Browse files Browse the repository at this point in the history
Remove non-critical debugs from trufflehog
  • Loading branch information
3asm authored Dec 2, 2024
2 parents 5cc8238 + f48609f commit 7093678
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions tests/trufflehog_test.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
"""Unittest for truflehog agent."""

import logging
from typing import Dict

import pytest
from ostorlab.agent.message import message
from pytest_mock import plugin

Expand Down Expand Up @@ -191,3 +193,40 @@ def testAgent_whenFileTypeIsUnrelated_skipIt(

assert len(agent_mock) == 0
assert subprocess_mock.call_count == 0


def testTrufflehog_whenProcessingSecrets_shouldLogNonCriticalMessagesAtDebugLeve(
scan_message_file: message.Message,
trufflehog_agent_file: trufflehog_agent.TruffleHogAgent,
agent_persist_mock: Dict[str | bytes, str | bytes],
mocker: plugin.MockerFixture,
agent_mock: list[message.Message],
caplog: pytest.LogCaptureFixture,
) -> None:
"""Tests that non-critical messages are logged at debug level."""

mocker.patch(
"subprocess.check_output",
return_value=b'{"SourceMetadata":{"Data":{"Git":{"commit":"77b2a3e56973785a52ba4ae4b8dac61d4bac016f",'
b'"file":"keys","email":"counter [email protected]",'
b'"repository":"https://github.com/trufflesecurity/test_keys","timestamp":"2022-06-16 10:27:56 -0700"'
b',"line":3}}},"SourceID":0,"SourceType":16,"SourceName":"trufflehog - git","DetectorType":17,'
b'"DetectorName":"URI","DecoderName":"BASE64","Verified":true,'
b'"Raw":"https://admin:[email protected]",'
b'"Redacted":"https://********:********@the-internet.herokuapp.com",'
b'"ExtraData":null,"StructuredData":null}',
)
msg = message.Message.from_data(
selector="v3.asset.file",
data={"content": b"some file content"},
)
logging.getLogger().setLevel(logging.DEBUG)

trufflehog_agent_file.process(msg)

for record in caplog.records:
if (
"Processing input and Starting trufflehog." in record.message
or "Parsing trufflehog output." in record.message
):
assert record.levelname == "DEBUG"

0 comments on commit 7093678

Please sign in to comment.