mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-20 06:39:54 +01:00
Include name/alias of already existing (pending) contact in error
This commit is contained in:
@@ -118,6 +118,14 @@ Until it is completed, a pending contact is returned as JSON:
|
|||||||
|
|
||||||
Possible errors when adding a pending contact are:
|
Possible errors when adding a pending contact are:
|
||||||
|
|
||||||
|
#### 400: Pending contact's link is invalid
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"error": "INVALID_LINK"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
#### 400: Pending contact's handshake public key is invalid
|
#### 400: Pending contact's handshake public key is invalid
|
||||||
|
|
||||||
```json
|
```json
|
||||||
@@ -147,7 +155,8 @@ when this happens:
|
|||||||
|
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
"error": "CONTACT_EXISTS"
|
"error": "CONTACT_EXISTS",
|
||||||
|
"remoteAuthorName": "Bob"
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -165,7 +174,8 @@ possible attack.
|
|||||||
|
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
"error": "PENDING_EXISTS"
|
"error": "PENDING_EXISTS",
|
||||||
|
"pendingContactAlias": "Alice"
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
-----------
|
-----------
|
||||||
|
|||||||
@@ -112,11 +112,13 @@ constructor(
|
|||||||
return ctx.json(details)
|
return ctx.json(details)
|
||||||
} catch (e: ContactExistsException) {
|
} catch (e: ContactExistsException) {
|
||||||
ctx.status(FORBIDDEN_403)
|
ctx.status(FORBIDDEN_403)
|
||||||
val details = mapOf("error" to "CONTACT_EXISTS")
|
val details =
|
||||||
|
mapOf("error" to "CONTACT_EXISTS", "remoteAuthorName" to e.remoteAuthor.name)
|
||||||
return ctx.json(details)
|
return ctx.json(details)
|
||||||
} catch (e: PendingContactExistsException) {
|
} catch (e: PendingContactExistsException) {
|
||||||
ctx.status(FORBIDDEN_403)
|
ctx.status(FORBIDDEN_403)
|
||||||
val details = mapOf("error" to "PENDING_EXISTS")
|
val details =
|
||||||
|
mapOf("error" to "PENDING_EXISTS", "pendingContactAlias" to e.pendingContact.alias)
|
||||||
return ctx.json(details)
|
return ctx.json(details)
|
||||||
}
|
}
|
||||||
return ctx.json(pendingContact.output())
|
return ctx.json(pendingContact.output())
|
||||||
|
|||||||
@@ -135,6 +135,7 @@ class ContactControllerIntegrationTest: IntegrationTest() {
|
|||||||
response = post("$url/contacts/add/pending", json)
|
response = post("$url/contacts/add/pending", json)
|
||||||
assertEquals(403, response.statusCode)
|
assertEquals(403, response.statusCode)
|
||||||
assertEquals("PENDING_EXISTS", response.jsonObject.getString("error"))
|
assertEquals("PENDING_EXISTS", response.jsonObject.getString("error"))
|
||||||
|
assertEquals(alias, response.jsonObject.getString("pendingContactAlias"))
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
@@ -183,8 +183,15 @@ internal class ContactControllerTest : ControllerTest() {
|
|||||||
link,
|
link,
|
||||||
alias
|
alias
|
||||||
)
|
)
|
||||||
} throws ContactExistsException(null, null)
|
} throws ContactExistsException(null, author)
|
||||||
every { ctx.json(mapOf("error" to "CONTACT_EXISTS")) } returns ctx
|
every {
|
||||||
|
ctx.json(
|
||||||
|
mapOf(
|
||||||
|
"error" to "CONTACT_EXISTS",
|
||||||
|
"remoteAuthorName" to author.name
|
||||||
|
)
|
||||||
|
)
|
||||||
|
} returns ctx
|
||||||
controller.addPendingContact(ctx)
|
controller.addPendingContact(ctx)
|
||||||
verify { ctx.status(403) }
|
verify { ctx.status(403) }
|
||||||
}
|
}
|
||||||
@@ -204,8 +211,15 @@ internal class ContactControllerTest : ControllerTest() {
|
|||||||
link,
|
link,
|
||||||
alias
|
alias
|
||||||
)
|
)
|
||||||
} throws PendingContactExistsException(null)
|
} throws PendingContactExistsException(pendingContact)
|
||||||
every { ctx.json(mapOf("error" to "PENDING_EXISTS")) } returns ctx
|
every {
|
||||||
|
ctx.json(
|
||||||
|
mapOf(
|
||||||
|
"error" to "PENDING_EXISTS",
|
||||||
|
"pendingContactAlias" to pendingContact.alias
|
||||||
|
)
|
||||||
|
)
|
||||||
|
} returns ctx
|
||||||
controller.addPendingContact(ctx)
|
controller.addPendingContact(ctx)
|
||||||
verify { ctx.status(403) }
|
verify { ctx.status(403) }
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user