briar-headless: Last round of review comments

This commit is contained in:
Torsten Grote
2018-10-09 12:19:21 -03:00
parent e3686186ee
commit b3615b4a77
11 changed files with 32 additions and 26 deletions

View File

@@ -11,4 +11,3 @@ fun Author.output() = JsonDict(
)
fun Author.Status.output() = name.toLowerCase()

View File

@@ -27,7 +27,7 @@ private val DEFAULT_DATA_DIR = getProperty("user.home") + separator + ".briar"
private class Main : CliktCommand(
name = "briar-headless",
help = "A Briar client without GUI that exposes a REST and Websocket API"
help = "A Briar peer without GUI that exposes a REST and Websocket API"
) {
private val debug by option("--debug", "-d", help = "Enable printing of debug messages").flag(
default = false

View File

@@ -6,7 +6,7 @@ import org.briarproject.briar.api.blog.MessageType
import org.briarproject.briar.headless.json.JsonDict
internal fun BlogPostHeader.output(body: String) = JsonDict(
"body" to body,
"text" to body,
"author" to author.output(),
"authorStatus" to authorStatus.output(),
"type" to type.output(),

View File

@@ -21,7 +21,7 @@ constructor(private val forumManager: ForumManager) : ForumController {
}
override fun create(ctx: Context): Context {
val name = ctx.getFromJson("text")
val name = ctx.getFromJson("name")
if (StringUtils.utf8IsTooLong(name, MAX_FORUM_NAME_LENGTH))
throw BadRequestResponse("Forum name is too long")
return ctx.json(forumManager.addForum(name).output())

View File

@@ -19,19 +19,22 @@ internal fun PrivateMessageHeader.output(contactId: ContactId) = JsonDict(
internal fun PrivateMessageHeader.output(contactId: ContactId, body: String?): JsonDict {
val dict = output(contactId)
dict["body"] = body
dict["text"] = body
return dict
}
/**
* Use only for outgoing messages that were just sent
*/
internal fun PrivateMessage.output(contactId: ContactId, body: String) = JsonDict(
"type" to "PrivateMessage",
"contactId" to contactId.int,
"timestamp" to message.timestamp,
"read" to true,
"seen" to true,
"sent" to true,
"seen" to false,
"sent" to false,
"local" to true,
"id" to message.id.bytes,
"groupId" to message.groupId.bytes,
"body" to body
"text" to body
)

View File

@@ -15,6 +15,7 @@ import org.briarproject.bramble.api.system.Clock
import org.briarproject.bramble.test.TestUtils.*
import org.briarproject.bramble.util.StringUtils.getRandomString
import org.skyscreamer.jsonassert.JSONAssert.assertEquals
import org.skyscreamer.jsonassert.JSONCompareMode.STRICT
import javax.servlet.http.HttpServletRequest
import javax.servlet.http.HttpServletResponse
@@ -38,7 +39,7 @@ abstract class ControllerTest {
protected val timestamp = 42L
protected fun assertJsonEquals(json: String, obj: Any) {
assertEquals(json, outputCtx.json(obj).resultString(), false)
assertEquals(json, outputCtx.json(obj).resultString(), STRICT)
}
}

View File

@@ -102,7 +102,7 @@ internal class BlogControllerTest : ControllerTest() {
fun testOutputBlogPost() {
val json = """
{
"body": "$body",
"text": "$body",
"author": ${toJson(author.output())},
"authorStatus": "ourselves",
"type": "post",

View File

@@ -41,6 +41,7 @@ internal class ContactControllerTest : ControllerTest() {
fun testOutputAuthor() {
val json = """
{
"formatVersion": 1,
"id": ${toJson(author.id.bytes)},
"name": "${author.name}",
"publicKey": ${toJson(author.publicKey)}

View File

@@ -30,7 +30,7 @@ internal class ForumControllerTest : ControllerTest() {
@Test
fun create() {
every { ctx.body() } returns """{"text": "${forum.name}"}"""
every { ctx.body() } returns """{"name": "${forum.name}"}"""
every { forumManager.addForum(forum.name) } returns forum
every { ctx.json(forum.output()) } returns ctx
@@ -46,14 +46,14 @@ internal class ForumControllerTest : ControllerTest() {
@Test
fun createEmptyName() {
every { ctx.body() } returns """{"text": ""}"""
every { ctx.body() } returns """{"name": ""}"""
assertThrows(BadRequestResponse::class.java) { controller.create(ctx) }
}
@Test
fun createNullName() {
every { ctx.body() } returns """{"text": null}"""
every { ctx.body() } returns """{"name": null}"""
assertThrows(BadRequestResponse::class.java) { controller.create(ctx) }
}
@@ -67,7 +67,7 @@ internal class ForumControllerTest : ControllerTest() {
@Test
fun createTooLongName() {
every { ctx.body() } returns """{"text": "${getRandomString(MAX_FORUM_NAME_LENGTH + 1)}"}"""
every { ctx.body() } returns """{"name": "${getRandomString(MAX_FORUM_NAME_LENGTH + 1)}"}"""
assertThrows(BadRequestResponse::class.java) { controller.create(ctx) }
}

View File

@@ -161,7 +161,7 @@ internal class MessagingControllerImplTest : ControllerTest() {
fun testOutputPrivateMessageHeader() {
val json = """
{
"body": "$body",
"text": "$body",
"type": "PrivateMessage",
"timestamp": $timestamp,
"groupId": ${toJson(header.groupId.bytes)},
@@ -180,15 +180,15 @@ internal class MessagingControllerImplTest : ControllerTest() {
fun testOutputPrivateMessage() {
val json = """
{
"body": "$body",
"text": "$body",
"type": "PrivateMessage",
"timestamp": ${message.timestamp},
"groupId": ${toJson(message.groupId.bytes)},
"contactId": ${contact.id.int},
"local": true,
"seen": true,
"seen": false,
"read": true,
"sent": true,
"sent": false,
"id": ${toJson(message.id.bytes)}
}
"""
@@ -203,7 +203,7 @@ internal class MessagingControllerImplTest : ControllerTest() {
)
val json = """
{
"body": null,
"text": null,
"type": "IntroductionRequest",
"timestamp": $timestamp,
"groupId": ${toJson(request.groupId.bytes)},