mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-13 19:29:06 +01:00
briar-headless: POST text as JSON in body instead of form parameter
This commit is contained in:
@@ -30,23 +30,15 @@ internal class BlogControllerTest : ControllerTest() {
|
||||
private val rssFeed = false
|
||||
private val read = true
|
||||
private val header = BlogPostHeader(
|
||||
POST,
|
||||
group.id,
|
||||
message.id,
|
||||
parentId,
|
||||
message.timestamp,
|
||||
timestamp,
|
||||
author,
|
||||
OURSELVES,
|
||||
rssFeed,
|
||||
read
|
||||
POST, group.id, message.id, parentId, message.timestamp, timestamp, author, OURSELVES,
|
||||
rssFeed, read
|
||||
)
|
||||
|
||||
@Test
|
||||
fun testCreate() {
|
||||
val post = BlogPost(message, null, localAuthor)
|
||||
|
||||
every { ctx.formParam("text") } returns body
|
||||
every { ctx.body() } returns """{"text": "$body"}"""
|
||||
every { identityManager.localAuthor } returns localAuthor
|
||||
every { blogManager.getPersonalBlog(localAuthor) } returns blog
|
||||
every { clock.currentTimeMillis() } returns message.timestamp
|
||||
@@ -68,21 +60,21 @@ internal class BlogControllerTest : ControllerTest() {
|
||||
|
||||
@Test
|
||||
fun testCreateNoText() {
|
||||
every { ctx.formParam("text") } returns null
|
||||
every { ctx.body() } returns """{"foo": "bar"}"""
|
||||
|
||||
assertThrows(BadRequestResponse::class.java) { controller.createPost(ctx) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testCreateEmptyText() {
|
||||
every { ctx.formParam("text") } returns ""
|
||||
every { ctx.body() } returns """{"text": ""}"""
|
||||
|
||||
assertThrows(BadRequestResponse::class.java) { controller.createPost(ctx) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testCreateTooLongText() {
|
||||
every { ctx.formParam("text") } returns getRandomString(MAX_BLOG_POST_BODY_LENGTH + 1)
|
||||
every { ctx.body() } returns """{"text": "${getRandomString(MAX_BLOG_POST_BODY_LENGTH + 1)}"}"""
|
||||
|
||||
assertThrows(BadRequestResponse::class.java) { controller.createPost(ctx) }
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ internal class ForumControllerTest : ControllerTest() {
|
||||
|
||||
@Test
|
||||
fun create() {
|
||||
every { ctx.formParam("text") } returns forum.name
|
||||
every { ctx.body() } returns """{"text": "${forum.name}"}"""
|
||||
every { forumManager.addForum(forum.name) } returns forum
|
||||
every { ctx.json(forum.output()) } returns ctx
|
||||
|
||||
@@ -39,21 +39,35 @@ internal class ForumControllerTest : ControllerTest() {
|
||||
|
||||
@Test
|
||||
fun createNoName() {
|
||||
every { ctx.formParam("text") } returns null
|
||||
every { ctx.body() } returns "{}"
|
||||
|
||||
assertThrows(BadRequestResponse::class.java) { controller.create(ctx) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun createEmptyName() {
|
||||
every { ctx.formParam("text") } returns ""
|
||||
every { ctx.body() } returns """{"text": ""}"""
|
||||
|
||||
assertThrows(BadRequestResponse::class.java) { controller.create(ctx) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun createNullName() {
|
||||
every { ctx.body() } returns """{"text": null}"""
|
||||
|
||||
assertThrows(BadRequestResponse::class.java) { controller.create(ctx) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun createNoJsonName() {
|
||||
every { ctx.body() } returns "foo"
|
||||
|
||||
assertThrows(BadRequestResponse::class.java) { controller.create(ctx) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun createTooLongName() {
|
||||
every { ctx.formParam("text") } returns getRandomString(MAX_FORUM_NAME_LENGTH + 1)
|
||||
every { ctx.body() } returns """{"text": "${getRandomString(MAX_FORUM_NAME_LENGTH + 1)}"}"""
|
||||
|
||||
assertThrows(BadRequestResponse::class.java) { controller.create(ctx) }
|
||||
}
|
||||
|
||||
@@ -95,7 +95,7 @@ internal class MessagingControllerImplTest : ControllerTest() {
|
||||
val slot = CapturingSlot<JsonDict>()
|
||||
|
||||
expectGetContact()
|
||||
every { ctx.formParam("text") } returns body
|
||||
every { ctx.body() } returns """{"text": "$body"}"""
|
||||
every { messagingManager.getContactGroup(contact) } returns group
|
||||
every { clock.currentTimeMillis() } returns timestamp
|
||||
every {
|
||||
@@ -126,7 +126,7 @@ internal class MessagingControllerImplTest : ControllerTest() {
|
||||
@Test
|
||||
fun writeNonexistentBody() {
|
||||
expectGetContact()
|
||||
every { ctx.formParam("text") } returns null
|
||||
every { ctx.body() } returns """{"foo": "bar"}"""
|
||||
|
||||
assertThrows(BadRequestResponse::class.java) { controller.write(ctx) }
|
||||
}
|
||||
@@ -134,7 +134,7 @@ internal class MessagingControllerImplTest : ControllerTest() {
|
||||
@Test
|
||||
fun writeEmptyBody() {
|
||||
expectGetContact()
|
||||
every { ctx.formParam("text") } returns ""
|
||||
every { ctx.body() } returns """{"text": ""}"""
|
||||
|
||||
assertThrows(BadRequestResponse::class.java) { controller.write(ctx) }
|
||||
}
|
||||
@@ -142,7 +142,7 @@ internal class MessagingControllerImplTest : ControllerTest() {
|
||||
@Test
|
||||
fun writeTooLongBody() {
|
||||
expectGetContact()
|
||||
every { ctx.formParam("text") } returns getRandomString(MAX_PRIVATE_MESSAGE_BODY_LENGTH + 1)
|
||||
every { ctx.body() } returns """{"text": "${getRandomString(MAX_PRIVATE_MESSAGE_BODY_LENGTH + 1)}"}"""
|
||||
|
||||
assertThrows(BadRequestResponse::class.java) { controller.write(ctx) }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user