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