Skip to content

Commit

Permalink
fixup! fixup! fixup! Fixes #24839: We cannot login with a user login …
Browse files Browse the repository at this point in the history
…containing uppercase letter if the option case-sensitivity is set to false

Fixes #24839: We cannot login with a user login containing uppercase letter if the option case-sensitivity is set to false
  • Loading branch information
clarktsiory committed May 6, 2024
1 parent 1c5f6d4 commit a325e13
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -491,8 +491,12 @@ class InMemoryUserRepository(userBase: Ref[Map[String, UserInfo]], sessionBase:
}

override def get(userId: String, isCaseSensitive: Boolean): IOResult[Option[UserInfo]] = {
userBase.get.map(_.collectFirst {
userBase.get.flatMap(_.collect {
case (k, v) if (if (isCaseSensitive) k == userId else k.equalsIgnoreCase(userId)) => v
} match {
case Nil => ZIO.none
case u :: Nil => ZIO.some(u)
case _ => Left(Inconsistency(s"Multiple users found for id '${userId}'")).toIO
})
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,21 @@ trait UserRepositoryTest extends Specification with Loggable {
repo.get("Alice", isCaseSensitive = false).runNow must beSome
}

"Getting user should raise an error for multiple found users" >> {
repo.setExistingUsers(AUTH_PLUGIN_NAME_LOCAL, users :+ "Alice", traceInit).runNow
repo.get("alice").runNow must beSome
repo.get("Alice").runNow must beSome
repo.get("alice", isCaseSensitive = false).either.runNow must beLeft(
errors.Inconsistency("Multiple users found for id 'alice'")
)
repo.get("Alice", isCaseSensitive = false).either.runNow must beLeft(
errors.Inconsistency("Multiple users found for id 'Alice'")
)
(repo.delete(List("Alice"), None, Nil, traceInit) *> repo.purge(List("Alice"), None, Nil, traceInit)).runNow must beEqualTo(
List("Alice")
)
}

"If an user is removed from list, it is marked as 'deleted' (but node erased)" >> {
repo.setExistingUsers(AUTH_PLUGIN_NAME_LOCAL, userFileBobRemoved, traceBobRemoved).runNow
repo.getAll().runNow.toUTC must containTheSameElementsAs(userInfosBobRemoved)
Expand Down

0 comments on commit a325e13

Please sign in to comment.