aboutsummaryrefslogtreecommitdiff
path: root/id/server/idserverlib
diff options
context:
space:
mode:
authorMartin Bonato <mbonato@datentechnik-innovation.com>2015-01-21 16:55:53 +0100
committerThomas Lenz <tlenz@iaik.tugraz.at>2015-06-19 11:08:37 +0200
commitd24179f90949ff6768f89eea0073f65990d0765a (patch)
tree842ee9a20e052fd1e347d93a080a657a8bac0028 /id/server/idserverlib
parent54cb4518bd64dba0c1f373f262afb7a988f35e1a (diff)
downloadmoa-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')
-rw-r--r--id/server/idserverlib/pom.xml10
-rw-r--r--id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/config/auth/AuthConfigurationProvider.java15
-rw-r--r--id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/config/auth/NewAuthConfigurationProvider.java13
-rw-r--r--id/server/idserverlib/src/test/java/at/gv/egovnerment/moa/id/config/auth/AuthConfigurationProviderLegacyCompatibilityTest.java110
-rw-r--r--id/server/idserverlib/src/test/java/at/gv/egovnerment/moa/id/config/auth/TestLegacyAuthConfigurationProvider.java31
-rw-r--r--id/server/idserverlib/src/test/resources/log4j.xml16
6 files changed, 188 insertions, 7 deletions
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 @@
<version>1.7.6</version>
</dependency> -->
+ <dependency>
+ <groupId>org.easymock</groupId>
+ <artifactId>easymock</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.unitils</groupId>
+ <artifactId>unitils-core</artifactId>
+ <scope>test</scope>
+ </dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
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
@@ -274,6 +274,12 @@ public class AuthConfigurationProvider extends ConfigurationProvider implements
}
/**
+ * 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 @@
+<?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>