-
-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1390 from c2corg/sanitize-username
Strip leading/trailing whitespaces from usernames when registering
- Loading branch information
Showing
2 changed files
with
51 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -196,6 +196,35 @@ def test_register_forum_username_unique(self, _send_email): | |
self.assertEqual(json['errors'][0]['description'], | ||
'already used forum_username') | ||
|
||
@patch('c2corg_api.emails.email_service.EmailService._send_email') | ||
def test_register_stripped_username(self, _send_email): | ||
request_body = { | ||
'username': ' contributor ', | ||
'forum_username': 'Foo', | ||
'name': 'Max Mustermann', | ||
'password': 'super secret', | ||
'email': '[email protected]' | ||
} | ||
url = self._prefix + '/register' | ||
json = self.app_post_json(url, request_body, status=400).json | ||
self.assertEqual(json['errors'][0]['description'], | ||
'This username already exists') | ||
|
||
request_body = { | ||
'username': ' username with spaces ', | ||
'forum_username': 'Spaceman', | ||
'name': 'Max Mustermann', | ||
'password': 'super secret', | ||
'email': '[email protected]' | ||
} | ||
url = self._prefix + '/register' | ||
body = self.app_post_json(url, request_body, status=200).json | ||
self.assertBodyEqual(body, 'username', 'username with spaces') | ||
user_id = body.get('id') | ||
user = self.session.query(User).get(user_id) | ||
self.assertIsNotNone(user) | ||
self.assertEqual(user.username, 'username with spaces') | ||
|
||
@patch('c2corg_api.emails.email_service.EmailService._send_email') | ||
def test_register_username_email_not_equals_email(self, _send_email): | ||
request_body = { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters