Add an API endpoint for deleting accounts.
This commit is contained in:
parent
61f515670c
commit
a553eba574
|
@ -482,6 +482,13 @@ public class AccountController {
|
||||||
directoryQueue.refreshRegisteredUser(account);
|
directoryQueue.refreshRegisteredUser(account);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GET
|
||||||
|
@Path("/me")
|
||||||
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
|
public AccountCreationResult getMe(@Auth Account account) {
|
||||||
|
return whoAmI(account);
|
||||||
|
}
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Path("/whoami")
|
@Path("/whoami")
|
||||||
@Produces(MediaType.APPLICATION_JSON)
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
|
@ -593,6 +600,13 @@ public class AccountController {
|
||||||
return new CaptchaRequirement(false, false);
|
return new CaptchaRequirement(false, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Timed
|
||||||
|
@DELETE
|
||||||
|
@Path("/me")
|
||||||
|
public void deleteAccount(@Auth Account account) {
|
||||||
|
accounts.delete(account);
|
||||||
|
}
|
||||||
|
|
||||||
private boolean shouldAutoBlock(String requester) {
|
private boolean shouldAutoBlock(String requester) {
|
||||||
try {
|
try {
|
||||||
rateLimiters.getAutoBlockLimiter().validate(requester);
|
rateLimiters.getAutoBlockLimiter().validate(requester);
|
||||||
|
|
|
@ -3,10 +3,13 @@ package org.whispersystems.textsecuregcm.tests.controllers;
|
||||||
import com.google.common.collect.ImmutableSet;
|
import com.google.common.collect.ImmutableSet;
|
||||||
import io.dropwizard.auth.PolymorphicAuthValueFactoryProvider;
|
import io.dropwizard.auth.PolymorphicAuthValueFactoryProvider;
|
||||||
import io.dropwizard.testing.junit.ResourceTestRule;
|
import io.dropwizard.testing.junit.ResourceTestRule;
|
||||||
|
import junitparams.JUnitParamsRunner;
|
||||||
|
import junitparams.Parameters;
|
||||||
import org.glassfish.jersey.test.grizzly.GrizzlyWebTestContainerFactory;
|
import org.glassfish.jersey.test.grizzly.GrizzlyWebTestContainerFactory;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Rule;
|
import org.junit.Rule;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
import org.mockito.ArgumentCaptor;
|
import org.mockito.ArgumentCaptor;
|
||||||
import org.mockito.ArgumentMatcher;
|
import org.mockito.ArgumentMatcher;
|
||||||
import org.whispersystems.textsecuregcm.auth.AuthenticationCredentials;
|
import org.whispersystems.textsecuregcm.auth.AuthenticationCredentials;
|
||||||
|
@ -76,6 +79,7 @@ import static org.mockito.Mockito.verify;
|
||||||
import static org.mockito.Mockito.verifyNoMoreInteractions;
|
import static org.mockito.Mockito.verifyNoMoreInteractions;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
@RunWith(JUnitParamsRunner.class)
|
||||||
public class AccountControllerTest {
|
public class AccountControllerTest {
|
||||||
|
|
||||||
private static final String SENDER = "+14152222222";
|
private static final String SENDER = "+14152222222";
|
||||||
|
@ -1063,10 +1067,11 @@ public class AccountControllerTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testWhoAmI() {
|
@Parameters({"/v1/accounts/whoami/", "/v1/accounts/me/"})
|
||||||
|
public void testWhoAmI(final String path) {
|
||||||
AccountCreationResult response =
|
AccountCreationResult response =
|
||||||
resources.getJerseyTest()
|
resources.getJerseyTest()
|
||||||
.target("/v1/accounts/whoami/")
|
.target(path)
|
||||||
.request()
|
.request()
|
||||||
.header("Authorization", AuthHelper.getAuthHeader(AuthHelper.VALID_NUMBER, AuthHelper.VALID_PASSWORD))
|
.header("Authorization", AuthHelper.getAuthHeader(AuthHelper.VALID_NUMBER, AuthHelper.VALID_PASSWORD))
|
||||||
.get(AccountCreationResult.class);
|
.get(AccountCreationResult.class);
|
||||||
|
@ -1171,4 +1176,17 @@ public class AccountControllerTest {
|
||||||
assertThat(response.getStatus()).isEqualTo(204);
|
assertThat(response.getStatus()).isEqualTo(204);
|
||||||
verify(directoryQueue, times(1)).refreshRegisteredUser(AuthHelper.VALID_ACCOUNT);
|
verify(directoryQueue, times(1)).refreshRegisteredUser(AuthHelper.VALID_ACCOUNT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDeleteAccount() {
|
||||||
|
Response response =
|
||||||
|
resources.getJerseyTest()
|
||||||
|
.target("/v1/accounts/me")
|
||||||
|
.request()
|
||||||
|
.header("Authorization", AuthHelper.getAuthHeader(AuthHelper.VALID_NUMBER, AuthHelper.VALID_PASSWORD))
|
||||||
|
.delete();
|
||||||
|
|
||||||
|
assertThat(response.getStatus()).isEqualTo(204);
|
||||||
|
verify(accountsManager).delete(AuthHelper.VALID_ACCOUNT);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue