diff --git a/lib/private/User/AccountMapper.php b/lib/private/User/AccountMapper.php index 0817f9542dc0..3d64f616154b 100644 --- a/lib/private/User/AccountMapper.php +++ b/lib/private/User/AccountMapper.php @@ -108,9 +108,11 @@ public function getByEmail($email) { throw new \InvalidArgumentException('$email must be defined'); } $qb = $this->db->getQueryBuilder(); + // RFC 5321 says that only domain name is case insensitive, but in practice + // it's the whole email $qb->select('*') ->from($this->getTableName()) - ->where($qb->expr()->eq('email', $qb->createNamedParameter($email))); + ->where($qb->expr()->eq($qb->createFunction('LOWER(`email`)'), $qb->createFunction('LOWER(' . $qb->createNamedParameter($email) . ')'))); return $this->findEntities($qb->getSQL(), $qb->getParameters()); } diff --git a/tests/lib/User/AccountMapperTest.php b/tests/lib/User/AccountMapperTest.php index 85b6607c8ac1..dc66acc14e45 100644 --- a/tests/lib/User/AccountMapperTest.php +++ b/tests/lib/User/AccountMapperTest.php @@ -120,11 +120,32 @@ public function testFindByDisplayName() { $this->assertEquals("TestFind2", array_shift($result)->getUserId()); } + public function findByEmailDataProvider() { + return [ + ['test3@find.tld'], + ['Test3@find.tld'], + ['test3@Find.tld'], + ]; + } + /** * find by email + * + * @dataProvider findByEmailDataProvider + */ + public function testFindByEmail($email) { + $result = $this->mapper->find($email); + $this->assertEquals(1, count($result)); + $this->assertEquals("TestFind3", array_shift($result)->getUserId()); + } + + /** + * get by email + * + * @dataProvider findByEmailDataProvider */ - public function testFindByEmail() { - $result= $this->mapper->find('test3@find.tld'); + public function testGetByEmail($email) { + $result = $this->mapper->getByEmail($email); $this->assertEquals(1, count($result)); $this->assertEquals("TestFind3", array_shift($result)->getUserId()); } @@ -148,4 +169,4 @@ public function testFindLimitAndOffset() { $this->assertEquals("TestFind3", array_shift($result)->getUserId()); $this->assertEquals("TestFind4", array_shift($result)->getUserId()); } -} \ No newline at end of file +}