pytest-dev / pytest-dev/pytest-factoryboy
Password is double-hashed with user factories
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 400
- Forks
- 44
- Avg merge
- 6h 34m
- Merged PRs (30d)
- 1
Description
Assume we have a user factory like so:
from factory.django import DjangoModelFactory, Password
class UserFactory(DjangoModelFactory[User]):
password = Password(USER_PASSWORD)
...
Then the following does not work as one would expect:
from django.contrib.auth.hashers import check_password
def test_password(user: User) -> None:
assert check_password(USER_PASSWORD, user.password) # raises AssertionError
The following does work properly though:
def test_password() -> None:
user = UserFactory()
assert check_password(USER_PASSWORD, user.password) # succeeds
I think the issue might be that the password is double-hashed when using pytest-factoryboy with this factory. Note that we are using the factories to generate synthetic data as well, so we need them to generate usable passwords (i.e. we cannot set the password to the raw string). Preferably both UserFactory() and the pytest-factoryboy fixture work at the same time.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the two examples using the Django UserFactory, Password, pytest-factoryboy fixture, and Django check_password entry points shown in the issue. Trace where the password is transformed for the fixture versus direct UserFactory() creation; done means both examples pass while generated synthetic users retain usable hashed passwords.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- django, python
- Domain
- testing
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 55/100