Skip to content

Password is double-hashed with user factories #269

Description

@GergelyKalmar

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions