Spaces:
Running
Running
Upload tests/test_secret_scanner.py with huggingface_hub
Browse files- tests/test_secret_scanner.py +50 -0
tests/test_secret_scanner.py
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Tests for SecretScanner."""
|
| 2 |
+
import pytest
|
| 3 |
+
from secret_scanner import SecretScanner, SecretMatch
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
def test_secret_scanner_initialization():
|
| 7 |
+
"""Test that SecretScanner initializes correctly."""
|
| 8 |
+
scanner = SecretScanner()
|
| 9 |
+
assert scanner is not None
|
| 10 |
+
assert len(scanner.patterns) > 0
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
def test_detect_aws_key():
|
| 14 |
+
"""Test AWS key detection."""
|
| 15 |
+
scanner = SecretScanner()
|
| 16 |
+
test_content = "aws_access_key_id=AKIAIOSFODNN7EXAMPLE"
|
| 17 |
+
files = [("test.txt", test_content)]
|
| 18 |
+
matches = scanner.scan_repo(files)
|
| 19 |
+
assert len(matches) > 0
|
| 20 |
+
assert any("AWS" in match.secret_type for match in matches)
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
def test_detect_github_token():
|
| 24 |
+
"""Test GitHub token detection."""
|
| 25 |
+
scanner = SecretScanner()
|
| 26 |
+
test_content = "token: ghp_1234567890abcdefghijklmnop"
|
| 27 |
+
files = [("test.txt", test_content)]
|
| 28 |
+
matches = scanner.scan_repo(files)
|
| 29 |
+
assert len(matches) > 0
|
| 30 |
+
assert any("GitHub" in match.secret_type for match in matches)
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
def test_no_secrets():
|
| 34 |
+
"""Test that clean content returns no matches."""
|
| 35 |
+
scanner = SecretScanner()
|
| 36 |
+
test_content = "This is just normal text with no secrets"
|
| 37 |
+
files = [("test.txt", test_content)]
|
| 38 |
+
matches = scanner.scan_repo(files)
|
| 39 |
+
assert len(matches) == 0
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
def test_summarize():
|
| 43 |
+
"""Test summary generation."""
|
| 44 |
+
scanner = SecretScanner()
|
| 45 |
+
test_content = "aws_access_key_id=AKIAIOSFODNN7EXAMPLE\ntoken: ghp_1234567890abcdefghijklmnop"
|
| 46 |
+
files = [("test.txt", test_content)]
|
| 47 |
+
matches = scanner.scan_repo(files)
|
| 48 |
+
summary = scanner.summarize(matches)
|
| 49 |
+
assert "total_matches" in summary
|
| 50 |
+
assert summary["total_matches"] > 0
|