YARN-6615. AmIpFilter drops query parameters on redirect. Contributed by Wilfred Spiegelenburg

(cherry picked from commit 7ef01c7c49)
This commit is contained in:
Jason Lowe 2017-05-24 11:31:39 -05:00
parent 6d657054eb
commit f99a48aa63
3 changed files with 23 additions and 4 deletions

View File

@ -96,6 +96,9 @@ Release 2.7.4 - UNRELEASED
YARN-4612. Fix rumen and scheduler load simulator handle killed tasks properly.
(Ming Ma via xgong)
YARN-6615. AmIpFilter drops query parameters on redirect. (Wilfred
Spiegelenburg via jlowe)
Release 2.7.3 - 2016-08-25
INCOMPATIBLE CHANGES

View File

@ -135,9 +135,16 @@ public class AmIpFilter implements Filter {
LOG.debug("Remote address for request is: {}", httpReq.getRemoteAddr());
}
if (!getProxyAddresses().contains(httpReq.getRemoteAddr())) {
String redirectUrl = findRedirectUrl();
String target = redirectUrl + httpReq.getRequestURI();
ProxyUtils.sendRedirect(httpReq, httpResp, target);
StringBuilder target = new StringBuilder().append(findRedirectUrl());
target.append(httpReq.getRequestURI());
// add the query parameters on the redirect if there were any
String queryString = httpReq.getQueryString();
if (queryString != null && !queryString.isEmpty()) {
target.append("?");
target.append(queryString);
}
ProxyUtils.sendRedirect(httpReq, httpResp, target.toString());
return;
}

View File

@ -21,6 +21,7 @@ package org.apache.hadoop.yarn.server.webproxy.amfilter;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.net.HttpURLConnection;
import java.util.*;
import java.util.concurrent.atomic.AtomicBoolean;
@ -163,9 +164,17 @@ public class TestAmFilter {
Mockito.when(request.getRequestURI()).thenReturn("/redirect");
testFilter.doFilter(request, response, chain);
// address "redirect" is not in host list
assertEquals(302, response.status);
assertEquals(HttpURLConnection.HTTP_MOVED_TEMP, response.status);
String redirect = response.getHeader(ProxyUtils.LOCATION);
assertEquals("http://bogus/redirect", redirect);
// check for query parameters
Mockito.when(request.getRequestURI()).thenReturn("/proxy/application_00_0");
Mockito.when(request.getQueryString()).thenReturn("id=0");
testFilter.doFilter(request, response, chain);
assertEquals(HttpURLConnection.HTTP_MOVED_TEMP, response.status);
redirect = response.getHeader(ProxyUtils.LOCATION);
assertEquals("http://bogus/proxy/application_00_0?id=0", redirect);
// "127.0.0.1" contains in host list. Without cookie
Mockito.when(request.getRemoteAddr()).thenReturn("127.0.0.1");
testFilter.doFilter(request, response, chain);