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

krisztiankasa pushed a commit to branch branch-2.6
in repository https://gitbox.apache.org/repos/asf/ambari.git


The following commit(s) were added to refs/heads/branch-2.6 by this push:
     new 4dcf342  AMBARI-25280 - Improper error handling when managing Ambari 
users (#2981)
4dcf342 is described below

commit 4dcf3428d7278dbc8a643c5a86a236bcc5203e9b
Author: kasakrisz <33458261+kasakr...@users.noreply.github.com>
AuthorDate: Tue May 21 14:15:38 2019 +0200

    AMBARI-25280 - Improper error handling when managing Ambari users (#2981)
---
 .../ambari/server/api/services/ResultStatus.java   |  2 +-
 .../server/api/handlers/ReadHandlerTest.java       | 34 +++++++++++++++-------
 .../services/serializers/JsonSerializerTest.java   | 22 +++++++-------
 3 files changed, 36 insertions(+), 22 deletions(-)

diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/api/services/ResultStatus.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/api/services/ResultStatus.java
index 6284879..aefac03 100644
--- 
a/ambari-server/src/main/java/org/apache/ambari/server/api/services/ResultStatus.java
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/api/services/ResultStatus.java
@@ -131,7 +131,7 @@ public class ResultStatus {
    */
   public ResultStatus(STATUS status, Exception e) {
     m_status = status;
-    m_msg = e.toString();
+    m_msg = e.getMessage();
   }
 
   /**
diff --git 
a/ambari-server/src/test/java/org/apache/ambari/server/api/handlers/ReadHandlerTest.java
 
b/ambari-server/src/test/java/org/apache/ambari/server/api/handlers/ReadHandlerTest.java
index ee97de3..c9e5ae0 100644
--- 
a/ambari-server/src/test/java/org/apache/ambari/server/api/handlers/ReadHandlerTest.java
+++ 
b/ambari-server/src/test/java/org/apache/ambari/server/api/handlers/ReadHandlerTest.java
@@ -18,6 +18,21 @@
 
 package org.apache.ambari.server.api.handlers;
 
+import static org.easymock.EasyMock.capture;
+import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.createNiceMock;
+import static org.easymock.EasyMock.createStrictMock;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.expectLastCall;
+import static org.easymock.EasyMock.replay;
+import static org.easymock.EasyMock.verify;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertSame;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
 import org.apache.ambari.server.api.query.Query;
 import org.apache.ambari.server.api.query.render.DefaultRenderer;
 import org.apache.ambari.server.api.query.render.Renderer;
@@ -26,20 +41,17 @@ import org.apache.ambari.server.api.services.Request;
 import org.apache.ambari.server.api.services.RequestBody;
 import org.apache.ambari.server.api.services.Result;
 import org.apache.ambari.server.api.services.ResultStatus;
-import org.apache.ambari.server.controller.spi.*;
+import org.apache.ambari.server.controller.spi.NoSuchParentResourceException;
+import org.apache.ambari.server.controller.spi.NoSuchResourceException;
+import org.apache.ambari.server.controller.spi.Predicate;
+import org.apache.ambari.server.controller.spi.Resource;
+import org.apache.ambari.server.controller.spi.SystemException;
+import org.apache.ambari.server.controller.spi.TemporalInfo;
+import org.apache.ambari.server.controller.spi.UnsupportedPropertyException;
 import org.apache.ambari.server.security.authorization.AuthorizationException;
 import org.easymock.Capture;
 import org.junit.Test;
 
-
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
-
-import static org.easymock.EasyMock.*;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertSame;
-
 /**
  * Unit tests for ReadHandler.
  */
@@ -161,7 +173,7 @@ public class ReadHandlerTest {
     ReadHandler handler = new ReadHandler();
     Result result = handler.handleRequest(request);
     assertEquals(ResultStatus.STATUS.SERVER_ERROR, 
result.getStatus().getStatus());
-    assertEquals(systemException.toString(), result.getStatus().getMessage());
+    assertEquals(systemException.getMessage(), 
result.getStatus().getMessage());
     verify(request, resource, query, predicate);
   }
 
diff --git 
a/ambari-server/src/test/java/org/apache/ambari/server/api/services/serializers/JsonSerializerTest.java
 
b/ambari-server/src/test/java/org/apache/ambari/server/api/services/serializers/JsonSerializerTest.java
index edddd4a..adab19b 100644
--- 
a/ambari-server/src/test/java/org/apache/ambari/server/api/services/serializers/JsonSerializerTest.java
+++ 
b/ambari-server/src/test/java/org/apache/ambari/server/api/services/serializers/JsonSerializerTest.java
@@ -18,6 +18,17 @@
 
 package org.apache.ambari.server.api.services.serializers;
 
+import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.replay;
+import static org.easymock.EasyMock.verify;
+import static org.junit.Assert.assertEquals;
+
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+import javax.ws.rs.core.UriInfo;
+
 import org.apache.ambari.server.api.services.DeleteResultMetadata;
 import org.apache.ambari.server.api.services.Result;
 import org.apache.ambari.server.api.services.ResultImpl;
@@ -27,14 +38,6 @@ import org.apache.ambari.server.controller.spi.Resource;
 import org.apache.ambari.server.security.authorization.AuthorizationException;
 import org.junit.Test;
 
-import javax.ws.rs.core.UriInfo;
-
-import java.util.LinkedHashMap;
-import java.util.Map;
-
-import static org.easymock.EasyMock.*;
-import static org.junit.Assert.assertEquals;
-
 /**
  * JSONSerializer unit tests
  */
@@ -232,8 +235,7 @@ public class JsonSerializerTest {
         "      \"error\" : {\n" +
         "        \"key\" : \"key2\",\n" +
         "        \"code\" : 403,\n" +
-        "        \"message\" : 
\"org.apache.ambari.server.security.authorization.AuthorizationException:"+
-                              " The authenticated user is not authorized to 
perform the requested operation\"\n" +
+        "        \"message\" : \"The authenticated user is not authorized to 
perform the requested operation\"\n" +
         "      }\n" +
         "    }\n" +
         "  ]\n" +

Reply via email to