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
1 /*  Copyright (c) 2019 AT&T Intellectual Property.                             #\r
2 #                                                                              #\r
3 #   Licensed under the Apache License, Version 2.0 (the "License");            #\r
4 #   you may not use this file except in compliance with the License.           #\r
5 #   You may obtain a copy of the License at                                    #\r
6 #                                                                              #\r
7 #       http://www.apache.org/licenses/LICENSE-2.0                             #\r
8 #                                                                              #\r
9 #   Unless required by applicable law or agreed to in writing, software        #\r
10 #   distributed under the License is distributed on an "AS IS" BASIS,          #\r
11 #   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   #\r
12 #   See the License for the specific language governing permissions and        #\r
13 #   limitations under the License.                                             #\r
14 ##############################################################################*/\r
15 \r
16 \r
17 package org.oran.otf.api.tests.unit.common.utility.http;\r
18 \r
19 import org.oran.otf.common.utility.http.HeadersUtility;\r
20 import java.util.HashMap;\r
21 import java.util.Map;\r
22 import org.assertj.core.api.Assertions;\r
23 import org.junit.Assert;\r
24 import org.junit.Before;\r
25 import org.junit.BeforeClass;\r
26 import org.junit.Test;\r
27 import org.junit.runner.RunWith;\r
28 import org.mockito.junit.MockitoJUnitRunner;\r
29 \r
30 @RunWith(MockitoJUnitRunner.class)\r
31 public class HeadersUtilityTest {\r
32   public Map<String, String> headers;\r
33 \r
34   @Before\r
35   public void setup(){\r
36     headers = new HashMap<>();\r
37     headers.put("GET", "/some/random/route/exmaple");\r
38     headers.put("Host", "localhost");\r
39     headers.put("Authorization", "Basic som3R4ndOmStringK3y");\r
40     headers.put("User-Agent", "James Bond");\r
41     headers.put("Accept", "*/*");\r
42 \r
43   }\r
44   @Test\r
45   public void authIsMasked(){\r
46 \r
47     System.out.println("Authorization header in format 'Basic: key' will mask the auth with 4 *");\r
48     Map<String, String> maskedAuth = HeadersUtility.maskAuth(headers);\r
49     Assertions.assertThat(maskedAuth.get("Authorization")).isEqualTo("Basic ****");\r
50   }\r
51   @Test\r
52   public void originalHeadersDidNotChange(){\r
53     System.out.println("Make sure HeaderUtility.maskAuth() does not change the map passed to function");\r
54     Map<String, String> maskedAuth = HeadersUtility.maskAuth(headers);\r
55     Assertions.assertThat(headers.get("Authorization")).isEqualTo("Basic som3R4ndOmStringK3y");\r
56   }\r
57 \r
58   @Test\r
59   public void noAuthHeadersPassed(){\r
60     System.out.println("Make sure HeaderUtility.maskAuth() works if headers are missing a Authorization field");\r
61     headers.remove("Authorization");\r
62     Map<String, String> maskedAuth = HeadersUtility.maskAuth(headers);\r
63     Assertions.assertThat(maskedAuth).isEqualTo(headers);\r
64   }\r
65 \r
66   @Test\r
67   public void authKeyFormatHasNoSpace(){\r
68     System.out.println("Make sure HeaderUtility.maskAuth() works if Authorization does not follow format 'Authorization: [Type] [Key]'");\r
69     headers.put("Authorization", "Basicsom3R4ndOmStringK3y");\r
70     Map<String, String> maskedAuth = HeadersUtility.maskAuth(headers);\r
71     Assertions.assertThat(maskedAuth.get("Authorization")).isEqualTo("****");\r
72   }\r
73 \r
74 }\r