Skip to content

Commit 0ea8aba

Browse files
committed
🐛(back) allow / and = characters in user sub field
We want to keep a restrict list of allowed characters in the user sub field. We allow now the = and / Fix #1280
1 parent 0892c05 commit 0ea8aba

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed

src/backend/core/models.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,21 +137,21 @@ class User(AbstractBaseUser, BaseModel, auth_models.PermissionsMixin):
137137
"""User model to work with OIDC only authentication."""
138138

139139
sub_validator = validators.RegexValidator(
140-
regex=r"^[\w.@+-:]+\Z",
140+
regex=r"^[\w.@+-:=/]+\Z",
141141
message=_(
142142
"Enter a valid sub. This value may contain only letters, "
143-
"numbers, and @/./+/-/_/: characters."
143+
"numbers, and @.+-_:=/ characters."
144144
),
145145
)
146146

147147
sub = models.CharField(
148148
_("sub"),
149149
help_text=_(
150-
"Required. 255 characters or fewer. Letters, numbers, and @/./+/-/_/: characters only."
150+
"Required. 255 characters or fewer. Letters, numbers, and @.+-_:=/ characters only."
151151
),
152152
max_length=255,
153-
unique=True,
154153
validators=[sub_validator],
154+
unique=True,
155155
blank=True,
156156
null=True,
157157
)

src/backend/core/tests/test_models_users.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,27 @@ def test_models_users_send_mail_main_missing():
4444
user.email_user("my subject", "my message")
4545

4646
assert str(excinfo.value) == "User has no email address."
47+
48+
49+
@pytest.mark.parametrize(
50+
"sub,is_valid",
51+
[
52+
("valid_sub.@+-:=/", True),
53+
("invalid sub", False),
54+
],
55+
)
56+
def test_models_users_sub_validator(sub, is_valid):
57+
"""The "sub" field should be validated."""
58+
user = factories.UserFactory()
59+
user.sub = sub
60+
if is_valid:
61+
user.full_clean()
62+
else:
63+
with pytest.raises(
64+
ValidationError,
65+
match=(
66+
"Enter a valid sub. This value may contain only letters,"
67+
" numbers, and @.+-_:=/ characters."
68+
),
69+
):
70+
user.full_clean()

0 commit comments

Comments
 (0)