Added another ARP filtering test combining two ARPs.
authorwassa <wassa@ab3bd59b-922f-494d-bb5f-6f0a3c29deca>
Thu, 23 Jan 2003 07:29:16 +0000 (07:29 +0000)
committerwassa <wassa@ab3bd59b-922f-494d-bb5f-6f0a3c29deca>
Thu, 23 Jan 2003 07:29:16 +0000 (07:29 +0000)
git-svn-id: https://subversion.switch.ch/svn/shibboleth/java-idp/trunk@411 ab3bd59b-922f-494d-bb5f-6f0a3c29deca

src/edu/internet2/middleware/shibboleth/aa/arp/ArpTests.java

index 94f89ac..840a93b 100755 (executable)
@@ -537,6 +537,7 @@ public class ArpTests extends TestCase {
                        arpApplicationTest18(repository, props, parser);
                        arpApplicationTest19(repository, props, parser);
                        arpApplicationTest20(repository, props, parser);
+                       arpApplicationTest21(repository, props, parser);
 
                } catch (Exception e) {
                        e.printStackTrace();
@@ -1718,10 +1719,161 @@ public class ArpTests extends TestCase {
                                url1);
 
                assertEquals(
-                       "ARP application test 6: ARP not applied as expected.",
+                       "ARP application test 20: ARP not applied as expected.",
                        new HashSet(Arrays.asList(releaseAttributes)),
                        new HashSet(Arrays.asList(new ArpAttribute[] { entitlementOutput, affiliationOutput, principalNameInput, preferredLanguageInput })));
        }
+       
+       /**
+        * ARPs: A site ARP and user ARP
+        * Target: various
+        * Attribute: various combinations (same ARPs as 20, different requester)
+        */
+       void arpApplicationTest21(ArpRepository repository, Properties props, DOMParser parser)
+               throws Exception {
+
+               //Gather the Input
+               String rawSiteArp =
+                       "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
+                               + "<AttributeReleasePolicy xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"ARP.xsd\">"
+                               + "                     <Rule>"
+                               + "                             <Target>"
+                               + "                                     <AnyTarget/>"
+                               + "                             </Target>"
+                               + "                             <Attribute name=\"urn:mace:eduPerson:1.0:eduPersonAffiliation\">"
+                               + "                                     <Value release=\"permit\">member@example.edu</Value>"
+                               + "                             </Attribute>"
+                               + "                             <Attribute name=\"urn:mace:inetOrgPerson:preferredLanguage\">"
+                               + "                                     <AnyValue release=\"permit\" />"
+                               + "                             </Attribute>"
+                               + "                     </Rule>"
+                               + "                     <Rule>"
+                               + "                             <Target>"
+                               + "                                     <Requester matchFunction=\"urn:mace:shibboleth:arp:matchFunction:regexMatch\">.*\\.example\\.edu</Requester>"
+                               + "                                     <AnyResource />"
+                               + "                             </Target>"
+                               + "                             <Attribute name=\"urn:mace:eduPerson:1.0:eduPersonPrincipalName\">"
+                               + "                                     <AnyValue release=\"permit\"/>"
+                               + "                             </Attribute>"
+                               + "                     </Rule>"
+                               + "                     <Rule>"
+                               + "                             <Target>"
+                               + "                                     <Requester>www.example.edu</Requester>"
+                               + "                                     <Resource>http://www.example.edu/</Resource>"
+                               + "                             </Target>"
+                               + "                             <Attribute name=\"urn:mace:eduPerson:1.0:eduPersonAffiliation\">"
+                               + "                                     <AnyValue release=\"permit\"/>"
+                               + "                             </Attribute>"
+                               + "                             <Attribute name=\"urn:mace:eduPerson:1.0:eduPersonEntitlement\">"
+                               + "                                     <Value release=\"permit\">urn:example:contract:4657483</Value>"
+                               + "                             </Attribute>"
+                               + "                     </Rule>"
+                               + "                     <Rule>"
+                               + "                             <Target>"
+                               + "                                     <Requester>www.external.com</Requester>"
+                               + "                                     <Resource>http://www.external.com/</Resource>"
+                               + "                             </Target>"
+                               + "                             <Attribute name=\"urn:mace:eduPerson:1.0:eduPersonEntitlement\">"
+                               + "                                     <Value release=\"permit\">urn:example:contract:113455</Value>"
+                               + "                             </Attribute>"
+                               + "                     </Rule>"
+                               + "     </AttributeReleasePolicy>";
+
+               String rawUserArp =
+                       "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
+                               + "<AttributeReleasePolicy xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"ARP.xsd\">"
+                               + "                     <Rule>"
+                               + "                             <Target>"
+                               + "                                     <AnyTarget/>"
+                               + "                             </Target>"
+                               + "                             <Attribute name=\"urn:mace:eduPerson:1.0:eduPersonEntitlement\">"
+                               + "                                     <Value release=\"deny\">urn:example:poorlyDressed</Value>"
+                               + "                             </Attribute>"
+                               + "                     </Rule>"
+                               + "                     <Rule>"
+                               + "                             <Target>"
+                               + "                                     <Requester matchFunction=\"urn:mace:shibboleth:arp:matchFunction:regexMatch\">.*\\.example\\.edu</Requester>"
+                               + "                                     <AnyResource />"
+                               + "                             </Target>"
+                               + "                             <Attribute name=\"urn:mace:eduPerson:1.0:eduPersonAffiliation\">"
+                               + "                                     <Value release=\"deny\">faculty@example.edu</Value>"
+                               + "                             </Attribute>"
+                               + "                             <Attribute name=\"urn:mace:eduPerson:1.0:eduPersonEntitlement\">"
+                               + "                                     <Value release=\"permit\">urn:example:lovesIceCream</Value>"
+                               + "                             </Attribute>"
+                               + "                     </Rule>"
+                               + "     </AttributeReleasePolicy>";
+
+               Principal principal1 = new AAPrincipal("TestPrincipal");
+               URL url1 = new URL("http://www.external.com/");
+
+               TestAttribute entitlementInput =
+                       new TestAttribute(
+                               "urn:mace:eduPerson:1.0:eduPersonEntitlement",
+                               new Object[] {
+                                       "urn:example:lovesIceCream",
+                                       "urn:example:poorlyDressed",
+                                       "urn:example:contract:113455",
+                                       "urn:example:contract:4657483" });
+
+               TestAttribute affiliationInput =
+                       new TestAttribute(
+                               "urn:mace:eduPerson:1.0:eduPersonAffiliation",
+                               new Object[] {
+                                       "member@example.edu",
+                                       "faculty@example.edu",
+                                       "employee@example.edu" });
+
+               TestAttribute principalNameInput =
+                       new TestAttribute(
+                               "urn:mace:eduPerson:1.0:eduPersonPrincipalName",
+                               new Object[] { "wassa@example.edu" });
+
+               TestAttribute preferredLanguageInput =
+                       new TestAttribute("urn:mace:inetOrgPerson:preferredLanguage", new Object[] { "EO" });
+                       
+                               TestAttribute entitlementOutput =
+                       new TestAttribute(
+                               "urn:mace:eduPerson:1.0:eduPersonEntitlement",
+                               new Object[] { "urn:example:contract:113455" });
+                                       
+               TestAttribute affiliationOutput =
+                       new TestAttribute(
+                               "urn:mace:eduPerson:1.0:eduPersonAffiliation",
+                               new Object[] { "member@example.edu" });
+
+               //Add the site ARP
+               parser.parse(new InputSource(new StringReader(rawSiteArp)));
+               Arp siteArp = new Arp();
+               siteArp.marshall(parser.getDocument().getDocumentElement());
+               repository.update(siteArp);
+
+               //Add the user ARP
+               parser.parse(new InputSource(new StringReader(rawUserArp)));
+               Arp userArp = new Arp();
+               userArp.setPrincipal(principal1);
+               userArp.marshall(parser.getDocument().getDocumentElement());
+               repository.update(userArp);
+
+               ArpEngine engine = new ArpEngine(repository, props);
+
+               //Apply the ARP
+               ArpAttribute[] releaseAttributes =
+                       engine.filterAttributes(
+                               new ArpAttribute[] {
+                                       entitlementInput,
+                                       affiliationInput,
+                                       principalNameInput,
+                                       preferredLanguageInput },
+                               principal1,
+                               "www.external.com",
+                               url1);
+
+               assertEquals(
+                       "ARP application test 21: ARP not applied as expected.",
+                       new HashSet(Arrays.asList(releaseAttributes)),
+                       new HashSet(Arrays.asList(new ArpAttribute[] { entitlementOutput, affiliationOutput, preferredLanguageInput })));
+       }
 
        public class TestAttribute implements ArpAttribute {
                private String name;