Skip to content

Commit 2efe8ae

Browse files
committed
Update to dropwizard 1.1.0
// FREEBIE
1 parent 8b2f46f commit 2efe8ae

5 files changed

Lines changed: 50 additions & 14 deletions

File tree

pom.xml

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
<version>1.51</version>
1313

1414
<properties>
15-
<dropwizard.version>0.9.2</dropwizard.version>
16-
<jackson.api.version>2.6.0</jackson.api.version>
15+
<dropwizard.version>1.1.0</dropwizard.version>
16+
<jackson.api.version>2.8.7</jackson.api.version>
1717
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
1818
</properties>
1919

@@ -56,7 +56,7 @@
5656
<dependency>
5757
<groupId>com.dcsquare</groupId>
5858
<artifactId>dropwizard-papertrail</artifactId>
59-
<version>1.1</version>
59+
<version>1.2</version>
6060
</dependency>
6161
<dependency>
6262
<groupId>org.bouncycastle</groupId>
@@ -96,12 +96,12 @@
9696
<dependency>
9797
<groupId>org.whispersystems</groupId>
9898
<artifactId>websocket-resources</artifactId>
99-
<version>0.4.1</version>
99+
<version>0.5.0</version>
100100
</dependency>
101101
<dependency>
102102
<groupId>org.whispersystems</groupId>
103103
<artifactId>dropwizard-simpleauth</artifactId>
104-
<version>0.1.1</version>
104+
<version>0.2.0</version>
105105
</dependency>
106106

107107
<dependency>
@@ -132,6 +132,12 @@
132132
</exclusions>
133133
</dependency>
134134

135+
<dependency>
136+
<groupId>org.mockito</groupId>
137+
<artifactId>mockito-core</artifactId>
138+
<version>2.7.22</version>
139+
<scope>test</scope>
140+
</dependency>
135141

136142

137143
</dependencies>
@@ -154,6 +160,12 @@
154160
<artifactId>jackson-databind</artifactId>
155161
<version>${jackson.api.version}</version>
156162
</dependency>
163+
164+
<dependency>
165+
<groupId>io.dropwizard</groupId>
166+
<artifactId>dropwizard-core</artifactId>
167+
<version>1.1.0</version>
168+
</dependency>
157169
</dependencies>
158170
</dependencyManagement>
159171

src/test/java/org/whispersystems/textsecuregcm/tests/controllers/DeviceControllerTest.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@
4444
import java.util.Map;
4545
import java.util.concurrent.TimeUnit;
4646

47-
import io.dropwizard.jersey.validation.ConstraintViolationExceptionMapper;
4847
import io.dropwizard.testing.junit.ResourceTestRule;
4948
import static org.assertj.core.api.Assertions.assertThat;
5049
import static org.junit.Assert.assertEquals;
@@ -86,7 +85,6 @@ protected VerificationCode generateVerificationCode() {
8685
.addProvider(new AuthValueFactoryProvider.Binder())
8786
.setTestContainerFactory(new GrizzlyWebTestContainerFactory())
8887
.addProvider(new DeviceLimitExceededExceptionMapper())
89-
.addProvider(new ConstraintViolationExceptionMapper())
9088
.addResource(new DumbVerificationDeviceController(pendingDevicesManager,
9189
accountsManager,
9290
messagesManager,

src/test/java/org/whispersystems/textsecuregcm/tests/controllers/DirectoryControllerTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
import io.dropwizard.testing.junit.ResourceTestRule;
2525
import static org.assertj.core.api.Assertions.assertThat;
26+
import static org.mockito.ArgumentMatchers.anyListOf;
2627
import static org.mockito.Matchers.anyList;
2728
import static org.mockito.Mockito.mock;
2829
import static org.mockito.Mockito.when;
@@ -46,7 +47,7 @@ public class DirectoryControllerTest {
4647
@Before
4748
public void setup() throws Exception {
4849
when(rateLimiters.getContactsLimiter()).thenReturn(rateLimiter);
49-
when(directoryManager.get(anyList())).thenAnswer(new Answer<List<byte[]>>() {
50+
when(directoryManager.get(anyListOf(byte[].class))).thenAnswer(new Answer<List<byte[]>>() {
5051
@Override
5152
public List<byte[]> answer(InvocationOnMock invocationOnMock) throws Throwable {
5253
List<byte[]> query = (List<byte[]>) invocationOnMock.getArguments()[0];

src/test/java/org/whispersystems/textsecuregcm/tests/controllers/MessageControllerTest.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,30 @@ public synchronized void testGetMessages() throws Exception {
211211
assertEquals(response.getMessages().get(1).getTimestamp(), timestampTwo);
212212
}
213213

214+
@Test
215+
public synchronized void testGetMessagesBadAuth() throws Exception {
216+
final long timestampOne = 313377;
217+
final long timestampTwo = 313388;
218+
219+
List<OutgoingMessageEntity> messages = new LinkedList<OutgoingMessageEntity>() {{
220+
add(new OutgoingMessageEntity(1L, Envelope.Type.CIPHERTEXT_VALUE, null, timestampOne, "+14152222222", 2, "hi there".getBytes(), null));
221+
add(new OutgoingMessageEntity(2L, Envelope.Type.RECEIPT_VALUE, null, timestampTwo, "+14152222222", 2, null, null));
222+
}};
223+
224+
OutgoingMessageEntityList messagesList = new OutgoingMessageEntityList(messages, false);
225+
226+
when(messagesManager.getMessagesForDevice(eq(AuthHelper.VALID_NUMBER), eq(1L))).thenReturn(messagesList);
227+
228+
Response response =
229+
resources.getJerseyTest().target("/v1/messages/")
230+
.request()
231+
.header("Authorization", AuthHelper.getAuthHeader(AuthHelper.VALID_NUMBER, AuthHelper.INVALID_PASSWORD))
232+
.accept(MediaType.APPLICATION_JSON_TYPE)
233+
.get();
234+
235+
assertThat("Unauthorized response", response.getStatus(), is(equalTo(401)));
236+
}
237+
214238
@Test
215239
public synchronized void testDeleteMessages() throws Exception {
216240
long timestamp = System.currentTimeMillis();

src/test/java/org/whispersystems/textsecuregcm/tests/websocket/WebSocketConnectionTest.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import com.google.protobuf.ByteString;
66
import org.eclipse.jetty.websocket.api.UpgradeRequest;
77
import org.junit.Test;
8+
import org.mockito.ArgumentMatchers;
89
import org.mockito.invocation.InvocationOnMock;
910
import org.mockito.stubbing.Answer;
1011
import org.whispersystems.textsecuregcm.auth.AccountAuthenticator;
@@ -130,7 +131,7 @@ public void testOpen() throws Exception {
130131
final List<SettableFuture<WebSocketResponseMessage>> futures = new LinkedList<>();
131132
final WebSocketClient client = mock(WebSocketClient.class);
132133

133-
when(client.sendRequest(eq("PUT"), eq("/api/v1/message"), any(List.class), any(Optional.class)))
134+
when(client.sendRequest(eq("PUT"), eq("/api/v1/message"), ArgumentMatchers.nullable(List.class), ArgumentMatchers.<Optional<byte[]>>any()))
134135
.thenAnswer(new Answer<SettableFuture<WebSocketResponseMessage>>() {
135136
@Override
136137
public SettableFuture<WebSocketResponseMessage> answer(InvocationOnMock invocationOnMock) throws Throwable {
@@ -145,7 +146,7 @@ public SettableFuture<WebSocketResponseMessage> answer(InvocationOnMock invocati
145146
account, device, client);
146147

147148
connection.onDispatchSubscribed(websocketAddress.serialize());
148-
verify(client, times(3)).sendRequest(eq("PUT"), eq("/api/v1/message"), anyList(), any(Optional.class));
149+
verify(client, times(3)).sendRequest(eq("PUT"), eq("/api/v1/message"), ArgumentMatchers.nullable(List.class), ArgumentMatchers.<Optional<byte[]>>any());
149150

150151
assertTrue(futures.size() == 3);
151152

@@ -214,7 +215,7 @@ public void testOnlineSend() throws Exception {
214215
final List<SettableFuture<WebSocketResponseMessage>> futures = new LinkedList<>();
215216
final WebSocketClient client = mock(WebSocketClient.class);
216217

217-
when(client.sendRequest(eq("PUT"), eq("/api/v1/message"), anyList(), any(Optional.class)))
218+
when(client.sendRequest(eq("PUT"), eq("/api/v1/message"), ArgumentMatchers.nullable(List.class), ArgumentMatchers.<Optional<byte[]>>any()))
218219
.thenAnswer(new Answer<SettableFuture<WebSocketResponseMessage>>() {
219220
@Override
220221
public SettableFuture<WebSocketResponseMessage> answer(InvocationOnMock invocationOnMock) throws Throwable {
@@ -239,7 +240,7 @@ public SettableFuture<WebSocketResponseMessage> answer(InvocationOnMock invocati
239240
.setContent(ByteString.copyFrom(secondMessage.toByteArray()))
240241
.build().toByteArray());
241242

242-
verify(client, times(2)).sendRequest(eq("PUT"), eq("/api/v1/message"), anyList(), any(Optional.class));
243+
verify(client, times(2)).sendRequest(eq("PUT"), eq("/api/v1/message"), ArgumentMatchers.nullable(List.class), ArgumentMatchers.<Optional<byte[]>>any());
243244

244245
assertEquals(futures.size(), 2);
245246

@@ -320,7 +321,7 @@ public void testPendingSend() throws Exception {
320321
final List<SettableFuture<WebSocketResponseMessage>> futures = new LinkedList<>();
321322
final WebSocketClient client = mock(WebSocketClient.class);
322323

323-
when(client.sendRequest(eq("PUT"), eq("/api/v1/message"), anyList(), any(Optional.class)))
324+
when(client.sendRequest(eq("PUT"), eq("/api/v1/message"), ArgumentMatchers.nullable(List.class), ArgumentMatchers.<Optional<byte[]>>any()))
324325
.thenAnswer(new Answer<SettableFuture<WebSocketResponseMessage>>() {
325326
@Override
326327
public SettableFuture<WebSocketResponseMessage> answer(InvocationOnMock invocationOnMock) throws Throwable {
@@ -336,7 +337,7 @@ public SettableFuture<WebSocketResponseMessage> answer(InvocationOnMock invocati
336337

337338
connection.onDispatchSubscribed(websocketAddress.serialize());
338339

339-
verify(client, times(2)).sendRequest(eq("PUT"), eq("/api/v1/message"), anyList(), any(Optional.class));
340+
verify(client, times(2)).sendRequest(eq("PUT"), eq("/api/v1/message"), ArgumentMatchers.nullable(List.class), ArgumentMatchers.<Optional<byte[]>>any());
340341

341342
assertEquals(futures.size(), 2);
342343

0 commit comments

Comments
 (0)