mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-12 18:59:06 +01:00
Actually throw TolerableFailureException when *deleting* a contact
Before, this was accidentally added to *listing* contacts.
This commit is contained in:
@@ -43,20 +43,20 @@ interface MailboxApi {
|
||||
/**
|
||||
* Deletes a contact from the mailbox.
|
||||
* This should get called after a contact was removed from Briar.
|
||||
*/
|
||||
void deleteContact(MailboxProperties properties, ContactId contactId)
|
||||
throws IOException, ApiException;
|
||||
|
||||
/**
|
||||
* Gets a list of {@link ContactId}s from the mailbox.
|
||||
* These are the contacts that the mailbox already knows about.
|
||||
*
|
||||
* @throws TolerableFailureException if response code is 404
|
||||
* (contact probably was already deleted).
|
||||
*/
|
||||
Collection<ContactId> getContacts(MailboxProperties properties)
|
||||
void deleteContact(MailboxProperties properties, ContactId contactId)
|
||||
throws IOException, ApiException, TolerableFailureException;
|
||||
|
||||
/**
|
||||
* Gets a list of {@link ContactId}s from the mailbox.
|
||||
* These are the contacts that the mailbox already knows about.
|
||||
*/
|
||||
Collection<ContactId> getContacts(MailboxProperties properties)
|
||||
throws IOException, ApiException;
|
||||
|
||||
@Immutable
|
||||
@JsonSerialize
|
||||
class MailboxContact {
|
||||
|
||||
@@ -113,7 +113,7 @@ class MailboxApiImpl implements MailboxApi {
|
||||
|
||||
@Override
|
||||
public void deleteContact(MailboxProperties properties, ContactId contactId)
|
||||
throws IOException, ApiException {
|
||||
throws IOException, ApiException, TolerableFailureException {
|
||||
if (!properties.isOwner()) throw new IllegalArgumentException();
|
||||
String url = properties.getOnionAddress() + "/contacts/" +
|
||||
contactId.getInt();
|
||||
@@ -123,15 +123,15 @@ class MailboxApiImpl implements MailboxApi {
|
||||
.build();
|
||||
OkHttpClient client = httpClientProvider.get();
|
||||
Response response = client.newCall(request).execute();
|
||||
if (response.code() == 404) throw new TolerableFailureException();
|
||||
if (response.code() != 200) throw new ApiException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<ContactId> getContacts(MailboxProperties properties)
|
||||
throws IOException, ApiException, TolerableFailureException {
|
||||
throws IOException, ApiException {
|
||||
if (!properties.isOwner()) throw new IllegalArgumentException();
|
||||
Response response = sendGetRequest(properties, "/contacts");
|
||||
if (response.code() == 404) throw new TolerableFailureException();
|
||||
if (response.code() != 200) throw new ApiException();
|
||||
|
||||
ResponseBody body = response.body();
|
||||
|
||||
@@ -230,6 +230,7 @@ public class MailboxApiTest extends BrambleTestCase {
|
||||
server.enqueue(new MockResponse());
|
||||
server.enqueue(new MockResponse().setResponseCode(205));
|
||||
server.enqueue(new MockResponse().setResponseCode(401));
|
||||
server.enqueue(new MockResponse().setResponseCode(404));
|
||||
server.start();
|
||||
String baseUrl = getBaseUrl(server);
|
||||
MailboxProperties properties =
|
||||
@@ -257,6 +258,14 @@ public class MailboxApiTest extends BrambleTestCase {
|
||||
assertEquals("DELETE", request3.getMethod());
|
||||
assertEquals("/contacts/" + contactId.getInt(), request3.getPath());
|
||||
assertToken(request3, token);
|
||||
|
||||
// tolerable 404 not found error
|
||||
assertThrows(TolerableFailureException.class,
|
||||
() -> api.deleteContact(properties, contactId));
|
||||
RecordedRequest request4 = server.takeRequest();
|
||||
assertEquals("/contacts/" + contactId.getInt(), request4.getPath());
|
||||
assertEquals("DELETE", request4.getMethod());
|
||||
assertToken(request4, token);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -286,7 +295,6 @@ public class MailboxApiTest extends BrambleTestCase {
|
||||
server.enqueue(new MockResponse().setBody(invalidResponse3));
|
||||
server.enqueue(new MockResponse().setResponseCode(401));
|
||||
server.enqueue(new MockResponse().setResponseCode(500));
|
||||
server.enqueue(new MockResponse().setResponseCode(404));
|
||||
server.start();
|
||||
String baseUrl = getBaseUrl(server);
|
||||
MailboxProperties properties =
|
||||
@@ -350,14 +358,6 @@ public class MailboxApiTest extends BrambleTestCase {
|
||||
assertEquals("/contacts", request8.getPath());
|
||||
assertEquals("GET", request8.getMethod());
|
||||
assertToken(request8, token);
|
||||
|
||||
// tolerable 404 not found error
|
||||
assertThrows(TolerableFailureException.class,
|
||||
() -> api.getContacts(properties));
|
||||
RecordedRequest request9 = server.takeRequest();
|
||||
assertEquals("/contacts", request9.getPath());
|
||||
assertEquals("GET", request9.getMethod());
|
||||
assertToken(request9, token);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user