Fix potential NPE when extracting data from query params. Fixes #3405
This commit is contained in:
@@ -65,6 +65,9 @@ import static org.springframework.boot.test.context.SpringBootTest.WebEnvironmen
|
||||
public class RibbonClientHttpRequestFactoryTests {
|
||||
|
||||
@Rule
|
||||
/**
|
||||
* JUnit rule
|
||||
*/
|
||||
public final ExpectedException exceptionRule = ExpectedException.none();
|
||||
|
||||
@LoadBalanced
|
||||
|
||||
@@ -38,14 +38,19 @@ import org.springframework.security.provisioning.InMemoryUserDetailsManager;
|
||||
@AutoConfigureBefore(SecurityAutoConfiguration.class)
|
||||
public class TestAutoConfiguration {
|
||||
|
||||
/**
|
||||
* User name
|
||||
*/
|
||||
public static final String USER = "user";
|
||||
|
||||
/**
|
||||
* Password
|
||||
*/
|
||||
public static final String PASSWORD = "{noop}password";
|
||||
|
||||
@Configuration
|
||||
@Order(Ordered.HIGHEST_PRECEDENCE)
|
||||
protected static class TestSecurityConfiguration
|
||||
extends WebSecurityConfigurerAdapter {
|
||||
static class TestSecurityConfiguration extends WebSecurityConfigurerAdapter {
|
||||
|
||||
TestSecurityConfiguration() {
|
||||
super(true);
|
||||
|
||||
@@ -98,6 +98,7 @@ public final class RequestContentDataExtractor {
|
||||
|
||||
if (listOfOnlyQueryParams != null) {
|
||||
listOfOnlyQueryParams = listOfOnlyQueryParams.stream()
|
||||
.filter(queryParam -> queryParam != null)
|
||||
.map(param -> uriDecode(param, Charset.defaultCharset()))
|
||||
.collect(Collectors.toList());
|
||||
if (!listOfOnlyQueryParams.containsAll(listOfAllParams)) {
|
||||
|
||||
@@ -16,7 +16,9 @@
|
||||
|
||||
package org.springframework.cloud.netflix.zuul.util;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -26,6 +28,7 @@ import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
import org.springframework.http.HttpEntity;
|
||||
import org.springframework.util.LinkedMultiValueMap;
|
||||
import org.springframework.util.MultiValueMap;
|
||||
import org.springframework.web.multipart.MultipartHttpServletRequest;
|
||||
@@ -140,4 +143,26 @@ public class RequestContentDataExtractorTest {
|
||||
assertThat(result.size()).isEqualTo(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void findQueryParamsGroupedByNameShouldReturnEmptyMapWhenQueryValueIsNull()
|
||||
throws IOException {
|
||||
// when
|
||||
Map<String, String[]> paramMap = new HashMap<>();
|
||||
paramMap.put("uid", new String[] { "foo", "bar" });
|
||||
when(request.getQueryString()).thenReturn("uid");
|
||||
when(request.getParameterMap()).thenReturn(paramMap);
|
||||
when(request.getMultiFileMap()).thenReturn(new LinkedMultiValueMap<>());
|
||||
|
||||
// action
|
||||
Map<String, List<Object>> result = RequestContentDataExtractor.extract(request);
|
||||
|
||||
// then
|
||||
List<Object> uidResult = new LinkedList();
|
||||
uidResult.add(new HttpEntity<>("foo"));
|
||||
uidResult.add(new HttpEntity<>("bar"));
|
||||
assertThat(result).isNotNull();
|
||||
assertThat(result).containsEntry("uid", uidResult);
|
||||
assertThat(result.size()).isEqualTo(1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user