fix: case sensitive account lookup (#1033)

This commit is contained in:
Diego Beraldin 2024-06-23 16:38:44 +02:00 committed by GitHub
parent 3b01922c3b
commit e541e02b9c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 14 additions and 5 deletions

View File

@ -27,7 +27,7 @@ class DefaultAccountRepositoryTest {
mockk<AccountsQueries>(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 =

View File

@ -14,14 +14,20 @@ internal class DefaultAccountRepository(
override suspend fun getAll(): List<AccountModel> =
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
}

View File

@ -37,7 +37,7 @@ FROM AccountEntity;
getBy:
SELECT *
FROM AccountEntity
WHERE username = ? AND instance = ?;
WHERE username = LOWER(?) AND instance = LOWER(?);
update:
UPDATE AccountEntity