Skip to content

Commit 39b2fb5

Browse files
committed
Add case insensitiviti to email search + test cases
Bug: T415017
1 parent 7e4264c commit 39b2fb5

File tree

5 files changed

+23
-2
lines changed

5 files changed

+23
-2
lines changed

app/Console/Commands/User/CheckUserEmailExist.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public function handle(WikiUserEmailChecker $emailChecker): int {
1616
foreach ($emails as $email) {
1717
$found = false;
1818

19-
if (User::whereEmail($email)->exists()) {
19+
if (User::whereEmailInsensitive($email)->exists()) {
2020
$this->line("FOUND: {$email} in apidb.users");
2121
$found = true;
2222
}

app/Services/WikiUserEmailChecker.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ private function emailExists(PDO $pdo, string $dbName, string $table, string $em
5151
$stmt = $pdo->prepare("
5252
SELECT 1
5353
FROM {$dbName}.{$table}
54-
WHERE user_email = :email
54+
WHERE LOWER(user_email) = LOWER(:email)
5555
LIMIT 1
5656
");
5757

app/User.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,4 +121,8 @@ public function sendEmailVerificationNotification() {
121121
public function getEmailForVerification() {
122122
return $this->email;
123123
}
124+
125+
public function scopeWhereEmailInsensitive($query, string $email) {
126+
return $query->whereRaw('LOWER(email) = ?', [strtolower($email)]);
127+
}
124128
}

tests/Commands/User/CheckUserEmailExistTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,13 @@ public function testEmailFoundInWikiDb() {
5151
->expectsOutput('FOUND: test@example.com in mwdb_test.mwdb_test_user')
5252
->assertExitCode(0);
5353
}
54+
55+
public function testCaseInsensitive() {
56+
User::factory()->create([
57+
'email' => 'Test@Example.com',
58+
]);
59+
$exists = User::whereEmailInsensitive('test@example.com')->exists();
60+
61+
$this->assertTrue($exists);
62+
}
5463
}

tests/Services/WikiUserEmailCheckerTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,12 @@ public function testEmailFoundInMultipleDatabases(): void {
6262
$checker->findEmail('user1@email.localhost')
6363
);
6464
}
65+
66+
public function testWikiUserEmailCheckerIsCaseInsensitive(): void {
67+
$checker = new WikiUserEmailChecker($this->db);
68+
$this->assertEquals(
69+
['mwdb_1.db_1_user'],
70+
$checker->findEmail('uSer2@eMAil.localhost')
71+
);
72+
}
6573
}

0 commit comments

Comments
 (0)