tests: add comprehensive unit tests for is_valid_hash() function#1529
Merged
alejandro-colomar merged 9 commits intoshadow-maint:masterfrom Feb 17, 2026
Merged
tests: add comprehensive unit tests for is_valid_hash() function#1529alejandro-colomar merged 9 commits intoshadow-maint:masterfrom
alejandro-colomar merged 9 commits intoshadow-maint:masterfrom
Conversation
Collaborator
Author
|
@AdamWill this is something that you asked for in one of the PRs that you opened when fixing hash validation. Pinging you just in case you'd like to take a look |
Contributor
|
Thanks a lot! This is great. I think it's missing checks of bare |
Fix misleading comment that stated "43-char (minimum) hash" when the actual regex pattern requires exactly 43 characters. Update comment to accurately reflect the implementation behavior. Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com> Reviewed-by: Alejandro Colomar <alx@kernel.org>
Introduce unit testing infrastructure for the `is_valid_hash()` function. Add yescrypt algorithm validation tests. Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
Add comprehensive bcrypt algorithm validation tests covering all variants ($2a$, $2b$, $2x$, $2y$) with different cost factors. Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
Add comprehensive SHA-512 algorithm validation tests covering rounds and salt cases. Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
Add comprehensive SHA-256 algorithm validation tests covering rounds and salt cases. Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
Add basic MD5 and DES algorithm validation tests. Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
*, ! and empty strings are special valid cases for shadow's second field. Add test cases for them. Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
Add comprehensive negative testing condition validation: - Invalid algorithm prefixes and hash length validation - Invalid delimiter handling - Invalid salt characters and rounds parameter testing Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
0d9b541 to
c55ab57
Compare
Collaborator
Author
That's already covered in test_is_valid_hash_ok_special() |
alejandro-colomar
approved these changes
Feb 10, 2026
Collaborator
alejandro-colomar
left a comment
There was a problem hiding this comment.
Thanks! LGTM.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add comprehensive unit testing for the
is_valid_hash()function inlib/chkhash.c, which is critical for preventing invalid password hashes from being written to/etc/shadow.The
is_valid_hash()function had no unit test coverage despite being security-critical. Recent issues and PRs (#1483, #1520, #1486, #1505) highlighted the need for robust testing to prevent regressions that could lock users out of their accounts.Finally, I've modified a misleading comment for yescrypt hash lenght.