diff options
author | Martin Bonato <mbonato@datentechnik-innovation.com> | 2015-01-21 16:55:53 +0100 |
---|---|---|
committer | Thomas Lenz <tlenz@iaik.tugraz.at> | 2015-06-19 11:08:37 +0200 |
commit | d24179f90949ff6768f89eea0073f65990d0765a (patch) | |
tree | 842ee9a20e052fd1e347d93a080a657a8bac0028 /id/server/idserverlib/src/test | |
parent | 54cb4518bd64dba0c1f373f262afb7a988f35e1a (diff) | |
download | moa-id-spss-d24179f90949ff6768f89eea0073f65990d0765a.tar.gz moa-id-spss-d24179f90949ff6768f89eea0073f65990d0765a.tar.bz2 moa-id-spss-d24179f90949ff6768f89eea0073f65990d0765a.zip |
Add unit initial unit tests.
Diffstat (limited to 'id/server/idserverlib/src/test')
3 files changed, 157 insertions, 0 deletions
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 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd"> + +<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/"> + <appender name="consoleAppender" class="org.apache.log4j.ConsoleAppender"> + <layout class="org.apache.log4j.PatternLayout"> + <param name="ConversionPattern" value="%d{dd MMM yyyy HH:mm:ss} %5p %c{1} - %m%n" /> + </layout> + </appender> + + <root> + <priority value="info" /> + <appender-ref ref="consoleAppender" /> + </root> + +</log4j:configuration> |