parent
8b2f46f0ba
commit
2efe8ae0cf
22
pom.xml
22
pom.xml
|
@ -12,8 +12,8 @@
|
||||||
<version>1.51</version>
|
<version>1.51</version>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<dropwizard.version>0.9.2</dropwizard.version>
|
<dropwizard.version>1.1.0</dropwizard.version>
|
||||||
<jackson.api.version>2.6.0</jackson.api.version>
|
<jackson.api.version>2.8.7</jackson.api.version>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
|
@ -56,7 +56,7 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.dcsquare</groupId>
|
<groupId>com.dcsquare</groupId>
|
||||||
<artifactId>dropwizard-papertrail</artifactId>
|
<artifactId>dropwizard-papertrail</artifactId>
|
||||||
<version>1.1</version>
|
<version>1.2</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.bouncycastle</groupId>
|
<groupId>org.bouncycastle</groupId>
|
||||||
|
@ -96,12 +96,12 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.whispersystems</groupId>
|
<groupId>org.whispersystems</groupId>
|
||||||
<artifactId>websocket-resources</artifactId>
|
<artifactId>websocket-resources</artifactId>
|
||||||
<version>0.4.1</version>
|
<version>0.5.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.whispersystems</groupId>
|
<groupId>org.whispersystems</groupId>
|
||||||
<artifactId>dropwizard-simpleauth</artifactId>
|
<artifactId>dropwizard-simpleauth</artifactId>
|
||||||
<version>0.1.1</version>
|
<version>0.2.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
|
@ -132,6 +132,12 @@
|
||||||
</exclusions>
|
</exclusions>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.mockito</groupId>
|
||||||
|
<artifactId>mockito-core</artifactId>
|
||||||
|
<version>2.7.22</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
@ -154,6 +160,12 @@
|
||||||
<artifactId>jackson-databind</artifactId>
|
<artifactId>jackson-databind</artifactId>
|
||||||
<version>${jackson.api.version}</version>
|
<version>${jackson.api.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.dropwizard</groupId>
|
||||||
|
<artifactId>dropwizard-core</artifactId>
|
||||||
|
<version>1.1.0</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</dependencyManagement>
|
</dependencyManagement>
|
||||||
|
|
||||||
|
|
|
@ -44,7 +44,6 @@ import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import io.dropwizard.jersey.validation.ConstraintViolationExceptionMapper;
|
|
||||||
import io.dropwizard.testing.junit.ResourceTestRule;
|
import io.dropwizard.testing.junit.ResourceTestRule;
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
@ -86,7 +85,6 @@ public class DeviceControllerTest {
|
||||||
.addProvider(new AuthValueFactoryProvider.Binder())
|
.addProvider(new AuthValueFactoryProvider.Binder())
|
||||||
.setTestContainerFactory(new GrizzlyWebTestContainerFactory())
|
.setTestContainerFactory(new GrizzlyWebTestContainerFactory())
|
||||||
.addProvider(new DeviceLimitExceededExceptionMapper())
|
.addProvider(new DeviceLimitExceededExceptionMapper())
|
||||||
.addProvider(new ConstraintViolationExceptionMapper())
|
|
||||||
.addResource(new DumbVerificationDeviceController(pendingDevicesManager,
|
.addResource(new DumbVerificationDeviceController(pendingDevicesManager,
|
||||||
accountsManager,
|
accountsManager,
|
||||||
messagesManager,
|
messagesManager,
|
||||||
|
|
|
@ -23,6 +23,7 @@ import java.util.List;
|
||||||
|
|
||||||
import io.dropwizard.testing.junit.ResourceTestRule;
|
import io.dropwizard.testing.junit.ResourceTestRule;
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
import static org.mockito.ArgumentMatchers.anyListOf;
|
||||||
import static org.mockito.Matchers.anyList;
|
import static org.mockito.Matchers.anyList;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
@ -46,7 +47,7 @@ public class DirectoryControllerTest {
|
||||||
@Before
|
@Before
|
||||||
public void setup() throws Exception {
|
public void setup() throws Exception {
|
||||||
when(rateLimiters.getContactsLimiter()).thenReturn(rateLimiter);
|
when(rateLimiters.getContactsLimiter()).thenReturn(rateLimiter);
|
||||||
when(directoryManager.get(anyList())).thenAnswer(new Answer<List<byte[]>>() {
|
when(directoryManager.get(anyListOf(byte[].class))).thenAnswer(new Answer<List<byte[]>>() {
|
||||||
@Override
|
@Override
|
||||||
public List<byte[]> answer(InvocationOnMock invocationOnMock) throws Throwable {
|
public List<byte[]> answer(InvocationOnMock invocationOnMock) throws Throwable {
|
||||||
List<byte[]> query = (List<byte[]>) invocationOnMock.getArguments()[0];
|
List<byte[]> query = (List<byte[]>) invocationOnMock.getArguments()[0];
|
||||||
|
|
|
@ -211,6 +211,30 @@ public class MessageControllerTest {
|
||||||
assertEquals(response.getMessages().get(1).getTimestamp(), timestampTwo);
|
assertEquals(response.getMessages().get(1).getTimestamp(), timestampTwo);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public synchronized void testGetMessagesBadAuth() throws Exception {
|
||||||
|
final long timestampOne = 313377;
|
||||||
|
final long timestampTwo = 313388;
|
||||||
|
|
||||||
|
List<OutgoingMessageEntity> messages = new LinkedList<OutgoingMessageEntity>() {{
|
||||||
|
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
|
@Test
|
||||||
public synchronized void testDeleteMessages() throws Exception {
|
public synchronized void testDeleteMessages() throws Exception {
|
||||||
long timestamp = System.currentTimeMillis();
|
long timestamp = System.currentTimeMillis();
|
||||||
|
|
|
@ -5,6 +5,7 @@ import com.google.common.util.concurrent.SettableFuture;
|
||||||
import com.google.protobuf.ByteString;
|
import com.google.protobuf.ByteString;
|
||||||
import org.eclipse.jetty.websocket.api.UpgradeRequest;
|
import org.eclipse.jetty.websocket.api.UpgradeRequest;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
import org.mockito.ArgumentMatchers;
|
||||||
import org.mockito.invocation.InvocationOnMock;
|
import org.mockito.invocation.InvocationOnMock;
|
||||||
import org.mockito.stubbing.Answer;
|
import org.mockito.stubbing.Answer;
|
||||||
import org.whispersystems.textsecuregcm.auth.AccountAuthenticator;
|
import org.whispersystems.textsecuregcm.auth.AccountAuthenticator;
|
||||||
|
@ -130,7 +131,7 @@ public class WebSocketConnectionTest {
|
||||||
final List<SettableFuture<WebSocketResponseMessage>> futures = new LinkedList<>();
|
final List<SettableFuture<WebSocketResponseMessage>> futures = new LinkedList<>();
|
||||||
final WebSocketClient client = mock(WebSocketClient.class);
|
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.<Optional<byte[]>>any()))
|
||||||
.thenAnswer(new Answer<SettableFuture<WebSocketResponseMessage>>() {
|
.thenAnswer(new Answer<SettableFuture<WebSocketResponseMessage>>() {
|
||||||
@Override
|
@Override
|
||||||
public SettableFuture<WebSocketResponseMessage> answer(InvocationOnMock invocationOnMock) throws Throwable {
|
public SettableFuture<WebSocketResponseMessage> answer(InvocationOnMock invocationOnMock) throws Throwable {
|
||||||
|
@ -145,7 +146,7 @@ public class WebSocketConnectionTest {
|
||||||
account, device, client);
|
account, device, client);
|
||||||
|
|
||||||
connection.onDispatchSubscribed(websocketAddress.serialize());
|
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.<Optional<byte[]>>any());
|
||||||
|
|
||||||
assertTrue(futures.size() == 3);
|
assertTrue(futures.size() == 3);
|
||||||
|
|
||||||
|
@ -214,7 +215,7 @@ public class WebSocketConnectionTest {
|
||||||
final List<SettableFuture<WebSocketResponseMessage>> futures = new LinkedList<>();
|
final List<SettableFuture<WebSocketResponseMessage>> futures = new LinkedList<>();
|
||||||
final WebSocketClient client = mock(WebSocketClient.class);
|
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.<Optional<byte[]>>any()))
|
||||||
.thenAnswer(new Answer<SettableFuture<WebSocketResponseMessage>>() {
|
.thenAnswer(new Answer<SettableFuture<WebSocketResponseMessage>>() {
|
||||||
@Override
|
@Override
|
||||||
public SettableFuture<WebSocketResponseMessage> answer(InvocationOnMock invocationOnMock) throws Throwable {
|
public SettableFuture<WebSocketResponseMessage> answer(InvocationOnMock invocationOnMock) throws Throwable {
|
||||||
|
@ -239,7 +240,7 @@ public class WebSocketConnectionTest {
|
||||||
.setContent(ByteString.copyFrom(secondMessage.toByteArray()))
|
.setContent(ByteString.copyFrom(secondMessage.toByteArray()))
|
||||||
.build().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.<Optional<byte[]>>any());
|
||||||
|
|
||||||
assertEquals(futures.size(), 2);
|
assertEquals(futures.size(), 2);
|
||||||
|
|
||||||
|
@ -320,7 +321,7 @@ public class WebSocketConnectionTest {
|
||||||
final List<SettableFuture<WebSocketResponseMessage>> futures = new LinkedList<>();
|
final List<SettableFuture<WebSocketResponseMessage>> futures = new LinkedList<>();
|
||||||
final WebSocketClient client = mock(WebSocketClient.class);
|
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.<Optional<byte[]>>any()))
|
||||||
.thenAnswer(new Answer<SettableFuture<WebSocketResponseMessage>>() {
|
.thenAnswer(new Answer<SettableFuture<WebSocketResponseMessage>>() {
|
||||||
@Override
|
@Override
|
||||||
public SettableFuture<WebSocketResponseMessage> answer(InvocationOnMock invocationOnMock) throws Throwable {
|
public SettableFuture<WebSocketResponseMessage> answer(InvocationOnMock invocationOnMock) throws Throwable {
|
||||||
|
@ -336,7 +337,7 @@ public class WebSocketConnectionTest {
|
||||||
|
|
||||||
connection.onDispatchSubscribed(websocketAddress.serialize());
|
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.<Optional<byte[]>>any());
|
||||||
|
|
||||||
assertEquals(futures.size(), 2);
|
assertEquals(futures.size(), 2);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue