mirror of
https://github.com/trustedsec/hate_crack.git
synced 2026-07-11 22:52:05 -07:00
Merge draft PR #63
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
import os
|
||||
import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
import uuid
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
@@ -17,12 +19,13 @@ def _require_docker():
|
||||
def docker_image():
|
||||
_require_docker()
|
||||
repo_root = Path(__file__).resolve().parents[1]
|
||||
image_tag = "hate-crack-e2e"
|
||||
dockerfile_path = repo_root / "Dockerfile.test"
|
||||
# Use a unique tag per test run to avoid conflicts
|
||||
image_tag = f"hate-crack-e2e-{uuid.uuid4().hex[:8]}"
|
||||
|
||||
dockerfile_path = str(repo_root / "Dockerfile.test")
|
||||
try:
|
||||
build = subprocess.run(
|
||||
["docker", "build", "-f", str(dockerfile_path), "-t", image_tag, str(repo_root)],
|
||||
["docker", "build", "-f", dockerfile_path, "-t", image_tag, str(repo_root)],
|
||||
capture_output=True,
|
||||
text=True,
|
||||
timeout=600,
|
||||
@@ -34,7 +37,26 @@ def docker_image():
|
||||
"Docker build failed. "
|
||||
f"stdout={build.stdout} stderr={build.stderr}"
|
||||
)
|
||||
return image_tag
|
||||
|
||||
yield image_tag
|
||||
|
||||
# Cleanup: remove the Docker image after tests complete
|
||||
try:
|
||||
result = subprocess.run(
|
||||
["docker", "image", "rm", image_tag],
|
||||
capture_output=True,
|
||||
text=True,
|
||||
timeout=60,
|
||||
)
|
||||
if result.returncode != 0:
|
||||
print(
|
||||
f"Warning: Failed to remove Docker image {image_tag}. "
|
||||
f"stderr={result.stderr}",
|
||||
file=sys.stderr
|
||||
)
|
||||
except Exception as e:
|
||||
# Don't fail the test if cleanup fails, but log the issue
|
||||
print(f"Warning: Exception while removing Docker image {image_tag}: {e}", file=sys.stderr)
|
||||
|
||||
|
||||
def _run_container(image_tag, command, timeout=180):
|
||||
@@ -65,11 +87,9 @@ def test_docker_script_install_and_run(docker_image):
|
||||
def test_docker_hashcat_cracks_simple_password(docker_image):
|
||||
command = (
|
||||
"set -euo pipefail; "
|
||||
"curl -fsSL -o /tmp/rockyou.txt.gz https://weakpass.com/download/90/rockyou.txt.gz; "
|
||||
"gzip -d /tmp/rockyou.txt.gz; "
|
||||
"head -n 5000 /tmp/rockyou.txt > /tmp/rockyou.small.txt; "
|
||||
"printf 'password\\nletmein\\n123456\\n' > /tmp/wordlist.txt; "
|
||||
"echo 5f4dcc3b5aa765d61d8327deb882cf99 > /tmp/hash.txt; "
|
||||
"hashcat -m 0 -a 0 --potfile-disable -o /tmp/out.txt /tmp/hash.txt /tmp/rockyou.small.txt --quiet; "
|
||||
"hashcat -m 0 -a 0 --potfile-disable -o /tmp/out.txt /tmp/hash.txt /tmp/wordlist.txt --quiet; "
|
||||
"grep -q ':password' /tmp/out.txt"
|
||||
)
|
||||
run = _run_container(docker_image, command, timeout=180)
|
||||
|
||||
Reference in New Issue
Block a user