Fixes test to check rawquery values.

Since https://github.com/joel-costigliola/assertj-core/issues/1699 assertj uses the raw query instead of the encoded one.

fixes gh-1551
This commit is contained in:
Spencer Gibb
2020-02-03 17:46:33 -05:00
parent 27b49a5a7d
commit fd71c30277
2 changed files with 8 additions and 5 deletions

View File

@@ -208,13 +208,16 @@ public final class ServerWebExchangeUtils {
boolean encoded = (uri.getRawQuery() != null && uri.getRawQuery().contains("%"))
|| (uri.getRawPath() != null && uri.getRawPath().contains("%"));
// Verify if it is really fully encoded. Treat partial encoded as uncoded.
// Verify if it is really fully encoded. Treat partial encoded as unencoded.
if (encoded) {
try {
UriComponentsBuilder.fromUri(uri).build(true);
return true;
}
catch (IllegalArgumentException ignore) {
if (log.isTraceEnabled()) {
log.trace("Error in containsEncodedParts", ignore);
}
}
return false;

View File

@@ -18,7 +18,6 @@ package org.springframework.cloud.gateway.filter;
import java.net.URI;
import org.junit.Ignore;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
import reactor.core.publisher.Mono;
@@ -116,7 +115,6 @@ public class RouteToRequestUrlFilterTests {
}
@Test
@Ignore // FIXME: gh-1551
public void partialEncodedParameters() {
URI url = UriComponentsBuilder
.fromUriString("http://localhost/get?key[]=test= key&start=1533108081")
@@ -134,10 +132,12 @@ public class RouteToRequestUrlFilterTests {
ServerWebExchange webExchange = testFilter(request, "http://myhost");
URI uri = webExchange.getRequiredAttribute(GATEWAY_REQUEST_URL_ATTR);
assertThat(uri).hasScheme("http").hasHost("myhost")
.hasParameter("key[]", "test= key").hasParameter("start", "1533108081");
// since https://github.com/joel-costigliola/assertj-core/issues/1699
// assertj uses raw query
.hasParameter("key[]", "test=%20key").hasParameter("start", "1533108081");
// prove that it is double encoded since partial encoded uri is treated as
// uncoded.
// unencoded.
assertThat(uri.getRawQuery()).isEqualTo("key[]=test=%2520key&start=1533108081");
}