Permalink
Browse files

fix(users): get user by username or email is case-insensitive

fixes #11841
  • Loading branch information...
jeabakker committed Mar 26, 2018
1 parent 4299c5c commit 00747e8c6682d1faec872071dd9461d65ee0fb98
@@ -78,6 +78,7 @@ public function getByUsername($username) {
[
'name' => 'username',
'value' => $username,
'case_sensitive' => false,
],
],
'limit' => 1,
@@ -103,6 +104,7 @@ public function getByEmail($email) {
[
'name' => 'email',
'value' => $email,
'case_sensitive' => false,
],
],
'limit' => 1,
@@ -107,6 +107,42 @@ public function testGetUserByUsernameAcceptsUrlEncoded() {
$this->user->delete();
}
public function testGetUserByUsernameCaseInsensitivity() {
$username = $this->getRandomUsername();
$this->user->username = $username;
$guid = $this->user->save();
$uc_username = strtoupper($username);
$user = get_user_by_username($uc_username);
$this->assertTrue((bool) $user);
$this->assertEquals($user->guid, $guid);
$this->user->delete();
}
public function testGetUserByEmailCaseInsensitivity() {
$email = 'Example.User@elgg.org';
$this->user->email = $email;
$guid = $this->user->save();
$users = get_user_by_email($email);
$this->assertCount(1, $users);
$this->assertEquals($users[0]->guid, $guid);
// lower case
$email = strtolower($email);
$users = get_user_by_email($email);
$this->assertCount(1, $users);
$this->assertEquals($users[0]->guid, $guid);
$this->user->delete();
}
public function testElggUserMakeAdmin() {
$CONFIG = _elgg_config();
@@ -62,6 +62,28 @@ public function testCanCacheElggUser() {
$this->assertNull(_elgg_services()->entityCache->load($user->guid));
$this->assertNull(_elgg_services()->dataCache->usernames->load($user->username));
}
public function testCacheUserByUsernameCaseInsensitive() {
$user = $this->createUser([
'username' => 'CaseInsensitiveTestUser',
]);
$user->invalidateCache();
$user->cache();
$this->assertEquals($user, _elgg_services()->entityCache->load($user->guid));
$this->assertEquals($user, _elgg_services()->dataCache->usernames->load($user->username));
$this->assertEquals($user, _elgg_services()->dataCache->usernames->load(strtolower($user->username)));
$user->invalidateCache();
$this->assertNull(_elgg_services()->entityCache->load($user->guid));
$this->assertNull(_elgg_services()->dataCache->usernames->load($user->username));
$this->assertNull(_elgg_services()->dataCache->usernames->load(strtolower($user->username)));
$user->delete();
}
public function testCanDisableCacheForEntity() {

0 comments on commit 00747e8

Please sign in to comment.