Update ktor-voter to version 2.2.0

This commit is contained in:
2020-10-05 15:00:34 +02:00
parent 74923891d0
commit 03401f711e
38 changed files with 403 additions and 384 deletions

View File

@@ -6,7 +6,7 @@ import fr.postgresjson.serializer.deserialize
import fr.postgresjson.serializer.serialize
import io.ktor.locations.KtorExperimentalLocationsAPI
import io.ktor.util.KtorExperimentalAPI
import org.amshove.kluent.`should equal`
import org.amshove.kluent.`should be equal to`
import org.amshove.kluent.shouldBe
import org.intellij.lang.annotations.Language
import org.joda.time.DateTime
@@ -96,6 +96,6 @@ class ArticleTest {
@Test
fun `test Article Deserialize`() {
val article2: Article = articleJson.deserialize()!!
article2.id.toString() `should equal` "83b0b60a-5ab3-44f2-b243-1dc469a7564f"
article2.id.toString() `should be equal to` "83b0b60a-5ab3-44f2-b243-1dc469a7564f"
}
}

View File

@@ -6,6 +6,7 @@ import fr.postgresjson.serializer.deserialize
import fr.postgresjson.serializer.serialize
import io.ktor.locations.KtorExperimentalLocationsAPI
import io.ktor.util.KtorExperimentalAPI
import org.amshove.kluent.`should be equal to`
import org.amshove.kluent.`should equal`
import org.amshove.kluent.shouldBe
import org.intellij.lang.annotations.Language
@@ -101,6 +102,6 @@ class ConstitutionTest {
@Test
fun `test Constitution Deserialize`() {
val constitution2: Constitution = constitutionJson.deserialize()!!
constitution2.id.toString() `should equal` "15814bb6-8d90-4c6a-a456-c3939a8ec75e"
constitution2.id.toString() `should be equal to` "15814bb6-8d90-4c6a-a456-c3939a8ec75e"
}
}

View File

@@ -3,6 +3,7 @@ import fr.postgresjson.serializer.deserialize
import fr.postgresjson.serializer.serialize
import io.ktor.locations.KtorExperimentalLocationsAPI
import io.ktor.util.KtorExperimentalAPI
import org.amshove.kluent.`should be equal to`
import org.amshove.kluent.`should equal`
import org.amshove.kluent.shouldBe
import org.intellij.lang.annotations.Language
@@ -103,6 +104,6 @@ class FollowTest {
@Test
fun `test Follow Article Deserialize`() {
val follow: Follow<ArticleSimple> = followJson.deserialize()!!
follow.id.toString() `should equal` "bae81585-d985-4d7a-9b58-3a13e911688a"
follow.id.toString() `should be equal to` "bae81585-d985-4d7a-9b58-3a13e911688a"
}
}

View File

@@ -6,7 +6,7 @@ import fr.dcproject.views.ArticleViewManager
import io.ktor.locations.KtorExperimentalLocationsAPI
import io.ktor.server.testing.withTestApplication
import io.ktor.util.KtorExperimentalAPI
import org.amshove.kluent.`should equal`
import org.amshove.kluent.`should be equal to`
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.TestInstance
import org.junit.jupiter.api.TestInstance.Lifecycle.PER_CLASS
@@ -61,8 +61,8 @@ class ViewTest {
val afterView = viewManager.getViewsCount(article)
/* Check if view has increment */
afterView.total `should equal` startView.total + 4
afterView.unique `should equal` startView.unique + 3
afterView.total `should be equal to` startView.total + 4
afterView.unique `should be equal to` startView.unique + 3
}
}
}

View File

@@ -3,6 +3,7 @@ import fr.postgresjson.serializer.deserialize
import fr.postgresjson.serializer.serialize
import io.ktor.locations.KtorExperimentalLocationsAPI
import io.ktor.util.KtorExperimentalAPI
import org.amshove.kluent.`should be equal to`
import org.amshove.kluent.`should equal`
import org.amshove.kluent.shouldBe
import org.intellij.lang.annotations.Language
@@ -125,7 +126,7 @@ class VoteTest {
@Test
fun `test Vote Article Deserialize`() {
val vote: Vote<Article> = voteJson.deserialize()!!
vote.id.toString() `should equal` "032acc3d-e8c5-4cb2-9297-bec913ff8d9b"
vote.note.toString() `should equal` "-1"
vote.id.toString() `should be equal to` "032acc3d-e8c5-4cb2-9297-bec913ff8d9b"
vote.note.toString() `should be equal to` "-1"
}
}

View File

@@ -1,9 +1,12 @@
package fr.dcproject.security.voter
import fr.dcproject.citizenOrNull
import fr.dcproject.entity.*
import fr.dcproject.user
import fr.ktorVoter.Vote
import fr.ktorVoter.can
import fr.ktorVoter.canAll
import fr.postgresjson.connexion.Paginated
import io.ktor.application.ApplicationCall
import io.mockk.every
import io.mockk.mockk
@@ -13,11 +16,12 @@ import org.joda.time.DateTime
import org.junit.jupiter.api.Tag
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.TestInstance
import fr.dcproject.repository.Article as ArticleRepo
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
@Tag("voter")
internal class ArticleVoterTest {
val tesla = CitizenBasic(
class ArticleVoterTest {
private val tesla = Citizen(
user = User(
username = "nicolas-tesla",
roles = listOf(UserI.Roles.ROLE_USER)
@@ -26,7 +30,7 @@ internal class ArticleVoterTest {
email = "tesla@best.com",
name = CitizenI.Name("Nicolas", "Tesla")
)
val einstein = CitizenBasic(
private val einstein = Citizen(
user = User(
username = "albert-einstein",
roles = listOf(UserI.Roles.ROLE_USER)
@@ -36,24 +40,30 @@ internal class ArticleVoterTest {
name = CitizenI.Name("Albert", "Einstein")
)
private fun getRepo(article: Article): ArticleRepo {
return mockk {
every { findVerionsByVersionsId(1, 1, any()) } returns Paginated(listOf(article), 0, 1, 1)
}
}
init {
mockkStatic("fr.dcproject.ApplicationContextKt")
}
@Test
fun `creator can be view the article`() = ArticleVoter().run {
fun `creator can be view the article`(): Unit {
val article = getArticle(tesla).apply { draft = true }
mockk<ApplicationCall> {
every { user } returns tesla.user
}.let {
supports(ArticleVoter.Action.VIEW, it, article) `should be` true
vote(ArticleVoter.Action.VIEW, it, article) `should be` Vote.GRANTED
ArticleVoter(getRepo(article)).run {
mockk<ApplicationCall> {
every { user } returns tesla.user
}.let {
this(ArticleVoter.Action.VIEW, it, article) `should be` Vote.GRANTED
}
}
}
@Test
fun `other user can be view the article`() = listOf(ArticleVoter()).run {
fun `other user can be view the article`(): Unit = listOf(ArticleVoter(mockk())).run {
val article = getArticle(tesla)
mockk<ApplicationCall> {
@@ -64,19 +74,19 @@ internal class ArticleVoterTest {
}
@Test
fun `other user can be view the article list`() = listOf(ArticleVoter()).run {
fun `other user can be view the article list`(): Unit = listOf(ArticleVoter(mockk())).run {
val article = getArticle(tesla)
val article2 = getArticle(tesla)
mockk<ApplicationCall> {
every { user } returns einstein.user
}.let {
can(ArticleVoter.Action.VIEW, it, listOf(article, article2)) `should be` true
canAll(ArticleVoter.Action.VIEW, it, listOf(article, article2)) `should be` true
}
}
@Test
fun `the no creator can not be view the article on draft`() = listOf(ArticleVoter()).run {
fun `the no creator can not be view the article on draft`(): Unit = listOf(ArticleVoter(mockk())).run {
val article = getArticle(tesla).apply { draft = true }
mockk<ApplicationCall> {
@@ -87,19 +97,19 @@ internal class ArticleVoterTest {
}
@Test
fun `the no creator can not be view list of articles if one is on draft`() = listOf(ArticleVoter()).run {
fun `the no creator can not be view list of articles if one is on draft`(): Unit = listOf(ArticleVoter(mockk())).run {
val article = getArticle(tesla)
val article2 = getArticle(tesla).apply { draft = true }
mockk<ApplicationCall> {
every { user } returns einstein.user
}.let {
can(ArticleVoter.Action.VIEW, it, listOf(article, article2)) `should be` false
canAll(ArticleVoter.Action.VIEW, it, listOf(article, article2)) `should be` false
}
}
@Test
fun `can not view deleted article`() = listOf(ArticleVoter()).run {
fun `can not view deleted article`(): Unit = listOf(ArticleVoter(mockk())).run {
val article = getArticle(tesla).apply { deletedAt = DateTime.now() }
mockk<ApplicationCall> {
@@ -110,7 +120,7 @@ internal class ArticleVoterTest {
}
@Test
fun `can delete article if owner`() = listOf(ArticleVoter()).run {
fun `can delete article if owner`(): Unit = listOf(ArticleVoter(mockk())).run {
val article = getArticle(tesla)
mockk<ApplicationCall> {
@@ -121,7 +131,7 @@ internal class ArticleVoterTest {
}
@Test
fun `can not delete article if not owner`() = listOf(ArticleVoter()).run {
fun `can not delete article if not owner`(): Unit = listOf(ArticleVoter(mockk())).run {
val article = getArticle(tesla).apply { deletedAt = DateTime.now() }
mockk<ApplicationCall> {
@@ -132,7 +142,7 @@ internal class ArticleVoterTest {
}
@Test
fun `can create article if logged`() = listOf(ArticleVoter()).run {
fun `can create article if logged`(): Unit = listOf(ArticleVoter(mockk())).run {
val article = getArticle(tesla)
mockk<ApplicationCall> {
@@ -143,7 +153,7 @@ internal class ArticleVoterTest {
}
@Test
fun `can not create article if not logged`() = listOf(ArticleVoter()).run {
fun `can not create article if not logged`(): Unit = listOf(ArticleVoter(mockk())).run {
val article = getArticle(tesla)
mockk<ApplicationCall> {
@@ -154,24 +164,28 @@ internal class ArticleVoterTest {
}
@Test
fun `can update article if yours`() = listOf(ArticleVoter()).run {
fun `can update article if yours`(): Unit {
val article = getArticle(tesla)
mockk<ApplicationCall> {
every { user } returns tesla.user
}.let {
can(ArticleVoter.Action.UPDATE, it, article) `should be` true
listOf(ArticleVoter(getRepo(article))).run {
mockk<ApplicationCall> {
every { user } returns tesla.user
every { citizenOrNull } returns tesla
}.let {
can(ArticleVoter.Action.UPDATE, it, article) `should be` true
}
}
}
@Test
fun `can not update article if not yours`() = listOf(ArticleVoter()).run {
fun `can not update article if not yours`(): Unit {
val article = getArticle(tesla)
mockk<ApplicationCall> {
every { user } returns einstein.user
}.let {
can(ArticleVoter.Action.UPDATE, it, article) `should be` false
listOf(ArticleVoter(getRepo(article))).run {
mockk<ApplicationCall> {
every { user } returns einstein.user
every { citizenOrNull } returns einstein
}.let {
can(ArticleVoter.Action.UPDATE, it, article) `should be` false
}
}
}

View File

@@ -6,7 +6,9 @@ import fr.dcproject.entity.User
import fr.dcproject.entity.UserI
import fr.dcproject.user
import fr.ktorVoter.ActionI
import fr.ktorVoter.Vote
import fr.ktorVoter.can
import fr.ktorVoter.canAll
import io.ktor.application.ApplicationCall
import io.ktor.locations.KtorExperimentalLocationsAPI
import io.mockk.every
@@ -21,7 +23,7 @@ import org.junit.jupiter.api.TestInstance
@KtorExperimentalLocationsAPI
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
@Tag("voter")
internal class CitizenVoterTest {
class CitizenVoterTest {
private val tesla = CitizenBasic(
user = User(
username = "nicolas-tesla",
@@ -56,18 +58,18 @@ internal class CitizenVoterTest {
}
@Test
fun `support citizen`() = CitizenVoter().run {
fun `support citizen`(): Unit = CitizenVoter().run {
val p = object : ActionI {}
mockk<ApplicationCall> {
every { user } returns tesla.user
}.let {
supports(CitizenVoter.Action.VIEW, it, einstein) `should be` true
supports(p, it, einstein) `should be` false
this(CitizenVoter.Action.VIEW, it, einstein) `should be` Vote.GRANTED
this(p, it, einstein) `should be` Vote.ABSTAIN
}
}
@Test
fun `can be view the citizen`() = listOf(CitizenVoter()).run {
fun `can be view the citizen`(): Unit = listOf(CitizenVoter()).run {
mockk<ApplicationCall> {
every { user } returns tesla.user
}.let {
@@ -76,16 +78,16 @@ internal class CitizenVoterTest {
}
@Test
fun `can be view the citizen list`() = listOf(CitizenVoter()).run {
fun `can be view the citizen list`(): Unit = listOf(CitizenVoter()).run {
mockk<ApplicationCall> {
every { user } returns einstein.user
}.let {
can(CitizenVoter.Action.VIEW, it, listOf(einstein, tesla)) `should be` true
canAll(CitizenVoter.Action.VIEW, it, listOf(einstein, tesla)) `should be` true
}
}
@Test
fun `can not view deleted citizen`() = listOf(CitizenVoter()).run {
fun `can not view deleted citizen`(): Unit = listOf(CitizenVoter()).run {
mockk<ApplicationCall> {
every { user } returns tesla.user
}.let {
@@ -94,7 +96,7 @@ internal class CitizenVoterTest {
}
@Test
fun `can be update itself`() = listOf(CitizenVoter()).run {
fun `can be update itself`(): Unit = listOf(CitizenVoter()).run {
mockk<ApplicationCall> {
every { user } returns einstein.user
}.let {
@@ -103,7 +105,7 @@ internal class CitizenVoterTest {
}
@Test
fun `can not be update other citizen`() = listOf(CitizenVoter()).run {
fun `can not be update other citizen`(): Unit = listOf(CitizenVoter()).run {
mockk<ApplicationCall> {
every { user } returns einstein.user
}.let {
@@ -112,7 +114,7 @@ internal class CitizenVoterTest {
}
@Test
fun `can be change password of itself`() = listOf(CitizenVoter()).run {
fun `can be change password of itself`(): Unit = listOf(CitizenVoter()).run {
mockk<ApplicationCall> {
every { user } returns einstein.user
}.let {
@@ -121,7 +123,7 @@ internal class CitizenVoterTest {
}
@Test
fun `can not be change password of other citizen`() = listOf(CitizenVoter()).run {
fun `can not be change password of other citizen`(): Unit = listOf(CitizenVoter()).run {
mockk<ApplicationCall> {
every { user } returns einstein.user
}.let {

View File

@@ -3,7 +3,10 @@ package fr.dcproject.security.voter
import fr.dcproject.entity.*
import fr.dcproject.user
import fr.ktorVoter.ActionI
import fr.ktorVoter.Vote
import fr.ktorVoter.can
import fr.ktorVoter.canAll
import fr.postgresjson.connexion.Paginated
import io.ktor.application.ApplicationCall
import io.ktor.locations.KtorExperimentalLocationsAPI
import io.mockk.every
@@ -14,6 +17,7 @@ import org.joda.time.DateTime
import org.junit.jupiter.api.Tag
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.TestInstance
import fr.dcproject.repository.Article as ArticleRepo
@KtorExperimentalLocationsAPI
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
@@ -51,6 +55,12 @@ internal class CommentVoterTest {
target = article1
)
private val comment2 = Comment(
content = "Hello2",
createdBy = einstein,
target = article1
)
private val commentTargetDeleted = Comment(
content = "Hello",
createdBy = tesla,
@@ -69,42 +79,48 @@ internal class CommentVoterTest {
target = ArticleRef()
)
private val repoArticle1 = mockk<ArticleRepo> {
every { findVerionsByVersionsId(1, 1, any()) } returns Paginated(listOf(article1), 0, 1, 1)
}
init {
mockkStatic("fr.dcproject.ApplicationContextKt")
}
@Test
fun `support comment`() = CommentVoter().run {
fun `support comment`(): Unit = CommentVoter().run {
val p = object : ActionI {}
mockk<ApplicationCall> {
every { user } returns tesla.user
}.let {
supports(CommentVoter.Action.VIEW, it, comment1) `should be` true
supports(CommentVoter.Action.VIEW, it, article1) `should be` false
supports(p, it, comment1) `should be` false
this(CommentVoter.Action.VIEW, it, comment1) `should be` Vote.GRANTED
this(CommentVoter.Action.VIEW, it, article1) `should be` Vote.ABSTAIN
this(p, it, comment1) `should be` Vote.ABSTAIN
}
}
@Test
fun `can be view the comment`() = listOf(CommentVoter(), ArticleVoter()).run {
mockk<ApplicationCall> {
every { user } returns tesla.user
}.let {
can(CommentVoter.Action.VIEW, it, comment1) `should be` true
fun `can be view the comment`(): Unit {
listOf(CommentVoter(), ArticleVoter(repoArticle1)).run {
mockk<ApplicationCall> {
every { user } returns tesla.user
}.let {
can(CommentVoter.Action.VIEW, it, comment1) `should be` true
}
}
}
@Test
fun `can be view the comment list`() = listOf(CommentVoter()).run {
fun `can be view the comment list`(): Unit = listOf(CommentVoter()).run {
mockk<ApplicationCall> {
every { user } returns einstein.user
}.let {
can(CommentVoter.Action.VIEW, it, listOf(comment1)) `should be` true
canAll(CommentVoter.Action.VIEW, it, listOf(comment1)) `should be` true
}
}
@Test
fun `can be update your comment`() = listOf(CommentVoter()).run {
fun `can be update your comment`(): Unit = listOf(CommentVoter()).run {
mockk<ApplicationCall> {
every { user } returns tesla.user
}.let {
@@ -113,7 +129,7 @@ internal class CommentVoterTest {
}
@Test
fun `can not be update other comment`() = listOf(CommentVoter()).run {
fun `can not be update other comment`(): Unit = listOf(CommentVoter()).run {
mockk<ApplicationCall> {
every { user } returns einstein.user
}.let {
@@ -122,7 +138,7 @@ internal class CommentVoterTest {
}
@Test
fun `can not be delete your comment`() = listOf(CommentVoter()).run {
fun `can not be delete your comment`(): Unit = listOf(CommentVoter()).run {
mockk<ApplicationCall> {
every { user } returns tesla.user
}.let {
@@ -131,7 +147,7 @@ internal class CommentVoterTest {
}
@Test
fun `can be create a comment`() = listOf(CommentVoter(), ArticleVoter()).run {
fun `can be create a comment`(): Unit = listOf(CommentVoter(), ArticleVoter(repoArticle1)).run {
mockk<ApplicationCall> {
every { user } returns tesla.user
}.let {
@@ -140,7 +156,7 @@ internal class CommentVoterTest {
}
@Test
fun `can not be create a comment if target is deleted`() = listOf(CommentVoter(), ArticleVoter()).run {
fun `can not be create a comment if target is deleted`(): Unit = listOf(CommentVoter(), ArticleVoter(repoArticle1)).run {
mockk<ApplicationCall> {
every { user } returns tesla.user
}.let {
@@ -149,7 +165,7 @@ internal class CommentVoterTest {
}
@Test
fun `can not be create a comment if target has no user`() = listOf(CommentVoter(), ArticleVoter()).run {
fun `can not be create a comment if target has no user`(): Unit = listOf(CommentVoter(), ArticleVoter(repoArticle1)).run {
mockk<ApplicationCall> {
every { user } returns tesla.user
}.let {
@@ -158,7 +174,7 @@ internal class CommentVoterTest {
}
@Test
fun `can not be create a comment with other creator`() = listOf(CommentVoter()).run {
fun `can not be create a comment with other creator`(): Unit = listOf(CommentVoter()).run {
mockk<ApplicationCall> {
every { user } returns einstein.user
}.let {
@@ -167,7 +183,7 @@ internal class CommentVoterTest {
}
@Test
fun `can not be create a comment if is null`() = listOf(CommentVoter()).run {
fun `can not be create a comment if is null`(): Unit = listOf(CommentVoter()).run {
mockk<ApplicationCall> {
every { user } returns einstein.user
}.let {
@@ -176,7 +192,7 @@ internal class CommentVoterTest {
}
@Test
fun `can not be create a comment if not connected`() = listOf(CommentVoter()).run {
fun `can not be create a comment if not connected`(): Unit = listOf(CommentVoter()).run {
mockk<ApplicationCall> {
every { user } returns null
}.let {

View File

@@ -3,7 +3,9 @@ package fr.dcproject.security.voter
import fr.dcproject.entity.*
import fr.dcproject.user
import fr.ktorVoter.ActionI
import fr.ktorVoter.Vote
import fr.ktorVoter.can
import fr.ktorVoter.canAll
import io.ktor.application.ApplicationCall
import io.ktor.locations.KtorExperimentalLocationsAPI
import io.mockk.every
@@ -63,19 +65,19 @@ internal class FollowVoterTest {
}
@Test
fun `support follow`() = FollowVoter().run {
fun `support follow`(): Unit = FollowVoter().run {
val p = object : ActionI {}
mockk<ApplicationCall> {
every { user } returns tesla.user
}.let {
supports(FollowVoter.Action.VIEW, it, follow1) `should be` true
supports(FollowVoter.Action.VIEW, it, article1) `should be` false
supports(p, it, follow1) `should be` false
this(FollowVoter.Action.VIEW, it, follow1) `should be` Vote.GRANTED
this(FollowVoter.Action.VIEW, it, article1) `should be` Vote.ABSTAIN
this(p, it, follow1) `should be` Vote.ABSTAIN
}
}
@Test
fun `can be view the follow`() = listOf(FollowVoter()).run {
fun `can be view the follow`(): Unit = listOf(FollowVoter()).run {
mockk<ApplicationCall> {
every { user } returns tesla.user
}.let {
@@ -84,16 +86,16 @@ internal class FollowVoterTest {
}
@Test
fun `can be view the follow list`() = listOf(FollowVoter()).run {
fun `can be view the follow list`(): Unit = listOf(FollowVoter()).run {
mockk<ApplicationCall> {
every { user } returns tesla.user
}.let {
can(FollowVoter.Action.VIEW, it, listOf(follow1)) `should be` true
canAll(FollowVoter.Action.VIEW, it, listOf(follow1)) `should be` true
}
}
@Test
fun `can be view your anonymous follow`() = listOf(FollowVoter()).run {
fun `can be view your anonymous follow`(): Unit = listOf(FollowVoter()).run {
mockk<ApplicationCall> {
every { user } returns einstein.user
}.let {
@@ -102,7 +104,7 @@ internal class FollowVoterTest {
}
@Test
fun `can not be view the anonymous follow of other`() = listOf(FollowVoter()).run {
fun `can not be view the anonymous follow of other`(): Unit = listOf(FollowVoter()).run {
mockk<ApplicationCall> {
every { user } returns tesla.user
}.let {
@@ -111,7 +113,7 @@ internal class FollowVoterTest {
}
@Test
fun `can be follow article`() = listOf(FollowVoter()).run {
fun `can be follow article`(): Unit = listOf(FollowVoter()).run {
mockk<ApplicationCall> {
every { user } returns tesla.user
}.let {
@@ -120,7 +122,7 @@ internal class FollowVoterTest {
}
@Test
fun `can not be follow article if not connected`() = listOf(FollowVoter()).run {
fun `can not be follow article if not connected`(): Unit = listOf(FollowVoter()).run {
mockk<ApplicationCall> {
every { user } returns null
}.let {
@@ -129,7 +131,7 @@ internal class FollowVoterTest {
}
@Test
fun `can be unfollow article`() = listOf(FollowVoter()).run {
fun `can be unfollow article`(): Unit = listOf(FollowVoter()).run {
mockk<ApplicationCall> {
every { user } returns tesla.user
}.let {
@@ -138,7 +140,7 @@ internal class FollowVoterTest {
}
@Test
fun `can not be unfollow article if not connected`() = listOf(FollowVoter()).run {
fun `can not be unfollow article if not connected`(): Unit = listOf(FollowVoter()).run {
mockk<ApplicationCall> {
every { user } returns null
}.let {

View File

@@ -3,7 +3,9 @@ package fr.dcproject.security.voter
import fr.dcproject.entity.*
import fr.dcproject.user
import fr.ktorVoter.ActionI
import fr.ktorVoter.Vote
import fr.ktorVoter.can
import fr.ktorVoter.canAll
import io.ktor.application.ApplicationCall
import io.ktor.locations.KtorExperimentalLocationsAPI
import io.mockk.every
@@ -47,19 +49,19 @@ internal class OpinionChoiceVoterTest {
}
@Test
fun `support opinion choice`() = OpinionChoiceVoter().run {
fun `support opinion choice`(): Unit = OpinionChoiceVoter().run {
val p = object : ActionI {}
mockk<ApplicationCall> {
every { user } returns tesla.user
}.let {
supports(OpinionChoiceVoter.Action.VIEW, it, choice1) `should be` true
supports(OpinionChoiceVoter.Action.VIEW, it, article1) `should be` false
supports(p, it, choice1) `should be` false
this(OpinionChoiceVoter.Action.VIEW, it, choice1) `should be` Vote.GRANTED
this(OpinionChoiceVoter.Action.VIEW, it, article1) `should be` Vote.ABSTAIN
this(p, it, choice1) `should be` Vote.ABSTAIN
}
}
@Test
fun `can be view the opinion choice`() = listOf(OpinionChoiceVoter()).run {
fun `can be view the opinion choice`(): Unit = listOf(OpinionChoiceVoter()).run {
mockk<ApplicationCall> {
every { user } returns tesla.user
}.let {
@@ -68,11 +70,11 @@ internal class OpinionChoiceVoterTest {
}
@Test
fun `can be view the opinion choice list`() = listOf(OpinionChoiceVoter()).run {
fun `can be view the opinion choice list`(): Unit = listOf(OpinionChoiceVoter()).run {
mockk<ApplicationCall> {
every { user } returns tesla.user
}.let {
can(OpinionChoiceVoter.Action.VIEW, it, listOf(choice1)) `should be` true
canAll(OpinionChoiceVoter.Action.VIEW, it, listOf(choice1)) `should be` true
}
}
}

View File

@@ -3,7 +3,9 @@ package fr.dcproject.security.voter
import fr.dcproject.entity.*
import fr.dcproject.user
import fr.ktorVoter.ActionI
import fr.ktorVoter.Vote
import fr.ktorVoter.can
import fr.ktorVoter.canAll
import io.ktor.application.ApplicationCall
import io.ktor.locations.KtorExperimentalLocationsAPI
import io.mockk.every
@@ -62,20 +64,20 @@ internal class OpinionVoterTest {
}
@Test
fun `support opinion`() = OpinionVoter().run {
fun `support opinion`(): Unit = OpinionVoter().run {
val p = object : ActionI {}
mockk<ApplicationCall> {
every { user } returns tesla.user
}.let {
supports(OpinionVoter.Action.VIEW, it, opinion1) `should be` true
supports(OpinionVoter.Action.VIEW, it, article1) `should be` true
supports(OpinionVoter.Action.VIEW, it, einstein) `should be` false
supports(p, it, opinion1) `should be` false
this(OpinionVoter.Action.VIEW, it, opinion1) `should be` Vote.GRANTED
this(OpinionVoter.Action.VIEW, it, article1) `should be` Vote.GRANTED
this(OpinionVoter.Action.VIEW, it, einstein) `should be` Vote.ABSTAIN
this(p, it, opinion1) `should be` Vote.ABSTAIN
}
}
@Test
fun `can be view the opinion`() = listOf(OpinionVoter()).run {
fun `can be view the opinion`(): Unit = listOf(OpinionVoter()).run {
mockk<ApplicationCall> {
every { user } returns tesla.user
}.let {
@@ -84,7 +86,7 @@ internal class OpinionVoterTest {
}
@Test
fun `can be not view the opinion if is null`() = listOf(OpinionVoter()).run {
fun `can be not view the opinion if is null`(): Unit = listOf(OpinionVoter()).run {
mockk<ApplicationCall> {
every { user } returns tesla.user
}.let {
@@ -93,16 +95,16 @@ internal class OpinionVoterTest {
}
@Test
fun `can be view the opinion list`() = listOf(OpinionVoter()).run {
fun `can be view the opinion list`(): Unit = listOf(OpinionVoter()).run {
mockk<ApplicationCall> {
every { user } returns tesla.user
}.let {
can(OpinionVoter.Action.VIEW, it, listOf(opinion1)) `should be` true
canAll(OpinionVoter.Action.VIEW, it, listOf(opinion1)) `should be` true
}
}
@Test
fun `can be opinion an article`() = listOf(OpinionVoter()).run {
fun `can be opinion an article`(): Unit = listOf(OpinionVoter()).run {
mockk<ApplicationCall> {
every { user } returns tesla.user
}.let {
@@ -120,7 +122,7 @@ internal class OpinionVoterTest {
}
@Test
fun `can be remove opinion`() = listOf(OpinionVoter()).run {
fun `can be remove opinion`(): Unit = listOf(OpinionVoter()).run {
mockk<ApplicationCall> {
every { user } returns tesla.user
}.let {
@@ -129,7 +131,7 @@ internal class OpinionVoterTest {
}
@Test
fun `can not be remove opinion if not connected`() = listOf(OpinionVoter()).run {
fun `can not be remove opinion if not connected`(): Unit = listOf(OpinionVoter()).run {
mockk<ApplicationCall> {
every { user } returns null
}.let {
@@ -138,7 +140,7 @@ internal class OpinionVoterTest {
}
@Test
fun `can not be remove opinion of other user`() = listOf(OpinionVoter()).run {
fun `can not be remove opinion of other user`(): Unit = listOf(OpinionVoter()).run {
mockk<ApplicationCall> {
every { user } returns einstein.user
}.let {

View File

@@ -3,7 +3,10 @@ package fr.dcproject.security.voter
import fr.dcproject.entity.*
import fr.dcproject.user
import fr.ktorVoter.ActionI
import fr.ktorVoter.Vote
import fr.ktorVoter.can
import fr.ktorVoter.canAll
import fr.postgresjson.connexion.Paginated
import io.ktor.application.ApplicationCall
import io.ktor.locations.KtorExperimentalLocationsAPI
import io.mockk.every
@@ -77,19 +80,19 @@ internal class VoteVoterTest {
}
@Test
fun `support vote`() = VoteVoter().run {
fun `support vote`(): Unit = VoteVoter().run {
val p = object : ActionI {}
mockk<ApplicationCall> {
every { user } returns tesla.user
}.let {
supports(VoteVoter.Action.VIEW, it, vote1) `should be` true
supports(VoteVoter.Action.VIEW, it, article1) `should be` false
supports(p, it, vote1) `should be` false
this(VoteVoter.Action.VIEW, it, vote1) `should be` Vote.GRANTED
this(VoteVoter.Action.VIEW, it, article1) `should be` Vote.ABSTAIN
this(p, it, vote1) `should be` Vote.ABSTAIN
}
}
@Test
fun `can be view your the vote`() = listOf(VoteVoter()).run {
fun `can be view your the vote`(): Unit = listOf(VoteVoter()).run {
mockk<ApplicationCall> {
every { user } returns tesla.user
}.let {
@@ -98,7 +101,7 @@ internal class VoteVoterTest {
}
@Test
fun `can not be view vote of other`() = listOf(VoteVoter()).run {
fun `can not be view vote of other`(): Unit = listOf(VoteVoter()).run {
mockk<ApplicationCall> {
every { user } returns einstein.user
}.let {
@@ -107,7 +110,7 @@ internal class VoteVoterTest {
}
@Test
fun `can be not view the vote if is null`() = listOf(VoteVoter()).run {
fun `can be not view the vote if is null`(): Unit = listOf(VoteVoter()).run {
mockk<ApplicationCall> {
every { user } returns tesla.user
}.let {
@@ -116,25 +119,27 @@ internal class VoteVoterTest {
}
@Test
fun `can be view your votes list`() = listOf(VoteVoter()).run {
fun `can be view your votes list`(): Unit = listOf(VoteVoter()).run {
mockk<ApplicationCall> {
every { user } returns tesla.user
}.let {
can(VoteVoter.Action.VIEW, it, listOf(vote1)) `should be` true
canAll(VoteVoter.Action.VIEW, it, listOf(vote1)) `should be` true
}
}
@Test
fun `can be vote an article`() = listOf(VoteVoter(), ArticleVoter()).run {
mockk<ApplicationCall> {
every { user } returns tesla.user
}.let {
can(VoteVoter.Action.CREATE, it, vote1) `should be` true
fun `can be vote an article`(): Unit {
listOf(VoteVoter(), ArticleVoter(mockk())).run {
mockk<ApplicationCall> {
every { user } returns tesla.user
}.let {
can(VoteVoter.Action.CREATE, it, vote1) `should be` true
}
}
}
@Test
fun `can not be vote if not connected`() = listOf(VoteVoter()).run {
fun `can not be vote if not connected`(): Unit = listOf(VoteVoter()).run {
mockk<ApplicationCall> {
every { user } returns null
}.let {
@@ -143,7 +148,7 @@ internal class VoteVoterTest {
}
@Test
fun `can not be vote an article if article is deleted`() = listOf(VoteVoter(), ArticleVoter()).run {
fun `can not be vote an article if article is deleted`(): Unit = listOf(VoteVoter(), ArticleVoter(mockk())).run {
mockk<ApplicationCall> {
every { user } returns tesla.user
}.let {
@@ -152,7 +157,7 @@ internal class VoteVoterTest {
}
@Test
fun `can not be vote an article if article have no user`() = listOf(VoteVoter(), ArticleVoter()).run {
fun `can not be vote an article if article have no user`(): Unit = listOf(VoteVoter(), ArticleVoter(mockk())).run {
mockk<ApplicationCall> {
every { user } returns tesla.user
}.let {
@@ -161,7 +166,7 @@ internal class VoteVoterTest {
}
@Test
fun `can not be comment an article if article is deleted`() = listOf(VoteVoter(), ArticleVoter()).run {
fun `can not be comment an article if article is deleted`(): Unit = listOf(VoteVoter(), ArticleVoter(mockk())).run {
mockk<ApplicationCall> {
every { user } returns tesla.user
}.let {

View File

@@ -3,6 +3,7 @@ package fr.dcproject.security.voter
import fr.dcproject.entity.*
import fr.dcproject.user
import fr.ktorVoter.ActionI
import fr.ktorVoter.Vote
import fr.ktorVoter.VoterException
import fr.ktorVoter.can
import io.ktor.application.ApplicationCall
@@ -74,19 +75,19 @@ internal class WorkgroupVoterTest {
}
@Test
fun `support workgroup`() = WorkgroupVoter().run {
fun `support workgroup`(): Unit = WorkgroupVoter().run {
val p = object : ActionI {}
mockk<ApplicationCall> {
every { user } returns tesla.user
}.let {
supports(WorkgroupVoter.Action.VIEW, it, workgroupPublic) `should be` true
supports(WorkgroupVoter.Action.VIEW, it, article1) `should be` false
supports(p, it, workgroupPublic) `should be` false
this(WorkgroupVoter.Action.VIEW, it, workgroupPublic) `should be` Vote.GRANTED
this(WorkgroupVoter.Action.VIEW, it, article1) `should be` Vote.ABSTAIN
this(p, it, workgroupPublic) `should be` Vote.ABSTAIN
}
}
@Test
fun `can be view your workgroup`() = listOf(WorkgroupVoter()).run {
fun `can be view your workgroup`(): Unit = listOf(WorkgroupVoter()).run {
mockk<ApplicationCall> {
every { user } returns tesla.user
}.let {
@@ -95,7 +96,7 @@ internal class WorkgroupVoterTest {
}
@Test
fun `can be view your workgroup if is not public`() = listOf(WorkgroupVoter()).run {
fun `can be view your workgroup if is not public`(): Unit = listOf(WorkgroupVoter()).run {
mockk<ApplicationCall> {
every { user } returns tesla.user
}.let {
@@ -104,7 +105,7 @@ internal class WorkgroupVoterTest {
}
@Test
fun `can be view workgroup of other if is public`() = listOf(WorkgroupVoter()).run {
fun `can be view workgroup of other if is public`(): Unit = listOf(WorkgroupVoter()).run {
mockk<ApplicationCall> {
every { user } returns einstein.user
}.let {
@@ -113,7 +114,7 @@ internal class WorkgroupVoterTest {
}
@Test
fun `can not be view workgroup of other if is not public`() = listOf(WorkgroupVoter()).run {
fun `can not be view workgroup of other if is not public`(): Unit = listOf(WorkgroupVoter()).run {
mockk<ApplicationCall> {
every { user } returns einstein.user
}.let {
@@ -122,7 +123,7 @@ internal class WorkgroupVoterTest {
}
@Test
fun `can be not view the workgroup if is null`() = listOf(WorkgroupVoter()).run {
fun `can be not view the workgroup if is null`(): Unit = listOf(WorkgroupVoter()).run {
mockk<ApplicationCall> {
every { user } returns tesla.user
}.let {
@@ -131,16 +132,18 @@ internal class WorkgroupVoterTest {
}
@Test
fun `can be view your workgroup list`() = listOf(WorkgroupVoter()).run {
fun `can be view your workgroup list`(): Unit = listOf(WorkgroupVoter()).run {
mockk<ApplicationCall> {
every { user } returns tesla.user
}.let {
can(WorkgroupVoter.Action.VIEW, it, listOf(workgroupPublic)) `should be` true
listOf(workgroupPublic).map { workgroup ->
can(WorkgroupVoter.Action.VIEW, it, workgroup)
}.all { it } `should be` true
}
}
@Test
fun `can be create workgroup`() = listOf(WorkgroupVoter()).run {
fun `can be create workgroup`(): Unit = listOf(WorkgroupVoter()).run {
mockk<ApplicationCall> {
every { user } returns tesla.user
}.let {
@@ -149,7 +152,7 @@ internal class WorkgroupVoterTest {
}
@Test
fun `can not be create workgroup if not connected`() = listOf(WorkgroupVoter()).run {
fun `can not be create workgroup if not connected`(): Unit = listOf(WorkgroupVoter()).run {
mockk<ApplicationCall> {
every { user } returns null
}.let {
@@ -158,7 +161,7 @@ internal class WorkgroupVoterTest {
}
@Test
fun `can be delete workgroup if owner`() = listOf(WorkgroupVoter()).run {
fun `can be delete workgroup if owner`(): Unit = listOf(WorkgroupVoter()).run {
mockk<ApplicationCall> {
every { user } returns tesla.user
}.let {
@@ -167,7 +170,7 @@ internal class WorkgroupVoterTest {
}
@Test
fun `can not be delete workgroup if not owner`() = listOf(WorkgroupVoter()).run {
fun `can not be delete workgroup if not owner`(): Unit = listOf(WorkgroupVoter()).run {
mockk<ApplicationCall> {
every { user } returns einstein.user
}.let {
@@ -176,7 +179,7 @@ internal class WorkgroupVoterTest {
}
@Test
fun `can be update workgroup if owner`() = listOf(WorkgroupVoter()).run {
fun `can be update workgroup if owner`(): Unit = listOf(WorkgroupVoter()).run {
mockk<ApplicationCall> {
every { user } returns tesla.user
}.let {
@@ -185,7 +188,7 @@ internal class WorkgroupVoterTest {
}
@Test
fun `can not be update workgroup if not owner`() = listOf(WorkgroupVoter()).run {
fun `can not be update workgroup if not owner`(): Unit = listOf(WorkgroupVoter()).run {
mockk<ApplicationCall> {
every { user } returns einstein.user
}.let {