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

[stable10] Fixes #31568 - Validate maximum length of a username befor… #31664

Merged
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions lib/private/User/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,11 @@ public function createUser($uid, $password) {
throw new \Exception($l->t('The username must be at least 3 characters long'));
}

// Username can only be a maximum of 64 characters long
if (\strlen($uid) > 64) {
throw new \Exception($l->t('The username can not be longer than 64 characters'));
}

// No empty password
if (trim($password) == '') {
throw new \Exception($l->t('A valid password must be provided'));
Expand Down
7 changes: 7 additions & 0 deletions tests/lib/User/ManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,13 @@ public function testCallForSeenUsers() {
$user4->delete();
}

public function testUsernameMaxLength() {
$this->expectException(\Exception::class);
$this->expectExceptionMessage('The username can not be longer than 64 characters');
$this->manager = \OC::$server->getUserManager();
$user = $this->manager->createUser('testuser123456789012345678901234567890123456789012345678901234567890', 'testuser1');
}

public function testNullUidMakesNoQueryToAccountsTable() {
// migration from versions below 10.0. accounts table hasn't been created yet.
$this->accountMapper->expects($this->never())->method('getByUid');
Expand Down