From d24179f90949ff6768f89eea0073f65990d0765a Mon Sep 17 00:00:00 2001 From: Martin Bonato Date: Wed, 21 Jan 2015 16:55:53 +0100 Subject: Add unit initial unit tests. --- id/server/idserverlib/pom.xml | 10 ++ .../id/config/auth/AuthConfigurationProvider.java | 15 ++- .../config/auth/NewAuthConfigurationProvider.java | 13 ++- ...nfigurationProviderLegacyCompatibilityTest.java | 110 +++++++++++++++++++++ .../auth/TestLegacyAuthConfigurationProvider.java | 31 ++++++ id/server/idserverlib/src/test/resources/log4j.xml | 16 +++ 6 files changed, 188 insertions(+), 7 deletions(-) create mode 100644 id/server/idserverlib/src/test/java/at/gv/egovnerment/moa/id/config/auth/AuthConfigurationProviderLegacyCompatibilityTest.java create mode 100644 id/server/idserverlib/src/test/java/at/gv/egovnerment/moa/id/config/auth/TestLegacyAuthConfigurationProvider.java create mode 100644 id/server/idserverlib/src/test/resources/log4j.xml (limited to 'id') diff --git a/id/server/idserverlib/pom.xml b/id/server/idserverlib/pom.xml index b224717c2..dd24f5d56 100644 --- a/id/server/idserverlib/pom.xml +++ b/id/server/idserverlib/pom.xml @@ -240,6 +240,16 @@ 1.7.6 --> + + org.easymock + easymock + test + + + org.unitils + unitils-core + test + commons-logging commons-logging diff --git a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/config/auth/AuthConfigurationProvider.java b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/config/auth/AuthConfigurationProvider.java index a143eb636..087b331b5 100644 --- a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/config/auth/AuthConfigurationProvider.java +++ b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/config/auth/AuthConfigurationProvider.java @@ -273,6 +273,12 @@ public class AuthConfigurationProvider extends ConfigurationProvider implements load(fileName); } + /** + * Protected constructor. Used by unit tests. + */ + protected AuthConfigurationProvider() { + } + /** * Load the configuration data from XML file with the given name and build * the internal data structures representing the MOA ID configuration. @@ -493,12 +499,15 @@ public class AuthConfigurationProvider extends ConfigurationProvider implements throw new ConfigurationException("config.02", null, t); } } - + + protected MOAIDConfiguration loadDataBaseConfig() { + return ConfigurationDBRead.getMOAIDConfiguration(); + } + public synchronized void reloadDataBaseConfig() throws ConfigurationException { Logger.info("Read MOA-ID 2.0 configuration from database."); - //moaidconfig = ConfigurationDBRead.getMOAIDConfiguration(); - moaidconfig = NewConfigurationDBRead.getMOAIDConfiguration(); + moaidconfig = loadDataBaseConfig(); Logger.info("MOA-ID 2.0 is loaded."); if (moaidconfig == null) { diff --git a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/config/auth/NewAuthConfigurationProvider.java b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/config/auth/NewAuthConfigurationProvider.java index 77a9f032c..0ee143a1a 100644 --- a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/config/auth/NewAuthConfigurationProvider.java +++ b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/config/auth/NewAuthConfigurationProvider.java @@ -54,10 +54,12 @@ import com.datentechnik.moa.id.conf.persistence.Configuration; */ public class NewAuthConfigurationProvider extends ConfigurationProvider implements AuthConfiguration { - @Autowired private Configuration configuration; private final Properties properties = new Properties(); + + public NewAuthConfigurationProvider() { + } public NewAuthConfigurationProvider(String fileName) throws ConfigurationException { File propertiesFile = new File(fileName); @@ -71,6 +73,11 @@ public class NewAuthConfigurationProvider extends ConfigurationProvider implemen throw new ConfigurationException("config.03", null, e); } } + + @Autowired + public void setConfiguration(Configuration configuration) { + this.configuration = configuration; + } private Properties getProperties() { return properties; @@ -105,11 +112,9 @@ public class NewAuthConfigurationProvider extends ConfigurationProvider implemen } catch (ConfigurationException e) { return null; } - ProtocolAllowed allowedProtcols = new ProtocolAllowed(); Protocols protocols = authComponentGeneral.getProtocols(); if (protocols != null) { - allowedProtcols = new ProtocolAllowed(); - + ProtocolAllowed allowedProtcols = new ProtocolAllowed(); if (protocols.getSAML1() != null) { allowedProtcols.setSAML1Active(protocols.getSAML1().isIsActive()); } diff --git a/id/server/idserverlib/src/test/java/at/gv/egovnerment/moa/id/config/auth/AuthConfigurationProviderLegacyCompatibilityTest.java b/id/server/idserverlib/src/test/java/at/gv/egovnerment/moa/id/config/auth/AuthConfigurationProviderLegacyCompatibilityTest.java new file mode 100644 index 000000000..bd997303a --- /dev/null +++ b/id/server/idserverlib/src/test/java/at/gv/egovnerment/moa/id/config/auth/AuthConfigurationProviderLegacyCompatibilityTest.java @@ -0,0 +1,110 @@ +package at.gv.egovnerment.moa.id.config.auth; + +import static org.easymock.EasyMock.createMock; +import static org.easymock.EasyMock.expect; +import static org.easymock.EasyMock.replay; +import static org.easymock.EasyMock.verify; + +import java.util.Collections; + +import org.junit.Test; +import org.unitils.reflectionassert.ReflectionAssert; + +import at.gv.egovernment.moa.id.commons.db.MOAIDConfigurationConstants; +import at.gv.egovernment.moa.id.commons.db.dao.config.AuthComponentGeneral; +import at.gv.egovernment.moa.id.commons.db.dao.config.ChainingModes; +import at.gv.egovernment.moa.id.commons.db.dao.config.GeneralConfiguration; +import at.gv.egovernment.moa.id.commons.db.dao.config.MOAIDConfiguration; +import at.gv.egovernment.moa.id.commons.db.dao.config.MOASP; +import at.gv.egovernment.moa.id.commons.db.dao.config.OAuth; +import at.gv.egovernment.moa.id.commons.db.dao.config.PVP2; +import at.gv.egovernment.moa.id.commons.db.dao.config.Protocols; +import at.gv.egovernment.moa.id.commons.db.dao.config.SAML1; +import at.gv.egovernment.moa.id.commons.db.dao.config.SLRequestTemplates; +import at.gv.egovernment.moa.id.commons.db.dao.config.SecurityLayer; +import at.gv.egovernment.moa.id.commons.db.dao.config.TransformsInfoType; +import at.gv.egovernment.moa.id.commons.db.dao.config.VerifyAuthBlock; +import at.gv.egovernment.moa.id.commons.db.dao.config.VerifyIdentityLink; +import at.gv.egovernment.moa.id.config.ConfigurationException; +import at.gv.egovernment.moa.id.config.auth.NewAuthConfigurationProvider; +import at.gv.egovernment.moa.id.config.auth.data.ProtocolAllowed; + +import com.datentechnik.moa.id.conf.persistence.Configuration; + +public class AuthConfigurationProviderLegacyCompatibilityTest { + + private MOAIDConfiguration getMinimalMoaidConfiguration() { + + MOAIDConfiguration moaidConfiguration = new MOAIDConfiguration(); + AuthComponentGeneral authComponentGeneral = new AuthComponentGeneral(); + MOASP moasp = new MOASP(); + VerifyAuthBlock verifyAuthBlock = new VerifyAuthBlock(); + moasp.setVerifyAuthBlock(verifyAuthBlock); + VerifyIdentityLink verifyIdentityLink = new VerifyIdentityLink(); + moasp.setVerifyIdentityLink(verifyIdentityLink); + authComponentGeneral.setMOASP(moasp); + SecurityLayer securityLayer = new SecurityLayer(); + TransformsInfoType transformsInfo = new TransformsInfoType(); + transformsInfo.setFilename("transforms/TransformsInfoAuthBlockTable_DE.xml"); + transformsInfo.setTransformation(new byte[] {}); + securityLayer.setTransformsInfo(Collections.singletonList(transformsInfo)); + authComponentGeneral.setSecurityLayer(securityLayer); + SLRequestTemplates slRequestTemplates = new SLRequestTemplates(); + moaidConfiguration.setSLRequestTemplates(slRequestTemplates); + GeneralConfiguration generalConfiguration = new GeneralConfiguration(); + generalConfiguration.setTrustManagerRevocationChecking(Boolean.FALSE); + generalConfiguration.setPublicURLPreFix("http://test.org"); + authComponentGeneral.setGeneralConfiguration(generalConfiguration); + moaidConfiguration.setAuthComponentGeneral(authComponentGeneral); + ChainingModes chainingModes = new ChainingModes(); + moaidConfiguration.setChainingModes(chainingModes); + + return moaidConfiguration; + } + + @Test + public void testGetAllowedProtocolls() throws ConfigurationException { + MOAIDConfiguration moaidConfiguration = getMinimalMoaidConfiguration(); + + testGetAllowedProtocolls(moaidConfiguration); + } + + @Test + public void testGetAllowedProtocollsAll() throws ConfigurationException { + MOAIDConfiguration moaidConfiguration = getMinimalMoaidConfiguration(); + Protocols protocols = new Protocols(); + SAML1 saml1 = new SAML1(); + saml1.setIsActive(Boolean.TRUE); + protocols.setSAML1(saml1); + PVP2 pvp2 = new PVP2(); + pvp2.setIsActive(Boolean.FALSE); + protocols.setPVP2(pvp2); + OAuth oAuth = new OAuth(); + oAuth.setIsActive(null); + protocols.setOAuth(oAuth); + moaidConfiguration.getAuthComponentGeneral().setProtocols(protocols); + + testGetAllowedProtocolls(moaidConfiguration); + } + + public void testGetAllowedProtocolls(MOAIDConfiguration moaidConfiguration) throws ConfigurationException { + + TestLegacyAuthConfigurationProvider legacyAuthConfigurationProvider = new TestLegacyAuthConfigurationProvider(moaidConfiguration); + ProtocolAllowed expectedAllowedProtocols = legacyAuthConfigurationProvider.getAllowedProtocols(); + + Configuration configuration = createMock(Configuration.class); + NewAuthConfigurationProvider newAuthConfigurationProvider = new NewAuthConfigurationProvider(); + newAuthConfigurationProvider.setConfiguration(configuration); + + expect(configuration.get(MOAIDConfigurationConstants.AUTH_COMPONENT_GENERAL_KEY, AuthComponentGeneral.class)).andReturn(moaidConfiguration.getAuthComponentGeneral()); + + replay(configuration); + + ProtocolAllowed actualAllowedProtocols = newAuthConfigurationProvider.getAllowedProtocols(); + + verify(configuration); + + ReflectionAssert.assertLenientEquals(expectedAllowedProtocols, actualAllowedProtocols); + } + +} diff --git a/id/server/idserverlib/src/test/java/at/gv/egovnerment/moa/id/config/auth/TestLegacyAuthConfigurationProvider.java b/id/server/idserverlib/src/test/java/at/gv/egovnerment/moa/id/config/auth/TestLegacyAuthConfigurationProvider.java new file mode 100644 index 000000000..39c8ef310 --- /dev/null +++ b/id/server/idserverlib/src/test/java/at/gv/egovnerment/moa/id/config/auth/TestLegacyAuthConfigurationProvider.java @@ -0,0 +1,31 @@ +package at.gv.egovnerment.moa.id.config.auth; + +import at.gv.egovernment.moa.id.commons.db.dao.config.MOAIDConfiguration; +import at.gv.egovernment.moa.id.config.ConfigurationException; +import at.gv.egovernment.moa.id.config.auth.AuthConfigurationProvider; + +public class TestLegacyAuthConfigurationProvider extends + AuthConfigurationProvider { + + private final MOAIDConfiguration moaidConfiguration; + + public TestLegacyAuthConfigurationProvider(MOAIDConfiguration moaidConfiguration) + throws ConfigurationException { + super(); + this.moaidConfiguration = moaidConfiguration; + reloadDataBaseConfig(); + } + + @SuppressWarnings("unused") + private TestLegacyAuthConfigurationProvider(String fileName) + throws ConfigurationException { + super(); + moaidConfiguration = new MOAIDConfiguration(); + } + + @Override + protected MOAIDConfiguration loadDataBaseConfig() { + return this.moaidConfiguration; + } + +} diff --git a/id/server/idserverlib/src/test/resources/log4j.xml b/id/server/idserverlib/src/test/resources/log4j.xml new file mode 100644 index 000000000..6685c1e82 --- /dev/null +++ b/id/server/idserverlib/src/test/resources/log4j.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + -- cgit v1.2.3