This is an automated email from the ASF dual-hosted git repository. pinal pushed a commit to branch branch-2.0 in repository https://gitbox.apache.org/repos/asf/atlas.git
The following commit(s) were added to refs/heads/branch-2.0 by this push: new 7f2582180 ATLAS-4757 : Regression - DSL queries redirected to passive server fails 7f2582180 is described below commit 7f2582180737282399ffab3e959636be32fa3243 Author: chaitali borole <chaitali.bor...@freestoneinfotech.com> AuthorDate: Thu Jun 8 19:06:01 2023 +0530 ATLAS-4757 : Regression - DSL queries redirected to passive server fails Signed-off-by: Pinal Shah <pinal.s...@freestoneinfotech.com> --- .../atlas/web/filters/ActiveServerFilter.java | 4 ++- .../atlas/web/filters/ActiveServerFilterTest.java | 35 ++++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/webapp/src/main/java/org/apache/atlas/web/filters/ActiveServerFilter.java b/webapp/src/main/java/org/apache/atlas/web/filters/ActiveServerFilter.java index 8d6aab688..a25a51b5a 100644 --- a/webapp/src/main/java/org/apache/atlas/web/filters/ActiveServerFilter.java +++ b/webapp/src/main/java/org/apache/atlas/web/filters/ActiveServerFilter.java @@ -160,7 +160,9 @@ public class ActiveServerFilter implements Filter { String queryString = servletRequest.getQueryString(); if (queryString != null && (!queryString.isEmpty())) { - queryString = UriUtils.encodeQuery(queryString, "UTF-8"); + //Decoding the queryString from UI to avoid partial encoding issue and re-encoding. + String decodedQueryString = UriUtils.decode(queryString, "UTF-8"); + queryString = UriUtils.encodeQuery(decodedQueryString, "UTF-8"); } if ((queryString != null) && (!queryString.isEmpty())) { diff --git a/webapp/src/test/java/org/apache/atlas/web/filters/ActiveServerFilterTest.java b/webapp/src/test/java/org/apache/atlas/web/filters/ActiveServerFilterTest.java index 04b4e4a35..0e42500bc 100644 --- a/webapp/src/test/java/org/apache/atlas/web/filters/ActiveServerFilterTest.java +++ b/webapp/src/test/java/org/apache/atlas/web/filters/ActiveServerFilterTest.java @@ -161,6 +161,41 @@ public class ActiveServerFilterTest { } + @Test + public void testOriginalRequestShouldNotEncodeQueryParametersAgain() throws IOException, ServletException { + when(serviceState.getState()).thenReturn(ServiceState.ServiceStateValue.PASSIVE); + + ActiveServerFilter activeServerFilter = new ActiveServerFilter(activeInstanceState, serviceState); + + when(activeInstanceState.getActiveServerAddress()).thenReturn(ACTIVE_SERVER_ADDRESS); + when(servletRequest.getMethod()).thenReturn(HttpMethod.GET); + when(servletRequest.getRequestURI()).thenReturn("api/atlas/v2/search/basic"); + when(servletRequest.getQueryString()).thenReturn("limit=25&excludeDeletedEntities=true&spaceParam=firstpart%20secondpart&_=1500969656054&listParam=value1,value2"); + + activeServerFilter.doFilter(servletRequest, servletResponse, filterChain); + + verify(servletResponse).sendRedirect(ACTIVE_SERVER_ADDRESS + + "api/atlas/v2/search/basic?limit=25&excludeDeletedEntities=true&spaceParam=firstpart%20secondpart&_=1500969656054&listParam=value1,value2"); + + } + + @Test + public void testOriginalRequestShouldNotEncodePartiallyEncodedQueryParameters() throws IOException, ServletException { + when(serviceState.getState()).thenReturn(ServiceState.ServiceStateValue.PASSIVE); + + ActiveServerFilter activeServerFilter = new ActiveServerFilter(activeInstanceState, serviceState); + + when(activeInstanceState.getActiveServerAddress()).thenReturn(ACTIVE_SERVER_ADDRESS); + when(servletRequest.getMethod()).thenReturn(HttpMethod.GET); + when(servletRequest.getRequestURI()).thenReturn("api/atlas/v2/search/basic"); + when(servletRequest.getQueryString()).thenReturn("limit=25&excludeDeletedEntities=true&query=where name%3D%22ABC%22&_=1500969656054&listParam=value1,value2"); + + activeServerFilter.doFilter(servletRequest, servletResponse, filterChain); + + verify(servletResponse).sendRedirect(ACTIVE_SERVER_ADDRESS + + "api/atlas/v2/search/basic?limit=25&excludeDeletedEntities=true&query=where%20name=%22ABC%22&_=1500969656054&listParam=value1,value2"); + + } @Test public void testShouldRedirectPOSTRequest() throws IOException, ServletException {