diff options
Diffstat (limited to 'auth/auth-certman/src')
3 files changed, 284 insertions, 2 deletions
diff --git a/auth/auth-certman/src/main/java/org/onap/aaf/auth/cm/AAF_CM.java b/auth/auth-certman/src/main/java/org/onap/aaf/auth/cm/AAF_CM.java index 689326e1..bfdb977d 100644 --- a/auth/auth-certman/src/main/java/org/onap/aaf/auth/cm/AAF_CM.java +++ b/auth/auth-certman/src/main/java/org/onap/aaf/auth/cm/AAF_CM.java @@ -80,7 +80,12 @@ public class AAF_CM extends AbsService<AuthzEnv, AuthzTrans> { public final Cluster cluster; public final LocateDAO locateDAO; public static AuthzEnv envLog; + CMService service; + //Added for junits + public CMService getService() { + return null; + } /** * Construct AuthzAPI with all the Context Supporting Routes that Authz needs * @@ -117,7 +122,6 @@ public class AAF_CM extends AbsService<AuthzEnv, AuthzTrans> { if (key.startsWith(CA.CM_CA_PREFIX)) { int idx = key.indexOf('.'); if (idx==key.lastIndexOf('.')) { // else it's a regular property - env.log(Level.INIT, "Loading Certificate Authority Module: " + key.substring(idx+1)); String[] segs = Split.split(',', env.getProperty(key)); if (segs.length>0) { @@ -145,7 +149,10 @@ public class AAF_CM extends AbsService<AuthzEnv, AuthzTrans> { throw new APIException("No Certificate Authorities have been configured in CertMan"); } - CMService service = new CMService(trans, this); + service = getService(); + if(service == null) { + service = new CMService(trans, this); + } // note: Service knows how to shutdown Cluster on Shutdown, etc. See Constructor facade1_0 = FacadeFactory.v1_0(this,trans, service,Data.TYPE.JSON); // Default Facade facade1_0_XML = FacadeFactory.v1_0(this,trans,service,Data.TYPE.XML); @@ -172,6 +179,7 @@ public class AAF_CM extends AbsService<AuthzEnv, AuthzTrans> { public CA getCA(String key) { return certAuths.get(key); } + /** * Setup XML and JSON implementations for each supported Version type diff --git a/auth/auth-certman/src/main/java/org/onap/aaf/auth/cm/LocalCAImpl.java b/auth/auth-certman/src/main/java/org/onap/aaf/auth/cm/LocalCAImpl.java new file mode 100644 index 00000000..632e719e --- /dev/null +++ b/auth/auth-certman/src/main/java/org/onap/aaf/auth/cm/LocalCAImpl.java @@ -0,0 +1,48 @@ +/** + * ============LICENSE_START==================================================== + * org.onap.aaf + * =========================================================================== + * Copyright (c) 2018 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.auth.cm; + +import java.io.IOException; + +import org.onap.aaf.auth.cm.ca.CA; +import org.onap.aaf.auth.cm.ca.X509andChain; +import org.onap.aaf.auth.cm.cert.CSRMeta; +import org.onap.aaf.cadi.Access; +import org.onap.aaf.cadi.configure.CertException; +import org.onap.aaf.misc.env.Trans; + +public class LocalCAImpl extends CA { + + protected LocalCAImpl(Access access, String caName, String env) throws IOException, CertException { + super(access, caName, env); + // TODO Auto-generated constructor stub + } + + public LocalCAImpl(Access access, final String name, final String env, final String[][] params) throws IOException, CertException { + super(access, name, env); + } + + @Override + public X509andChain sign(Trans trans, CSRMeta csrmeta) throws IOException, CertException { + // TODO Auto-generated method stub + return null; + } +}
\ No newline at end of file diff --git a/auth/auth-certman/src/test/java/org/onap/aaf/auth/cm/JU_AAF_CM.java b/auth/auth-certman/src/test/java/org/onap/aaf/auth/cm/JU_AAF_CM.java new file mode 100644 index 00000000..e770fec7 --- /dev/null +++ b/auth/auth-certman/src/test/java/org/onap/aaf/auth/cm/JU_AAF_CM.java @@ -0,0 +1,226 @@ +/** + * ============LICENSE_START==================================================== + * org.onap.aaf + * =========================================================================== + * Copyright (c) 2018 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.auth.cm; + +import static org.junit.Assert.assertTrue; +import static org.mockito.MockitoAnnotations.initMocks; + +import java.lang.reflect.Field; +import java.lang.reflect.Modifier; +import java.security.NoSuchAlgorithmException; +import java.util.Properties; + +import javax.servlet.Filter; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.onap.aaf.auth.cm.ca.CA; +import org.onap.aaf.auth.cm.facade.Facade1_0; +import org.onap.aaf.auth.cm.facade.FacadeFactory; +import org.onap.aaf.auth.cm.mapper.Mapper.API; +import org.onap.aaf.auth.cm.service.CMService; +import org.onap.aaf.auth.cm.service.Code; +import org.onap.aaf.auth.env.AuthzEnv; +import org.onap.aaf.auth.env.AuthzTransImpl; +import org.onap.aaf.auth.rserv.HttpMethods; +import org.onap.aaf.cadi.CadiException; +import org.onap.aaf.cadi.LocatorException; +import org.onap.aaf.cadi.PropAccess; +import org.onap.aaf.cadi.aaf.v2_0.AAFConHttp; +import org.onap.aaf.cadi.config.Config; +import org.onap.aaf.misc.env.Data; +import org.onap.aaf.misc.env.Env; +import org.onap.aaf.misc.env.LogTarget; +import org.onap.aaf.misc.env.TimeTaken; +import org.onap.aaf.misc.env.impl.BasicEnv; +import org.onap.aaf.misc.rosetta.env.RosettaDF; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; + +@RunWith(PowerMockRunner.class) +@PrepareForTest(FacadeFactory.class) +public class JU_AAF_CM { + + @Mock + AuthzEnv env; + + BasicEnv baseEnv; + + @Mock + PropAccess access; + + AuthzTransImpl1 trans; + + AAF_CMImpl rosettaObj = null; + + @Before + public void setUp() { + initMocks(this); + + try { + Mockito.doReturn(access).when(env).access(); + Mockito.doReturn("test.test").when(access).getProperty(Config.AAF_ROOT_NS,"org.osaaf.aaf"); + Properties props=new Properties(); + Mockito.doReturn(props).when(access).getProperties(); + props.setProperty("cm_ca.props", "test"); + Mockito.doReturn("test:2.1").when(access).getProperty(Config.AAF_COMPONENT, null); + Mockito.doReturn("test").when(access).getProperty("https.protocols","TLSv1.1,TLSv1.2"); + Mockito.doReturn("test").when(env).getProperty("cm_ca.props.perm_type",null); + Mockito.doReturn("test").when(env).getProperty("cm_ca.props.baseSubject",null); + Mockito.doReturn("10").when(env).getProperty("CACHE_CLEAN_INTERVAL","60000"); + Mockito.doReturn("10").when(env).getProperty("CACHE_HIGH_COUNT","5000"); + trans = new AuthzTransImpl1(env); + Mockito.doReturn(trans).when(env).newTrans(); +// Mockito.doReturn("test").when(trans).getProperty("cm_ca.props.baseSubject",null); +// Mockito.doReturn(Mockito.mock(TimeTaken.class)).when(trans).start("Clear Reset Deque",8); + + Mockito.doReturn("TLSv1.1").when(access).getProperty("cadi_protocols","test"); + Mockito.doReturn("https://www.google.com").when(access).getProperty(Config.AAF_URL,null); + Mockito.doReturn("test").when(env).getProperty(Config.AAF_ENV); + Mockito.doReturn("10").when(env).getProperty(Config.CADI_LATITUDE); + Mockito.doReturn("10").when(env).getProperty(Config.CADI_LONGITUDE); + Mockito.doReturn("org.onap.aaf.auth.cm.LocalCAImpl,test;test").when(env).getProperty("cm_ca.props"); + Mockito.doReturn("google.com").when(env).getProperty("cassandra.clusters",null); +// Mockito.doReturn(Mockito.mock(AuthzTransImpl.class)).when(env).newTrans(); + Mockito.doReturn(Mockito.mock(LogTarget.class)).when(env).init(); + AAF_CM tempObj = Mockito.mock(AAF_CM.class); + Field envField = tempObj.getClass().getField("env"); + Field modifiersField = Field.class.getDeclaredField("modifiers"); + modifiersField.setAccessible(true); + modifiersField.setInt(envField, envField.getModifiers() & ~Modifier.FINAL); + envField.setAccessible(true); + envField.set(tempObj, env); + RosettaDF rosettaObjTemp = Mockito.mock(RosettaDF.class); + Mockito.doReturn(rosettaObjTemp).when(rosettaObjTemp).in(Data.TYPE.JSON); + Mockito.doReturn(rosettaObjTemp).when(env).newDataFactory(aaf.v2_0.Error.class); + Mockito.doReturn(rosettaObjTemp).when(env).newDataFactory(certman.v1_0.CertificateRequest.class); + Mockito.doReturn(rosettaObjTemp).when(env).newDataFactory(certman.v1_0.CertificateRenew.class); + Mockito.doReturn(rosettaObjTemp).when(env).newDataFactory(certman.v1_0.CertificateDrop.class); + Mockito.doReturn(rosettaObjTemp).when(env).newDataFactory(certman.v1_0.CertInfo.class); + Mockito.doReturn(rosettaObjTemp).when(env).newDataFactory(certman.v1_0.Artifacts.class); + Mockito.doReturn(Data.TYPE.XML).when(rosettaObjTemp).getOutType(); + + Facade1_0 facadeObj = Mockito.mock(Facade1_0.class); + PowerMockito.mockStatic(FacadeFactory.class); + FacadeFactory factObj = PowerMockito.mock(FacadeFactory.class); + PowerMockito.when(factObj.v1_0(tempObj,trans, null,Data.TYPE.JSON)).thenReturn(facadeObj); + +// Mockito.doReturn(Mockito.mock(Mapper.class)).when(facadeObj).mapper(); + + + rosettaObj = new AAF_CMImpl(env); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + assertTrue(e instanceof NullPointerException); + } + } + + @Test + public void testTestCA() { + CA obj = rosettaObj.getCA("props"); + assertTrue(obj instanceof CA); + } + +// @Test +// public void testRoute() { +// try { +// rosettaObj.route(null, "", null, null); +// } catch (Exception e) { +// // TODO Auto-generated catch block +// e.printStackTrace(); +// } +//// System.out.println(obj); +//// assertTrue(obj instanceof CA); +// } + + @Test + public void testFilters() { + try { + Filter[] obj = rosettaObj._filters(new Object[] {"props"}); + System.out.println(obj); + } catch (CadiException | LocatorException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + assertTrue(e.getMessage().contains("NoSuchAlgorithmException")); + } +// assertTrue(obj instanceof CA); + } + + class AAF_CMImpl extends AAF_CM{ + + public AAF_CMImpl(AuthzEnv env) throws Exception { + super(env); + // TODO Auto-generated constructor stub + } + + @Override + public synchronized AAFConHttp aafCon() throws CadiException, LocatorException { + return Mockito.mock(AAFConHttp.class); + } + + public CMService getService() { + return Mockito.mock(CMService.class); + } + + @Override + public void route(HttpMethods meth, String path, API api, Code code) throws Exception { + + } + } + + + + class AuthzTransImpl1 extends AuthzTransImpl{ + + public AuthzTransImpl1(AuthzEnv env) { + super(env); + // TODO Auto-generated constructor stub + } + + @Override + protected TimeTaken newTimeTaken(String name, int flag) { + // TODO Auto-generated method stub + TimeTaken tt= new TimeTaken("nameTest", Env.XML) { + + @Override + public void output(StringBuilder sb) { + // TODO Auto-generated method stub + + } + }; + return tt; + } + + @Override + public Metric auditTrail(int indent, StringBuilder sb, int ... flag) { + return null; + } + + } + + +} |