summaryrefslogtreecommitdiff
path: root/bkucommon/src/test
diff options
context:
space:
mode:
authorwbauer <wbauer@8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4>2008-09-04 14:56:54 +0000
committerwbauer <wbauer@8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4>2008-09-04 14:56:54 +0000
commite0f2c64ad6360e2ecec983cb5e0a60f812672106 (patch)
tree75040ef0d3424c8722d81163570c6770125b4d8c /bkucommon/src/test
parentea5a30db385d2859cc45c889877954bda00ac560 (diff)
downloadmocca-e0f2c64ad6360e2ecec983cb5e0a60f812672106.tar.gz
mocca-e0f2c64ad6360e2ecec983cb5e0a60f812672106.tar.bz2
mocca-e0f2c64ad6360e2ecec983cb5e0a60f812672106.zip
finished access controller, accessed it from command invoker and
configured everything within onlinebku git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@14 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4
Diffstat (limited to 'bkucommon/src/test')
-rw-r--r--bkucommon/src/test/java/at/gv/egiz/bku/accesscontroller/ConfigTest.java91
-rw-r--r--bkucommon/src/test/java/at/gv/egiz/bku/binding/BindingProcessorManagerTest.java12
-rw-r--r--bkucommon/src/test/java/at/gv/egiz/bku/binding/DataUrlConnectionTest.java22
-rw-r--r--bkucommon/src/test/java/at/gv/egiz/bku/binding/ExpiryRemoverTest.java10
-rw-r--r--bkucommon/src/test/java/at/gv/egiz/bku/binding/HttpBindingProcessorTest.java2
-rw-r--r--bkucommon/src/test/java/at/gv/egiz/bku/binding/MultipartSLRequestTest.java5
-rw-r--r--bkucommon/src/test/java/at/gv/egiz/bku/binding/NullOperationTest.java5
-rw-r--r--bkucommon/src/test/java/at/gv/egiz/bku/binding/TestDataUrlConnection.java7
-rw-r--r--bkucommon/src/test/resources/at/gv/egiz/bku/accesscontroller/AccessControlConfig.xml6
-rw-r--r--bkucommon/src/test/resources/at/gv/egiz/bku/accesscontroller/SimpleChainTest.xml39
10 files changed, 163 insertions, 36 deletions
diff --git a/bkucommon/src/test/java/at/gv/egiz/bku/accesscontroller/ConfigTest.java b/bkucommon/src/test/java/at/gv/egiz/bku/accesscontroller/ConfigTest.java
index b53db264..bce3cdd9 100644
--- a/bkucommon/src/test/java/at/gv/egiz/bku/accesscontroller/ConfigTest.java
+++ b/bkucommon/src/test/java/at/gv/egiz/bku/accesscontroller/ConfigTest.java
@@ -4,14 +4,101 @@ import javax.xml.bind.JAXBException;
import org.junit.Test;
+import at.gv.egiz.bku.slcommands.InfoboxReadCommand;
+import at.gv.egiz.bku.slcommands.SLCommandContext;
+import at.gv.egiz.bku.slcommands.SLResult;
+import at.gv.egiz.bku.slcommands.impl.InfoboxReadCommandImpl;
+import at.gv.egiz.bku.slexceptions.SLCommandException;
+import at.gv.egiz.bku.slexceptions.SLException;
+import static org.junit.Assert.*;
+
public class ConfigTest {
- public final static String RESOURCE = "at/gv/egiz/bku/accesscontroller/AccessControlConfig.xml";
+ public final static String RESOURCE1 = "at/gv/egiz/bku/accesscontroller/AccessControlConfig.xml";
+ public final static String RESOURCE2 = "at/gv/egiz/bku/accesscontroller/SimpleChainTest.xml";
+
+ static class MyInfoBox implements InfoboxReadCommand {
+ private String domainId;
+ private String boxId;
+ private String name;
+
+ public MyInfoBox(String identifier, String domainId) {
+ this.boxId = identifier;
+ this.domainId = domainId;
+ }
+
+ @Override
+ public String getIdentityLinkDomainId() {
+ return domainId;
+ }
+
+ @Override
+ public String getInfoboxIdentifier() {
+ return boxId;
+ }
+
+ @Override
+ public SLResult execute() {
+ return null;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ @Override
+ public String getName() {
+ return "InfoboxReadRequest";
+ }
+
+ @Override
+ public void init(SLCommandContext ctx, Object unmarshalledRequest)
+ throws SLCommandException {
+ }
+ }
@Test
public void testUnmarshall() throws JAXBException {
AccessControllerFactory.getInstance().init(
- getClass().getClassLoader().getResourceAsStream(RESOURCE));
+ getClass().getClassLoader().getResourceAsStream(RESOURCE1));
+ }
+
+ @Test
+ public void testBasicFunction() throws JAXBException, SLException {
+ AccessControllerFactory.getInstance().init(
+ getClass().getClassLoader().getResourceAsStream(RESOURCE2));
+ ChainChecker cc = AccessControllerFactory.getInstance().getChainChecker(
+ "InputFilter");
+ assertNotNull(cc);
+
+ AccessCheckerContext ctx = new AccessCheckerContext(null,
+ AuthenticationClass.ANONYMOUS, null);
+ ChainResult cr = cc.check(ctx);
+ assertFalse(cr.matchFound());
+
+ ctx = new AccessCheckerContext(new MyInfoBox("IdentityLink", "hansi"),
+ AuthenticationClass.CERTIFIED, null);
+ cr = cc.check(ctx);
+ assertTrue(cr.matchFound());
+
+ ctx = new AccessCheckerContext(new MyInfoBox("Something", "hansi"),
+ AuthenticationClass.CERTIFIED, null);
+ cr = cc.check(ctx);
+ assertFalse(cr.matchFound());
+
+ MyInfoBox mib = new MyInfoBox("IdentityLink", "seppl");
+ mib.setName("ReadInfoboxSchickSchnack");
+ ctx = new AccessCheckerContext(mib, AuthenticationClass.CERTIFIED, null);
+ cr = cc.check(ctx);
+ assertTrue(cr.matchFound());
+ assertTrue(cr.getAction()==Action.ALLOW);
+
+ mib = new MyInfoBox("IdentityLink", null);
+ mib.setName("ReadInfoboxSchickSchnack");
+ ctx = new AccessCheckerContext(mib, AuthenticationClass.CERTIFIED, null);
+ cr = cc.check(ctx);
+ assertTrue(cr.matchFound());
+ assertTrue(cr.getAction()==Action.DENY);
}
}
diff --git a/bkucommon/src/test/java/at/gv/egiz/bku/binding/BindingProcessorManagerTest.java b/bkucommon/src/test/java/at/gv/egiz/bku/binding/BindingProcessorManagerTest.java
index 16d5451a..9481f0bc 100644
--- a/bkucommon/src/test/java/at/gv/egiz/bku/binding/BindingProcessorManagerTest.java
+++ b/bkucommon/src/test/java/at/gv/egiz/bku/binding/BindingProcessorManagerTest.java
@@ -17,6 +17,8 @@
package at.gv.egiz.bku.binding;
import static org.junit.Assert.*;
+
+import java.net.MalformedURLException;
import org.junit.Before;
import org.junit.Test;
@@ -29,16 +31,16 @@ public class BindingProcessorManagerTest {
}
- @Test(expected = UnsupportedOperationException.class)
- public void basicCreationTest() {
+ @Test(expected = MalformedURLException.class)
+ public void basicCreationTest() throws MalformedURLException {
BindingProcessorManager manager = new BindingProcessorManagerImpl(new DummyStalFactory(), new SLCommandInvokerImpl());
- BindingProcessor bp = manager.createBindingProcessor("http", null);
+ BindingProcessor bp = manager.createBindingProcessor("http://www.at/", null);
assertNotNull(bp.getId().toString());
assertEquals(40, bp.getId().toString().length());
String hansi = "Hansi";
- bp = manager.createBindingProcessor("http",hansi);
+ bp = manager.createBindingProcessor("http://www.iaik.at",hansi);
assertEquals(hansi, bp.getId().toString());
- bp = manager.createBindingProcessor("HtTp", null);
+ bp = manager.createBindingProcessor("HtTp://www.iaik.at", null);
assertNotNull(bp);
manager.createBindingProcessor("seppl", null);
}
diff --git a/bkucommon/src/test/java/at/gv/egiz/bku/binding/DataUrlConnectionTest.java b/bkucommon/src/test/java/at/gv/egiz/bku/binding/DataUrlConnectionTest.java
index d9995fdd..87726c49 100644
--- a/bkucommon/src/test/java/at/gv/egiz/bku/binding/DataUrlConnectionTest.java
+++ b/bkucommon/src/test/java/at/gv/egiz/bku/binding/DataUrlConnectionTest.java
@@ -20,41 +20,31 @@
*/
package at.gv.egiz.bku.binding;
-import at.gv.egiz.bku.slcommands.SLCommandFactory;
-import at.gv.egiz.bku.slcommands.SLResult;
-
-import com.sun.net.httpserver.Headers;
-import com.sun.net.httpserver.HttpExchange;
-import com.sun.net.httpserver.HttpHandler;
-import com.sun.net.httpserver.HttpServer;
-import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
-import java.io.InputStreamReader;
import java.io.OutputStream;
-import java.io.OutputStreamWriter;
import java.net.InetSocketAddress;
import java.net.URL;
-import java.net.URLConnection;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
-import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.junit.After;
-import static org.junit.Assert.*;
-
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
+import com.sun.net.httpserver.Headers;
+import com.sun.net.httpserver.HttpExchange;
+import com.sun.net.httpserver.HttpHandler;
+import com.sun.net.httpserver.HttpServer;
+
/**
*
* @author clemens
@@ -83,7 +73,7 @@ public class DataUrlConnectionTest {
manager = new BindingProcessorManagerImpl(new DummyStalFactory(),
new SLCommandInvokerImpl());
bindingProcessor = (HTTPBindingProcessor) manager.createBindingProcessor(
- "http", null);
+ "http://www.iaik.at", null);
Map<String, String> headers = new HashMap<String, String>();
headers.put("Content-Type", InputDecoderFactory.MULTIPART_FORMDATA
+ ";boundary=---------------------------2330864292941");
diff --git a/bkucommon/src/test/java/at/gv/egiz/bku/binding/ExpiryRemoverTest.java b/bkucommon/src/test/java/at/gv/egiz/bku/binding/ExpiryRemoverTest.java
index 41c69a1d..61729567 100644
--- a/bkucommon/src/test/java/at/gv/egiz/bku/binding/ExpiryRemoverTest.java
+++ b/bkucommon/src/test/java/at/gv/egiz/bku/binding/ExpiryRemoverTest.java
@@ -16,16 +16,18 @@
*/
package at.gv.egiz.bku.binding;
+import java.net.MalformedURLException;
+
import org.junit.Test;
import static org.junit.Assert.*;
public class ExpiryRemoverTest {
@Test
- public void testMe() throws InterruptedException {
+ public void testMe() throws InterruptedException, MalformedURLException {
BindingProcessorManager manager = new BindingProcessorManagerImpl(new DummyStalFactory(),
new SLCommandInvokerImpl());
- BindingProcessor bp = manager.createBindingProcessor("http", null);
+ BindingProcessor bp = manager.createBindingProcessor("http://www.at", null);
ExpiryRemover remover = new ExpiryRemover();
remover.setBindingProcessorManager(manager);
remover.execute();
@@ -42,10 +44,10 @@ public class ExpiryRemoverTest {
}
@Test
- public void testMe2() throws InterruptedException {
+ public void testMe2() throws InterruptedException, MalformedURLException {
BindingProcessorManager manager = new BindingProcessorManagerImpl(new DummyStalFactory(),
new SLCommandInvokerImpl());
- BindingProcessor bp = manager.createBindingProcessor("http", null);
+ BindingProcessor bp = manager.createBindingProcessor("http://www.iaik.at", null);
ExpiryRemover remover = new ExpiryRemover();
remover.setBindingProcessorManager(manager);
remover.execute();
diff --git a/bkucommon/src/test/java/at/gv/egiz/bku/binding/HttpBindingProcessorTest.java b/bkucommon/src/test/java/at/gv/egiz/bku/binding/HttpBindingProcessorTest.java
index 38f61aa2..6a0792d5 100644
--- a/bkucommon/src/test/java/at/gv/egiz/bku/binding/HttpBindingProcessorTest.java
+++ b/bkucommon/src/test/java/at/gv/egiz/bku/binding/HttpBindingProcessorTest.java
@@ -93,7 +93,7 @@ public class HttpBindingProcessorTest {
manager = new BindingProcessorManagerImpl(new DummyStalFactory(),
new SLCommandInvokerImpl());
bindingProcessor = (HTTPBindingProcessor) manager.createBindingProcessor(
- "http", null);
+ "http://www.iaik.at", null);
clientHeaderMap = new HashMap<String, String>();
clientHeaderMap.put("Content-Type",
"application/x-www-form-urlencoded;charset=utf8");
diff --git a/bkucommon/src/test/java/at/gv/egiz/bku/binding/MultipartSLRequestTest.java b/bkucommon/src/test/java/at/gv/egiz/bku/binding/MultipartSLRequestTest.java
index 7ef1a9bf..2c48bf4e 100644
--- a/bkucommon/src/test/java/at/gv/egiz/bku/binding/MultipartSLRequestTest.java
+++ b/bkucommon/src/test/java/at/gv/egiz/bku/binding/MultipartSLRequestTest.java
@@ -17,6 +17,7 @@
package at.gv.egiz.bku.binding;
import java.io.InputStream;
+import java.net.MalformedURLException;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
@@ -34,11 +35,11 @@ public class MultipartSLRequestTest {
protected BindingProcessorManager manager;
@Before
- public void setUp() {
+ public void setUp() throws MalformedURLException {
manager = new BindingProcessorManagerImpl(new DummyStalFactory(),
new SLCommandInvokerImpl());
HTTPBindingProcessor http = (HTTPBindingProcessor) manager
- .createBindingProcessor("http", null);
+ .createBindingProcessor("http://www.at/", null);
Map<String, String> headers = new HashMap<String, String>();
headers.put("Content-Type", InputDecoderFactory.MULTIPART_FORMDATA
+ ";boundary=---------------------------2330864292941");
diff --git a/bkucommon/src/test/java/at/gv/egiz/bku/binding/NullOperationTest.java b/bkucommon/src/test/java/at/gv/egiz/bku/binding/NullOperationTest.java
index 66b9dffb..b2a7d387 100644
--- a/bkucommon/src/test/java/at/gv/egiz/bku/binding/NullOperationTest.java
+++ b/bkucommon/src/test/java/at/gv/egiz/bku/binding/NullOperationTest.java
@@ -17,6 +17,7 @@
package at.gv.egiz.bku.binding;
import java.io.InputStream;
+import java.net.MalformedURLException;
import java.util.HashMap;
import java.util.Map;
@@ -32,9 +33,9 @@ public class NullOperationTest {
protected BindingProcessorManager manager;
@Before
- public void setUp() {
+ public void setUp() throws MalformedURLException {
manager = new BindingProcessorManagerImpl(new DummyStalFactory(), new SLCommandInvokerImpl());
- HTTPBindingProcessor http = (HTTPBindingProcessor) manager.createBindingProcessor("http", null);
+ HTTPBindingProcessor http = (HTTPBindingProcessor) manager.createBindingProcessor("http://www.at/", null);
Map<String, String> headers = new HashMap<String, String>();
headers.put("Content-Type", "application/x-www-form-urlencoded");
http.setHTTPHeaders(headers);
diff --git a/bkucommon/src/test/java/at/gv/egiz/bku/binding/TestDataUrlConnection.java b/bkucommon/src/test/java/at/gv/egiz/bku/binding/TestDataUrlConnection.java
index e644f964..45e38674 100644
--- a/bkucommon/src/test/java/at/gv/egiz/bku/binding/TestDataUrlConnection.java
+++ b/bkucommon/src/test/java/at/gv/egiz/bku/binding/TestDataUrlConnection.java
@@ -119,5 +119,10 @@ public class TestDataUrlConnection implements DataUrlConnectionSPI {
@Override
public DataUrlConnectionSPI newInstance() {
return this;
- }
+ }
+
+ @Override
+ public URL getUrl() {
+ return url;
+ }
}
diff --git a/bkucommon/src/test/resources/at/gv/egiz/bku/accesscontroller/AccessControlConfig.xml b/bkucommon/src/test/resources/at/gv/egiz/bku/accesscontroller/AccessControlConfig.xml
index 2455d68d..22f9e4a5 100644
--- a/bkucommon/src/test/resources/at/gv/egiz/bku/accesscontroller/AccessControlConfig.xml
+++ b/bkucommon/src/test/resources/at/gv/egiz/bku/accesscontroller/AccessControlConfig.xml
@@ -29,7 +29,7 @@
</Rule>
<Rule Id="rule-4">
<AuthClass>anonymous</AuthClass>
- <DomainName>*.gv.at</DomainName>
+ <DomainName>$.gv.at</DomainName>
<Action>
<RuleAction>allow</RuleAction>
</Action>
@@ -44,7 +44,7 @@
<AnyPeer />
<Command Name="Infobox*">
<Param Name="InfoboxIdentifier">IdentityLink</Param>
- <Param Name="PersonIdentifier">*</Param>
+ <Param Name="PersonIdentifier">.*</Param>
</Command>
<Action>
<RuleAction>allow</RuleAction>
@@ -56,7 +56,7 @@
<URL>https://finanzonline.bmf.gv.at/*</URL>
<Command Name="InfoboxReadRequest">
<Param Name="InfoboxIdentifier">Mandates</Param>
- <Param Name="PersonIdentifier">*</Param>
+ <Param Name="PersonIdentifier">.*</Param>
</Command>
<Action>
<RuleAction>allow</RuleAction>
diff --git a/bkucommon/src/test/resources/at/gv/egiz/bku/accesscontroller/SimpleChainTest.xml b/bkucommon/src/test/resources/at/gv/egiz/bku/accesscontroller/SimpleChainTest.xml
new file mode 100644
index 00000000..92490fb2
--- /dev/null
+++ b/bkucommon/src/test/resources/at/gv/egiz/bku/accesscontroller/SimpleChainTest.xml
@@ -0,0 +1,39 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<AccessControl>
+ <Chains>
+ <Chain Id="InputFilter">
+ <Rules>
+ <Rule Id="rule-IF1">
+ <AuthClass>pseudoanonymous</AuthClass>
+ <Action>
+ <ChainRef>DelegateFilter</ChainRef>
+ </Action>
+ </Rule>
+ </Rules>
+ </Chain>
+
+ <Chain Id="DelegateFilter">
+ <Rules>
+ <Rule Id="rule-DF1">
+ <AuthClass>certified</AuthClass>
+ <Command Name="Infobox.*">
+ <Param Name="InfoboxIdentifier">IdentityLink</Param>
+ <Param Name="PersonIdentifier">derived</Param>
+ </Command>
+ <Action>
+ <RuleAction>allow</RuleAction>
+ </Action>
+ </Rule>
+ <Rule Id="rule-DF2">
+ <AuthClass>certified</AuthClass>
+ <Command Name="Infobox.*">
+ <Param Name="InfoboxIdentifier">IdentityLink</Param>
+ </Command>
+ <Action>
+ <RuleAction>deny</RuleAction>
+ </Action>
+ </Rule>
+ </Rules>
+ </Chain>
+ </Chains>
+</AccessControl> \ No newline at end of file