From e541e02b9ccc31a4392ea110781fb03ce97b9929 Mon Sep 17 00:00:00 2001 From: Diego Beraldin Date: Sun, 23 Jun 2024 16:38:44 +0200 Subject: [PATCH] fix: case sensitive account lookup (#1033) --- .../repository/DefaultAccountRepositoryTest.kt | 2 +- .../repository/DefaultAccountRepository.kt | 15 ++++++++++++--- .../raccoonforlemmy/core/persistence/accounts.sq | 2 +- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/core/persistence/src/androidUnitTest/kotlin/com/github/diegoberaldin/raccoonforlemmy/core/persistence/repository/DefaultAccountRepositoryTest.kt b/core/persistence/src/androidUnitTest/kotlin/com/github/diegoberaldin/raccoonforlemmy/core/persistence/repository/DefaultAccountRepositoryTest.kt index 8da628354..8382fdf3a 100644 --- a/core/persistence/src/androidUnitTest/kotlin/com/github/diegoberaldin/raccoonforlemmy/core/persistence/repository/DefaultAccountRepositoryTest.kt +++ b/core/persistence/src/androidUnitTest/kotlin/com/github/diegoberaldin/raccoonforlemmy/core/persistence/repository/DefaultAccountRepositoryTest.kt @@ -27,7 +27,7 @@ class DefaultAccountRepositoryTest { mockk(relaxUnitFun = true) { every { getAll() } returns query every { getActive() } returns query - every { getBy(username = any(), instance = any()) } returns query + every { getBy(any(), any()) } returns query every { getActive() } returns query } private val provider = diff --git a/core/persistence/src/commonMain/kotlin/com/github/diegoberaldin/raccoonforlemmy/core/persistence/repository/DefaultAccountRepository.kt b/core/persistence/src/commonMain/kotlin/com/github/diegoberaldin/raccoonforlemmy/core/persistence/repository/DefaultAccountRepository.kt index 3306aca6c..63e6fc870 100644 --- a/core/persistence/src/commonMain/kotlin/com/github/diegoberaldin/raccoonforlemmy/core/persistence/repository/DefaultAccountRepository.kt +++ b/core/persistence/src/commonMain/kotlin/com/github/diegoberaldin/raccoonforlemmy/core/persistence/repository/DefaultAccountRepository.kt @@ -14,14 +14,20 @@ internal class DefaultAccountRepository( override suspend fun getAll(): List = withContext(Dispatchers.IO) { - db.accountsQueries.getAll().executeAsList().map { it.toModel() } + db.accountsQueries + .getAll() + .executeAsList() + .map { it.toModel() } } override suspend fun getBy( username: String, instance: String, ) = withContext(Dispatchers.IO) { - db.accountsQueries.getBy(username, instance).executeAsOneOrNull()?.toModel() + db.accountsQueries + .getBy(username.lowercase(), instance.lowercase()) + .executeAsOneOrNull() + ?.toModel() } override suspend fun createAccount(account: AccountModel) = @@ -33,7 +39,10 @@ internal class DefaultAccountRepository( avatar = account.avatar, ) val entity = - db.accountsQueries.getAll().executeAsList().firstOrNull { it.jwt == account.jwt } + db.accountsQueries + .getAll() + .executeAsList() + .firstOrNull { it.jwt == account.jwt } entity?.id ?: 0 } diff --git a/core/persistence/src/commonMain/sqldelight/com/github/diegoberaldin/raccoonforlemmy/core/persistence/accounts.sq b/core/persistence/src/commonMain/sqldelight/com/github/diegoberaldin/raccoonforlemmy/core/persistence/accounts.sq index 11fb72cfd..10fe5aaef 100644 --- a/core/persistence/src/commonMain/sqldelight/com/github/diegoberaldin/raccoonforlemmy/core/persistence/accounts.sq +++ b/core/persistence/src/commonMain/sqldelight/com/github/diegoberaldin/raccoonforlemmy/core/persistence/accounts.sq @@ -37,7 +37,7 @@ FROM AccountEntity; getBy: SELECT * FROM AccountEntity -WHERE username = ? AND instance = ?; +WHERE username = LOWER(?) AND instance = LOWER(?); update: UPDATE AccountEntity