added svcapi ui and camunda code
[it/otf.git] / otf-camunda / src / test / java / org / oran / otf / api / tests / unit / common / utility / http / HeadersUtilityTest.java
diff --git a/otf-camunda/src/test/java/org/oran/otf/api/tests/unit/common/utility/http/HeadersUtilityTest.java b/otf-camunda/src/test/java/org/oran/otf/api/tests/unit/common/utility/http/HeadersUtilityTest.java
new file mode 100644 (file)
index 0000000..ae0e133
--- /dev/null
@@ -0,0 +1,74 @@
+/*  Copyright (c) 2019 AT&T Intellectual Property.                             #\r
+#                                                                              #\r
+#   Licensed under the Apache License, Version 2.0 (the "License");            #\r
+#   you may not use this file except in compliance with the License.           #\r
+#   You may obtain a copy of the License at                                    #\r
+#                                                                              #\r
+#       http://www.apache.org/licenses/LICENSE-2.0                             #\r
+#                                                                              #\r
+#   Unless required by applicable law or agreed to in writing, software        #\r
+#   distributed under the License is distributed on an "AS IS" BASIS,          #\r
+#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   #\r
+#   See the License for the specific language governing permissions and        #\r
+#   limitations under the License.                                             #\r
+##############################################################################*/\r
+\r
+\r
+package org.oran.otf.api.tests.unit.common.utility.http;\r
+\r
+import org.oran.otf.common.utility.http.HeadersUtility;\r
+import java.util.HashMap;\r
+import java.util.Map;\r
+import org.assertj.core.api.Assertions;\r
+import org.junit.Assert;\r
+import org.junit.Before;\r
+import org.junit.BeforeClass;\r
+import org.junit.Test;\r
+import org.junit.runner.RunWith;\r
+import org.mockito.junit.MockitoJUnitRunner;\r
+\r
+@RunWith(MockitoJUnitRunner.class)\r
+public class HeadersUtilityTest {\r
+  public Map<String, String> headers;\r
+\r
+  @Before\r
+  public void setup(){\r
+    headers = new HashMap<>();\r
+    headers.put("GET", "/some/random/route/exmaple");\r
+    headers.put("Host", "localhost");\r
+    headers.put("Authorization", "Basic som3R4ndOmStringK3y");\r
+    headers.put("User-Agent", "James Bond");\r
+    headers.put("Accept", "*/*");\r
+\r
+  }\r
+  @Test\r
+  public void authIsMasked(){\r
+\r
+    System.out.println("Authorization header in format 'Basic: key' will mask the auth with 4 *");\r
+    Map<String, String> maskedAuth = HeadersUtility.maskAuth(headers);\r
+    Assertions.assertThat(maskedAuth.get("Authorization")).isEqualTo("Basic ****");\r
+  }\r
+  @Test\r
+  public void originalHeadersDidNotChange(){\r
+    System.out.println("Make sure HeaderUtility.maskAuth() does not change the map passed to function");\r
+    Map<String, String> maskedAuth = HeadersUtility.maskAuth(headers);\r
+    Assertions.assertThat(headers.get("Authorization")).isEqualTo("Basic som3R4ndOmStringK3y");\r
+  }\r
+\r
+  @Test\r
+  public void noAuthHeadersPassed(){\r
+    System.out.println("Make sure HeaderUtility.maskAuth() works if headers are missing a Authorization field");\r
+    headers.remove("Authorization");\r
+    Map<String, String> maskedAuth = HeadersUtility.maskAuth(headers);\r
+    Assertions.assertThat(maskedAuth).isEqualTo(headers);\r
+  }\r
+\r
+  @Test\r
+  public void authKeyFormatHasNoSpace(){\r
+    System.out.println("Make sure HeaderUtility.maskAuth() works if Authorization does not follow format 'Authorization: [Type] [Key]'");\r
+    headers.put("Authorization", "Basicsom3R4ndOmStringK3y");\r
+    Map<String, String> maskedAuth = HeadersUtility.maskAuth(headers);\r
+    Assertions.assertThat(maskedAuth.get("Authorization")).isEqualTo("****");\r
+  }\r
+\r
+}\r