Repository navigation
Use a fast password hasher when running the tests - #217
Merged
Merged
Conversation
The suite spent nearly all of its time hashing passwords: 112 s locally, 3.5 s with MD5. Only the test command is affected. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
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.
The CI test job takes about 5 minutes for a fairly small app. Almost all of that is password hashing.
What I measured
Django hashes passwords with PBKDF2 on purpose; one hash costs about 89 ms here. The tests create users constantly (the slowest tests, all about 0.46 s, are the ones that make four or five users in setup), so hashing was nearly the whole run time. Splitting the suite across runners, parallel test processes and dependency caching would each have saved little, because setup is only about 7 s and the tests are CPU-bound on hashing.
What changes
Tests
`krill/tests/test_password_hasher.py` (4 tests): the test command uses the fast hasher; users made in tests get an `md5$` hash and can still log in (and a wrong password is refused); a test can still ask for `pbkdf2_sha256`; and a separate `manage.py shell` process still reports the default hashers with PBKDF2 and no MD5, which guards against the fast hasher leaking into the app. The first three skip themselves if the tests are run some other way, such as through pytest, where the check would not apply. Full suite: 873 tests, OK, in about 3.6 s locally.
How to check it worked
Compare this PR's CI `Run tests` step against the 4 m 50 s above. My estimate for CI is roughly 10 s, but I have not measured it there.
🤖 Generated with Claude Code