-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Add TestIsWeakHashAlgo tests for is_weak_hash_algo() in ssl.py #1452
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 2 commits
765a8f2
e1c5911
10c12fb
ab27688
32ad7e6
26f6791
f3a1406
af4c736
2ab186b
b74e0f9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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, | ||
| ) | ||
|
|
||
|
|
||
|
|
@@ -572,3 +572,53 @@ 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.) | ||
| """ | ||
|
|
||
| # --- 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 on lines
+577
to
+606
|
||
| # --- 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 | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PR description says this adds 11 tests, but
TestIsWeakHashAlgodefines 12 new test methods (4 weak + 2 uppercase + 3 safe + 3 edge). Also, this file already has anis_weak_hash_algotest earlier, so the stated coverage delta / “no dedicated tests” may be outdated. Please update the PR description to match the actual changes.