Skip to content
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
7 changes: 6 additions & 1 deletion lib/private/User/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,12 @@ public function checkPassword($loginName, $password) {
* @return IUser|false the User object on success, false otherwise
*/
public function checkPasswordNoLogging($loginName, $password) {
$loginName = str_replace("\0", '', $loginName);
// A NUL byte in the login name must not turn it into a second name for an
// account: the checks done before the password check (e.g. 2FA enforcement
// in Session::logClientIn()) see the name as sent, so the name has to stay the same
if (str_contains($loginName, "\0")) {
return false;
}
$password = str_replace("\0", '', $password);

$cachedBackend = $this->cache->get($loginName);
Expand Down
38 changes: 27 additions & 11 deletions tests/lib/User/ManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@ public function testGetBackends() {
$this->assertEquals([$userDummyBackend, $dummyDatabaseBackend], $manager->getBackends());
}


public function testUserExistsSingleBackendExists() {
public function testUserExistsSingleBackendExists(): void {
/**
* @var \Test\Util\User\Dummy | \PHPUnit\Framework\MockObject\MockObject $backend
*/
Expand Down Expand Up @@ -196,7 +195,28 @@ public function testCheckPasswordNotSupported() {
$this->assertFalse($manager->checkPassword('foo', 'bar'));
}

public function testGetOneBackendExists() {
public function testCheckPasswordNullByteInLoginName(): void {
$backend = $this->createMock(\Test\Util\User\Dummy::class);
$backend->expects($this->never())
->method('checkPassword');

$backend->expects($this->any())
->method('implementsActions')
->willReturnCallback(function ($actions) {
if ($actions === BACKEND::CHECK_PASSWORD) {
return true;
} else {
return false;
}
});

$manager = new Manager($this->config, $this->cacheFactory, $this->eventDispatcher, $this->logger);
$manager->registerBackend($backend);

$this->assertFalse($manager->checkPassword("foo\0", 'bar'));
}

public function testGetOneBackendExists(): void {
/**
* @var \Test\Util\User\Dummy | \PHPUnit\Framework\MockObject\MockObject $backend
*/
Expand Down Expand Up @@ -347,8 +367,7 @@ public function testCreateUserInvalid($uid, $password, $exception) {
->with(\OC\User\Backend::CREATE_USER)
->willReturn(true);


$manager = new \OC\User\Manager($this->config, $this->cacheFactory, $this->eventDispatcher, $this->logger);
$manager = new Manager($this->config, $this->cacheFactory, $this->eventDispatcher, $this->logger);
$manager->registerBackend($backend);

$this->expectException(\InvalidArgumentException::class, $exception);
Expand Down Expand Up @@ -382,8 +401,7 @@ public function testCreateUserSingleBackendNotExists() {
$this->assertEquals('foo', $user->getUID());
}


public function testCreateUserSingleBackendExists() {
public function testCreateUserSingleBackendExists(): void {
$this->expectException(\Exception::class);

/**
Expand Down Expand Up @@ -435,8 +453,7 @@ public function testCreateUserNoBackends() {
$this->assertFalse($manager->createUser('foo', 'bar'));
}


public function testCreateUserFromBackendWithBackendError() {
public function testCreateUserFromBackendWithBackendError(): void {
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('Could not create user');

Expand All @@ -454,8 +471,7 @@ public function testCreateUserFromBackendWithBackendError() {
$manager->createUserFromBackend('MyUid', 'MyPassword', $backend);
}


public function testCreateUserTwoBackendExists() {
public function testCreateUserTwoBackendExists(): void {
$this->expectException(\Exception::class);

/**
Expand Down
Loading