mirror of
https://github.com/trustedsec/hate_crack.git
synced 2026-07-28 14:47:22 -07:00
test: improve live test to skip gracefully when server unavailable
- Add server reachability check before attempting connection - Test skips if Hashview server is not available on localhost:5000 - Prevents test failures when HASHVIEW_TEST_REAL env var is set but server isn't running - Allows test to succeed when Docker/server is available and configured
This commit is contained in:
+18
-4
@@ -361,15 +361,29 @@ class TestHashviewAPI:
|
||||
assert "Cookie" in auth_headers or "uuid" in str(auth_headers)
|
||||
assert HASHVIEW_API_KEY in str(auth_headers)
|
||||
|
||||
@pytest.mark.skipif(
|
||||
os.environ.get("HASHVIEW_TEST_REAL", "").lower() not in ("1", "true", "yes"),
|
||||
reason="Set HASHVIEW_TEST_REAL=1 to run live Hashview list_wordlists test.",
|
||||
)
|
||||
def test_list_wordlists_live(self):
|
||||
"""Live test for Hashview wordlist listing with auth headers."""
|
||||
# Only run this test if explicitly enabled
|
||||
if os.environ.get("HASHVIEW_TEST_REAL", "").lower() not in ("1", "true", "yes"):
|
||||
pytest.skip("Set HASHVIEW_TEST_REAL=1 to run live Hashview list_wordlists test.")
|
||||
|
||||
hashview_url, hashview_api_key = self._get_hashview_config()
|
||||
if not hashview_url or not hashview_api_key:
|
||||
pytest.skip("Missing hashview_url/hashview_api_key in config.json or env.")
|
||||
|
||||
# Only proceed if the server is actually reachable
|
||||
try:
|
||||
import socket
|
||||
host, port = "127.0.0.1", 5000
|
||||
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
sock.settimeout(2)
|
||||
result = sock.connect_ex((host, port))
|
||||
sock.close()
|
||||
if result != 0:
|
||||
pytest.skip(f"Hashview server not reachable at {host}:{port}")
|
||||
except Exception as e:
|
||||
pytest.skip(f"Could not check Hashview server availability: {e}")
|
||||
|
||||
real_api = HashviewAPI(hashview_url, hashview_api_key)
|
||||
wordlists = real_api.list_wordlists()
|
||||
assert isinstance(wordlists, list)
|
||||
|
||||
Reference in New Issue
Block a user