Skip to content

Conversation

@notypecheck
Copy link
Owner

This PR fixes test setup for bcrypt and django_bcrypt hashers by ignoring certain tests with bcrypt>=5.0.0, without changing any of the hashers themselves.
@chapmajs, @mo7ty, would like you to take a look too - I don't really like current test setup (they even fail if you move a testcase class into a different module 👀), this may just come from being unfamiliar with underlying code, but I find it really hard to work with.

@mo7ty
Copy link

mo7ty commented Oct 18, 2025

Hi @notypecheck,
Agree that you need to be familiar with the underlying code to understand the existing test setup, and not against this update, just need to be used to it. 😉
The new tests.test_handlers_bcrypt.test_known_hashes and test_with_truncate_size will then need to be updated in either #23 or #24 for proper changes validation.

@notypecheck
Copy link
Owner Author

Are #23 and #24 even needed? #23 introduces implicit truncation, which I don't really want, even if it's in line with how bcrypt<5.0.0 behaved, and #24 essentially does the same. As I mentioned previously I think it'll be better long-term to raise an error if users pass long password into default bcrypt hasher. bcrypt=5.0.0also seems to raise the same error when calling checkpw, I think this may be handled in passlib, so older password/hashes continue to work.

@chapmajs
Copy link
Contributor

I agree that the tests are kind of a mess here! I have been reluctant to alter them significantly as there are security implications, given the nature of this library...but not doing so is just prolonging the problem. This commit is a good improvement.

If we're not going to force truncate when using bcrypt >= 5.0.0 we probably ought to set up TruncateMixin to raise on truncation by default.

We would still need to truncate in verify() to allow verification of hashes created with secrets exceeding 72 characters if TruncateMixin is configured to not reject on verify(). I don't see any way around truncating for that, though it could warn instead of doing so silently.

@notypecheck notypecheck merged commit 8bb648b into main Oct 27, 2025
22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants