Skip to content

Commit

Permalink
Registration form: better error for mixed case username
Browse files Browse the repository at this point in the history
Fixes: #1327
Signed-off-by: Aurélien Bompard <aurelien@bompard.org>
  • Loading branch information
abompard committed Dec 1, 2023
1 parent fbad470 commit c439a4a
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Expand Up @@ -22,7 +22,7 @@ repos:
rev: 5.12.0
hooks:
- id: isort
args: ["-c"]
args: ["-c", "--diff"]

- repo: https://github.com/Lucas-C/pre-commit-hooks-bandit
rev: v1.0.6
Expand Down
1 change: 1 addition & 0 deletions news/1327.feature
@@ -0,0 +1 @@
Give a clearer error message to registering users who use a mixed case username
4 changes: 3 additions & 1 deletion noggin/form/register_user.py
Expand Up @@ -14,10 +14,11 @@
Email,
PasswordLength,
StopOnError,
no_mixed_case,
validator_proxy,
)

from .base import BaseForm, lower, ModestForm, strip, SubmitButtonField
from .base import BaseForm, ModestForm, SubmitButtonField, lower, strip


class RegisterUserForm(ModestForm):
Expand Down Expand Up @@ -45,6 +46,7 @@ class RegisterUserForm(ModestForm):
)
)
),
StopOnError(no_mixed_case),
validator_proxy(
lambda: Regexp(
current_app.config["ALLOWED_USERNAME_PATTERN"],
Expand Down
1 change: 0 additions & 1 deletion pyproject.toml
Expand Up @@ -185,7 +185,6 @@ twisted = "23.8.0"
profile = "black"
known_first_party = ["noggin", "noggin_messages"]
lines_after_imports = 2
force_alphabetical_sort_within_sections = true

[tool.pytest.ini_options]
testpaths = [
Expand Down
17 changes: 17 additions & 0 deletions tests/unit/controller/test_registration.py
Expand Up @@ -179,6 +179,23 @@ def test_step_1_bad_length(client, post_data_step_1, mocker, username):
assert len(outbox) == 0


def test_step1_mixed_case(client, post_data_step_1, mocker):
"""Test giving username uppercase letters"""
post_data_step_1["register-username"] = "DummyUser"
record_signal = mocker.Mock()
with mailer.record_messages() as outbox, stageuser_created.connected_to(
record_signal
):
result = client.post('/', data=post_data_step_1)
assert_form_field_error(
result,
"register-username",
"Mixed case is not allowed, try lower case.",
)
record_signal.assert_not_called()
assert len(outbox) == 0


@pytest.mark.parametrize(
"username", ["dummy_user", "dummy.user", "dummy user", "_dummy", ".dummy", "dummy-"]
)
Expand Down

0 comments on commit c439a4a

Please sign in to comment.