2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * Copyright © 2017-2018 Amdocs
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
21 package org.onap.aai.sa.auth;
24 import java.io.IOException;
25 import java.lang.reflect.Field;
26 import java.lang.reflect.Modifier;
27 import org.junit.Assert;
28 import org.junit.Before;
29 import org.junit.Test;
30 import org.mockito.Mock;
31 import org.mockito.MockitoAnnotations;
32 import org.onap.aai.sa.searchdbabstraction.util.SearchDbConstants;
33 import org.springframework.http.HttpHeaders;
35 // import javax.servlet.http.Cookie;
37 public class SearchDbServiceAuthTest {
43 // Cookie mockedCookie;
46 public void setUp() throws NoSuchFieldException, IllegalAccessException, IOException {
47 MockitoAnnotations.initMocks(this);
48 System.setProperty("AJSC_HOME", new File(".").getCanonicalPath().replace('\\', '/'));
49 setFinalStatic(System.getProperty("AJSC_HOME") + "/src/test/resources/json/search_policy.json");
53 public void testAuthUser() {
54 SearchDbServiceAuth aaiAuth = new SearchDbServiceAuth();
55 String auth = aaiAuth.authUser(headers, "user-1", "function-1");
56 Assert.assertEquals(auth, "AAI_9101");
60 // public void testAuthCookie_NullCookie(){
61 // SearchDbServiceAuth aaiAuth = new SearchDbServiceAuth();
62 // Cookie cookie = null;
63 // Assert.assertFalse(aaiAuth.authCookie(cookie, "function-1", new StringBuilder("user-1")));
67 // public void testAuthCookie_NotNullCookie(){
68 // SearchDbServiceAuth aaiAuth = new SearchDbServiceAuth();
69 // Cookie cookie = new Cookie ( "TestCookie", "TestValue");
70 // // Cookie cookie = new Cookie ( "TestCookie", "TestValue" );
71 // boolean retValue = aaiAuth.authCookie(cookie, "GET:testFunction", new StringBuilder("testuser"));
72 // Assert.assertTrue(retValue);
75 static void setFinalStatic(String fieldValue)
76 throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
77 Field configField = SearchDbConstants.class.getDeclaredField("SDB_AUTH_CONFIG_FILENAME");
78 configField.setAccessible(true);
80 Field modifiersField = Field.class.getDeclaredField("modifiers");
81 modifiersField.setAccessible(true);
82 modifiersField.setInt(configField, configField.getModifiers() & ~Modifier.FINAL);
84 configField.set(null, fieldValue);