af558428e77d8dfdc2936c403b32c8593869eb04
[aaf/authz.git] / cadi / cass / src / test / java / org / onap / aaf / cadi / cass / JU_AAFAuthenticator.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
46 public class JU_AAFAuthenticator 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         // TODO: Call may be broken due to missing ATT specific code
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                 Access access = new PropAccess();
77                 AAFAuthenticatedUser aau = new AAFAuthenticatedUser(access,username);
78                 String fullName=aau.getFullName();
79                 access.log(Level.DEBUG, "Authenticating", aau.getName(),"(", fullName,")");
80                 //test.authenticate(cred);
81                 //Assert.assert
82                 
83         }
84         
85         @Test(expected = AuthenticationException.class)
86         public void checkThrowsUser() throws AuthenticationException {
87                 AAFAuthenticator test = new AAFAuthenticator();
88                 Map<String, String> cred = new HashMap<String,String>();
89                 cred.put("username", null);
90                 Assert.assertNull(cred.get("username"));
91                 test.authenticate(cred);
92         }
93
94         // TODO: Ian - Fix this failing test
95         //@Test(expected = AuthenticationException.class)
96         public void checkThrowsPass() throws AuthenticationException {
97                 AAFAuthenticator test = new AAFAuthenticator();
98                 Map<String, String> cred = new HashMap<String,String>();
99                 cred.put("username", "testUser");
100                 cred.put("password", "bsf:");
101                 Assert.assertNotNull(cred.get("password"));
102                 test.authenticate(cred);
103                 
104                 cred.put("password", null);
105                 Assert.assertNull(cred.get("password"));
106                 test.authenticate(cred);
107         }
108
109
110
111 }