Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove user-management error cases from scenario-service proto. #12460

Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
meh... done over by scala's poor excuse for a type system
  • Loading branch information
nickchapman-da committed Jan 19, 2022
commit 35ef23c8d619b3324e481d01610988a164c0eb30
Original file line number Diff line number Diff line change
Expand Up @@ -25,60 +25,60 @@ final class InMemoryUserManagementStoreSpec extends AnyFreeSpec with Matchers {
"in-memory user management" - {
"allow creating a fresh user" in {
val mgmt = new UserManagementStore()
mgmt.createUser(User("user1", None), Set.empty) shouldBe Right(())
mgmt.createUser(User("user2", None), Set.empty) shouldBe Right(())
mgmt.createUser(User("user1", None), Set.empty) shouldBe Some(())
mgmt.createUser(User("user2", None), Set.empty) shouldBe Some(())
}

"disallow re-creating an existing user" in {
val mgmt = new UserManagementStore()
val user = User("user1", None)
mgmt.createUser(user, Set.empty) shouldBe Right(())
mgmt.createUser(user, Set.empty) shouldBe Left(())
mgmt.createUser(user, Set.empty) shouldBe Some(())
mgmt.createUser(user, Set.empty) shouldBe None
}

"find a freshly created user" in {
val mgmt = new UserManagementStore()
val user = User("user1", None)
mgmt.createUser(user, Set.empty) shouldBe Right(())
mgmt.getUser("user1") shouldBe Right(user)
mgmt.createUser(user, Set.empty) shouldBe Some(())
mgmt.getUser("user1") shouldBe Some(user)
}

"not find a non-existent user" in {
val mgmt = new UserManagementStore()
mgmt.getUser("user1") shouldBe Left(())
mgmt.getUser("user1") shouldBe None
}
"not find a deleted user" in {
val mgmt = new UserManagementStore()
val user = User("user1", None)
mgmt.createUser(user, Set.empty) shouldBe Right(())
mgmt.getUser("user1") shouldBe Right(user)
mgmt.deleteUser("user1") shouldBe Right(())
mgmt.getUser("user1") shouldBe Left(())
mgmt.createUser(user, Set.empty) shouldBe Some(())
mgmt.getUser("user1") shouldBe Some(user)
mgmt.deleteUser("user1") shouldBe Some(())
mgmt.getUser("user1") shouldBe None
}
"allow recreating a deleted user" in {
val mgmt = new UserManagementStore()
val user = User("user1", None)
mgmt.createUser(user, Set.empty) shouldBe Right(())
mgmt.deleteUser(user.id) shouldBe Right(())
mgmt.createUser(user, Set.empty) shouldBe Right(())
mgmt.createUser(user, Set.empty) shouldBe Some(())
mgmt.deleteUser(user.id) shouldBe Some(())
mgmt.createUser(user, Set.empty) shouldBe Some(())
}
"fail to delete a non-existent user" in {
val mgmt = new UserManagementStore()
mgmt.deleteUser("user1") shouldBe Left(())
mgmt.deleteUser("user1") shouldBe None
}
"list created users" in {
val mgmt = new UserManagementStore()
mgmt.createUser(User("user1", None), Set.empty) shouldBe Right(())
mgmt.createUser(User("user2", None), Set.empty) shouldBe Right(())
mgmt.listUsers() shouldBe Right(Seq(User("user1", None), User("user2", None)))
mgmt.createUser(User("user1", None), Set.empty) shouldBe Some(())
mgmt.createUser(User("user2", None), Set.empty) shouldBe Some(())
mgmt.listUsers() shouldBe Seq(User("user1", None), User("user2", None))
}
"not list deleted users" in {
val mgmt = new UserManagementStore()
mgmt.createUser(User("user1", None), Set.empty) shouldBe Right(())
mgmt.createUser(User("user2", None), Set.empty) shouldBe Right(())
mgmt.listUsers() shouldBe Right(Seq(User("user1", None), User("user2", None)))
mgmt.deleteUser("user1") shouldBe Right(())
mgmt.listUsers() shouldBe Right(Seq(User("user2", None)))
mgmt.createUser(User("user1", None), Set.empty) shouldBe Some(())
mgmt.createUser(User("user2", None), Set.empty) shouldBe Some(())
mgmt.listUsers() shouldBe Seq(User("user1", None), User("user2", None))
mgmt.deleteUser("user1") shouldBe Some(())
mgmt.listUsers() shouldBe Seq(User("user2", None))
}
}

Expand All @@ -90,56 +90,56 @@ final class InMemoryUserManagementStoreSpec extends AnyFreeSpec with Matchers {
import UserRight._
"listUserRights should find the rights of a freshly created user" in {
val mgmt = new UserManagementStore()
mgmt.createUser(User("user1", None), Set.empty) shouldBe Right(())
mgmt.listUserRights("user1") shouldBe Right(Set.empty)
mgmt.createUser(User("user1", None), Set.empty) shouldBe Some(())
mgmt.listUserRights("user1") shouldBe Some(Set.empty)
mgmt.createUser(
User("user2", None),
Set(ParticipantAdmin, CanActAs("party1"), CanReadAs("party2")),
) shouldBe Right(())
mgmt.listUserRights("user2") shouldBe Right(
) shouldBe Some(())
mgmt.listUserRights("user2") shouldBe Some(
Set(ParticipantAdmin, CanActAs("party1"), CanReadAs("party2"))
)
}
"listUserRights should fail on non-existent user" in {
val mgmt = new UserManagementStore()
mgmt.listUserRights("user1") shouldBe Left(())
mgmt.listUserRights("user1") shouldBe None
}
"grantUserRights should add new rights" in {
val mgmt = new UserManagementStore()
mgmt.createUser(User("user1", None), Set.empty) shouldBe Right(())
mgmt.grantRights("user1", Set(ParticipantAdmin)) shouldBe Right(Set(ParticipantAdmin))
mgmt.grantRights("user1", Set(ParticipantAdmin)) shouldBe Right(Set.empty)
mgmt.grantRights("user1", Set(CanActAs("party1"), CanReadAs("party2"))) shouldBe Right(
mgmt.createUser(User("user1", None), Set.empty) shouldBe Some(())
mgmt.grantRights("user1", Set(ParticipantAdmin)) shouldBe Some(Set(ParticipantAdmin))
mgmt.grantRights("user1", Set(ParticipantAdmin)) shouldBe Some(Set.empty)
mgmt.grantRights("user1", Set(CanActAs("party1"), CanReadAs("party2"))) shouldBe Some(
Set(CanActAs("party1"), CanReadAs("party2"))
)
mgmt.listUserRights("user1") shouldBe Right(
mgmt.listUserRights("user1") shouldBe Some(
Set(ParticipantAdmin, CanActAs("party1"), CanReadAs("party2"))
)
}
"grantRights should fail on non-existent user" in {
val mgmt = new UserManagementStore()
mgmt.grantRights("user1", Set.empty) shouldBe Left(())
mgmt.grantRights("user1", Set.empty) shouldBe None
}
"revokeRights should revoke rights" in {
val mgmt = new UserManagementStore()
mgmt.createUser(
User("user1", None),
Set(ParticipantAdmin, CanActAs("party1"), CanReadAs("party2")),
) shouldBe Right(())
mgmt.listUserRights("user1") shouldBe Right(
) shouldBe Some(())
mgmt.listUserRights("user1") shouldBe Some(
Set(ParticipantAdmin, CanActAs("party1"), CanReadAs("party2"))
)
mgmt.revokeRights("user1", Set(ParticipantAdmin)) shouldBe Right(Set(ParticipantAdmin))
mgmt.revokeRights("user1", Set(ParticipantAdmin)) shouldBe Right(Set.empty)
mgmt.listUserRights("user1") shouldBe Right(Set(CanActAs("party1"), CanReadAs("party2")))
mgmt.revokeRights("user1", Set(CanActAs("party1"), CanReadAs("party2"))) shouldBe Right(
mgmt.revokeRights("user1", Set(ParticipantAdmin)) shouldBe Some(Set(ParticipantAdmin))
mgmt.revokeRights("user1", Set(ParticipantAdmin)) shouldBe Some(Set.empty)
mgmt.listUserRights("user1") shouldBe Some(Set(CanActAs("party1"), CanReadAs("party2")))
mgmt.revokeRights("user1", Set(CanActAs("party1"), CanReadAs("party2"))) shouldBe Some(
Set(CanActAs("party1"), CanReadAs("party2"))
)
mgmt.listUserRights("user1") shouldBe Right(Set.empty)
mgmt.listUserRights("user1") shouldBe Some(Set.empty)
}
"revokeRights should fail on non-existent user" in {
val mgmt = new UserManagementStore()
mgmt.revokeRights("user1", Set.empty) shouldBe Left(())
mgmt.revokeRights("user1", Set.empty) shouldBe None
}
}
}