Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 50 additions & 1 deletion tests/core/lib/test_ssl.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
SslEngine,
SslLibrary,
create_tcp_socket,
is_weak_cipher_suite,
is_weak_hash_algo,
is_weak_ssl_version,
is_weak_cipher_suite,
)


Expand Down Expand Up @@ -572,3 +572,52 @@ def test_response_conditions_matched_none_response(self, ssl_engine, substeps):
result = ssl_engine.response_conditions_matched(substeps.ssl_weak_version_vuln, None)

assert result == []
class TestIsWeakHashAlgo:
"""
Tests for is_weak_hash_algo(algo).
This function returns True if the algorithm is considered weak
(md2, md4, md5, sha1), and False if it is safe (sha256, sha512 etc.)
"""
Comment thread
Raavi29 marked this conversation as resolved.
Outdated

# --- WEAK algorithms — should return True ---

def test_sha1_is_weak(self):
assert is_weak_hash_algo("sha1WithRSAEncryption") is True

def test_md5_is_weak(self):
assert is_weak_hash_algo("md5WithRSAEncryption") is True

def test_md2_is_weak(self):
assert is_weak_hash_algo("md2WithRSAEncryption") is True

def test_md4_is_weak(self):
assert is_weak_hash_algo("md4WithRSAEncryption") is True

# --- Case insensitivity — function lowercases input, so these must also work ---

def test_sha1_uppercase_is_weak(self):
# The function does algo.lower() so uppercase should still be caught
assert is_weak_hash_algo("SHA1WithRSAEncryption") is True

def test_md5_uppercase_is_weak(self):
assert is_weak_hash_algo("MD5WithRSAEncryption") is True

Comment thread
Raavi29 marked this conversation as resolved.
Outdated
# --- SAFE algorithms — should return False ---

def test_sha256_is_safe(self):
assert is_weak_hash_algo("sha256WithRSAEncryption") is False

def test_sha512_is_safe(self):
assert is_weak_hash_algo("sha512WithRSAEncryption") is False

def test_sha384_is_safe(self):
assert is_weak_hash_algo("sha384WithRSAEncryption") is False

# --- Edge cases ---

def test_empty_string_does_not_crash(self):
# Empty string should return False, not raise an exception
assert is_weak_hash_algo("") is False

def test_random_string_is_not_weak(self):
assert is_weak_hash_algo("someRandomAlgorithm") is False
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated