s3shastra / test_github_scanner.py
Atharv834
Deploy S3Shastra backend - FastAPI + scanners + ML models
6a4dcb6
import asyncio
import sys
import os
# Add current directory to sys.path to ensure we can import github_scanner
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
import github_scanner
class MockWebSocket:
async def send_json(self, data):
print(f"[WebSocket Mock] {data}")
async def main():
if len(sys.argv) < 2:
print("Usage: python test_github_scanner.py <domain>")
return
domain = sys.argv[1]
print(f"Testing GitHub Scanner against: {domain}")
# Check if token is loaded
headers = await github_scanner.get_github_headers()
if "Authorization" in headers:
print("✅ GITHUB_TOKEN is found and loaded.")
else:
print("⚠️ GITHUB_TOKEN NOT FOUND. You might hit rate limits.")
mock_ws = MockWebSocket()
# Run the main scan
await github_scanner.scan_github(domain, mock_ws)
print("\n--- Testing Scanner Logic with Dummy Data ---")
dummy_content = "Here is a leak: https://my-secret-bucket.s3.amazonaws.com/database.dump"
print(f"Scanning content: '{dummy_content}'")
findings = github_scanner.scan_content(dummy_content, "test_file.txt", "http://github.com/test/repo")
print(f"Findings: {findings}")
if findings and findings[0]['type'] == 'bucket' and 'my-secret-bucket' in findings[0]['match']:
print("✅ Regex verification PASSED: Bucket detected.")
else:
print("❌ Regex verification FAILED: Bucket NOT detected.")
if __name__ == "__main__":
asyncio.run(main())