Fix #245 : handle email as case insensitive while retrieving user in DB (#250)

* Add unit tests to enforce email case insensitivity

* Handle email as case insentitive while retrieving user in DB

* Apply isort/black

* Add migration doc
This commit is contained in:
François Voron
2020-07-09 18:44:25 +02:00
committed by GitHub
parent e63a67ead3
commit b7dbdf6ea6
12 changed files with 70 additions and 25 deletions

View File

@ -65,18 +65,24 @@ class TestRegister:
assert response.status_code == status.HTTP_422_UNPROCESSABLE_ENTITY
assert after_register.called is False
@pytest.mark.parametrize(
"email", ["king.arthur@camelot.bt", "King.Arthur@camelot.bt"]
)
async def test_existing_user(
self, test_app_client: httpx.AsyncClient, after_register
self, email, test_app_client: httpx.AsyncClient, after_register
):
json = {"email": "king.arthur@camelot.bt", "password": "guinevere"}
json = {"email": email, "password": "guinevere"}
response = await test_app_client.post("/register", json=json)
assert response.status_code == status.HTTP_400_BAD_REQUEST
data = cast(Dict[str, Any], response.json())
assert data["detail"] == ErrorCode.REGISTER_USER_ALREADY_EXISTS
assert after_register.called is False
async def test_valid_body(self, test_app_client: httpx.AsyncClient, after_register):
json = {"email": "lancelot@camelot.bt", "password": "guinevere"}
@pytest.mark.parametrize("email", ["lancelot@camelot.bt", "Lancelot@camelot.bt"])
async def test_valid_body(
self, email, test_app_client: httpx.AsyncClient, after_register
):
json = {"email": email, "password": "guinevere"}
response = await test_app_client.post("/register", json=json)
assert response.status_code == status.HTTP_201_CREATED
assert after_register.called is True
@ -88,6 +94,7 @@ class TestRegister:
actual_user = after_register.call_args[0][0]
assert str(actual_user.id) == data["id"]
assert str(actual_user.email) == email
request = after_register.call_args[0][1]
assert isinstance(request, Request)