Skip to content

Commit

Permalink
chore: add test
Browse files Browse the repository at this point in the history
  • Loading branch information
gg-mmill committed Nov 27, 2024
1 parent d9d2625 commit 5d11cb0
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions tests/unit/verticals/secret/test_secret_scanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -402,3 +402,31 @@ def test_scan_ignore_known_secrets(scan_mock: Mock, client, ignore_known_secrets
assert results.results[0].policy_breaks == [unknown_secret]
else:
assert results.results[0].policy_breaks == [known_secret, unknown_secret]


@patch("pygitguardian.GGClient.multi_content_scan")
def test_scan_unexpected_error(scan_mock: Mock, client):
"""
GIVEN a call multi_content_scan raising an exception
WHEN calling scanner.scan
THEN an UnexpectedError is raised
"""
scannable = StringScannable(url="localhost", content="known\nunknown")

def raise_exc(*args, **kwargs):
raise Exception("dummy")

scan_mock.side_effect = raise_exc

scanner = SecretScanner(
client=client,
cache=Cache(),
scan_context=ScanContext(
scan_mode=ScanMode.PATH,
command_path="ggshield",
),
check_api_key=False,
secret_config=SecretConfig(),
)
with pytest.raises(UnexpectedError, match="Scanning failed.*"):
scanner.scan([scannable], scanner_ui=Mock())

0 comments on commit 5d11cb0

Please sign in to comment.