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;
45 //TODO:DELETE THIS OLD TEST
46 public class JU_AAFAuthorizerTest extends AAFBase
57 public void tearDown()
63 public void checkRequiredAuth() {
64 AAFAuthenticator test = new AAFAuthenticator();
65 Assert.assertTrue(test.requireAuthentication());
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);
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);
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);
102 cred.put("password", null);
103 Assert.assertNull(cred.get("password"));
104 test.authenticate(cred);