Rename `ClientConnectionManager` to `GrpcClientConnectionManager`

This commit is contained in:
Jon Chambers 2024-11-10 10:49:39 -05:00 committed by Jon Chambers
parent a843f1af6c
commit 1323b42169
16 changed files with 115 additions and 117 deletions

View File

@ -155,7 +155,7 @@ import org.whispersystems.textsecuregcm.grpc.PaymentsGrpcService;
import org.whispersystems.textsecuregcm.grpc.ProfileAnonymousGrpcService; import org.whispersystems.textsecuregcm.grpc.ProfileAnonymousGrpcService;
import org.whispersystems.textsecuregcm.grpc.ProfileGrpcService; import org.whispersystems.textsecuregcm.grpc.ProfileGrpcService;
import org.whispersystems.textsecuregcm.grpc.RequestAttributesInterceptor; import org.whispersystems.textsecuregcm.grpc.RequestAttributesInterceptor;
import org.whispersystems.textsecuregcm.grpc.net.ClientConnectionManager; import org.whispersystems.textsecuregcm.grpc.net.GrpcClientConnectionManager;
import org.whispersystems.textsecuregcm.grpc.net.ManagedDefaultEventLoopGroup; import org.whispersystems.textsecuregcm.grpc.net.ManagedDefaultEventLoopGroup;
import org.whispersystems.textsecuregcm.grpc.net.ManagedLocalGrpcServer; import org.whispersystems.textsecuregcm.grpc.net.ManagedLocalGrpcServer;
import org.whispersystems.textsecuregcm.grpc.net.ManagedNioEventLoopGroup; import org.whispersystems.textsecuregcm.grpc.net.ManagedNioEventLoopGroup;
@ -820,7 +820,7 @@ public class WhisperServerService extends Application<WhisperServerConfiguration
false false
); );
final ClientConnectionManager clientConnectionManager = new ClientConnectionManager(); final GrpcClientConnectionManager grpcClientConnectionManager = new GrpcClientConnectionManager();
final ManagedDefaultEventLoopGroup localEventLoopGroup = new ManagedDefaultEventLoopGroup(); final ManagedDefaultEventLoopGroup localEventLoopGroup = new ManagedDefaultEventLoopGroup();
@ -830,7 +830,7 @@ public class WhisperServerService extends Application<WhisperServerConfiguration
final ErrorMappingInterceptor errorMappingInterceptor = new ErrorMappingInterceptor(); final ErrorMappingInterceptor errorMappingInterceptor = new ErrorMappingInterceptor();
final RequestAttributesInterceptor requestAttributesInterceptor = final RequestAttributesInterceptor requestAttributesInterceptor =
new RequestAttributesInterceptor(clientConnectionManager); new RequestAttributesInterceptor(grpcClientConnectionManager);
final LocalAddress anonymousGrpcServerAddress = new LocalAddress("grpc-anonymous"); final LocalAddress anonymousGrpcServerAddress = new LocalAddress("grpc-anonymous");
final LocalAddress authenticatedGrpcServerAddress = new LocalAddress("grpc-authenticated"); final LocalAddress authenticatedGrpcServerAddress = new LocalAddress("grpc-authenticated");
@ -850,7 +850,7 @@ public class WhisperServerService extends Application<WhisperServerConfiguration
.intercept(errorMappingInterceptor) .intercept(errorMappingInterceptor)
.intercept(remoteDeprecationFilter) .intercept(remoteDeprecationFilter)
.intercept(requestAttributesInterceptor) .intercept(requestAttributesInterceptor)
.intercept(new ProhibitAuthenticationInterceptor(clientConnectionManager)) .intercept(new ProhibitAuthenticationInterceptor(grpcClientConnectionManager))
.addService(new AccountsAnonymousGrpcService(accountsManager, rateLimiters)) .addService(new AccountsAnonymousGrpcService(accountsManager, rateLimiters))
.addService(new KeysAnonymousGrpcService(accountsManager, keysManager, zkSecretParams, Clock.systemUTC())) .addService(new KeysAnonymousGrpcService(accountsManager, keysManager, zkSecretParams, Clock.systemUTC()))
.addService(new PaymentsGrpcService(currencyManager)) .addService(new PaymentsGrpcService(currencyManager))
@ -871,7 +871,7 @@ public class WhisperServerService extends Application<WhisperServerConfiguration
.intercept(errorMappingInterceptor) .intercept(errorMappingInterceptor)
.intercept(remoteDeprecationFilter) .intercept(remoteDeprecationFilter)
.intercept(requestAttributesInterceptor) .intercept(requestAttributesInterceptor)
.intercept(new RequireAuthenticationInterceptor(clientConnectionManager)) .intercept(new RequireAuthenticationInterceptor(grpcClientConnectionManager))
.addService(new AccountsGrpcService(accountsManager, rateLimiters, usernameHashZkProofVerifier, registrationRecoveryPasswordsManager)) .addService(new AccountsGrpcService(accountsManager, rateLimiters, usernameHashZkProofVerifier, registrationRecoveryPasswordsManager))
.addService(ExternalServiceCredentialsGrpcService.createForAllExternalServices(config, rateLimiters)) .addService(ExternalServiceCredentialsGrpcService.createForAllExternalServices(config, rateLimiters))
.addService(new KeysGrpcService(accountsManager, keysManager, rateLimiters)) .addService(new KeysGrpcService(accountsManager, keysManager, rateLimiters))
@ -919,7 +919,7 @@ public class WhisperServerService extends Application<WhisperServerConfiguration
noiseWebSocketTlsPrivateKey, noiseWebSocketTlsPrivateKey,
noiseWebSocketEventLoopGroup, noiseWebSocketEventLoopGroup,
noiseWebSocketDelegatedTaskExecutor, noiseWebSocketDelegatedTaskExecutor,
clientConnectionManager, grpcClientConnectionManager,
clientPublicKeysManager, clientPublicKeysManager,
config.getNoiseWebSocketTunnelConfiguration().noiseStaticKeyPair(), config.getNoiseWebSocketTunnelConfiguration().noiseStaticKeyPair(),
authenticatedGrpcServerAddress, authenticatedGrpcServerAddress,

View File

@ -6,22 +6,22 @@ import io.grpc.ServerCall;
import io.grpc.ServerInterceptor; import io.grpc.ServerInterceptor;
import io.grpc.Status; import io.grpc.Status;
import io.netty.channel.local.LocalAddress; import io.netty.channel.local.LocalAddress;
import org.whispersystems.textsecuregcm.grpc.net.ClientConnectionManager; import org.whispersystems.textsecuregcm.grpc.net.GrpcClientConnectionManager;
import java.util.Optional; import java.util.Optional;
abstract class AbstractAuthenticationInterceptor implements ServerInterceptor { abstract class AbstractAuthenticationInterceptor implements ServerInterceptor {
private final ClientConnectionManager clientConnectionManager; private final GrpcClientConnectionManager grpcClientConnectionManager;
private static final Metadata EMPTY_TRAILERS = new Metadata(); private static final Metadata EMPTY_TRAILERS = new Metadata();
AbstractAuthenticationInterceptor(final ClientConnectionManager clientConnectionManager) { AbstractAuthenticationInterceptor(final GrpcClientConnectionManager grpcClientConnectionManager) {
this.clientConnectionManager = clientConnectionManager; this.grpcClientConnectionManager = grpcClientConnectionManager;
} }
protected Optional<AuthenticatedDevice> getAuthenticatedDevice(final ServerCall<?, ?> call) { protected Optional<AuthenticatedDevice> getAuthenticatedDevice(final ServerCall<?, ?> call) {
if (call.getAttributes().get(Grpc.TRANSPORT_ATTR_REMOTE_ADDR) instanceof LocalAddress localAddress) { if (call.getAttributes().get(Grpc.TRANSPORT_ATTR_REMOTE_ADDR) instanceof LocalAddress localAddress) {
return clientConnectionManager.getAuthenticatedDevice(localAddress); return grpcClientConnectionManager.getAuthenticatedDevice(localAddress);
} else { } else {
throw new AssertionError("Unexpected channel type: " + call.getAttributes().get(Grpc.TRANSPORT_ATTR_REMOTE_ADDR)); throw new AssertionError("Unexpected channel type: " + call.getAttributes().get(Grpc.TRANSPORT_ATTR_REMOTE_ADDR));
} }

View File

@ -3,7 +3,7 @@ package org.whispersystems.textsecuregcm.auth.grpc;
import io.grpc.Metadata; import io.grpc.Metadata;
import io.grpc.ServerCall; import io.grpc.ServerCall;
import io.grpc.ServerCallHandler; import io.grpc.ServerCallHandler;
import org.whispersystems.textsecuregcm.grpc.net.ClientConnectionManager; import org.whispersystems.textsecuregcm.grpc.net.GrpcClientConnectionManager;
/** /**
* A "prohibit authentication" interceptor ensures that requests to endpoints that should be invoked anonymously do not * A "prohibit authentication" interceptor ensures that requests to endpoints that should be invoked anonymously do not
@ -12,8 +12,8 @@ import org.whispersystems.textsecuregcm.grpc.net.ClientConnectionManager;
*/ */
public class ProhibitAuthenticationInterceptor extends AbstractAuthenticationInterceptor { public class ProhibitAuthenticationInterceptor extends AbstractAuthenticationInterceptor {
public ProhibitAuthenticationInterceptor(final ClientConnectionManager clientConnectionManager) { public ProhibitAuthenticationInterceptor(final GrpcClientConnectionManager grpcClientConnectionManager) {
super(clientConnectionManager); super(grpcClientConnectionManager);
} }
@Override @Override

View File

@ -5,7 +5,7 @@ import io.grpc.Contexts;
import io.grpc.Metadata; import io.grpc.Metadata;
import io.grpc.ServerCall; import io.grpc.ServerCall;
import io.grpc.ServerCallHandler; import io.grpc.ServerCallHandler;
import org.whispersystems.textsecuregcm.grpc.net.ClientConnectionManager; import org.whispersystems.textsecuregcm.grpc.net.GrpcClientConnectionManager;
/** /**
* A "require authentication" interceptor requires that requests be issued from a connection that is associated with an * A "require authentication" interceptor requires that requests be issued from a connection that is associated with an
@ -14,8 +14,8 @@ import org.whispersystems.textsecuregcm.grpc.net.ClientConnectionManager;
*/ */
public class RequireAuthenticationInterceptor extends AbstractAuthenticationInterceptor { public class RequireAuthenticationInterceptor extends AbstractAuthenticationInterceptor {
public RequireAuthenticationInterceptor(final ClientConnectionManager clientConnectionManager) { public RequireAuthenticationInterceptor(final GrpcClientConnectionManager grpcClientConnectionManager) {
super(clientConnectionManager); super(grpcClientConnectionManager);
} }
@Override @Override

View File

@ -11,7 +11,7 @@ import io.grpc.Status;
import io.netty.channel.local.LocalAddress; import io.netty.channel.local.LocalAddress;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.whispersystems.textsecuregcm.grpc.net.ClientConnectionManager; import org.whispersystems.textsecuregcm.grpc.net.GrpcClientConnectionManager;
import org.whispersystems.textsecuregcm.util.ua.UserAgent; import org.whispersystems.textsecuregcm.util.ua.UserAgent;
import java.net.InetAddress; import java.net.InetAddress;
import java.util.List; import java.util.List;
@ -20,12 +20,12 @@ import java.util.Optional;
public class RequestAttributesInterceptor implements ServerInterceptor { public class RequestAttributesInterceptor implements ServerInterceptor {
private final ClientConnectionManager clientConnectionManager; private final GrpcClientConnectionManager grpcClientConnectionManager;
private static final Logger log = LoggerFactory.getLogger(RequestAttributesInterceptor.class); private static final Logger log = LoggerFactory.getLogger(RequestAttributesInterceptor.class);
public RequestAttributesInterceptor(final ClientConnectionManager clientConnectionManager) { public RequestAttributesInterceptor(final GrpcClientConnectionManager grpcClientConnectionManager) {
this.clientConnectionManager = clientConnectionManager; this.grpcClientConnectionManager = grpcClientConnectionManager;
} }
@Override @Override
@ -37,7 +37,7 @@ public class RequestAttributesInterceptor implements ServerInterceptor {
Context context = Context.current(); Context context = Context.current();
{ {
final Optional<InetAddress> maybeRemoteAddress = clientConnectionManager.getRemoteAddress(localAddress); final Optional<InetAddress> maybeRemoteAddress = grpcClientConnectionManager.getRemoteAddress(localAddress);
if (maybeRemoteAddress.isEmpty()) { if (maybeRemoteAddress.isEmpty()) {
// We should never have a call from a party whose remote address we can't identify // We should never have a call from a party whose remote address we can't identify
@ -52,7 +52,7 @@ public class RequestAttributesInterceptor implements ServerInterceptor {
{ {
final Optional<List<Locale.LanguageRange>> maybeAcceptLanguage = final Optional<List<Locale.LanguageRange>> maybeAcceptLanguage =
clientConnectionManager.getAcceptableLanguages(localAddress); grpcClientConnectionManager.getAcceptableLanguages(localAddress);
if (maybeAcceptLanguage.isPresent()) { if (maybeAcceptLanguage.isPresent()) {
context = context.withValue(RequestAttributesUtil.ACCEPT_LANGUAGE_CONTEXT_KEY, maybeAcceptLanguage.get()); context = context.withValue(RequestAttributesUtil.ACCEPT_LANGUAGE_CONTEXT_KEY, maybeAcceptLanguage.get());
@ -60,7 +60,7 @@ public class RequestAttributesInterceptor implements ServerInterceptor {
} }
{ {
final Optional<UserAgent> maybeUserAgent = clientConnectionManager.getUserAgent(localAddress); final Optional<UserAgent> maybeUserAgent = grpcClientConnectionManager.getUserAgent(localAddress);
if (maybeUserAgent.isPresent()) { if (maybeUserAgent.isPresent()) {
context = context.withValue(RequestAttributesUtil.USER_AGENT_CONTEXT_KEY, maybeUserAgent.get()); context = context.withValue(RequestAttributesUtil.USER_AGENT_CONTEXT_KEY, maybeUserAgent.get());

View File

@ -22,7 +22,7 @@ import org.slf4j.LoggerFactory;
*/ */
class EstablishLocalGrpcConnectionHandler extends ChannelInboundHandlerAdapter { class EstablishLocalGrpcConnectionHandler extends ChannelInboundHandlerAdapter {
private final ClientConnectionManager clientConnectionManager; private final GrpcClientConnectionManager grpcClientConnectionManager;
private final LocalAddress authenticatedGrpcServerAddress; private final LocalAddress authenticatedGrpcServerAddress;
private final LocalAddress anonymousGrpcServerAddress; private final LocalAddress anonymousGrpcServerAddress;
@ -31,11 +31,11 @@ class EstablishLocalGrpcConnectionHandler extends ChannelInboundHandlerAdapter {
private static final Logger log = LoggerFactory.getLogger(EstablishLocalGrpcConnectionHandler.class); private static final Logger log = LoggerFactory.getLogger(EstablishLocalGrpcConnectionHandler.class);
public EstablishLocalGrpcConnectionHandler(final ClientConnectionManager clientConnectionManager, public EstablishLocalGrpcConnectionHandler(final GrpcClientConnectionManager grpcClientConnectionManager,
final LocalAddress authenticatedGrpcServerAddress, final LocalAddress authenticatedGrpcServerAddress,
final LocalAddress anonymousGrpcServerAddress) { final LocalAddress anonymousGrpcServerAddress) {
this.clientConnectionManager = clientConnectionManager; this.grpcClientConnectionManager = grpcClientConnectionManager;
this.authenticatedGrpcServerAddress = authenticatedGrpcServerAddress; this.authenticatedGrpcServerAddress = authenticatedGrpcServerAddress;
this.anonymousGrpcServerAddress = anonymousGrpcServerAddress; this.anonymousGrpcServerAddress = anonymousGrpcServerAddress;
@ -70,7 +70,7 @@ class EstablishLocalGrpcConnectionHandler extends ChannelInboundHandlerAdapter {
.connect() .connect()
.addListener((ChannelFutureListener) localChannelFuture -> { .addListener((ChannelFutureListener) localChannelFuture -> {
if (localChannelFuture.isSuccess()) { if (localChannelFuture.isSuccess()) {
clientConnectionManager.handleConnectionEstablished((LocalChannel) localChannelFuture.channel(), grpcClientConnectionManager.handleConnectionEstablished((LocalChannel) localChannelFuture.channel(),
remoteChannelContext.channel(), remoteChannelContext.channel(),
noiseIdentityDeterminedEvent.authenticatedDevice()); noiseIdentityDeterminedEvent.authenticatedDevice());

View File

@ -30,14 +30,14 @@ import org.whispersystems.textsecuregcm.util.ua.UserAgentUtil;
* authenticated identity of the device that opened the connection (for non-anonymous connections). It can also close * authenticated identity of the device that opened the connection (for non-anonymous connections). It can also close
* connections associated with a given device if that device's credentials have changed and clients must reauthenticate. * connections associated with a given device if that device's credentials have changed and clients must reauthenticate.
*/ */
public class ClientConnectionManager { public class GrpcClientConnectionManager {
private final Map<LocalAddress, Channel> remoteChannelsByLocalAddress = new ConcurrentHashMap<>(); private final Map<LocalAddress, Channel> remoteChannelsByLocalAddress = new ConcurrentHashMap<>();
private final Map<AuthenticatedDevice, List<Channel>> remoteChannelsByAuthenticatedDevice = new ConcurrentHashMap<>(); private final Map<AuthenticatedDevice, List<Channel>> remoteChannelsByAuthenticatedDevice = new ConcurrentHashMap<>();
@VisibleForTesting @VisibleForTesting
static final AttributeKey<AuthenticatedDevice> AUTHENTICATED_DEVICE_ATTRIBUTE_KEY = static final AttributeKey<AuthenticatedDevice> AUTHENTICATED_DEVICE_ATTRIBUTE_KEY =
AttributeKey.valueOf(ClientConnectionManager.class, "authenticatedDevice"); AttributeKey.valueOf(GrpcClientConnectionManager.class, "authenticatedDevice");
@VisibleForTesting @VisibleForTesting
static final AttributeKey<InetAddress> REMOTE_ADDRESS_ATTRIBUTE_KEY = static final AttributeKey<InetAddress> REMOTE_ADDRESS_ATTRIBUTE_KEY =
@ -55,7 +55,7 @@ public class ClientConnectionManager {
static final AttributeKey<List<Locale.LanguageRange>> ACCEPT_LANGUAGE_ATTRIBUTE_KEY = static final AttributeKey<List<Locale.LanguageRange>> ACCEPT_LANGUAGE_ATTRIBUTE_KEY =
AttributeKey.valueOf(WebsocketHandshakeCompleteHandler.class, "acceptLanguage"); AttributeKey.valueOf(WebsocketHandshakeCompleteHandler.class, "acceptLanguage");
private static final Logger log = LoggerFactory.getLogger(ClientConnectionManager.class); private static final Logger log = LoggerFactory.getLogger(GrpcClientConnectionManager.class);
/** /**
* Returns the authenticated device associated with the given local address, if any. An authenticated device is * Returns the authenticated device associated with the given local address, if any. An authenticated device is
@ -154,13 +154,13 @@ public class ClientConnectionManager {
@Nullable final String userAgentHeader, @Nullable final String userAgentHeader,
@Nullable final String acceptLanguageHeader) { @Nullable final String acceptLanguageHeader) {
channel.attr(ClientConnectionManager.REMOTE_ADDRESS_ATTRIBUTE_KEY).set(preferredRemoteAddress); channel.attr(GrpcClientConnectionManager.REMOTE_ADDRESS_ATTRIBUTE_KEY).set(preferredRemoteAddress);
if (StringUtils.isNotBlank(userAgentHeader)) { if (StringUtils.isNotBlank(userAgentHeader)) {
channel.attr(ClientConnectionManager.RAW_USER_AGENT_ATTRIBUTE_KEY).set(userAgentHeader); channel.attr(GrpcClientConnectionManager.RAW_USER_AGENT_ATTRIBUTE_KEY).set(userAgentHeader);
try { try {
channel.attr(ClientConnectionManager.PARSED_USER_AGENT_ATTRIBUTE_KEY) channel.attr(GrpcClientConnectionManager.PARSED_USER_AGENT_ATTRIBUTE_KEY)
.set(UserAgentUtil.parseUserAgentString(userAgentHeader)); .set(UserAgentUtil.parseUserAgentString(userAgentHeader));
} catch (final UnrecognizedUserAgentException ignored) { } catch (final UnrecognizedUserAgentException ignored) {
} }
@ -168,7 +168,7 @@ public class ClientConnectionManager {
if (StringUtils.isNotBlank(acceptLanguageHeader)) { if (StringUtils.isNotBlank(acceptLanguageHeader)) {
try { try {
channel.attr(ClientConnectionManager.ACCEPT_LANGUAGE_ATTRIBUTE_KEY).set(Locale.LanguageRange.parse(acceptLanguageHeader)); channel.attr(GrpcClientConnectionManager.ACCEPT_LANGUAGE_ATTRIBUTE_KEY).set(Locale.LanguageRange.parse(acceptLanguageHeader));
} catch (final IllegalArgumentException e) { } catch (final IllegalArgumentException e) {
log.debug("Invalid Accept-Language header from User-Agent {}: {}", userAgentHeader, acceptLanguageHeader, e); log.debug("Invalid Accept-Language header from User-Agent {}: {}", userAgentHeader, acceptLanguageHeader, e);
} }
@ -188,7 +188,7 @@ public class ClientConnectionManager {
@SuppressWarnings("OptionalUsedAsFieldOrParameterType") final Optional<AuthenticatedDevice> maybeAuthenticatedDevice) { @SuppressWarnings("OptionalUsedAsFieldOrParameterType") final Optional<AuthenticatedDevice> maybeAuthenticatedDevice) {
maybeAuthenticatedDevice.ifPresent(authenticatedDevice -> maybeAuthenticatedDevice.ifPresent(authenticatedDevice ->
remoteChannel.attr(ClientConnectionManager.AUTHENTICATED_DEVICE_ATTRIBUTE_KEY).set(authenticatedDevice)); remoteChannel.attr(GrpcClientConnectionManager.AUTHENTICATED_DEVICE_ATTRIBUTE_KEY).set(authenticatedDevice));
remoteChannelsByLocalAddress.put(localChannel.localAddress(), remoteChannel); remoteChannelsByLocalAddress.put(localChannel.localAddress(), remoteChannel);

View File

@ -50,7 +50,7 @@ public class NoiseWebSocketTunnelServer implements Managed {
@Nullable final PrivateKey tlsPrivateKey, @Nullable final PrivateKey tlsPrivateKey,
final NioEventLoopGroup eventLoopGroup, final NioEventLoopGroup eventLoopGroup,
final Executor delegatedTaskExecutor, final Executor delegatedTaskExecutor,
final ClientConnectionManager clientConnectionManager, final GrpcClientConnectionManager grpcClientConnectionManager,
final ClientPublicKeysManager clientPublicKeysManager, final ClientPublicKeysManager clientPublicKeysManager,
final ECKeyPair ecKeyPair, final ECKeyPair ecKeyPair,
final LocalAddress authenticatedGrpcServerAddress, final LocalAddress authenticatedGrpcServerAddress,
@ -109,7 +109,7 @@ public class NoiseWebSocketTunnelServer implements Managed {
.addLast(new WebsocketHandshakeCompleteHandler(clientPublicKeysManager, ecKeyPair, recognizedProxySecret)) .addLast(new WebsocketHandshakeCompleteHandler(clientPublicKeysManager, ecKeyPair, recognizedProxySecret))
// This handler will open a local connection to the appropriate gRPC server and install a ProxyHandler // This handler will open a local connection to the appropriate gRPC server and install a ProxyHandler
// once the Noise handshake has completed // once the Noise handshake has completed
.addLast(new EstablishLocalGrpcConnectionHandler(clientConnectionManager, authenticatedGrpcServerAddress, anonymousGrpcServerAddress)) .addLast(new EstablishLocalGrpcConnectionHandler(grpcClientConnectionManager, authenticatedGrpcServerAddress, anonymousGrpcServerAddress))
.addLast(new ErrorHandler()); .addLast(new ErrorHandler());
} }
}); });

View File

@ -74,7 +74,7 @@ class WebsocketHandshakeCompleteHandler extends ChannelInboundHandlerAdapter {
preferredRemoteAddress = maybePreferredRemoteAddress.get(); preferredRemoteAddress = maybePreferredRemoteAddress.get();
} }
ClientConnectionManager.handleWebSocketHandshakeComplete(context.channel(), GrpcClientConnectionManager.handleWebSocketHandshakeComplete(context.channel(),
preferredRemoteAddress, preferredRemoteAddress,
handshakeCompleteEvent.requestHeaders().getAsString(HttpHeaderNames.USER_AGENT), handshakeCompleteEvent.requestHeaders().getAsString(HttpHeaderNames.USER_AGENT),
handshakeCompleteEvent.requestHeaders().getAsString(HttpHeaderNames.ACCEPT_LANGUAGE)); handshakeCompleteEvent.requestHeaders().getAsString(HttpHeaderNames.ACCEPT_LANGUAGE));

View File

@ -18,13 +18,13 @@ import org.signal.chat.rpc.GetAuthenticatedDeviceRequest;
import org.signal.chat.rpc.GetAuthenticatedDeviceResponse; import org.signal.chat.rpc.GetAuthenticatedDeviceResponse;
import org.signal.chat.rpc.RequestAttributesGrpc; import org.signal.chat.rpc.RequestAttributesGrpc;
import org.whispersystems.textsecuregcm.grpc.RequestAttributesServiceImpl; import org.whispersystems.textsecuregcm.grpc.RequestAttributesServiceImpl;
import org.whispersystems.textsecuregcm.grpc.net.ClientConnectionManager; import org.whispersystems.textsecuregcm.grpc.net.GrpcClientConnectionManager;
abstract class AbstractAuthenticationInterceptorTest { abstract class AbstractAuthenticationInterceptorTest {
private static DefaultEventLoopGroup eventLoopGroup; private static DefaultEventLoopGroup eventLoopGroup;
private ClientConnectionManager clientConnectionManager; private GrpcClientConnectionManager grpcClientConnectionManager;
private Server server; private Server server;
private ManagedChannel managedChannel; private ManagedChannel managedChannel;
@ -38,7 +38,7 @@ abstract class AbstractAuthenticationInterceptorTest {
void setUp() throws IOException { void setUp() throws IOException {
final LocalAddress serverAddress = new LocalAddress("test-authentication-interceptor-server"); final LocalAddress serverAddress = new LocalAddress("test-authentication-interceptor-server");
clientConnectionManager = mock(ClientConnectionManager.class); grpcClientConnectionManager = mock(GrpcClientConnectionManager.class);
// `RequestAttributesInterceptor` operates on `LocalAddresses`, so we need to do some slightly fancy plumbing to make // `RequestAttributesInterceptor` operates on `LocalAddresses`, so we need to do some slightly fancy plumbing to make
// sure that we're using local channels and addresses // sure that we're using local channels and addresses
@ -66,8 +66,8 @@ abstract class AbstractAuthenticationInterceptorTest {
protected abstract AbstractAuthenticationInterceptor getInterceptor(); protected abstract AbstractAuthenticationInterceptor getInterceptor();
protected ClientConnectionManager getClientConnectionManager() { protected GrpcClientConnectionManager getClientConnectionManager() {
return clientConnectionManager; return grpcClientConnectionManager;
} }
protected GetAuthenticatedDeviceResponse getAuthenticatedDevice() { protected GetAuthenticatedDeviceResponse getAuthenticatedDevice() {

View File

@ -4,9 +4,8 @@ import io.grpc.Status;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.signal.chat.rpc.GetAuthenticatedDeviceResponse; import org.signal.chat.rpc.GetAuthenticatedDeviceResponse;
import org.whispersystems.textsecuregcm.grpc.GrpcTestUtils; import org.whispersystems.textsecuregcm.grpc.GrpcTestUtils;
import org.whispersystems.textsecuregcm.grpc.net.ClientConnectionManager; import org.whispersystems.textsecuregcm.grpc.net.GrpcClientConnectionManager;
import org.whispersystems.textsecuregcm.storage.Device; import org.whispersystems.textsecuregcm.storage.Device;
import org.whispersystems.textsecuregcm.util.UUIDUtil;
import java.util.Optional; import java.util.Optional;
import java.util.UUID; import java.util.UUID;
@ -24,16 +23,16 @@ class ProhibitAuthenticationInterceptorTest extends AbstractAuthenticationInterc
@Test @Test
void interceptCall() { void interceptCall() {
final ClientConnectionManager clientConnectionManager = getClientConnectionManager(); final GrpcClientConnectionManager grpcClientConnectionManager = getClientConnectionManager();
when(clientConnectionManager.getAuthenticatedDevice(any())).thenReturn(Optional.empty()); when(grpcClientConnectionManager.getAuthenticatedDevice(any())).thenReturn(Optional.empty());
final GetAuthenticatedDeviceResponse response = getAuthenticatedDevice(); final GetAuthenticatedDeviceResponse response = getAuthenticatedDevice();
assertTrue(response.getAccountIdentifier().isEmpty()); assertTrue(response.getAccountIdentifier().isEmpty());
assertEquals(0, response.getDeviceId()); assertEquals(0, response.getDeviceId());
final AuthenticatedDevice authenticatedDevice = new AuthenticatedDevice(UUID.randomUUID(), Device.PRIMARY_ID); final AuthenticatedDevice authenticatedDevice = new AuthenticatedDevice(UUID.randomUUID(), Device.PRIMARY_ID);
when(clientConnectionManager.getAuthenticatedDevice(any())).thenReturn(Optional.of(authenticatedDevice)); when(grpcClientConnectionManager.getAuthenticatedDevice(any())).thenReturn(Optional.of(authenticatedDevice));
GrpcTestUtils.assertStatusException(Status.UNAUTHENTICATED, this::getAuthenticatedDevice); GrpcTestUtils.assertStatusException(Status.UNAUTHENTICATED, this::getAuthenticatedDevice);
} }

View File

@ -10,7 +10,7 @@ import java.util.UUID;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.signal.chat.rpc.GetAuthenticatedDeviceResponse; import org.signal.chat.rpc.GetAuthenticatedDeviceResponse;
import org.whispersystems.textsecuregcm.grpc.GrpcTestUtils; import org.whispersystems.textsecuregcm.grpc.GrpcTestUtils;
import org.whispersystems.textsecuregcm.grpc.net.ClientConnectionManager; import org.whispersystems.textsecuregcm.grpc.net.GrpcClientConnectionManager;
import org.whispersystems.textsecuregcm.storage.Device; import org.whispersystems.textsecuregcm.storage.Device;
import org.whispersystems.textsecuregcm.util.UUIDUtil; import org.whispersystems.textsecuregcm.util.UUIDUtil;
@ -23,14 +23,14 @@ class RequireAuthenticationInterceptorTest extends AbstractAuthenticationInterce
@Test @Test
void interceptCall() { void interceptCall() {
final ClientConnectionManager clientConnectionManager = getClientConnectionManager(); final GrpcClientConnectionManager grpcClientConnectionManager = getClientConnectionManager();
when(clientConnectionManager.getAuthenticatedDevice(any())).thenReturn(Optional.empty()); when(grpcClientConnectionManager.getAuthenticatedDevice(any())).thenReturn(Optional.empty());
GrpcTestUtils.assertStatusException(Status.UNAUTHENTICATED, this::getAuthenticatedDevice); GrpcTestUtils.assertStatusException(Status.UNAUTHENTICATED, this::getAuthenticatedDevice);
final AuthenticatedDevice authenticatedDevice = new AuthenticatedDevice(UUID.randomUUID(), Device.PRIMARY_ID); final AuthenticatedDevice authenticatedDevice = new AuthenticatedDevice(UUID.randomUUID(), Device.PRIMARY_ID);
when(clientConnectionManager.getAuthenticatedDevice(any())).thenReturn(Optional.of(authenticatedDevice)); when(grpcClientConnectionManager.getAuthenticatedDevice(any())).thenReturn(Optional.of(authenticatedDevice));
final GetAuthenticatedDeviceResponse response = getAuthenticatedDevice(); final GetAuthenticatedDeviceResponse response = getAuthenticatedDevice();
assertEquals(UUIDUtil.toByteString(authenticatedDevice.accountIdentifier()), response.getAccountIdentifier()); assertEquals(UUIDUtil.toByteString(authenticatedDevice.accountIdentifier()), response.getAccountIdentifier());

View File

@ -21,7 +21,6 @@ import java.io.IOException;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.Optional; import java.util.Optional;
import org.apache.commons.lang3.StringUtils;
import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeAll;
@ -30,7 +29,7 @@ import org.junit.jupiter.api.Test;
import org.signal.chat.rpc.GetRequestAttributesRequest; import org.signal.chat.rpc.GetRequestAttributesRequest;
import org.signal.chat.rpc.GetRequestAttributesResponse; import org.signal.chat.rpc.GetRequestAttributesResponse;
import org.signal.chat.rpc.RequestAttributesGrpc; import org.signal.chat.rpc.RequestAttributesGrpc;
import org.whispersystems.textsecuregcm.grpc.net.ClientConnectionManager; import org.whispersystems.textsecuregcm.grpc.net.GrpcClientConnectionManager;
import org.whispersystems.textsecuregcm.util.ua.UnrecognizedUserAgentException; import org.whispersystems.textsecuregcm.util.ua.UnrecognizedUserAgentException;
import org.whispersystems.textsecuregcm.util.ua.UserAgent; import org.whispersystems.textsecuregcm.util.ua.UserAgent;
import org.whispersystems.textsecuregcm.util.ua.UserAgentUtil; import org.whispersystems.textsecuregcm.util.ua.UserAgentUtil;
@ -39,7 +38,7 @@ class RequestAttributesUtilTest {
private static DefaultEventLoopGroup eventLoopGroup; private static DefaultEventLoopGroup eventLoopGroup;
private ClientConnectionManager clientConnectionManager; private GrpcClientConnectionManager grpcClientConnectionManager;
private Server server; private Server server;
private ManagedChannel managedChannel; private ManagedChannel managedChannel;
@ -53,9 +52,9 @@ class RequestAttributesUtilTest {
void setUp() throws IOException { void setUp() throws IOException {
final LocalAddress serverAddress = new LocalAddress("test-request-metadata-server"); final LocalAddress serverAddress = new LocalAddress("test-request-metadata-server");
clientConnectionManager = mock(ClientConnectionManager.class); grpcClientConnectionManager = mock(GrpcClientConnectionManager.class);
when(clientConnectionManager.getRemoteAddress(any())) when(grpcClientConnectionManager.getRemoteAddress(any()))
.thenReturn(Optional.of(InetAddresses.forString("127.0.0.1"))); .thenReturn(Optional.of(InetAddresses.forString("127.0.0.1")));
// `RequestAttributesInterceptor` operates on `LocalAddresses`, so we need to do some slightly fancy plumbing to make // `RequestAttributesInterceptor` operates on `LocalAddresses`, so we need to do some slightly fancy plumbing to make
@ -64,7 +63,7 @@ class RequestAttributesUtilTest {
.channelType(LocalServerChannel.class) .channelType(LocalServerChannel.class)
.bossEventLoopGroup(eventLoopGroup) .bossEventLoopGroup(eventLoopGroup)
.workerEventLoopGroup(eventLoopGroup) .workerEventLoopGroup(eventLoopGroup)
.intercept(new RequestAttributesInterceptor(clientConnectionManager)) .intercept(new RequestAttributesInterceptor(grpcClientConnectionManager))
.addService(new RequestAttributesServiceImpl()) .addService(new RequestAttributesServiceImpl())
.build() .build()
.start(); .start();
@ -89,12 +88,12 @@ class RequestAttributesUtilTest {
@Test @Test
void getAcceptableLanguages() { void getAcceptableLanguages() {
when(clientConnectionManager.getAcceptableLanguages(any())) when(grpcClientConnectionManager.getAcceptableLanguages(any()))
.thenReturn(Optional.empty()); .thenReturn(Optional.empty());
assertTrue(getRequestAttributes().getAcceptableLanguagesList().isEmpty()); assertTrue(getRequestAttributes().getAcceptableLanguagesList().isEmpty());
when(clientConnectionManager.getAcceptableLanguages(any())) when(grpcClientConnectionManager.getAcceptableLanguages(any()))
.thenReturn(Optional.of(Locale.LanguageRange.parse("en,ja"))); .thenReturn(Optional.of(Locale.LanguageRange.parse("en,ja")));
assertEquals(List.of("en", "ja"), getRequestAttributes().getAcceptableLanguagesList()); assertEquals(List.of("en", "ja"), getRequestAttributes().getAcceptableLanguagesList());
@ -102,12 +101,12 @@ class RequestAttributesUtilTest {
@Test @Test
void getAvailableAcceptedLocales() { void getAvailableAcceptedLocales() {
when(clientConnectionManager.getAcceptableLanguages(any())) when(grpcClientConnectionManager.getAcceptableLanguages(any()))
.thenReturn(Optional.empty()); .thenReturn(Optional.empty());
assertTrue(getRequestAttributes().getAvailableAcceptedLocalesList().isEmpty()); assertTrue(getRequestAttributes().getAvailableAcceptedLocalesList().isEmpty());
when(clientConnectionManager.getAcceptableLanguages(any())) when(grpcClientConnectionManager.getAcceptableLanguages(any()))
.thenReturn(Optional.of(Locale.LanguageRange.parse("en,ja"))); .thenReturn(Optional.of(Locale.LanguageRange.parse("en,ja")));
final GetRequestAttributesResponse response = getRequestAttributes(); final GetRequestAttributesResponse response = getRequestAttributes();
@ -121,14 +120,14 @@ class RequestAttributesUtilTest {
@Test @Test
void getRemoteAddress() { void getRemoteAddress() {
when(clientConnectionManager.getRemoteAddress(any())) when(grpcClientConnectionManager.getRemoteAddress(any()))
.thenReturn(Optional.empty()); .thenReturn(Optional.empty());
GrpcTestUtils.assertStatusException(Status.INTERNAL, this::getRequestAttributes); GrpcTestUtils.assertStatusException(Status.INTERNAL, this::getRequestAttributes);
final String remoteAddressString = "6.7.8.9"; final String remoteAddressString = "6.7.8.9";
when(clientConnectionManager.getRemoteAddress(any())) when(grpcClientConnectionManager.getRemoteAddress(any()))
.thenReturn(Optional.of(InetAddresses.forString(remoteAddressString))); .thenReturn(Optional.of(InetAddresses.forString(remoteAddressString)));
assertEquals(remoteAddressString, getRequestAttributes().getRemoteAddress()); assertEquals(remoteAddressString, getRequestAttributes().getRemoteAddress());
@ -136,14 +135,14 @@ class RequestAttributesUtilTest {
@Test @Test
void getUserAgent() throws UnrecognizedUserAgentException { void getUserAgent() throws UnrecognizedUserAgentException {
when(clientConnectionManager.getUserAgent(any())) when(grpcClientConnectionManager.getUserAgent(any()))
.thenReturn(Optional.empty()); .thenReturn(Optional.empty());
assertFalse(getRequestAttributes().hasUserAgent()); assertFalse(getRequestAttributes().hasUserAgent());
final UserAgent userAgent = UserAgentUtil.parseUserAgentString("Signal-Desktop/1.2.3 Linux"); final UserAgent userAgent = UserAgentUtil.parseUserAgentString("Signal-Desktop/1.2.3 Linux");
when(clientConnectionManager.getUserAgent(any())) when(grpcClientConnectionManager.getUserAgent(any()))
.thenReturn(Optional.of(userAgent)); .thenReturn(Optional.of(userAgent));
final GetRequestAttributesResponse response = getRequestAttributes(); final GetRequestAttributesResponse response = getRequestAttributes();

View File

@ -36,7 +36,7 @@ import java.util.UUID;
import static org.junit.jupiter.api.Assertions.*; import static org.junit.jupiter.api.Assertions.*;
class ClientConnectionManagerTest { class GrpcClientConnectionManagerTest {
private static EventLoopGroup eventLoopGroup; private static EventLoopGroup eventLoopGroup;
@ -45,7 +45,7 @@ class ClientConnectionManagerTest {
private LocalServerChannel localServerChannel; private LocalServerChannel localServerChannel;
private ClientConnectionManager clientConnectionManager; private GrpcClientConnectionManager grpcClientConnectionManager;
@BeforeAll @BeforeAll
static void setUpBeforeAll() { static void setUpBeforeAll() {
@ -56,7 +56,7 @@ class ClientConnectionManagerTest {
void setUp() throws InterruptedException { void setUp() throws InterruptedException {
eventLoopGroup = new DefaultEventLoopGroup(); eventLoopGroup = new DefaultEventLoopGroup();
clientConnectionManager = new ClientConnectionManager(); grpcClientConnectionManager = new GrpcClientConnectionManager();
// We have to jump through some hoops to get "real" LocalChannel instances to test with, and so we run a trivial // We have to jump through some hoops to get "real" LocalChannel instances to test with, and so we run a trivial
// local server to which we can open trivial local connections // local server to which we can open trivial local connections
@ -100,10 +100,10 @@ class ClientConnectionManagerTest {
@ParameterizedTest @ParameterizedTest
@MethodSource @MethodSource
void getAuthenticatedDevice(@SuppressWarnings("OptionalUsedAsFieldOrParameterType") final Optional<AuthenticatedDevice> maybeAuthenticatedDevice) { void getAuthenticatedDevice(@SuppressWarnings("OptionalUsedAsFieldOrParameterType") final Optional<AuthenticatedDevice> maybeAuthenticatedDevice) {
clientConnectionManager.handleConnectionEstablished(localChannel, remoteChannel, maybeAuthenticatedDevice); grpcClientConnectionManager.handleConnectionEstablished(localChannel, remoteChannel, maybeAuthenticatedDevice);
assertEquals(maybeAuthenticatedDevice, assertEquals(maybeAuthenticatedDevice,
clientConnectionManager.getAuthenticatedDevice(localChannel.localAddress())); grpcClientConnectionManager.getAuthenticatedDevice(localChannel.localAddress()));
} }
private static List<Optional<AuthenticatedDevice>> getAuthenticatedDevice() { private static List<Optional<AuthenticatedDevice>> getAuthenticatedDevice() {
@ -115,62 +115,62 @@ class ClientConnectionManagerTest {
@Test @Test
void getAcceptableLanguages() { void getAcceptableLanguages() {
clientConnectionManager.handleConnectionEstablished(localChannel, remoteChannel, Optional.empty()); grpcClientConnectionManager.handleConnectionEstablished(localChannel, remoteChannel, Optional.empty());
assertEquals(Optional.empty(), assertEquals(Optional.empty(),
clientConnectionManager.getAcceptableLanguages(localChannel.localAddress())); grpcClientConnectionManager.getAcceptableLanguages(localChannel.localAddress()));
final List<Locale.LanguageRange> acceptLanguageRanges = Locale.LanguageRange.parse("en,ja"); final List<Locale.LanguageRange> acceptLanguageRanges = Locale.LanguageRange.parse("en,ja");
remoteChannel.attr(ClientConnectionManager.ACCEPT_LANGUAGE_ATTRIBUTE_KEY).set(acceptLanguageRanges); remoteChannel.attr(GrpcClientConnectionManager.ACCEPT_LANGUAGE_ATTRIBUTE_KEY).set(acceptLanguageRanges);
assertEquals(Optional.of(acceptLanguageRanges), assertEquals(Optional.of(acceptLanguageRanges),
clientConnectionManager.getAcceptableLanguages(localChannel.localAddress())); grpcClientConnectionManager.getAcceptableLanguages(localChannel.localAddress()));
} }
@Test @Test
void getRemoteAddress() { void getRemoteAddress() {
clientConnectionManager.handleConnectionEstablished(localChannel, remoteChannel, Optional.empty()); grpcClientConnectionManager.handleConnectionEstablished(localChannel, remoteChannel, Optional.empty());
assertEquals(Optional.empty(), assertEquals(Optional.empty(),
clientConnectionManager.getRemoteAddress(localChannel.localAddress())); grpcClientConnectionManager.getRemoteAddress(localChannel.localAddress()));
final InetAddress remoteAddress = InetAddresses.forString("6.7.8.9"); final InetAddress remoteAddress = InetAddresses.forString("6.7.8.9");
remoteChannel.attr(ClientConnectionManager.REMOTE_ADDRESS_ATTRIBUTE_KEY).set(remoteAddress); remoteChannel.attr(GrpcClientConnectionManager.REMOTE_ADDRESS_ATTRIBUTE_KEY).set(remoteAddress);
assertEquals(Optional.of(remoteAddress), assertEquals(Optional.of(remoteAddress),
clientConnectionManager.getRemoteAddress(localChannel.localAddress())); grpcClientConnectionManager.getRemoteAddress(localChannel.localAddress()));
} }
@Test @Test
void getUserAgent() throws UnrecognizedUserAgentException { void getUserAgent() throws UnrecognizedUserAgentException {
clientConnectionManager.handleConnectionEstablished(localChannel, remoteChannel, Optional.empty()); grpcClientConnectionManager.handleConnectionEstablished(localChannel, remoteChannel, Optional.empty());
assertEquals(Optional.empty(), assertEquals(Optional.empty(),
clientConnectionManager.getUserAgent(localChannel.localAddress())); grpcClientConnectionManager.getUserAgent(localChannel.localAddress()));
final UserAgent userAgent = UserAgentUtil.parseUserAgentString("Signal-Desktop/1.2.3 Linux"); final UserAgent userAgent = UserAgentUtil.parseUserAgentString("Signal-Desktop/1.2.3 Linux");
remoteChannel.attr(ClientConnectionManager.PARSED_USER_AGENT_ATTRIBUTE_KEY).set(userAgent); remoteChannel.attr(GrpcClientConnectionManager.PARSED_USER_AGENT_ATTRIBUTE_KEY).set(userAgent);
assertEquals(Optional.of(userAgent), assertEquals(Optional.of(userAgent),
clientConnectionManager.getUserAgent(localChannel.localAddress())); grpcClientConnectionManager.getUserAgent(localChannel.localAddress()));
} }
@Test @Test
void closeConnection() throws InterruptedException { void closeConnection() throws InterruptedException {
final AuthenticatedDevice authenticatedDevice = new AuthenticatedDevice(UUID.randomUUID(), Device.PRIMARY_ID); final AuthenticatedDevice authenticatedDevice = new AuthenticatedDevice(UUID.randomUUID(), Device.PRIMARY_ID);
clientConnectionManager.handleConnectionEstablished(localChannel, remoteChannel, Optional.of(authenticatedDevice)); grpcClientConnectionManager.handleConnectionEstablished(localChannel, remoteChannel, Optional.of(authenticatedDevice));
assertTrue(remoteChannel.isOpen()); assertTrue(remoteChannel.isOpen());
assertEquals(remoteChannel, clientConnectionManager.getRemoteChannelByLocalAddress(localChannel.localAddress())); assertEquals(remoteChannel, grpcClientConnectionManager.getRemoteChannelByLocalAddress(localChannel.localAddress()));
assertEquals(List.of(remoteChannel), assertEquals(List.of(remoteChannel),
clientConnectionManager.getRemoteChannelsByAuthenticatedDevice(authenticatedDevice)); grpcClientConnectionManager.getRemoteChannelsByAuthenticatedDevice(authenticatedDevice));
remoteChannel.close().await(); remoteChannel.close().await();
assertNull(clientConnectionManager.getRemoteChannelByLocalAddress(localChannel.localAddress())); assertNull(grpcClientConnectionManager.getRemoteChannelByLocalAddress(localChannel.localAddress()));
assertNull(clientConnectionManager.getRemoteChannelsByAuthenticatedDevice(authenticatedDevice)); assertNull(grpcClientConnectionManager.getRemoteChannelsByAuthenticatedDevice(authenticatedDevice));
} }
@Test @Test
@ -179,13 +179,13 @@ class ClientConnectionManagerTest {
final InetAddress preferredRemoteAddress = InetAddresses.forString("192.168.1.1"); final InetAddress preferredRemoteAddress = InetAddresses.forString("192.168.1.1");
ClientConnectionManager.handleWebSocketHandshakeComplete(embeddedChannel, GrpcClientConnectionManager.handleWebSocketHandshakeComplete(embeddedChannel,
preferredRemoteAddress, preferredRemoteAddress,
null, null,
null); null);
assertEquals(preferredRemoteAddress, assertEquals(preferredRemoteAddress,
embeddedChannel.attr(ClientConnectionManager.REMOTE_ADDRESS_ATTRIBUTE_KEY).get()); embeddedChannel.attr(GrpcClientConnectionManager.REMOTE_ADDRESS_ATTRIBUTE_KEY).get());
} }
@ParameterizedTest @ParameterizedTest
@ -195,16 +195,16 @@ class ClientConnectionManagerTest {
final EmbeddedChannel embeddedChannel = new EmbeddedChannel(); final EmbeddedChannel embeddedChannel = new EmbeddedChannel();
ClientConnectionManager.handleWebSocketHandshakeComplete(embeddedChannel, GrpcClientConnectionManager.handleWebSocketHandshakeComplete(embeddedChannel,
InetAddresses.forString("127.0.0.1"), InetAddresses.forString("127.0.0.1"),
userAgentHeader, userAgentHeader,
null); null);
assertEquals(userAgentHeader, assertEquals(userAgentHeader,
embeddedChannel.attr(ClientConnectionManager.RAW_USER_AGENT_ATTRIBUTE_KEY).get()); embeddedChannel.attr(GrpcClientConnectionManager.RAW_USER_AGENT_ATTRIBUTE_KEY).get());
assertEquals(expectedParsedUserAgent, assertEquals(expectedParsedUserAgent,
embeddedChannel.attr(ClientConnectionManager.PARSED_USER_AGENT_ATTRIBUTE_KEY).get()); embeddedChannel.attr(GrpcClientConnectionManager.PARSED_USER_AGENT_ATTRIBUTE_KEY).get());
} }
private static List<Arguments> handleWebSocketHandshakeCompleteUserAgent() { private static List<Arguments> handleWebSocketHandshakeCompleteUserAgent() {
@ -228,13 +228,13 @@ class ClientConnectionManagerTest {
final EmbeddedChannel embeddedChannel = new EmbeddedChannel(); final EmbeddedChannel embeddedChannel = new EmbeddedChannel();
ClientConnectionManager.handleWebSocketHandshakeComplete(embeddedChannel, GrpcClientConnectionManager.handleWebSocketHandshakeComplete(embeddedChannel,
InetAddresses.forString("127.0.0.1"), InetAddresses.forString("127.0.0.1"),
null, null,
acceptLanguageHeader); acceptLanguageHeader);
assertEquals(expectedLanguageRanges, assertEquals(expectedLanguageRanges,
embeddedChannel.attr(ClientConnectionManager.ACCEPT_LANGUAGE_ATTRIBUTE_KEY).get()); embeddedChannel.attr(GrpcClientConnectionManager.ACCEPT_LANGUAGE_ATTRIBUTE_KEY).get());
} }
private static List<Arguments> handleWebSocketHandshakeCompleteAcceptLanguage() { private static List<Arguments> handleWebSocketHandshakeCompleteAcceptLanguage() {
@ -254,30 +254,30 @@ class ClientConnectionManagerTest {
void handleConnectionEstablishedAuthenticated() throws InterruptedException { void handleConnectionEstablishedAuthenticated() throws InterruptedException {
final AuthenticatedDevice authenticatedDevice = new AuthenticatedDevice(UUID.randomUUID(), Device.PRIMARY_ID); final AuthenticatedDevice authenticatedDevice = new AuthenticatedDevice(UUID.randomUUID(), Device.PRIMARY_ID);
assertNull(clientConnectionManager.getRemoteChannelByLocalAddress(localChannel.localAddress())); assertNull(grpcClientConnectionManager.getRemoteChannelByLocalAddress(localChannel.localAddress()));
assertNull(clientConnectionManager.getRemoteChannelsByAuthenticatedDevice(authenticatedDevice)); assertNull(grpcClientConnectionManager.getRemoteChannelsByAuthenticatedDevice(authenticatedDevice));
clientConnectionManager.handleConnectionEstablished(localChannel, remoteChannel, Optional.of(authenticatedDevice)); grpcClientConnectionManager.handleConnectionEstablished(localChannel, remoteChannel, Optional.of(authenticatedDevice));
assertEquals(remoteChannel, clientConnectionManager.getRemoteChannelByLocalAddress(localChannel.localAddress())); assertEquals(remoteChannel, grpcClientConnectionManager.getRemoteChannelByLocalAddress(localChannel.localAddress()));
assertEquals(List.of(remoteChannel), clientConnectionManager.getRemoteChannelsByAuthenticatedDevice(authenticatedDevice)); assertEquals(List.of(remoteChannel), grpcClientConnectionManager.getRemoteChannelsByAuthenticatedDevice(authenticatedDevice));
remoteChannel.close().await(); remoteChannel.close().await();
assertNull(clientConnectionManager.getRemoteChannelByLocalAddress(localChannel.localAddress())); assertNull(grpcClientConnectionManager.getRemoteChannelByLocalAddress(localChannel.localAddress()));
assertNull(clientConnectionManager.getRemoteChannelsByAuthenticatedDevice(authenticatedDevice)); assertNull(grpcClientConnectionManager.getRemoteChannelsByAuthenticatedDevice(authenticatedDevice));
} }
@Test @Test
void handleConnectionEstablishedAnonymous() throws InterruptedException { void handleConnectionEstablishedAnonymous() throws InterruptedException {
assertNull(clientConnectionManager.getRemoteChannelByLocalAddress(localChannel.localAddress())); assertNull(grpcClientConnectionManager.getRemoteChannelByLocalAddress(localChannel.localAddress()));
clientConnectionManager.handleConnectionEstablished(localChannel, remoteChannel, Optional.empty()); grpcClientConnectionManager.handleConnectionEstablished(localChannel, remoteChannel, Optional.empty());
assertEquals(remoteChannel, clientConnectionManager.getRemoteChannelByLocalAddress(localChannel.localAddress())); assertEquals(remoteChannel, grpcClientConnectionManager.getRemoteChannelByLocalAddress(localChannel.localAddress()));
remoteChannel.close().await(); remoteChannel.close().await();
assertNull(clientConnectionManager.getRemoteChannelByLocalAddress(localChannel.localAddress())); assertNull(grpcClientConnectionManager.getRemoteChannelByLocalAddress(localChannel.localAddress()));
} }
} }

View File

@ -86,7 +86,7 @@ class NoiseWebSocketTunnelServerIntegrationTest extends AbstractLeakDetectionTes
private static X509Certificate serverTlsCertificate; private static X509Certificate serverTlsCertificate;
private ClientConnectionManager clientConnectionManager; private GrpcClientConnectionManager grpcClientConnectionManager;
private ClientPublicKeysManager clientPublicKeysManager; private ClientPublicKeysManager clientPublicKeysManager;
private ECKeyPair serverKeyPair; private ECKeyPair serverKeyPair;
@ -156,7 +156,7 @@ class NoiseWebSocketTunnelServerIntegrationTest extends AbstractLeakDetectionTes
clientKeyPair = Curve.generateKeyPair(); clientKeyPair = Curve.generateKeyPair();
serverKeyPair = Curve.generateKeyPair(); serverKeyPair = Curve.generateKeyPair();
clientConnectionManager = new ClientConnectionManager(); grpcClientConnectionManager = new GrpcClientConnectionManager();
clientPublicKeysManager = mock(ClientPublicKeysManager.class); clientPublicKeysManager = mock(ClientPublicKeysManager.class);
when(clientPublicKeysManager.findPublicKey(any(), anyByte())) when(clientPublicKeysManager.findPublicKey(any(), anyByte()))
@ -172,8 +172,8 @@ class NoiseWebSocketTunnelServerIntegrationTest extends AbstractLeakDetectionTes
@Override @Override
protected void configureServer(final ServerBuilder<?> serverBuilder) { protected void configureServer(final ServerBuilder<?> serverBuilder) {
serverBuilder.addService(new RequestAttributesServiceImpl()) serverBuilder.addService(new RequestAttributesServiceImpl())
.intercept(new RequestAttributesInterceptor(clientConnectionManager)) .intercept(new RequestAttributesInterceptor(grpcClientConnectionManager))
.intercept(new RequireAuthenticationInterceptor(clientConnectionManager)); .intercept(new RequireAuthenticationInterceptor(grpcClientConnectionManager));
} }
}; };
@ -183,8 +183,8 @@ class NoiseWebSocketTunnelServerIntegrationTest extends AbstractLeakDetectionTes
@Override @Override
protected void configureServer(final ServerBuilder<?> serverBuilder) { protected void configureServer(final ServerBuilder<?> serverBuilder) {
serverBuilder.addService(new RequestAttributesServiceImpl()) serverBuilder.addService(new RequestAttributesServiceImpl())
.intercept(new RequestAttributesInterceptor(clientConnectionManager)) .intercept(new RequestAttributesInterceptor(grpcClientConnectionManager))
.intercept(new ProhibitAuthenticationInterceptor(clientConnectionManager)); .intercept(new ProhibitAuthenticationInterceptor(grpcClientConnectionManager));
} }
}; };
@ -195,7 +195,7 @@ class NoiseWebSocketTunnelServerIntegrationTest extends AbstractLeakDetectionTes
serverTlsPrivateKey, serverTlsPrivateKey,
nioEventLoopGroup, nioEventLoopGroup,
delegatedTaskExecutor, delegatedTaskExecutor,
clientConnectionManager, grpcClientConnectionManager,
clientPublicKeysManager, clientPublicKeysManager,
serverKeyPair, serverKeyPair,
authenticatedGrpcServerAddress, authenticatedGrpcServerAddress,
@ -209,7 +209,7 @@ class NoiseWebSocketTunnelServerIntegrationTest extends AbstractLeakDetectionTes
null, null,
nioEventLoopGroup, nioEventLoopGroup,
delegatedTaskExecutor, delegatedTaskExecutor,
clientConnectionManager, grpcClientConnectionManager,
clientPublicKeysManager, clientPublicKeysManager,
serverKeyPair, serverKeyPair,
authenticatedGrpcServerAddress, authenticatedGrpcServerAddress,
@ -569,7 +569,7 @@ class NoiseWebSocketTunnelServerIntegrationTest extends AbstractLeakDetectionTes
assertEquals(UUIDUtil.toByteString(ACCOUNT_IDENTIFIER), response.getAccountIdentifier()); assertEquals(UUIDUtil.toByteString(ACCOUNT_IDENTIFIER), response.getAccountIdentifier());
assertEquals(DEVICE_ID, response.getDeviceId()); assertEquals(DEVICE_ID, response.getDeviceId());
clientConnectionManager.closeConnection(new AuthenticatedDevice(ACCOUNT_IDENTIFIER, DEVICE_ID)); grpcClientConnectionManager.closeConnection(new AuthenticatedDevice(ACCOUNT_IDENTIFIER, DEVICE_ID));
assertTrue(connectionCloseLatch.await(2, TimeUnit.SECONDS)); assertTrue(connectionCloseLatch.await(2, TimeUnit.SECONDS));
assertEquals(ApplicationWebSocketCloseReason.REAUTHENTICATION_REQUIRED.getStatusCode(), assertEquals(ApplicationWebSocketCloseReason.REAUTHENTICATION_REQUIRED.getStatusCode(),

View File

@ -135,7 +135,7 @@ class WebsocketHandshakeCompleteHandlerTest extends AbstractLeakDetectionTest {
embeddedChannel.pipeline().fireUserEventTriggered(handshakeCompleteEvent); embeddedChannel.pipeline().fireUserEventTriggered(handshakeCompleteEvent);
assertEquals(expectedRemoteAddress, assertEquals(expectedRemoteAddress,
embeddedChannel.attr(ClientConnectionManager.REMOTE_ADDRESS_ATTRIBUTE_KEY).get()); embeddedChannel.attr(GrpcClientConnectionManager.REMOTE_ADDRESS_ATTRIBUTE_KEY).get());
} }
private static List<Arguments> getRemoteAddress() { private static List<Arguments> getRemoteAddress() {