Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

W-15772074: Enable tests with Netty #841

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions build.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
projectType: extension
mavenTool: "3.9.5"
mavenTool: "3.9.9"

mavenAdditionalArgs: -pl .,mule-http-connector

additionalTestConfigs:
functionalTests:
functionalTestsGrizzly:
jdkTool: OPEN-JDK17
mavenAdditionalArgs: -pl functional-tests,functional-tests/http,functional-tests/cors -Drevapi.skip -DexportedPackagesValidator.skip -Dmaven.javadoc.skip=true -Dmule.jvm.version.extension.enforcement=LOOSE -Dmule.module.tweaking.validation.skip=true
munitTests:
munitTestsGrizzly:
testJdkTool: OPEN-JDK17
mavenAdditionalArgs: -pl mule-http-connector -DmunitMinMuleVersion=4.6.0 -Drevapi.skip -DexportedPackagesValidator.skip -Dmaven.javadoc.skip=true -Dmule.jvm.version.extension.enforcement=LOOSE -Dmule.module.tweaking.validation.skip=true
functionalTestsNetty:
jdkTool: OPEN-JDK17
mavenAdditionalArgs: -pl functional-tests,functional-tests/http,functional-tests/cors -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
munitTestsNetty:
testJdkTool: OPEN-JDK17
mavenAdditionalArgs: -pl mule-http-connector -DmunitMinMuleVersion=4.10.0-SNAPSHOT -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
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>
8 changes: 1 addition & 7 deletions functional-tests/http/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -249,12 +249,6 @@
<version>${mule.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.mule.runtime</groupId>
<artifactId>mule-module-javaee</artifactId>
<version>${mule.version}</version>
<scope>provided</scope>
</dependency>

<!-- Mule Services -->
<dependency>
Expand All @@ -273,7 +267,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 Down
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 @@ -23,6 +23,7 @@
import org.mule.runtime.http.api.HttpConstants.HttpStatus;
import org.mule.runtime.http.api.domain.entity.ByteArrayHttpEntity;
import org.mule.runtime.http.api.domain.message.request.HttpRequest;
import org.mule.service.http.netty.impl.provider.NettyHttpServiceProvider;
import org.mule.tck.junit4.rule.DynamicPort;
import org.mule.tck.junit4.rule.SystemProperty;
import org.mule.test.http.functional.AbstractHttpTestCase;
Expand Down Expand Up @@ -113,8 +114,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
6 changes: 3 additions & 3 deletions functional-tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@
<maven.surefire.plugin.version>3.5.2</maven.surefire.plugin.version>

<muleDependenciesVersion>1.x-SNAPSHOT</muleDependenciesVersion>
<mule.version>4.9.0-SNAPSHOT</mule.version>
<mule.version>4.10.0-SNAPSHOT</mule.version>
<muleBomVersion>${mule.version}</muleBomVersion>
<muleApiVersion>1.9.0-SNAPSHOT</muleApiVersion>
<muleApiVersion>1.10.0-SNAPSHOT</muleApiVersion>
<httpConnectorVersion>${project.version}</httpConnectorVersion>

<!-- fips testing -->
Expand Down Expand Up @@ -96,7 +96,7 @@
<dependency>
<groupId>org.mule.runtime</groupId>
<artifactId>mule-dwb-api</artifactId>
<version>2.9.0-20241028</version>
<version>2.10.0-SNAPSHOT</version>
</dependency>

<!-- fips testing -->
Expand Down
Loading