Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Registration form: better error for mixed case username #1331

Merged
merged 2 commits into from Dec 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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: 2 additions & 2 deletions noggin/form/base.py
@@ -1,9 +1,9 @@
from flask_wtf import FlaskForm
from markupsafe import escape, Markup
from markupsafe import Markup, escape
from wtforms import Field, SubmitField
from wtforms.fields import FieldList, SelectField, StringField
from wtforms.utils import unset_value
from wtforms.widgets import html_params, TextInput
from wtforms.widgets import TextInput, html_params


class BaseForm(FlaskForm):
Expand Down
6 changes: 3 additions & 3 deletions noggin/form/edit_user.py
Expand Up @@ -15,11 +15,11 @@
URLField,
)
from wtforms.validators import (
URL,
AnyOf,
DataRequired,
Length,
Optional,
URL,
ValidationError,
)

Expand All @@ -32,11 +32,11 @@
CSVListField,
ModestForm,
NonEmptyFieldList,
SubmitButtonField,
TypeAndStringField,
replace,
strip,
strip_at,
SubmitButtonField,
TypeAndStringField,
)


Expand Down
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
2 changes: 1 addition & 1 deletion noggin/security/ipa_admin.py
Expand Up @@ -2,7 +2,7 @@

from flask import current_app, session

from .ipa import choose_server, Client
from .ipa import Client, choose_server


class IPAAdmin:
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
2 changes: 1 addition & 1 deletion tests/unit/security/test_ipa.py
Expand Up @@ -8,8 +8,8 @@

from noggin.app import ipa_admin
from noggin.security.ipa import (
choose_server,
Client,
choose_server,
maybe_ipa_login,
maybe_ipa_session,
untouched_ipa_client,
Expand Down