diff --git a/pom.xml b/pom.xml index 91e63f5db..30bcab01c 100644 --- a/pom.xml +++ b/pom.xml @@ -12,8 +12,8 @@ 1.51 - 0.9.2 - 2.6.0 + 1.1.0 + 2.8.7 UTF-8 @@ -56,7 +56,7 @@ com.dcsquare dropwizard-papertrail - 1.1 + 1.2 org.bouncycastle @@ -96,12 +96,12 @@ org.whispersystems websocket-resources - 0.4.1 + 0.5.0 org.whispersystems dropwizard-simpleauth - 0.1.1 + 0.2.0 @@ -132,6 +132,12 @@ + + org.mockito + mockito-core + 2.7.22 + test + @@ -154,6 +160,12 @@ jackson-databind ${jackson.api.version} + + + io.dropwizard + dropwizard-core + 1.1.0 + diff --git a/src/test/java/org/whispersystems/textsecuregcm/tests/controllers/DeviceControllerTest.java b/src/test/java/org/whispersystems/textsecuregcm/tests/controllers/DeviceControllerTest.java index 5fc674d3a..47a25a24f 100644 --- a/src/test/java/org/whispersystems/textsecuregcm/tests/controllers/DeviceControllerTest.java +++ b/src/test/java/org/whispersystems/textsecuregcm/tests/controllers/DeviceControllerTest.java @@ -44,7 +44,6 @@ import java.util.HashMap; import java.util.Map; import java.util.concurrent.TimeUnit; -import io.dropwizard.jersey.validation.ConstraintViolationExceptionMapper; import io.dropwizard.testing.junit.ResourceTestRule; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assert.assertEquals; @@ -86,7 +85,6 @@ public class DeviceControllerTest { .addProvider(new AuthValueFactoryProvider.Binder()) .setTestContainerFactory(new GrizzlyWebTestContainerFactory()) .addProvider(new DeviceLimitExceededExceptionMapper()) - .addProvider(new ConstraintViolationExceptionMapper()) .addResource(new DumbVerificationDeviceController(pendingDevicesManager, accountsManager, messagesManager, diff --git a/src/test/java/org/whispersystems/textsecuregcm/tests/controllers/DirectoryControllerTest.java b/src/test/java/org/whispersystems/textsecuregcm/tests/controllers/DirectoryControllerTest.java index 0b2e4618a..e244d1e63 100644 --- a/src/test/java/org/whispersystems/textsecuregcm/tests/controllers/DirectoryControllerTest.java +++ b/src/test/java/org/whispersystems/textsecuregcm/tests/controllers/DirectoryControllerTest.java @@ -23,6 +23,7 @@ import java.util.List; import io.dropwizard.testing.junit.ResourceTestRule; import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.ArgumentMatchers.anyListOf; import static org.mockito.Matchers.anyList; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -46,7 +47,7 @@ public class DirectoryControllerTest { @Before public void setup() throws Exception { when(rateLimiters.getContactsLimiter()).thenReturn(rateLimiter); - when(directoryManager.get(anyList())).thenAnswer(new Answer>() { + when(directoryManager.get(anyListOf(byte[].class))).thenAnswer(new Answer>() { @Override public List answer(InvocationOnMock invocationOnMock) throws Throwable { List query = (List) invocationOnMock.getArguments()[0]; diff --git a/src/test/java/org/whispersystems/textsecuregcm/tests/controllers/MessageControllerTest.java b/src/test/java/org/whispersystems/textsecuregcm/tests/controllers/MessageControllerTest.java index fff0dc1c7..809d47272 100644 --- a/src/test/java/org/whispersystems/textsecuregcm/tests/controllers/MessageControllerTest.java +++ b/src/test/java/org/whispersystems/textsecuregcm/tests/controllers/MessageControllerTest.java @@ -211,6 +211,30 @@ public class MessageControllerTest { assertEquals(response.getMessages().get(1).getTimestamp(), timestampTwo); } + @Test + public synchronized void testGetMessagesBadAuth() throws Exception { + final long timestampOne = 313377; + final long timestampTwo = 313388; + + List messages = new LinkedList() {{ + add(new OutgoingMessageEntity(1L, Envelope.Type.CIPHERTEXT_VALUE, null, timestampOne, "+14152222222", 2, "hi there".getBytes(), null)); + add(new OutgoingMessageEntity(2L, Envelope.Type.RECEIPT_VALUE, null, timestampTwo, "+14152222222", 2, null, null)); + }}; + + OutgoingMessageEntityList messagesList = new OutgoingMessageEntityList(messages, false); + + when(messagesManager.getMessagesForDevice(eq(AuthHelper.VALID_NUMBER), eq(1L))).thenReturn(messagesList); + + Response response = + resources.getJerseyTest().target("/v1/messages/") + .request() + .header("Authorization", AuthHelper.getAuthHeader(AuthHelper.VALID_NUMBER, AuthHelper.INVALID_PASSWORD)) + .accept(MediaType.APPLICATION_JSON_TYPE) + .get(); + + assertThat("Unauthorized response", response.getStatus(), is(equalTo(401))); + } + @Test public synchronized void testDeleteMessages() throws Exception { long timestamp = System.currentTimeMillis(); diff --git a/src/test/java/org/whispersystems/textsecuregcm/tests/websocket/WebSocketConnectionTest.java b/src/test/java/org/whispersystems/textsecuregcm/tests/websocket/WebSocketConnectionTest.java index bdb231839..6785d7c39 100644 --- a/src/test/java/org/whispersystems/textsecuregcm/tests/websocket/WebSocketConnectionTest.java +++ b/src/test/java/org/whispersystems/textsecuregcm/tests/websocket/WebSocketConnectionTest.java @@ -5,6 +5,7 @@ import com.google.common.util.concurrent.SettableFuture; import com.google.protobuf.ByteString; import org.eclipse.jetty.websocket.api.UpgradeRequest; import org.junit.Test; +import org.mockito.ArgumentMatchers; import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; import org.whispersystems.textsecuregcm.auth.AccountAuthenticator; @@ -130,7 +131,7 @@ public class WebSocketConnectionTest { final List> futures = new LinkedList<>(); final WebSocketClient client = mock(WebSocketClient.class); - when(client.sendRequest(eq("PUT"), eq("/api/v1/message"), any(List.class), any(Optional.class))) + when(client.sendRequest(eq("PUT"), eq("/api/v1/message"), ArgumentMatchers.nullable(List.class), ArgumentMatchers.>any())) .thenAnswer(new Answer>() { @Override public SettableFuture answer(InvocationOnMock invocationOnMock) throws Throwable { @@ -145,7 +146,7 @@ public class WebSocketConnectionTest { account, device, client); connection.onDispatchSubscribed(websocketAddress.serialize()); - verify(client, times(3)).sendRequest(eq("PUT"), eq("/api/v1/message"), anyList(), any(Optional.class)); + verify(client, times(3)).sendRequest(eq("PUT"), eq("/api/v1/message"), ArgumentMatchers.nullable(List.class), ArgumentMatchers.>any()); assertTrue(futures.size() == 3); @@ -214,7 +215,7 @@ public class WebSocketConnectionTest { final List> futures = new LinkedList<>(); final WebSocketClient client = mock(WebSocketClient.class); - when(client.sendRequest(eq("PUT"), eq("/api/v1/message"), anyList(), any(Optional.class))) + when(client.sendRequest(eq("PUT"), eq("/api/v1/message"), ArgumentMatchers.nullable(List.class), ArgumentMatchers.>any())) .thenAnswer(new Answer>() { @Override public SettableFuture answer(InvocationOnMock invocationOnMock) throws Throwable { @@ -239,7 +240,7 @@ public class WebSocketConnectionTest { .setContent(ByteString.copyFrom(secondMessage.toByteArray())) .build().toByteArray()); - verify(client, times(2)).sendRequest(eq("PUT"), eq("/api/v1/message"), anyList(), any(Optional.class)); + verify(client, times(2)).sendRequest(eq("PUT"), eq("/api/v1/message"), ArgumentMatchers.nullable(List.class), ArgumentMatchers.>any()); assertEquals(futures.size(), 2); @@ -320,7 +321,7 @@ public class WebSocketConnectionTest { final List> futures = new LinkedList<>(); final WebSocketClient client = mock(WebSocketClient.class); - when(client.sendRequest(eq("PUT"), eq("/api/v1/message"), anyList(), any(Optional.class))) + when(client.sendRequest(eq("PUT"), eq("/api/v1/message"), ArgumentMatchers.nullable(List.class), ArgumentMatchers.>any())) .thenAnswer(new Answer>() { @Override public SettableFuture answer(InvocationOnMock invocationOnMock) throws Throwable { @@ -336,7 +337,7 @@ public class WebSocketConnectionTest { connection.onDispatchSubscribed(websocketAddress.serialize()); - verify(client, times(2)).sendRequest(eq("PUT"), eq("/api/v1/message"), anyList(), any(Optional.class)); + verify(client, times(2)).sendRequest(eq("PUT"), eq("/api/v1/message"), ArgumentMatchers.nullable(List.class), ArgumentMatchers.>any()); assertEquals(futures.size(), 2);