1 /*******************************************************************************
2 * ============LICENSE_START====================================================
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
11 * * http://www.apache.org/licenses/LICENSE-2.0
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====================================================
21 ******************************************************************************/
22 package org.onap.aaf.cadi.cass;
24 import static org.junit.Assert.*;
26 import java.util.HashMap;
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.*;
40 import com.att.aaf.cadi.cass.AAFAuthenticatedUser;
41 import com.att.aaf.cadi.cass.AAFAuthenticator;
42 import com.att.aaf.cadi.cass.AAFBase;
44 import junit.framework.Assert;
46 public class JU_AAFAuthenticator extends AAFBase
57 public void tearDown()
63 public void checkRequiredAuth() {
64 AAFAuthenticator test = new AAFAuthenticator();
65 Assert.assertTrue(test.requireAuthentication());
67 // TODO: Call may be broken due to missing ATT specific code
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);
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);
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);
104 cred.put("password", null);
105 Assert.assertNull(cred.get("password"));
106 test.authenticate(cred);