Test openapi schema response of FindArticlesVersion,GetOneArticle,UpsertArticle
change snack_case to camelCase
This commit is contained in:
@@ -3,10 +3,13 @@ package unit.security
|
||||
import fr.dcproject.common.security.AccessDecision.DENIED
|
||||
import fr.dcproject.common.security.AccessDecision.GRANTED
|
||||
import fr.dcproject.component.article.ArticleAccessControl
|
||||
import fr.dcproject.component.article.database.ArticleForListing
|
||||
import fr.dcproject.component.article.database.ArticleForView
|
||||
import fr.dcproject.component.auth.database.User
|
||||
import fr.dcproject.component.auth.database.UserCreator
|
||||
import fr.dcproject.component.auth.database.UserI
|
||||
import fr.dcproject.component.citizen.database.CitizenCart
|
||||
import fr.dcproject.component.citizen.database.CitizenCreator
|
||||
import fr.dcproject.component.citizen.database.CitizenI
|
||||
import fr.postgresjson.connexion.Paginated
|
||||
import io.mockk.every
|
||||
@@ -26,13 +29,13 @@ import fr.dcproject.component.article.database.ArticleRepository as ArticleRepo
|
||||
@Execution(CONCURRENT)
|
||||
@Tags(Tag("security"), Tag("unit"))
|
||||
internal class `Article Access Control` {
|
||||
private val tesla = CitizenCart(
|
||||
private val tesla = CitizenCreator(
|
||||
id = UUID.fromString("e6efc288-4283-4729-a268-6debb18de1a0"),
|
||||
user = User(
|
||||
user = UserCreator(
|
||||
username = "nicolas-tesla",
|
||||
roles = listOf(UserI.Roles.ROLE_USER)
|
||||
),
|
||||
name = CitizenI.Name("Nicolas", "Tesla")
|
||||
name = CitizenI.Name("Nicolas", "Tesla"),
|
||||
email = "nikola-tesla@volt.com"
|
||||
)
|
||||
private val einstein = CitizenCart(
|
||||
user = User(
|
||||
@@ -42,16 +45,16 @@ internal class `Article Access Control` {
|
||||
name = CitizenI.Name("Albert", "Einstein")
|
||||
)
|
||||
|
||||
private fun getRepo(article: ArticleForView): ArticleRepo {
|
||||
private fun getRepo(article: ArticleForListing): ArticleRepo {
|
||||
return mockk {
|
||||
every { findVersionsByVersionId(1, 1, any()) } returns Paginated(listOf(article), 0, 1, 1)
|
||||
every { find(1, 1, any()) } returns Paginated(listOf(article), 0, 1, 1)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `creator can be view the article`() {
|
||||
val article = getArticle(tesla).copy(draft = true)
|
||||
ArticleAccessControl(getRepo(article))
|
||||
ArticleAccessControl(getRepo(getArticleForListing(tesla)))
|
||||
.canView(article, tesla)
|
||||
.decision `should be` GRANTED
|
||||
}
|
||||
@@ -59,7 +62,7 @@ internal class `Article Access Control` {
|
||||
@Test
|
||||
fun `other user can be view the article`() {
|
||||
val article = getArticle(tesla)
|
||||
ArticleAccessControl(getRepo(article))
|
||||
ArticleAccessControl(getRepo(getArticleForListing(tesla)))
|
||||
.canView(article, einstein)
|
||||
.decision `should be` GRANTED
|
||||
}
|
||||
@@ -69,7 +72,7 @@ internal class `Article Access Control` {
|
||||
val article = getArticle(tesla)
|
||||
val article2 = getArticle(tesla)
|
||||
|
||||
ArticleAccessControl(getRepo(article))
|
||||
ArticleAccessControl(getRepo(getArticleForListing(tesla)))
|
||||
.canView(listOf(article, article2), einstein)
|
||||
.decision `should be` GRANTED
|
||||
}
|
||||
@@ -77,7 +80,7 @@ internal class `Article Access Control` {
|
||||
@Test
|
||||
fun `the no creator can not be view the article on draft`() {
|
||||
val article = getArticle(tesla).copy(draft = true)
|
||||
ArticleAccessControl(getRepo(article))
|
||||
ArticleAccessControl(getRepo(getArticleForListing(tesla)))
|
||||
.canView(article, einstein)
|
||||
.decision `should be` DENIED
|
||||
}
|
||||
@@ -87,7 +90,7 @@ internal class `Article Access Control` {
|
||||
val article = getArticle(tesla)
|
||||
val article2 = getArticle(tesla).copy(draft = true)
|
||||
|
||||
ArticleAccessControl(getRepo(article))
|
||||
ArticleAccessControl(getRepo(getArticleForListing(tesla)))
|
||||
.canView(listOf(article, article2), einstein)
|
||||
.decision `should be` DENIED
|
||||
}
|
||||
@@ -95,7 +98,7 @@ internal class `Article Access Control` {
|
||||
@Test
|
||||
fun `can not view deleted article`() {
|
||||
val article = getArticle(tesla).copy(deletedAt = DateTime.now())
|
||||
ArticleAccessControl(getRepo(article))
|
||||
ArticleAccessControl(getRepo(getArticleForListing(tesla)))
|
||||
.canView(article, tesla)
|
||||
.decision `should be` DENIED
|
||||
}
|
||||
@@ -103,7 +106,7 @@ internal class `Article Access Control` {
|
||||
@Test
|
||||
fun `can delete article if owner`() {
|
||||
val article = getArticle(tesla)
|
||||
ArticleAccessControl(getRepo(article))
|
||||
ArticleAccessControl(getRepo(getArticleForListing(tesla)))
|
||||
.canDelete(article, tesla)
|
||||
.decision `should be` GRANTED
|
||||
}
|
||||
@@ -111,7 +114,7 @@ internal class `Article Access Control` {
|
||||
@Test
|
||||
fun `can not delete article if not owner`() {
|
||||
val article = getArticle(tesla).copy(deletedAt = DateTime.now())
|
||||
ArticleAccessControl(getRepo(article))
|
||||
ArticleAccessControl(getRepo(getArticleForListing(tesla)))
|
||||
.canDelete(article, einstein)
|
||||
.code `should be` "article.delete.notYours"
|
||||
}
|
||||
@@ -119,7 +122,7 @@ internal class `Article Access Control` {
|
||||
@Test
|
||||
fun `can create article if logged`() {
|
||||
val article = getArticle(tesla)
|
||||
ArticleAccessControl(getRepo(article))
|
||||
ArticleAccessControl(getRepo(getArticleForListing(tesla)))
|
||||
.canUpsert(article, tesla)
|
||||
.decision `should be` GRANTED
|
||||
}
|
||||
@@ -127,7 +130,7 @@ internal class `Article Access Control` {
|
||||
@Test
|
||||
fun `can not create article if not logged`() {
|
||||
val article = getArticle(tesla)
|
||||
ArticleAccessControl(getRepo(article))
|
||||
ArticleAccessControl(getRepo(getArticleForListing(tesla)))
|
||||
.canUpsert(article, null)
|
||||
.code `should be` "article.create.notConnected"
|
||||
}
|
||||
@@ -135,7 +138,7 @@ internal class `Article Access Control` {
|
||||
@Test
|
||||
fun `can update article if yours`() {
|
||||
val article = getArticle(tesla)
|
||||
ArticleAccessControl(getRepo(article))
|
||||
ArticleAccessControl(getRepo(getArticleForListing(tesla)))
|
||||
.canUpsert(article, tesla)
|
||||
.decision `should be` GRANTED
|
||||
}
|
||||
@@ -143,12 +146,12 @@ internal class `Article Access Control` {
|
||||
@Test
|
||||
fun `can not update article if not yours`() {
|
||||
val article = getArticle(tesla)
|
||||
ArticleAccessControl(getRepo(article))
|
||||
ArticleAccessControl(getRepo(getArticleForListing(tesla)))
|
||||
.canUpsert(article, einstein)
|
||||
.code `should be` "article.update.notYours"
|
||||
}
|
||||
|
||||
private fun getArticle(createdBy: CitizenCart = tesla) = ArticleForView(
|
||||
private fun getArticle(createdBy: CitizenCreator = tesla) = ArticleForView(
|
||||
id = UUID.randomUUID(),
|
||||
title = "Hello world",
|
||||
content = "Super",
|
||||
@@ -158,4 +161,10 @@ internal class `Article Access Control` {
|
||||
versionId = UUID.randomUUID(),
|
||||
versionNumber = 1
|
||||
)
|
||||
|
||||
private fun getArticleForListing(createdBy: CitizenCreator = tesla) = ArticleForListing(
|
||||
id = UUID.randomUUID(),
|
||||
title = "Hello world",
|
||||
createdBy = createdBy,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -5,9 +5,10 @@ import fr.dcproject.common.security.AccessDecision.GRANTED
|
||||
import fr.dcproject.component.article.database.ArticleForView
|
||||
import fr.dcproject.component.article.database.ArticleRef
|
||||
import fr.dcproject.component.auth.database.User
|
||||
import fr.dcproject.component.auth.database.UserCreator
|
||||
import fr.dcproject.component.auth.database.UserI
|
||||
import fr.dcproject.component.citizen.database.Citizen
|
||||
import fr.dcproject.component.citizen.database.CitizenCart
|
||||
import fr.dcproject.component.citizen.database.CitizenCreator
|
||||
import fr.dcproject.component.citizen.database.CitizenI
|
||||
import fr.dcproject.component.comment.generic.CommentAccessControl
|
||||
import fr.dcproject.component.comment.generic.database.CommentForUpdate
|
||||
@@ -46,13 +47,13 @@ internal class `Comment Access Control` {
|
||||
name = CitizenI.Name("Albert", "Einstein")
|
||||
)
|
||||
|
||||
private val einstein2 = CitizenCart(
|
||||
private val einstein2 = CitizenCreator(
|
||||
id = UUID.fromString("319f1226-8f47-4df3-babd-2c7671ad0fbc"),
|
||||
user = User(
|
||||
user = UserCreator(
|
||||
username = "albert-einstein",
|
||||
roles = listOf(UserI.Roles.ROLE_USER)
|
||||
),
|
||||
name = CitizenI.Name("Albert", "Einstein")
|
||||
name = CitizenI.Name("Albert", "Einstein"),
|
||||
email = "albert-einstein@email.com"
|
||||
)
|
||||
|
||||
private val article1 = ArticleForView(
|
||||
|
||||
@@ -7,7 +7,6 @@ import fr.dcproject.component.auth.database.User
|
||||
import fr.dcproject.component.auth.database.UserCreator
|
||||
import fr.dcproject.component.auth.database.UserI
|
||||
import fr.dcproject.component.citizen.database.Citizen
|
||||
import fr.dcproject.component.citizen.database.CitizenCart
|
||||
import fr.dcproject.component.citizen.database.CitizenCreator
|
||||
import fr.dcproject.component.citizen.database.CitizenI
|
||||
import fr.dcproject.component.follow.FollowAccessControl
|
||||
@@ -55,13 +54,13 @@ internal class `Follow Access Control` {
|
||||
followAnonymous = true
|
||||
)
|
||||
|
||||
private val einstein2 = CitizenCart(
|
||||
private val einstein2 = CitizenCreator(
|
||||
id = UUID.fromString("319f1226-8f47-4df3-babd-2c7671ad0fbc"),
|
||||
user = User(
|
||||
user = UserCreator(
|
||||
username = "albert-einstein",
|
||||
roles = listOf(UserI.Roles.ROLE_USER)
|
||||
),
|
||||
name = CitizenI.Name("Albert", "Einstein")
|
||||
name = CitizenI.Name("Albert", "Einstein"),
|
||||
email = "albert-einstein@email.com"
|
||||
)
|
||||
|
||||
private val einstein3 = Citizen(
|
||||
|
||||
@@ -3,10 +3,7 @@ package unit.security
|
||||
import fr.dcproject.common.security.AccessDecision.DENIED
|
||||
import fr.dcproject.common.security.AccessDecision.GRANTED
|
||||
import fr.dcproject.component.article.database.ArticleForView
|
||||
import fr.dcproject.component.auth.database.User
|
||||
import fr.dcproject.component.auth.database.UserCreator
|
||||
import fr.dcproject.component.auth.database.UserI
|
||||
import fr.dcproject.component.citizen.database.CitizenCart
|
||||
import fr.dcproject.component.citizen.database.CitizenCreator
|
||||
import fr.dcproject.component.citizen.database.CitizenI
|
||||
import fr.dcproject.component.citizen.database.CitizenRef
|
||||
@@ -39,13 +36,13 @@ internal class `Opinion Access Control` {
|
||||
id = UUID.fromString("319f1226-8f47-4df3-babd-2c7671ad0fbc"),
|
||||
)
|
||||
|
||||
private val einstein2 = CitizenCart(
|
||||
private val einstein2 = CitizenCreator(
|
||||
id = UUID.fromString("319f1226-8f47-4df3-babd-2c7671ad0fbc"),
|
||||
user = User(
|
||||
user = UserCreator(
|
||||
username = "albert-einstein",
|
||||
roles = listOf(UserI.Roles.ROLE_USER)
|
||||
),
|
||||
name = CitizenI.Name("Albert", "Einstein")
|
||||
name = CitizenI.Name("Albert", "Einstein"),
|
||||
email = "albert-einstein@email.com"
|
||||
)
|
||||
|
||||
private val article1 = ArticleForView(
|
||||
|
||||
@@ -7,7 +7,6 @@ import fr.dcproject.component.auth.database.User
|
||||
import fr.dcproject.component.auth.database.UserCreator
|
||||
import fr.dcproject.component.auth.database.UserI
|
||||
import fr.dcproject.component.citizen.database.Citizen
|
||||
import fr.dcproject.component.citizen.database.CitizenCart
|
||||
import fr.dcproject.component.citizen.database.CitizenCreator
|
||||
import fr.dcproject.component.citizen.database.CitizenI
|
||||
import fr.dcproject.component.vote.VoteAccessControl
|
||||
@@ -60,13 +59,13 @@ internal class `Vote Access Control` {
|
||||
followAnonymous = true
|
||||
)
|
||||
|
||||
private val einstein2 = CitizenCart(
|
||||
private val einstein2 = CitizenCreator(
|
||||
id = UUID.fromString("319f1226-8f47-4df3-babd-2c7671ad0fbc"),
|
||||
user = User(
|
||||
user = UserCreator(
|
||||
username = "albert-einstein",
|
||||
roles = listOf(UserI.Roles.ROLE_USER)
|
||||
),
|
||||
name = CitizenI.Name("Albert", "Einstein")
|
||||
name = CitizenI.Name("Albert", "Einstein"),
|
||||
email = "albert-einstein@email.com"
|
||||
)
|
||||
|
||||
private val article1 = ArticleForView(
|
||||
|
||||
Reference in New Issue
Block a user