mirror of
https://github.com/signalapp/Signal-Server
synced 2026-04-22 22:58:06 +01:00
Upgrade to dropwizard 3.0
This commit is contained in:
@@ -19,7 +19,6 @@ import static org.mockito.Mockito.when;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.protobuf.InvalidProtocolBufferException;
|
||||
import io.dropwizard.auth.Auth;
|
||||
import io.dropwizard.auth.PolymorphicAuthDynamicFeature;
|
||||
import io.dropwizard.auth.PolymorphicAuthValueFactoryProvider;
|
||||
@@ -28,9 +27,11 @@ import io.dropwizard.jersey.DropwizardResourceConfig;
|
||||
import io.dropwizard.jersey.jackson.JacksonMessageBodyProvider;
|
||||
import io.dropwizard.testing.junit5.DropwizardExtensionsSupport;
|
||||
import io.dropwizard.testing.junit5.ResourceExtension;
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.Principal;
|
||||
import java.time.Duration;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Base64;
|
||||
@@ -57,6 +58,7 @@ import javax.ws.rs.core.Response;
|
||||
import org.eclipse.jetty.websocket.api.RemoteEndpoint;
|
||||
import org.eclipse.jetty.websocket.api.Session;
|
||||
import org.eclipse.jetty.websocket.api.UpgradeRequest;
|
||||
import org.eclipse.jetty.websocket.api.WriteCallback;
|
||||
import org.glassfish.jersey.server.ApplicationHandler;
|
||||
import org.glassfish.jersey.server.ResourceConfig;
|
||||
import org.glassfish.jersey.server.monitoring.ApplicationEventListener;
|
||||
@@ -337,7 +339,7 @@ class AuthEnablementRefreshRequirementProviderTest {
|
||||
|
||||
provider = new WebSocketResourceProvider<>("127.0.0.1", applicationHandler,
|
||||
requestLog, new TestPrincipal("test", account, authenticatedDevice), new ProtobufWebSocketMessageFactory(),
|
||||
Optional.empty(), 30000);
|
||||
Optional.empty(), Duration.ofMillis(30000));
|
||||
|
||||
remoteEndpoint = mock(RemoteEndpoint.class);
|
||||
Session session = mock(Session.class);
|
||||
@@ -363,9 +365,9 @@ class AuthEnablementRefreshRequirementProviderTest {
|
||||
}
|
||||
|
||||
private SubProtocol.WebSocketResponseMessage verifyAndGetResponse(final RemoteEndpoint remoteEndpoint)
|
||||
throws InvalidProtocolBufferException {
|
||||
throws IOException {
|
||||
ArgumentCaptor<ByteBuffer> responseBytesCaptor = ArgumentCaptor.forClass(ByteBuffer.class);
|
||||
verify(remoteEndpoint).sendBytesByFuture(responseBytesCaptor.capture());
|
||||
verify(remoteEndpoint).sendBytes(responseBytesCaptor.capture(), any(WriteCallback.class));
|
||||
|
||||
return SubProtocol.WebSocketMessage.parseFrom(responseBytesCaptor.getValue().array()).getResponse();
|
||||
}
|
||||
|
||||
@@ -22,8 +22,10 @@ import io.dropwizard.jersey.jackson.JacksonMessageBodyProvider;
|
||||
import io.micrometer.core.instrument.Counter;
|
||||
import io.micrometer.core.instrument.MeterRegistry;
|
||||
import io.micrometer.core.instrument.Tag;
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.security.Principal;
|
||||
import java.time.Duration;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedList;
|
||||
@@ -36,6 +38,7 @@ import javax.ws.rs.Path;
|
||||
import org.eclipse.jetty.websocket.api.RemoteEndpoint;
|
||||
import org.eclipse.jetty.websocket.api.Session;
|
||||
import org.eclipse.jetty.websocket.api.UpgradeRequest;
|
||||
import org.eclipse.jetty.websocket.api.WriteCallback;
|
||||
import org.glassfish.jersey.server.ApplicationHandler;
|
||||
import org.glassfish.jersey.server.ContainerRequest;
|
||||
import org.glassfish.jersey.server.ContainerResponse;
|
||||
@@ -121,7 +124,7 @@ class MetricsRequestEventListenerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testActualRouteMessageSuccess() throws InvalidProtocolBufferException {
|
||||
void testActualRouteMessageSuccess() throws IOException {
|
||||
final MetricsApplicationEventListener applicationEventListener = mock(MetricsApplicationEventListener.class);
|
||||
when(applicationEventListener.onRequest(any())).thenReturn(listener);
|
||||
|
||||
@@ -140,7 +143,7 @@ class MetricsRequestEventListenerTest {
|
||||
new TestPrincipal("foo"),
|
||||
new ProtobufWebSocketMessageFactory(),
|
||||
Optional.empty(),
|
||||
30000);
|
||||
Duration.ofMillis(30000));
|
||||
|
||||
final Session session = mock(Session.class);
|
||||
final RemoteEndpoint remoteEndpoint = mock(RemoteEndpoint.class);
|
||||
@@ -163,7 +166,7 @@ class MetricsRequestEventListenerTest {
|
||||
provider.onWebSocketBinary(message, 0, message.length);
|
||||
|
||||
final ArgumentCaptor<ByteBuffer> responseBytesCaptor = ArgumentCaptor.forClass(ByteBuffer.class);
|
||||
verify(remoteEndpoint).sendBytesByFuture(responseBytesCaptor.capture());
|
||||
verify(remoteEndpoint).sendBytes(responseBytesCaptor.capture(), any(WriteCallback.class));
|
||||
|
||||
SubProtocol.WebSocketResponseMessage response = getResponse(responseBytesCaptor);
|
||||
|
||||
@@ -187,7 +190,7 @@ class MetricsRequestEventListenerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testActualRouteMessageSuccessNoUserAgent() throws InvalidProtocolBufferException {
|
||||
void testActualRouteMessageSuccessNoUserAgent() throws IOException {
|
||||
final MetricsApplicationEventListener applicationEventListener = mock(MetricsApplicationEventListener.class);
|
||||
when(applicationEventListener.onRequest(any())).thenReturn(listener);
|
||||
|
||||
@@ -200,8 +203,10 @@ class MetricsRequestEventListenerTest {
|
||||
|
||||
final ApplicationHandler applicationHandler = new ApplicationHandler(resourceConfig);
|
||||
final WebsocketRequestLog requestLog = mock(WebsocketRequestLog.class);
|
||||
final WebSocketResourceProvider<TestPrincipal> provider = new WebSocketResourceProvider<>("127.0.0.1", applicationHandler,
|
||||
requestLog, new TestPrincipal("foo"), new ProtobufWebSocketMessageFactory(), Optional.empty(), 30000);
|
||||
final WebSocketResourceProvider<TestPrincipal> provider = new WebSocketResourceProvider<>("127.0.0.1",
|
||||
applicationHandler,
|
||||
requestLog, new TestPrincipal("foo"), new ProtobufWebSocketMessageFactory(), Optional.empty(),
|
||||
Duration.ofMillis(30000));
|
||||
|
||||
final Session session = mock(Session.class);
|
||||
final RemoteEndpoint remoteEndpoint = mock(RemoteEndpoint.class);
|
||||
@@ -222,7 +227,7 @@ class MetricsRequestEventListenerTest {
|
||||
provider.onWebSocketBinary(message, 0, message.length);
|
||||
|
||||
final ArgumentCaptor<ByteBuffer> responseBytesCaptor = ArgumentCaptor.forClass(ByteBuffer.class);
|
||||
verify(remoteEndpoint).sendBytesByFuture(responseBytesCaptor.capture());
|
||||
verify(remoteEndpoint).sendBytes(responseBytesCaptor.capture(), any(WriteCallback.class));
|
||||
|
||||
SubProtocol.WebSocketResponseMessage response = getResponse(responseBytesCaptor);
|
||||
|
||||
|
||||
@@ -137,7 +137,7 @@ class AccountsManagerTest {
|
||||
|
||||
//noinspection unchecked
|
||||
asyncCommands = mock(RedisAdvancedClusterAsyncCommands.class);
|
||||
when(asyncCommands.del(any())).thenReturn(MockRedisFuture.completedFuture(0L));
|
||||
when(asyncCommands.del(any(String[].class))).thenReturn(MockRedisFuture.completedFuture(0L));
|
||||
when(asyncCommands.get(any())).thenReturn(MockRedisFuture.completedFuture(null));
|
||||
when(asyncCommands.setex(any(), anyLong(), any())).thenReturn(MockRedisFuture.completedFuture("OK"));
|
||||
|
||||
|
||||
@@ -679,7 +679,7 @@ class MessagesCacheTest {
|
||||
pages.add(generatePage());
|
||||
pages.add(generateStaleEphemeralPage());
|
||||
|
||||
when(reactiveCommands.evalsha(any(), any(), any(), any()))
|
||||
when(reactiveCommands.evalsha(any(), any(), any(byte[][].class), any(byte[][].class)))
|
||||
.thenReturn(Flux.just(pages.pop()))
|
||||
.thenReturn(Flux.just(pages.pop()))
|
||||
.thenReturn(Flux.just(pages.pop()))
|
||||
@@ -688,7 +688,7 @@ class MessagesCacheTest {
|
||||
final AsyncCommand<?, ?, ?> removeSuccess = new AsyncCommand<>(mock(RedisCommand.class));
|
||||
removeSuccess.complete();
|
||||
|
||||
when(asyncCommands.evalsha(any(), any(), any(), any()))
|
||||
when(asyncCommands.evalsha(any(), any(), any(byte[][].class), any(byte[][].class)))
|
||||
.thenReturn((RedisFuture) removeSuccess);
|
||||
|
||||
final Publisher<?> allMessages = messagesCache.get(UUID.randomUUID(), Device.PRIMARY_ID);
|
||||
@@ -696,9 +696,9 @@ class MessagesCacheTest {
|
||||
StepVerifier.setDefaultTimeout(Duration.ofSeconds(5));
|
||||
|
||||
// async commands are used for remove(), and nothing should happen until we are subscribed
|
||||
verify(asyncCommands, never()).evalsha(any(), any(), any(byte[][].class), any(byte[].class));
|
||||
verify(asyncCommands, never()).evalsha(any(), any(), any(byte[][].class), any(byte[][].class));
|
||||
// the reactive commands will be called once, to prep the first page fetch (but no remote request would actually be sent)
|
||||
verify(reactiveCommands, times(1)).evalsha(any(), any(), any(byte[][].class), any(byte[].class));
|
||||
verify(reactiveCommands, times(1)).evalsha(any(), any(), any(byte[][].class), any(byte[][].class));
|
||||
|
||||
StepVerifier.create(allMessages)
|
||||
.expectSubscription()
|
||||
@@ -708,7 +708,7 @@ class MessagesCacheTest {
|
||||
.verify();
|
||||
|
||||
assertTrue(pages.isEmpty());
|
||||
verify(asyncCommands, atLeast(1)).evalsha(any(), any(), any(), any());
|
||||
verify(asyncCommands, atLeast(1)).evalsha(any(), any(), any(byte[][].class), any(byte[][].class));
|
||||
}
|
||||
|
||||
private List<byte[]> generatePage() {
|
||||
|
||||
@@ -5,12 +5,11 @@
|
||||
|
||||
package org.whispersystems.textsecuregcm.tests.util;
|
||||
|
||||
import static io.dropwizard.testing.FixtureHelpers.fixture;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import java.io.IOException;
|
||||
import io.dropwizard.util.Resources;
|
||||
import org.whispersystems.textsecuregcm.util.SystemMapper;
|
||||
|
||||
public class JsonHelpers {
|
||||
@@ -26,6 +25,7 @@ public class JsonHelpers {
|
||||
}
|
||||
|
||||
public static String jsonFixture(String filename) throws IOException {
|
||||
return objectMapper.writeValueAsString(objectMapper.readValue(fixture(filename), JsonNode.class));
|
||||
return objectMapper.writeValueAsString(
|
||||
objectMapper.readValue(Resources.getResource(filename), JsonNode.class));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,24 +50,6 @@ public class RedisClusterHelper {
|
||||
return null;
|
||||
}).when(cluster).useCluster(any(Consumer.class));
|
||||
|
||||
when(cluster.withCluster(any(Function.class))).thenAnswer(invocation -> {
|
||||
return invocation.getArgument(0, Function.class).apply(stringConnection);
|
||||
});
|
||||
|
||||
doAnswer(invocation -> {
|
||||
invocation.getArgument(0, Consumer.class).accept(stringConnection);
|
||||
return null;
|
||||
}).when(cluster).useCluster(any(Consumer.class));
|
||||
|
||||
when(cluster.withBinaryCluster(any(Function.class))).thenAnswer(invocation -> {
|
||||
return invocation.getArgument(0, Function.class).apply(binaryConnection);
|
||||
});
|
||||
|
||||
doAnswer(invocation -> {
|
||||
invocation.getArgument(0, Consumer.class).accept(binaryConnection);
|
||||
return null;
|
||||
}).when(cluster).useBinaryCluster(any(Consumer.class));
|
||||
|
||||
when(cluster.withBinaryCluster(any(Function.class))).thenAnswer(invocation -> {
|
||||
return invocation.getArgument(0, Function.class).apply(binaryConnection);
|
||||
});
|
||||
|
||||
@@ -7,6 +7,7 @@ package org.whispersystems.textsecuregcm.util.logging;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.matches;
|
||||
import static org.mockito.Mockito.doAnswer;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.reset;
|
||||
import static org.mockito.Mockito.spy;
|
||||
@@ -20,8 +21,10 @@ import io.dropwizard.jersey.DropwizardResourceConfig;
|
||||
import io.dropwizard.jersey.jackson.JacksonMessageBodyProvider;
|
||||
import io.dropwizard.testing.junit5.DropwizardExtensionsSupport;
|
||||
import io.dropwizard.testing.junit5.ResourceExtension;
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.security.Principal;
|
||||
import java.time.Duration;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -40,6 +43,7 @@ import javax.ws.rs.core.Response;
|
||||
import org.eclipse.jetty.websocket.api.RemoteEndpoint;
|
||||
import org.eclipse.jetty.websocket.api.Session;
|
||||
import org.eclipse.jetty.websocket.api.UpgradeRequest;
|
||||
import org.eclipse.jetty.websocket.api.WriteCallback;
|
||||
import org.glassfish.jersey.server.ApplicationHandler;
|
||||
import org.glassfish.jersey.server.ResourceConfig;
|
||||
import org.glassfish.jersey.server.ServerProperties;
|
||||
@@ -159,7 +163,7 @@ class LoggingUnhandledExceptionMapperTest {
|
||||
}
|
||||
|
||||
private WebSocketResourceProvider<TestPrincipal> createWebsocketProvider(final String userAgentHeader,
|
||||
final Session session, final Consumer<ByteBuffer> responseHandler) {
|
||||
final Session session, final Consumer<ByteBuffer> responseHandler) throws IOException {
|
||||
ResourceConfig resourceConfig = new DropwizardResourceConfig();
|
||||
resourceConfig.register(exceptionMapper);
|
||||
resourceConfig.register(new TestController());
|
||||
@@ -170,14 +174,14 @@ class LoggingUnhandledExceptionMapperTest {
|
||||
ApplicationHandler applicationHandler = new ApplicationHandler(resourceConfig);
|
||||
WebsocketRequestLog requestLog = mock(WebsocketRequestLog.class);
|
||||
WebSocketResourceProvider<TestPrincipal> provider = new WebSocketResourceProvider<>("127.0.0.1", applicationHandler,
|
||||
requestLog, new TestPrincipal("foo"), new ProtobufWebSocketMessageFactory(), Optional.empty(), 30000);
|
||||
requestLog, new TestPrincipal("foo"), new ProtobufWebSocketMessageFactory(), Optional.empty(),
|
||||
Duration.ofMillis(30000));
|
||||
|
||||
RemoteEndpoint remoteEndpoint = mock(RemoteEndpoint.class);
|
||||
when(remoteEndpoint.sendBytesByFuture(any()))
|
||||
.thenAnswer(answer -> {
|
||||
responseHandler.accept(answer.getArgument(0, ByteBuffer.class));
|
||||
return CompletableFuture.completedFuture(null);
|
||||
});
|
||||
doAnswer(answer -> {
|
||||
responseHandler.accept(answer.getArgument(0, ByteBuffer.class));
|
||||
return null;
|
||||
}).when(remoteEndpoint).sendBytes(any(), any(WriteCallback.class));
|
||||
UpgradeRequest request = mock(UpgradeRequest.class);
|
||||
|
||||
when(session.getUpgradeRequest()).thenReturn(request);
|
||||
|
||||
Reference in New Issue
Block a user