Don't build credentials if user name is empty 99/48999/1 2.0.0-ONAP beijing 2.0.0-ONAP v1.2.3
authorJim Hahn <jrh3@att.com>
Thu, 24 May 2018 17:24:12 +0000 (13:24 -0400)
committerJim Hahn <jrh3@att.com>
Thu, 24 May 2018 17:24:12 +0000 (13:24 -0400)
Modified code to skip building credentials if user name
is empty, in addition to case where user name is null.

Change-Id: I5b53d4f97263df98cfe082f44a4e6af64b1e488b
Issue-ID: POLICY-868
Signed-off-by: Jim Hahn <jrh3@att.com>
controlloop/common/model-impl/rest/src/main/java/org/onap/policy/rest/RESTManager.java
controlloop/common/model-impl/rest/src/test/java/org/onap/policy/rest/TestGet.java
controlloop/common/model-impl/rest/src/test/java/org/onap/policy/rest/TestPost.java

index 6b8b6f0..52ce13e 100644 (file)
@@ -146,7 +146,7 @@ public class RESTManager {
     }
 
     private String makeAuthHeader(String username, String password) {
-        if (username == null) {
+        if (username == null || username.isEmpty()) {
             return null;
         }
 
index a2252a0..a830181 100755 (executable)
@@ -44,6 +44,16 @@ public class TestGet {
         assertTrue(result.b.length() > 0);
     }
 
+    @Test
+    public void testUsernameEmpty() {
+        RESTManager mgr = new RESTManager();
+
+        Pair<Integer, String> result = mgr.get("http://www.example.org", "", null, null);
+        assertEquals((Integer)200, result.a);
+        assertTrue(result.b != null);
+        assertTrue(result.b.length() > 0);
+    }
+
     @Test
     public void testUrlExampleOrg() {
         RESTManager mgr = new RESTManager();
index de44dec..58ba5d2 100755 (executable)
@@ -34,6 +34,13 @@ public class TestPost {
         assertEquals(null, result);
     }
 
+    @Test
+    public void testUsernameEmpty() {
+        RESTManager mgr = new RESTManager();
+        Pair<Integer, String> result = mgr.post("http://www.example.org", "", null, null, null, null);
+        assertEquals(null, result);
+    }
+
     @Test
     public void testBodyNull() {
         RESTManager mgr = new RESTManager();