From 5a8e29c1cb80af184c9ef7e41f3ef237af14e3a3 Mon Sep 17 00:00:00 2001 From: wassa Date: Tue, 23 May 2006 20:28:15 +0000 Subject: [PATCH] Beginnings of a test suite for strawman attribute constraint syntax. git-svn-id: https://subversion.switch.ch/svn/shibboleth/java-idp/trunk@1944 ab3bd59b-922f-494d-bb5f-6f0a3c29deca --- .../middleware/shibboleth/aa/arp/ArpTests.java | 261 ++++++++++++++++++++ 1 file changed, 261 insertions(+) diff --git a/tests/edu/internet2/middleware/shibboleth/aa/arp/ArpTests.java b/tests/edu/internet2/middleware/shibboleth/aa/arp/ArpTests.java index bb04701..eef8ea1 100755 --- a/tests/edu/internet2/middleware/shibboleth/aa/arp/ArpTests.java +++ b/tests/edu/internet2/middleware/shibboleth/aa/arp/ArpTests.java @@ -1604,9 +1604,270 @@ public class ArpTests extends TestCase { } + /** + * Use Case: must have an attribute + * Example: release uid only if user has any value for attribute "foo" + */ + void arpConstraintTest1(ArpRepository repository, Parser.DOMParser parser) throws Exception { + + String rawArp = "" + + "" + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " "; + + // Setup the engine + parser.parse(new InputSource(new StringReader(rawArp))); + Arp siteArp = new Arp(); + siteArp.marshall(parser.getDocument().getDocumentElement()); + repository.update(siteArp); + ArpEngine engine = new ArpEngine(repository); + + Principal principal = new LocalPrincipal("TestPrincipal"); + + // test user who meets constraint + Collection inputSet1 = new ArrayList(); + inputSet1.add(new AAAttribute("urn:mace:dir:attribute-def:uid", new Object[]{"gpburdell"})); + inputSet1.add(new AAAttribute("urn:mace:dir:attribute-def:foo", new Object[]{"bar"})); + Collection releaseSet1 = new ArrayList(); + releaseSet1.add(new AAAttribute("urn:mace:dir:attribute-def:uid", new Object[]{"gpburdell"})); + engine.filterAttributes(inputSet1, principal, "shar.example.edu"); + assertEquals("ARP application test 1a: ARP not applied as expected.", releaseSet1, inputSet1); + // test user who does not meet constraint + Collection inputSet2 = new ArrayList(); + inputSet2.add(new AAAttribute("urn:mace:dir:attribute-def:uid", new Object[]{"gpburdell"})); + + Collection releaseSet2 = new ArrayList(); + + engine.filterAttributes(inputSet2, principal, "shar.example.edu"); + assertEquals("ARP application test 1b: ARP not applied as expected.", releaseSet2, inputSet2); + + } + /** + * Use Case: must have an attribute value + * Example: release uid only if user has a specific value for attribute "foo" + */ + void arpConstraintTest2(ArpRepository repository, Parser.DOMParser parser) throws Exception { + + String rawArp = "" + + "" + + " " + + " bar" + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " "; + + // Setup the engine + parser.parse(new InputSource(new StringReader(rawArp))); + Arp siteArp = new Arp(); + siteArp.marshall(parser.getDocument().getDocumentElement()); + repository.update(siteArp); + ArpEngine engine = new ArpEngine(repository); + + Principal principal = new LocalPrincipal("TestPrincipal"); + + // test user who meets constraint + Collection inputSet1 = new ArrayList(); + inputSet1.add(new AAAttribute("urn:mace:dir:attribute-def:uid", new Object[]{"gpburdell"})); + inputSet1.add(new AAAttribute("urn:mace:dir:attribute-def:foo", new Object[]{"bar"})); + + Collection releaseSet1 = new ArrayList(); + releaseSet1.add(new AAAttribute("urn:mace:dir:attribute-def:uid", new Object[]{"gpburdell"})); + + engine.filterAttributes(inputSet1, principal, "shar.example.edu"); + assertEquals("ARP application test 1a: ARP not applied as expected.", releaseSet1, inputSet1); + + // test user who does not meet constraint + Collection inputSet2 = new ArrayList(); + inputSet2.add(new AAAttribute("urn:mace:dir:attribute-def:uid", new Object[]{"gpburdell"})); + + Collection releaseSet2 = new ArrayList(); + + engine.filterAttributes(inputSet2, principal, "shar.example.edu"); + assertEquals("ARP application test 1b: ARP not applied as expected.", releaseSet2, inputSet2); + + } + /** + * Use Case: must have only a specific attribute value + * Example: release uid only if user has a specific value for attribute "foo", but not if it has other values + */ + void arpConstraintTest3(ArpRepository repository, Parser.DOMParser parser) throws Exception { + + String rawArp = "" + + "" + + " " + + " bar" + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " "; + + // Setup the engine + parser.parse(new InputSource(new StringReader(rawArp))); + Arp siteArp = new Arp(); + siteArp.marshall(parser.getDocument().getDocumentElement()); + repository.update(siteArp); + ArpEngine engine = new ArpEngine(repository); + + Principal principal = new LocalPrincipal("TestPrincipal"); + // test user who meets constraint + Collection inputSet1 = new ArrayList(); + inputSet1.add(new AAAttribute("urn:mace:dir:attribute-def:uid", new Object[]{"gpburdell"})); + inputSet1.add(new AAAttribute("urn:mace:dir:attribute-def:foo", new Object[]{"bar"})); + + Collection releaseSet1 = new ArrayList(); + releaseSet1.add(new AAAttribute("urn:mace:dir:attribute-def:uid", new Object[]{"gpburdell"})); + + engine.filterAttributes(inputSet1, principal, "shar.example.edu"); + assertEquals("ARP application test 1a: ARP not applied as expected.", releaseSet1, inputSet1); + + // test user who does not meet constraint + Collection inputSet2 = new ArrayList(); + inputSet2.add(new AAAttribute("urn:mace:dir:attribute-def:uid", new Object[]{"gpburdell"})); + + Collection releaseSet2 = new ArrayList(); + + engine.filterAttributes(inputSet2, principal, "shar.example.edu"); + assertEquals("ARP application test 1b: ARP not applied as expected.", releaseSet2, inputSet2); + + } + /** + * Use Case: must have two specific attribute values + * Example: release uid only if user has two specific value for attribute "foo", "bar" and "wee" + */ + void arpConstraintTest4(ArpRepository repository, Parser.DOMParser parser) throws Exception { + + String rawArp = "" + + "" + + " " + + " bar" + + " wee" + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " "; + + // Setup the engine + parser.parse(new InputSource(new StringReader(rawArp))); + Arp siteArp = new Arp(); + siteArp.marshall(parser.getDocument().getDocumentElement()); + repository.update(siteArp); + ArpEngine engine = new ArpEngine(repository); + + Principal principal = new LocalPrincipal("TestPrincipal"); + + // test user who meets constraint + Collection inputSet1 = new ArrayList(); + inputSet1.add(new AAAttribute("urn:mace:dir:attribute-def:uid", new Object[]{"gpburdell"})); + inputSet1.add(new AAAttribute("urn:mace:dir:attribute-def:foo", new Object[]{"bar"})); + + Collection releaseSet1 = new ArrayList(); + releaseSet1.add(new AAAttribute("urn:mace:dir:attribute-def:uid", new Object[]{"gpburdell"})); + + engine.filterAttributes(inputSet1, principal, "shar.example.edu"); + assertEquals("ARP application test 1a: ARP not applied as expected.", releaseSet1, inputSet1); + + // test user who does not meet constraint + Collection inputSet2 = new ArrayList(); + inputSet2.add(new AAAttribute("urn:mace:dir:attribute-def:uid", new Object[]{"gpburdell"})); + + Collection releaseSet2 = new ArrayList(); + + engine.filterAttributes(inputSet2, principal, "shar.example.edu"); + assertEquals("ARP application test 1b: ARP not applied as expected.", releaseSet2, inputSet2); + + } + + /** + * Use Case: must not have a specific attribute value + * Example: release uid only if user does not have a specific value for attribute "foo" + */ + void arpConstraintTest5(ArpRepository repository, Parser.DOMParser parser) throws Exception { + + String rawArp = "" + + "" + + " " + + " bar" + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " "; + + // Setup the engine + parser.parse(new InputSource(new StringReader(rawArp))); + Arp siteArp = new Arp(); + siteArp.marshall(parser.getDocument().getDocumentElement()); + repository.update(siteArp); + ArpEngine engine = new ArpEngine(repository); + + Principal principal = new LocalPrincipal("TestPrincipal"); + + // test user who meets constraint + Collection inputSet1 = new ArrayList(); + inputSet1.add(new AAAttribute("urn:mace:dir:attribute-def:uid", new Object[]{"gpburdell"})); + inputSet1.add(new AAAttribute("urn:mace:dir:attribute-def:foo", new Object[]{"bar"})); + + Collection releaseSet1 = new ArrayList(); + releaseSet1.add(new AAAttribute("urn:mace:dir:attribute-def:uid", new Object[]{"gpburdell"})); + + engine.filterAttributes(inputSet1, principal, "shar.example.edu"); + assertEquals("ARP application test 1a: ARP not applied as expected.", releaseSet1, inputSet1); + + // test user who does not meet constraint + Collection inputSet2 = new ArrayList(); + inputSet2.add(new AAAttribute("urn:mace:dir:attribute-def:uid", new Object[]{"gpburdell"})); + + Collection releaseSet2 = new ArrayList(); + + engine.filterAttributes(inputSet2, principal, "shar.example.edu"); + assertEquals("ARP application test 1b: ARP not applied as expected.", releaseSet2, inputSet2); + + } } -- 1.7.10.4