Skip to content

Commit

Permalink
W-15772074: Enable tests with Netty (#841)
Browse files Browse the repository at this point in the history
  • Loading branch information
eze210 authored Dec 27, 2024
1 parent ae7d2ec commit add23af
Show file tree
Hide file tree
Showing 14 changed files with 77 additions and 51 deletions.
7 changes: 5 additions & 2 deletions build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ projectType: extension
mavenTool: "3.9.9"
jdkTool: OPEN-JDK17
testJdkTool: OPEN-JDK17
mavenAdditionalArgs: -Drevapi.skip -DexportedPackagesValidator.skip -Dmaven.javadoc.skip=true -Dmule.jvm.version.extension.enforcement=LOOSE -Dmule.module.tweaking.validation.skip=true
mavenAdditionalArgs: -Dmule.jvm.version.extension.enforcement=LOOSE -Dmule.module.tweaking.validation.skip=true
additionalTestConfigs:
mtf-jdk8:
testJdkTool: OPEN-JDK8
Expand All @@ -13,4 +13,7 @@ additionalTestConfigs:
# testJdkTool: OPEN-JDK11
# mavenAdditionalArgs: -pl mule-http-connector -DskipUnitTests=true
jdk21:
testJdkTool: TEMURIN-JDK21
testJdkTool: TEMURIN-JDK21
netty-jdk17:
mavenAdditionalArgs: -Drevapi.skip -DexportedPackagesValidator.skip -Dmaven.javadoc.skip=true -Dmule.jvm.version.extension.enforcement=LOOSE -Dmule.module.tweaking.validation.skip=true -Dmule.http.service.implementation=NETTY -DmunitMinMuleVersion=4.9.0

4 changes: 2 additions & 2 deletions functional-tests/cors/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@
<dependency>
<groupId>org.mule.runtime</groupId>
<artifactId>mule-dwb-api</artifactId>
<version>2.9.0-20241028</version>
<version>2.10.0-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand All @@ -126,4 +126,4 @@
</exclusions>
</dependency>
</dependencies>
</project>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,11 @@ public abstract class AbstractHttpTestCase extends MuleArtifactFunctionalTestCas
protected static final String J17_SSL_ERROR_RESPONSE = "PKIX path validation failed";
// Expected validation messages for certificates when testing fips.
public static final String BOUNCY_CASTLE_CERTIFICATE_UNKNOWN_ERROR_MESSAGE = "certificate_unknown";
// Expected validation error message when using Netty.
protected static final String NETTY_SSL_ERROR_RESPONSE = "Received fatal alert: handshake_failure";
protected static final String APPROPRIATE_PROTOCOL_ERROR =
"No appropriate protocol (protocol is disabled or cipher suites are inappropriate)";
protected static final String NETTY_APPROPRIATE_PROTOCOL_ERROR = "Received fatal alert: protocol_version";

@Rule
public TestHttpClient httpClient = new TestHttpClient.Builder(getService(HttpService.class)).build();
Expand Down Expand Up @@ -83,6 +86,8 @@ protected Matcher<String> sslValidationError() {
containsString(J8_275_SSL_ERROR_RESPONSE),
containsString(J11_SSL_ERROR_RESPONSE),
containsString(J17_SSL_ERROR_RESPONSE),
containsString(APPROPRIATE_PROTOCOL_ERROR)));
containsString(NETTY_SSL_ERROR_RESPONSE),
containsString(APPROPRIATE_PROTOCOL_ERROR),
containsString(NETTY_APPROPRIATE_PROTOCOL_ERROR)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,18 @@ public void noListenerConfigWithSpecialCharacters() throws Exception {
SocketRequester socketRequester = new SocketRequester("localhost", noListenerConfigPort.getNumber());
socketRequester.initialize();
socketRequester.doRequest("GET " + invalidPathWithSpecialCharacters + " HTTP/1.1");
assertThat(socketRequester.getResponse(),
containsString(format(NO_LISTENER_ENTITY_FORMAT, escapeHtml4(invalidPathWithSpecialCharacters))));

String errorMessage;
if (System.getProperty("mule.http.service.implementation", "GRIZZLY").equals("GRIZZLY")) {
errorMessage = format(NO_LISTENER_ENTITY_FORMAT, escapeHtml4(invalidPathWithSpecialCharacters));
} else {
String url = format("http://127.0.0.1:%d%s", noListenerConfigPort.getNumber(), invalidPathWithSpecialCharacters);
int indexOfLT = url.indexOf('<');
errorMessage =
format("HTTP request parsing failed with error: \"Illegal character in path at index %d: %s\"", indexOfLT, url);
}

assertThat(socketRequester.getResponse(), containsString(errorMessage));
socketRequester.finalizeGracefully();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,14 @@
*/
package org.mule.test.http.functional.listener;

import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThat;
import static org.mule.runtime.http.api.HttpHeaders.Names.CONNECTION;
import static org.mule.runtime.http.api.HttpHeaders.Values.KEEP_ALIVE;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.emptyOrNullString;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.not;

import org.mule.runtime.core.api.util.StringUtils;
import org.mule.tck.junit4.rule.DynamicPort;
import org.mule.test.http.functional.AbstractHttpTestCase;
Expand Down Expand Up @@ -122,7 +126,11 @@ private HttpResponse doPerformRequest(int port, HttpVersion httpVersion, boolean
}

private void assertResponse(String response, boolean shouldBeValid) {
assertThat(StringUtils.isEmpty(response), is(!shouldBeValid));
if (shouldBeValid) {
assertThat(response, not(emptyOrNullString()));
} else {
assertThat(response, emptyOrNullString());
}
}

private void sendRequest(Socket socket, HttpVersion httpVersion) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,6 @@ private HttpResponse statusLineResponseBuilderTest(String url, int expectedStatu
throws IOException {
final Response response = Request.Get(url).connectTimeout(DEFAULT_TIMEOUT).execute();
final HttpResponse httpResponse = response.returnResponse();
assertThat(httpResponse.getAllHeaders().length, is(greaterThanOrEqualTo((2))));
assertThat(httpResponse.getStatusLine().getStatusCode(), is(expectedStatus));
assertThat(httpResponse.getStatusLine().getReasonPhrase(), is(expectedReasonPhrase));
return httpResponse;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,10 @@

import static java.lang.String.format;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThat;

import org.mule.extension.http.api.HttpResponseAttributes;
import org.mule.extension.http.api.error.HttpError;
Expand All @@ -53,7 +54,6 @@
import io.qameta.allure.Issue;
import io.qameta.allure.Stories;
import io.qameta.allure.Story;
import org.apache.commons.lang3.SystemUtils;
import org.junit.Rule;
import org.junit.Test;

Expand Down Expand Up @@ -157,17 +157,10 @@ public void timeout() throws Exception {

@Test
public void connectivity() throws Exception {

String customMessage = ": Connection refused";
if (SystemUtils.IS_OS_WINDOWS) {
customMessage = customMessage.concat(": no further information");
}

CoreEvent result = getFlowRunner("handled", unusedPort.getNumber()).run();
assertThat(result.getMessage(),
hasPayload(equalTo(getErrorMessage(customMessage, unusedPort)
+ " connectivity")));

// The exact message depends on the OS and the underlying framework, but all contain "Connection refused".
assertThat(result.getMessage(), hasPayload(containsString("Connection refused")));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,13 @@ public void errorMessageIsLoadedFromCauseIfNull() throws Exception {
String msg = exception.getMessage();
assertThat(msg, containsString("HTTP GET on resource 'http://notarealsite.mulesoft:124/fakeresource'"));

// Using runtime version 4.1.1, the message contains the name of the exception: "UnresolvedAddressException"
// Using latest, the message is "Couldn't resolve address"
// Using latest grizzly, the message is "Couldn't resolve address"
// Using latest Netty, the message is "nodename nor servname provided, or not known"
// Using Reactor Netty, the message is "Failed to resolve..."
assertThat(msg, anyOf(containsString("UnresolvedAddressException"),
containsString("Couldn't resolve address")));
containsString("Couldn't resolve address"),
containsString("nodename nor servname provided, or not known"),
containsString("Failed to resolve")));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@

import static org.mule.runtime.http.api.HttpConstants.HttpStatus.EXPECTATION_FAILED;

import static org.junit.Assert.assertThat;
import static java.lang.System.getProperty;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.junit.Assume.assumeThat;

import org.mule.extension.http.api.HttpResponseAttributes;
import org.mule.runtime.core.api.event.CoreEvent;
Expand All @@ -31,6 +35,9 @@ protected String getConfigFile() {

@Test
public void handlesExpectationFailedResponse() throws Exception {
// TODO (W-15666548): Enable this for NETTY too.
assumeThat(getProperty("mule.http.service.implementation", "GRIZZLY"), is("GRIZZLY"));

startExpectFailedServer();

// Set a payload that will fail when consumed. As the server rejects the request after processing
Expand All @@ -48,5 +55,4 @@ public int read() throws IOException {

stopServer();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,21 @@
* LICENSE.txt file.
*/

import static org.mule.runtime.core.api.util.NetworkUtils.getLocalHost;

import static javax.servlet.http.HttpServletResponse.SC_OK;
import static javax.servlet.http.HttpServletResponse.SC_UNAUTHORIZED;

import org.mule.runtime.core.api.util.Base64;
import org.mule.test.http.functional.requester.TestAuthorizer;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.ning.http.client.ntlm.NTLMEngine;

public class NtlmProxyTestAuthorizer implements TestAuthorizer {

private static final String TYPE_2_MESSAGE_CHALLENGE = "TlRMTVNTUAACAAAAAAAAACgAAAABggAAU3J2Tm9uY2UAAAAAAAAAAA==";
private static final String TYPE_2_MESSAGE = "NTLM " + TYPE_2_MESSAGE_CHALLENGE;
private static final String TYPE_1_MESSAGE = "NTLM TlRMTVNTUAABAAAAAYIIogAAAAAoAAAAAAAAACgAAAAFASgKAAAADw==";
private static final String AUTHORIZED = "Authorized";

private String clientAuthHeader;
Expand All @@ -42,8 +38,6 @@ public class NtlmProxyTestAuthorizer implements TestAuthorizer {
private String domain;
private String workstation;

private String type3Message;


public NtlmProxyTestAuthorizer(String clientAuthHeader, String serverAuthHeader, int unauthorizedHeader, String user,
String password, String domain, String workstation) {
Expand All @@ -56,12 +50,6 @@ public NtlmProxyTestAuthorizer(String clientAuthHeader, String serverAuthHeader,
this.workstation = workstation;
}

public void setUp() throws Exception {
String ntlmHost = workstation != null ? workstation : getLocalHost().getHostName();
String type3Challenge = NTLMEngine.INSTANCE.generateType3Msg(user, password, domain, ntlmHost, TYPE_2_MESSAGE_CHALLENGE);
type3Message = "NTLM " + type3Challenge;
}

@Override
public boolean authorizeRequest(String address, HttpServletRequest request, HttpServletResponse response,
boolean addAuthorizeMessageInProxy)
Expand All @@ -72,11 +60,11 @@ public boolean authorizeRequest(String address, HttpServletRequest request, Http
response.addHeader(serverAuthHeader, "NTLM");
return false;
}
if (TYPE_1_MESSAGE.equals(auth)) {
if (isNtlmTypeN(auth, 1)) {
response.setStatus(unauthorizedHeader);
response.setHeader(serverAuthHeader, TYPE_2_MESSAGE);
return false;
} else if (type3Message.equals(auth)) {
} else if (isNtlmTypeN(auth, 3)) {
response.setStatus(SC_OK);
if (addAuthorizeMessageInProxy) {
response.getWriter().print(AUTHORIZED);
Expand All @@ -88,6 +76,17 @@ public boolean authorizeRequest(String address, HttpServletRequest request, Http
}
}

private static boolean isNtlmTypeN(String header, int n) {
if (!header.startsWith("NTLM ")) {
return false;
}

String base64 = header.substring(5);
byte[] asByteArray = Base64.decode(base64);
byte type = asByteArray[8];
return type == n;
}

public static class Builder {

private String clientAuthHeader;
Expand Down Expand Up @@ -134,11 +133,8 @@ public Builder setWorkstation(String workstation) {
}

public NtlmProxyTestAuthorizer build() throws Exception {
NtlmProxyTestAuthorizer testAuthorizer = new NtlmProxyTestAuthorizer(clientAuthHeader, serverAuthHeader, unauthorizedHeader,
user, password, domain, workstation);
testAuthorizer.setUp();

return testAuthorizer;
return new NtlmProxyTestAuthorizer(clientAuthHeader, serverAuthHeader, unauthorizedHeader, user, password, domain,
workstation);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import static java.lang.System.getProperty;

import static org.apache.commons.lang3.SystemUtils.isJavaVersionAtLeast;
import static org.hamcrest.CoreMatchers.anyOf;
import static org.hamcrest.CoreMatchers.containsString;
import static org.junit.Assume.assumeTrue;

Expand Down Expand Up @@ -80,7 +81,9 @@ public static void assumeJdkIsCompatible() {
@Test
public void testClient12ToServer13() throws Exception {
expectedError.expectErrorType("HTTP", "CONNECTIVITY");
expectedError.expectMessage(containsString(ERROR_RESPONSE));
expectedError.expectMessage(anyOf(
containsString(ERROR_RESPONSE),
containsString("Received fatal alert: protocol_version")));
flowRunner(client12).run();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@

<Loggers>

<AsyncLogger name="org.mule.service.http.impl.service.HttpMessageLogger" level="DEBUG" />
<AsyncLogger name="org.mule.service.http.impl.service.HttpMessageLogger" level="INFO" />
<AsyncLogger name="org.mule.service.http.netty.impl.client" level="WARN" />

<AsyncLogger name="org.mule.runtime.core.internal.processor.LoggerMessageProcessor" level="INFO"/>
<AsyncLogger name="com.mulesoft.agent" level="INFO"/>
Expand Down
1 change: 0 additions & 1 deletion functional-tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@
<groupId>org.mule.services</groupId>
<artifactId>mule-service-weave</artifactId>
<classifier>mule-service</classifier>
<version>2.7.2</version>
</dependency>
<dependency>
<groupId>org.mule.runtime</groupId>
Expand Down
2 changes: 1 addition & 1 deletion mule-http-connector/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@
<type>pom</type>
<scope>import</scope>
</dependency>

<!-- These override the version obtained transitively from a dependency declared in the parent pom. -->
<dependency>
<groupId>org.springframework</groupId>
Expand Down

0 comments on commit add23af

Please sign in to comment.