diff options
author | Instrumental <jcgmisc@stl.gathman.org> | 2018-03-26 13:49:56 -0700 |
---|---|---|
committer | Instrumental <jcgmisc@stl.gathman.org> | 2018-03-26 13:50:07 -0700 |
commit | a20accc73189d8e5454cd26049c0e6fae75da16f (patch) | |
tree | 3526110a1f65591354eff6400383512df4828903 /cadi/cass/src/test | |
parent | ac1e1ec76e9125206be91a2f32c7104c9392dc9a (diff) |
AT&T 2.0.19 Code drop, stage 2
Issue-ID: AAF-197
Change-Id: Ifc93308f52c10d6ad82e99cd3ff5ddb900bf219a
Signed-off-by: Instrumental <jcgmisc@stl.gathman.org>
Diffstat (limited to 'cadi/cass/src/test')
5 files changed, 485 insertions, 0 deletions
diff --git a/cadi/cass/src/test/java/org/onap/aaf/cadi/cass/JU_AAFAuthenticatedUserTest.java b/cadi/cass/src/test/java/org/onap/aaf/cadi/cass/JU_AAFAuthenticatedUserTest.java new file mode 100644 index 00000000..2f196720 --- /dev/null +++ b/cadi/cass/src/test/java/org/onap/aaf/cadi/cass/JU_AAFAuthenticatedUserTest.java @@ -0,0 +1,90 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aaf + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * + ******************************************************************************/ +package org.onap.aaf.cadi.cass; + +import static org.junit.Assert.*; + +import org.apache.cassandra.auth.AuthenticatedUser; +import org.junit.Before; +import org.junit.Test; + +import com.att.aaf.cadi.cass.AAFAuthenticatedUser; + +public class JU_AAFAuthenticatedUserTest { + + @Before + public void setUp() throws Exception { + } + + @Test + public void test() { + AAFAuthenticatedUser user = new AAFAuthenticatedUser(null, "User1@aaf"); + assertEquals(user.getFullName(),"User1@aaf"); + assertEquals(user.getName(),"User1@aaf"); + assertFalse(user.isAnonymous()); + assertFalse(user.isSuper()); + assertFalse(user.isLocal()); + + + + } + + @Test + public void testone() { + AAFAuthenticatedUser user = new AAFAuthenticatedUser(null, "User2@aaf"); + assertEquals(user.getFullName(),"User2@aaf"); + assertEquals(user.getName(),"User2@aaf"); + assertFalse(user.isAnonymous()); + assertFalse(user.isSuper()); + assertFalse(user.isLocal()); + + + + } + + @Test + public void testtwo() { + AAFAuthenticatedUser user = new AAFAuthenticatedUser(null, "onap@aaf"); + assertEquals(user.getFullName(),"onap@aaf"); + assertEquals(user.getName(),"onap@aaf"); + assertFalse(user.isAnonymous()); + assertFalse(user.isSuper()); + assertFalse(user.isLocal()); + + + + } + + @Test + public void testthree() { + AAFAuthenticatedUser user = new AAFAuthenticatedUser(null, "openecomp@aaf"); + assertEquals(user.getFullName(),"openecomp@aaf"); + assertEquals(user.getName(),"openecomp@aaf"); + assertFalse(user.isAnonymous()); + assertFalse(user.isSuper()); + assertFalse(user.isLocal()); + + + + } + +} diff --git a/cadi/cass/src/test/java/org/onap/aaf/cadi/cass/JU_AAFAuthenticator.java b/cadi/cass/src/test/java/org/onap/aaf/cadi/cass/JU_AAFAuthenticator.java new file mode 100644 index 00000000..2dcb033e --- /dev/null +++ b/cadi/cass/src/test/java/org/onap/aaf/cadi/cass/JU_AAFAuthenticator.java @@ -0,0 +1,110 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aaf + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * + ******************************************************************************/ +package org.onap.aaf.cadi.cass; + +import static org.junit.Assert.*; + +import java.util.HashMap; +import java.util.Map; + +import org.junit.Test; +import org.onap.aaf.cadi.Access; +import org.onap.aaf.cadi.PropAccess; +import org.onap.aaf.cadi.Access.Level; +import org.apache.cassandra.auth.AuthenticatedUser; +import org.apache.cassandra.exceptions.AuthenticationException; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import static org.junit.Assert.*; + +import com.att.aaf.cadi.cass.AAFAuthenticatedUser; +import com.att.aaf.cadi.cass.AAFAuthenticator; +import com.att.aaf.cadi.cass.AAFBase; + +import junit.framework.Assert; + +public class JU_AAFAuthenticator extends AAFBase +{ + + + @Before + public void setUp() + { + + } + + @After + public void tearDown() + { + + } + + @Test + public void checkRequiredAuth() { + AAFAuthenticator test = new AAFAuthenticator(); + Assert.assertTrue(test.requireAuthentication()); + } + //TODO: Call may be broken due to missing ATT specific code + @Test + public void checkAuthenticate() throws AuthenticationException { + AuthenticatedUser user = new AuthenticatedUser("testUser"); + AAFAuthenticator test = new AAFAuthenticator(); + Map<String, String> cred = new HashMap<String,String>(); + cred.put("username", "testUser"); + cred.put("password", "testPass"); + String username = (String)cred.get("username"); + Access access = new PropAccess(); + AAFAuthenticatedUser aau = new AAFAuthenticatedUser(access,username); + String fullName=aau.getFullName(); + access.log(Level.DEBUG, "Authenticating", aau.getName(),"(", fullName,")"); + //test.authenticate(cred); + //Assert.assert + + } + + @Test(expected = AuthenticationException.class) + public void checkThrowsUser() throws AuthenticationException { + AAFAuthenticator test = new AAFAuthenticator(); + Map<String, String> cred = new HashMap<String,String>(); + cred.put("username", null); + Assert.assertNull(cred.get("username")); + test.authenticate(cred); + } + + @Test(expected = AuthenticationException.class) + public void checkThrowsPass() throws AuthenticationException { + AAFAuthenticator test = new AAFAuthenticator(); + Map<String, String> cred = new HashMap<String,String>(); + cred.put("username", "testUser"); + cred.put("password", "bsf:"); + Assert.assertNotNull(cred.get("password")); + test.authenticate(cred); + + cred.put("password", null); + Assert.assertNull(cred.get("password")); + test.authenticate(cred); + } + + + +} diff --git a/cadi/cass/src/test/java/org/onap/aaf/cadi/cass/JU_AAFAuthorizerTest.java b/cadi/cass/src/test/java/org/onap/aaf/cadi/cass/JU_AAFAuthorizerTest.java new file mode 100644 index 00000000..6f2e9da8 --- /dev/null +++ b/cadi/cass/src/test/java/org/onap/aaf/cadi/cass/JU_AAFAuthorizerTest.java @@ -0,0 +1,109 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aaf + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * + ******************************************************************************/ +package org.onap.aaf.cadi.cass; + +import static org.junit.Assert.*; + +import java.util.HashMap; +import java.util.Map; + +import org.junit.Test; +import org.onap.aaf.cadi.Access; +import org.onap.aaf.cadi.PropAccess; +import org.onap.aaf.cadi.Access.Level; +import org.apache.cassandra.auth.AuthenticatedUser; +import org.apache.cassandra.exceptions.AuthenticationException; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import static org.junit.Assert.*; + +import com.att.aaf.cadi.cass.AAFAuthenticatedUser; +import com.att.aaf.cadi.cass.AAFAuthenticator; +import com.att.aaf.cadi.cass.AAFBase; + +import junit.framework.Assert; +//TODO:DELETE THIS OLD TEST +public class JU_AAFAuthorizerTest extends AAFBase +{ + + + @Before + public void setUp() + { + + } + + @After + public void tearDown() + { + + } + + @Test + public void checkRequiredAuth() { + AAFAuthenticator test = new AAFAuthenticator(); + Assert.assertTrue(test.requireAuthentication()); + } + + @Test + public void checkAuthenticate() throws AuthenticationException { + AuthenticatedUser user = new AuthenticatedUser("testUser"); + AAFAuthenticator test = new AAFAuthenticator(); + Map<String, String> cred = new HashMap<String,String>(); + cred.put("username", "testUser"); + cred.put("password", "testPass"); + String username = (String)cred.get("username"); + AAFAuthenticatedUser aau = new AAFAuthenticatedUser(access,username); + String fullName=aau.getFullName(); + //access.log(Level.DEBUG, "Authenticating", aau.getName(),"(", fullName,")"); + test.authenticate(cred); + //Assert.assert + + } + + @Test(expected = AuthenticationException.class) + public void checkThrowsUser() throws AuthenticationException { + AAFAuthenticator test = new AAFAuthenticator(); + Map<String, String> cred = new HashMap<String,String>(); + cred.put("username", null); + Assert.assertNull(cred.get("username")); + test.authenticate(cred); + } + + @Test(expected = AuthenticationException.class) + public void checkThrowsPass() throws AuthenticationException { + AAFAuthenticator test = new AAFAuthenticator(); + Map<String, String> cred = new HashMap<String,String>(); + cred.put("username", "testUser"); + cred.put("password", "bsf:"); + Assert.assertNotNull(cred.get("password")); + test.authenticate(cred); + + cred.put("password", null); + Assert.assertNull(cred.get("password")); + test.authenticate(cred); + } + + + +} diff --git a/cadi/cass/src/test/java/org/onap/aaf/cadi/cass/JU_AAFBaseTest.java b/cadi/cass/src/test/java/org/onap/aaf/cadi/cass/JU_AAFBaseTest.java new file mode 100644 index 00000000..49854865 --- /dev/null +++ b/cadi/cass/src/test/java/org/onap/aaf/cadi/cass/JU_AAFBaseTest.java @@ -0,0 +1,70 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aaf + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * + ******************************************************************************/ +package org.onap.aaf.cadi.cass; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.onap.aaf.cadi.Access; +import org.onap.aaf.cadi.Lur; +import org.onap.aaf.cadi.PropAccess; +import org.onap.aaf.cadi.Access.Level; + +import junit.framework.Assert; + +import com.att.aaf.cadi.cass.AAFBase; + +import static org.junit.Assert.*; + +import org.apache.cassandra.exceptions.ConfigurationException; + +public class JU_AAFBaseTest +{ + + //TODO: REmove this file, no need for junit for abstract class + @Before + public void setUp() + { + + } + + @After + public void tearDown() + { + + } + + + @Test + public void test_method_setAccess_0_branch_0() + { + System.out.println("Now Testing Method:setAccess Branch:0"); + + //Call Method + AAFBase.setAccess(null); + + } + + + + +} diff --git a/cadi/cass/src/test/java/org/onap/aaf/cadi/cass/JU_CASS.java b/cadi/cass/src/test/java/org/onap/aaf/cadi/cass/JU_CASS.java new file mode 100644 index 00000000..60fd5487 --- /dev/null +++ b/cadi/cass/src/test/java/org/onap/aaf/cadi/cass/JU_CASS.java @@ -0,0 +1,106 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aaf + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * + ******************************************************************************/ +package org.onap.aaf.cadi.cass; + +import java.util.HashMap; +import java.util.Map; +import java.util.Set; + +import org.apache.cassandra.auth.AuthenticatedUser; +import org.apache.cassandra.auth.IResource; +import org.apache.cassandra.auth.Permission; +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; + +import com.att.aaf.cadi.cass.AAFAuthenticator; +import com.att.aaf.cadi.cass.AAFAuthorizer; + +public class JU_CASS { + + private static AAFAuthenticator aa; + private static AAFAuthorizer an; + + @BeforeClass + public static void setUpBeforeClass() throws Exception { + System.setProperty("cadi_prop_files", "etc/cadi.properties"); + + aa = new AAFAuthenticator(); + an = new AAFAuthorizer(); + + aa.setup(); + an.setup(); // does nothing after aa. + + aa.validateConfiguration(); + + } + + @AfterClass + public static void tearDownAfterClass() throws Exception { + } + + @Test + public void test() throws Exception { + Map<String,String> creds = new HashMap<String,String>(); + creds.put("username", "XXX@NS"); + creds.put("password", "enc:???"); + AuthenticatedUser aaf = aa.authenticate(creds); + + // Test out "aaf_default_domain + creds.put("username", "XX"); + aaf = aa.authenticate(creds); + + IResource resource = new IResource() { + public String getName() { + return "data/authz"; + } + + public IResource getParent() { + return null; + } + + public boolean hasParent() { + return false; + } + + public boolean exists() { + return true; + } + + }; + + Set<Permission> perms = an.authorize(aaf, resource); + + // Test out "AAF" access + creds.put("username", "XXX@NS"); + creds.put("password", "enc:???"); + aaf = aa.authenticate(creds); + perms = an.authorize(aaf, resource); + Assert.assertFalse(perms.isEmpty()); + + perms = an.authorize(aaf, resource); + Assert.assertFalse(perms.isEmpty()); + + } + +} |