generated from Ostorlab/template_agent
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #29 from Ostorlab/fixit/usless-logs-info-to-debug
Remove non-critical debugs from trufflehog
- Loading branch information
Showing
1 changed file
with
39 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
||
|
@@ -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" |