Skip to content

Commit

Permalink
fix very long emails as username
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcelGeo committed Feb 26, 2025
1 parent a6c0178 commit e5d1873
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
2 changes: 2 additions & 0 deletions server/mergin/auth/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,8 @@ def generate_username(cls, email: str) -> Optional[str]:
).ljust(4, "0")
# additional check for reserved words
username = f"{username}0" if is_reserved_word(username) else username
# some value until 25 + space for suffix
username = username[:22]
# check if we already do not have existing usernames
query = db.session.execute(
text(
Expand Down
5 changes: 5 additions & 0 deletions server/mergin/tests/test_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ def test_logout(client):
400,
), # tests with upper case, but email already exists
(" [email protected] ", "#pwd123", 400), # invalid password
("[email protected]", "#pwd1234", 201),
]


Expand Down Expand Up @@ -851,6 +852,10 @@ def test_username_generation(client):

user = add_user("support1", "user")
assert User.generate_username("[email protected]") == "support0"
assert (
User.generate_username("[email protected]")
== "verylonglonglonglonglo"
)


def test_server_usage(client):
Expand Down

0 comments on commit e5d1873

Please sign in to comment.