Merge "Add target to missing .gitignore"
[aaf/authz.git] / cadi / cass / src / test / java / org / onap / aaf / cadi / cass / JU_AAFAuthorizerTest.java
1 /*******************************************************************************
2  * ============LICENSE_START====================================================
3  * * org.onap.aaf
4  * * ===========================================================================
5  * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
6  * * ===========================================================================
7  * * Licensed under the Apache License, Version 2.0 (the "License");
8  * * you may not use this file except in compliance with the License.
9  * * You may obtain a copy of the License at
10  * * 
11  *  *      http://www.apache.org/licenses/LICENSE-2.0
12  * * 
13  *  * Unless required by applicable law or agreed to in writing, software
14  * * distributed under the License is distributed on an "AS IS" BASIS,
15  * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * * See the License for the specific language governing permissions and
17  * * limitations under the License.
18  * * ============LICENSE_END====================================================
19  * *
20  * *
21  ******************************************************************************/
22 package org.onap.aaf.cadi.cass;
23
24 import static org.junit.Assert.*;
25
26 import java.util.HashMap;
27 import java.util.Map;
28
29 import org.junit.Test;
30 import org.onap.aaf.cadi.Access;
31 import org.onap.aaf.cadi.PropAccess;
32 import org.onap.aaf.cadi.Access.Level;
33 import org.apache.cassandra.auth.AuthenticatedUser;
34 import org.apache.cassandra.exceptions.AuthenticationException;
35 import org.junit.After;
36 import org.junit.Before;
37 import org.junit.Test;
38 import static org.junit.Assert.*;
39
40 import com.att.aaf.cadi.cass.AAFAuthenticatedUser;
41 import com.att.aaf.cadi.cass.AAFAuthenticator;
42 import com.att.aaf.cadi.cass.AAFBase;
43
44 import junit.framework.Assert;
45 //TODO:DELETE THIS OLD TEST
46 public class JU_AAFAuthorizerTest extends AAFBase
47 {
48         
49
50         @Before
51         public void setUp()
52         {
53                 
54         }
55
56         @After
57         public void tearDown()
58         {
59                 
60         }
61         
62         @Test
63         public void checkRequiredAuth() {
64                 AAFAuthenticator test = new AAFAuthenticator();
65                 Assert.assertTrue(test.requireAuthentication());
66         }
67         
68         @Test
69         public void checkAuthenticate()  throws AuthenticationException {
70                 AuthenticatedUser user = new AuthenticatedUser("testUser");
71                 AAFAuthenticator test = new AAFAuthenticator(); 
72                 Map<String, String> cred = new HashMap<String,String>();
73                 cred.put("username", "testUser");
74                 cred.put("password", "testPass");
75                 String username = (String)cred.get("username");
76                 AAFAuthenticatedUser aau = new AAFAuthenticatedUser(access,username);
77                 String fullName=aau.getFullName();
78                 //access.log(Level.DEBUG, "Authenticating", aau.getName(),"(", fullName,")");
79                 test.authenticate(cred);
80                 //Assert.assert
81                 
82         }
83         
84         @Test(expected = AuthenticationException.class)
85         public void checkThrowsUser() throws AuthenticationException {
86                 AAFAuthenticator test = new AAFAuthenticator();
87                 Map<String, String> cred = new HashMap<String,String>();
88                 cred.put("username", null);
89                 Assert.assertNull(cred.get("username"));
90                 test.authenticate(cred);
91         }
92         
93         @Test(expected = AuthenticationException.class)
94         public void checkThrowsPass() throws AuthenticationException {
95                 AAFAuthenticator test = new AAFAuthenticator();
96                 Map<String, String> cred = new HashMap<String,String>();
97                 cred.put("username", "testUser");
98                 cred.put("password", "bsf:");
99                 Assert.assertNotNull(cred.get("password"));
100                 test.authenticate(cred);
101                 
102                 cred.put("password", null);
103                 Assert.assertNull(cred.get("password"));
104                 test.authenticate(cred);
105         }
106
107
108
109 }