pytest-dev / pytest-dev/pytest-factoryboy

Password is double-hashed with user factories

Open
#269 0 comments 0 reactions 0 assignees View on GitHub

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

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.