Skip to content

Commit

Permalink
refactor(iot-service, e2e): Upgrade Guava and Jackson dependencies
Browse files Browse the repository at this point in the history
Adding a proxy implementation to our code so that we can make some modifications so it is compatible with more recent guava versions. For the most part, this proxy implementation is equivalent to the dependency we previously took

All this proxy code now lives in the "tests/integration/com/microsoft/azure/sdk/iot/helpers/proxy" path.
  • Loading branch information
timtay-microsoft authored Apr 18, 2022
1 parent 24c59ee commit a3e4e29
Show file tree
Hide file tree
Showing 50 changed files with 7,662 additions and 55 deletions.
24 changes: 11 additions & 13 deletions iot-e2e-tests/common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -84,24 +84,22 @@
<artifactId>jmockit</artifactId>
<version>1.24</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.littleshoot/littleproxy -->
<dependency>
<groupId>org.littleshoot</groupId>
<artifactId>littleproxy</artifactId>
<version>1.1.2</version>
<exclusions>
<!--Littleproxy is Android compatible except for this dependency. Luckily, we don't need this dependency for our tests-->
<exclusion>
<groupId>com.barchart.udt</groupId>
<artifactId>barchart-udt-bundle</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.5</version>
</dependency>

<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-all</artifactId>
</dependency>
<!--
This newer Azure storage SDK has some compatibility issues with Android. Leaving this dependency alone
until this issue can be investigated further
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,15 @@
import org.junit.rules.Timeout;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.littleshoot.proxy.HttpProxyServer;
import org.littleshoot.proxy.impl.DefaultHttpProxyServer;
import tests.integration.com.microsoft.azure.sdk.iot.digitaltwin.helpers.E2ETestConstants;
import tests.integration.com.microsoft.azure.sdk.iot.helpers.BasicProxyAuthenticator;
import tests.integration.com.microsoft.azure.sdk.iot.helpers.IntegrationTest;
import tests.integration.com.microsoft.azure.sdk.iot.helpers.SasTokenTools;
import tests.integration.com.microsoft.azure.sdk.iot.helpers.Tools;
import tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.DigitalTwinTest;
import tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.StandardTierHubOnlyTest;
import tests.integration.com.microsoft.azure.sdk.iot.helpers.proxy.HttpProxyServer;
import tests.integration.com.microsoft.azure.sdk.iot.helpers.proxy.impl.DefaultHttpProxyServer;

import java.io.IOException;
import java.net.InetSocketAddress;
Expand Down Expand Up @@ -144,8 +145,8 @@ private DeviceClient createDeviceClient(IotHubClientProtocol protocol, String mo
public static void startProxy()
{
proxyServer = DefaultHttpProxyServer.bootstrap()
.withPort(testProxyPort)
.start();
.withPort(testProxyPort)
.start();
}

@AfterClass
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

package tests.integration.com.microsoft.azure.sdk.iot.helpers;

import org.littleshoot.proxy.ProxyAuthenticator;
import tests.integration.com.microsoft.azure.sdk.iot.helpers.proxy.ProxyAuthenticator;

public class BasicProxyAuthenticator implements ProxyAuthenticator
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
package tests.integration.com.microsoft.azure.sdk.iot.helpers.proxy;

import io.netty.handler.codec.http.HttpRequest;
import io.netty.handler.codec.http.HttpResponse;

import javax.net.ssl.SSLSession;
import java.net.InetSocketAddress;

/**
* <p>
* Interface for receiving information about activity in the proxy.
* </p>
*
* <p>
* Sub-classes may wish to extend {@link ActivityTrackerAdapter} for sensible
* defaults.
* </p>
*/
public interface ActivityTracker {

/**
* Record that a client connected.
*
* @param clientAddress
*/
void clientConnected(InetSocketAddress clientAddress);

/**
* Record that a client's SSL handshake completed.
*
* @param clientAddress
* @param sslSession
*/
void clientSSLHandshakeSucceeded(InetSocketAddress clientAddress,
SSLSession sslSession);

/**
* Record that a client disconnected.
*
* @param clientAddress
* @param sslSession
*/
void clientDisconnected(InetSocketAddress clientAddress,
SSLSession sslSession);

/**
* Record that the proxy received bytes from the client.
*
* @param flowContext
* if full information is available, this will be a
* {@link FullFlowContext}.
* @param numberOfBytes
*/
void bytesReceivedFromClient(FlowContext flowContext,
int numberOfBytes);

/**
* <p>
* Record that proxy received an {@link HttpRequest} from the client.
* </p>
*
* <p>
* Note - on chunked transfers, this is only called once (for the initial
* HttpRequest object).
* </p>
*
* @param flowContext
* if full information is available, this will be a
* {@link FullFlowContext}.
* @param httpRequest
*/
void requestReceivedFromClient(FlowContext flowContext,
HttpRequest httpRequest);

/**
* Record that the proxy attempted to send bytes to the server.
*
* @param flowContext
* provides contextual information about the flow
* @param numberOfBytes
*/
void bytesSentToServer(FullFlowContext flowContext, int numberOfBytes);

/**
* <p>
* Record that proxy attempted to send a request to the server.
* </p>
*
* <p>
* Note - on chunked transfers, this is only called once (for the initial
* HttpRequest object).
* </p>
*
* @param flowContext
* provides contextual information about the flow
* @param httpRequest
*/
void requestSentToServer(FullFlowContext flowContext,
HttpRequest httpRequest);

/**
* Record that the proxy received bytes from the server.
*
* @param flowContext
* provides contextual information about the flow
* @param numberOfBytes
*/
void bytesReceivedFromServer(FullFlowContext flowContext, int numberOfBytes);

/**
* <p>
* Record that the proxy received an {@link HttpResponse} from the server.
* </p>
*
* <p>
* Note - on chunked transfers, this is only called once (for the initial
* HttpRequest object).
* </p>
*
* @param flowContext
* provides contextual information about the flow
* @param httpResponse
*/
void responseReceivedFromServer(FullFlowContext flowContext,
HttpResponse httpResponse);

/**
* Record that the proxy sent bytes to the client.
*
* @param flowContext
* if full information is available, this will be a
* {@link FullFlowContext}.
* @param numberOfBytes
*/
void bytesSentToClient(FlowContext flowContext, int numberOfBytes);

/**
* <p>
* Record that the proxy sent a response to the client.
* </p>
*
* <p>
* Note - on chunked transfers, this is only called once (for the initial
* HttpRequest object).
* </p>
*
* @param flowContext
* if full information is available, this will be a
* {@link FullFlowContext}.
* @param httpResponse
*/
void responseSentToClient(FlowContext flowContext,
HttpResponse httpResponse);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package tests.integration.com.microsoft.azure.sdk.iot.helpers.proxy;

import io.netty.handler.codec.http.HttpRequest;
import io.netty.handler.codec.http.HttpResponse;

import javax.net.ssl.SSLSession;
import java.net.InetSocketAddress;

/**
* Adapter of {@link ActivityTracker} interface that provides default no-op
* implementations of all methods.
*/
public class ActivityTrackerAdapter implements ActivityTracker {

@Override
public void bytesReceivedFromClient(FlowContext flowContext,
int numberOfBytes) {
}

@Override
public void requestReceivedFromClient(FlowContext flowContext,
HttpRequest httpRequest) {
}

@Override
public void bytesSentToServer(FullFlowContext flowContext, int numberOfBytes) {
}

@Override
public void requestSentToServer(FullFlowContext flowContext,
HttpRequest httpRequest) {
}

@Override
public void bytesReceivedFromServer(FullFlowContext flowContext,
int numberOfBytes) {
}

@Override
public void responseReceivedFromServer(FullFlowContext flowContext,
HttpResponse httpResponse) {
}

@Override
public void bytesSentToClient(FlowContext flowContext,
int numberOfBytes) {
}

@Override
public void responseSentToClient(FlowContext flowContext,
HttpResponse httpResponse) {
}

@Override
public void clientConnected(InetSocketAddress clientAddress) {
}

@Override
public void clientSSLHandshakeSucceeded(InetSocketAddress clientAddress,
SSLSession sslSession) {
}

@Override
public void clientDisconnected(InetSocketAddress clientAddress,
SSLSession sslSession) {
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package tests.integration.com.microsoft.azure.sdk.iot.helpers.proxy;

import io.netty.handler.codec.http.HttpObject;

import java.net.InetSocketAddress;

/**
* <p>
* Encapsulates information needed to connect to a chained proxy.
* </p>
*
* <p>
* Sub-classes may wish to extend {@link ChainedProxyAdapter} for sensible
* defaults.
* </p>
*/
public interface ChainedProxy extends SslEngineSource
{
/**
* Return the {@link InetSocketAddress} for connecting to the chained proxy.
* Returning null indicates that we won't chain.
*
* @return The Chain Proxy with Host and Port.
*/
InetSocketAddress getChainedProxyAddress();

/**
* (Optional) ensure that the connection is opened from a specific local
* address (useful when doing NAT traversal).
*
* @return
*/
InetSocketAddress getLocalAddress();

/**
* Tell LittleProxy what kind of TransportProtocol to use to communicate
* with the chained proxy.
*
* @return
*/
TransportProtocol getTransportProtocol();

/**
* Implement this method to tell LittleProxy whether or not to encrypt
* connections to the chained proxy for the given request. If true,
* LittleProxy will call {@link SslEngineSource#newSslEngine()} to obtain an
* SSLContext used by the downstream proxy.
*
* @return true of the connection to the chained proxy should be encrypted
*/
boolean requiresEncryption();

/**
* Filters requests on their way to the chained proxy.
*
* @param httpObject
*/
void filterRequest(HttpObject httpObject);

/**
* Called to let us know that connecting to this proxy succeeded.
*/
void connectionSucceeded();

/**
* Called to let us know that connecting to this proxy failed.
*
* @param cause
* exception that caused this failure (may be null)
*/
void connectionFailed(Throwable cause);

/**
* Called to let us know that we were disconnected.
*/
void disconnected();
}
Loading

0 comments on commit a3e4e29

Please sign in to comment.