You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@atlas.apache.org by pi...@apache.org on 2023/06/13 16:04:53 UTC

[atlas] branch master updated: ATLAS-4757 : Regression - DSL queries redirected to passive server fails

This is an automated email from the ASF dual-hosted git repository.

pinal pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/atlas.git


The following commit(s) were added to refs/heads/master by this push:
     new 75eb33f0f ATLAS-4757 : Regression - DSL queries redirected to passive server fails
75eb33f0f is described below

commit 75eb33f0fb3ac7baf6547bdd35bd65acdea0d8f9
Author: chaitali borole <ch...@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 <pi...@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 {