You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by co...@apache.org on 2015/12/22 17:08:49 UTC

[2/3] cxf-fediz git commit: Fixed IdP unit tests when run with realm b.

Fixed IdP unit tests when run with realm b.


Project: http://git-wip-us.apache.org/repos/asf/cxf-fediz/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf-fediz/commit/4e33f8af
Tree: http://git-wip-us.apache.org/repos/asf/cxf-fediz/tree/4e33f8af
Diff: http://git-wip-us.apache.org/repos/asf/cxf-fediz/diff/4e33f8af

Branch: refs/heads/master
Commit: 4e33f8af53e1552c861a73ea69e6fc674f906f08
Parents: 4a8a69d
Author: Colm O hEigeartaigh <co...@apache.org>
Authored: Tue Dec 22 15:33:04 2015 +0000
Committer: Colm O hEigeartaigh <co...@apache.org>
Committed: Tue Dec 22 15:33:04 2015 +0000

----------------------------------------------------------------------
 services/idp/pom.xml                            |   3 +
 .../idp/integrationtests/RestITTest.java        | 131 +++++++++++++------
 2 files changed, 93 insertions(+), 41 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf-fediz/blob/4e33f8af/services/idp/pom.xml
----------------------------------------------------------------------
diff --git a/services/idp/pom.xml b/services/idp/pom.xml
index fe45ebe..2a03bb2 100644
--- a/services/idp/pom.xml
+++ b/services/idp/pom.xml
@@ -435,6 +435,7 @@
                             <skip>false</skip>
                             <systemPropertyVariables>
                                 <idp.https.port>${idp.https.port}</idp.https.port>
+                                <realm>${realm}</realm>
                                 <catalina.base>target</catalina.base>
                             </systemPropertyVariables>
                             <includes>
@@ -488,6 +489,7 @@
                 <jpa.url>jdbc:hsqldb:target/db/realma/myDB;shutdown=true</jpa.url>
                 <idp.https.port>9443</idp.https.port>
                 <idp.http.port>9080</idp.http.port>
+                <realm>realm-a</realm>
             </properties>
             <build>
                 <filters>
@@ -515,6 +517,7 @@
                 <jpa.url>jdbc:hsqldb:target/db/realmb/myDB;shutdown=true</jpa.url>
                 <idp.https.port>12346</idp.https.port>
                 <idp.http.port>12345</idp.http.port>
+                <realm>realm-b</realm>
             </properties>
             <build>
                 <filters>

http://git-wip-us.apache.org/repos/asf/cxf-fediz/blob/4e33f8af/services/idp/src/test/java/org/apache/cxf/fediz/service/idp/integrationtests/RestITTest.java
----------------------------------------------------------------------
diff --git a/services/idp/src/test/java/org/apache/cxf/fediz/service/idp/integrationtests/RestITTest.java b/services/idp/src/test/java/org/apache/cxf/fediz/service/idp/integrationtests/RestITTest.java
index 9b3147f..8c02d11 100644
--- a/services/idp/src/test/java/org/apache/cxf/fediz/service/idp/integrationtests/RestITTest.java
+++ b/services/idp/src/test/java/org/apache/cxf/fediz/service/idp/integrationtests/RestITTest.java
@@ -45,6 +45,7 @@ import org.junit.Test;
 public class RestITTest {
         
     private static String idpHttpsPort;
+    private static String realm;
     private static Bus bus;
 
 
@@ -62,6 +63,9 @@ public class RestITTest {
 
         idpHttpsPort = System.getProperty("idp.https.port");
         Assert.assertNotNull("Property 'idp.https.port' null", idpHttpsPort);
+        
+        realm = System.getProperty("realm");
+        Assert.assertNotNull("Property 'realm' null", realm);
 
         SpringBusFactory bf = new SpringBusFactory();
         
@@ -81,7 +85,7 @@ public class RestITTest {
     
     @Test
     public void testGetAllIdps() throws UnsupportedEncodingException, MalformedURLException {
-        String address = "https://localhost:" + idpHttpsPort + "/fediz-idp/services/rs";
+        String address = "https://localhost:" + idpHttpsPort + "/" + getContextName() + "/services/rs";
         Client client = ClientBuilder.newClient();
         Idps idps = client.target(address).path("idps")
             .request("application/xml").header("Authorization", getBasicAuthentication("admin", "password"))
@@ -89,57 +93,96 @@ public class RestITTest {
         Assert.assertEquals(1L, idps.getIdps().size());
         
         Idp idp = idps.getIdps().iterator().next();
-        Assert.assertEquals("Certificate doesn't match",
-                            "stsKeystoreA.properties", idp.getCertificate());
-        Assert.assertEquals("Certificate password doesn't match",
-                            "realma", idp.getCertificatePassword());
-        Assert.assertEquals("Realm doesn't match",
-                            "urn:org:apache:cxf:fediz:idp:realm-A", idp.getRealm());
-        Assert.assertEquals("ServiceDescription doesn't match",
-                            "IDP of Realm A", idp.getServiceDescription());
-        Assert.assertEquals("ServiceDisplayName doesn't match",
-                            "REALM A", idp.getServiceDisplayName());
-        Assert.assertEquals("IdpUrl doesn't match",
-                            new URL("https://localhost:9443/fediz-idp/federation"), idp.getIdpUrl());
-        Assert.assertEquals("StsUrl doesn't match",
-                            new URL("https://localhost:9443/fediz-idp-sts/REALMA"), idp.getStsUrl());
-        Assert.assertEquals("Uri doesn't match",
-                            "realma", idp.getUri());
-        Assert.assertTrue("ProvideIDPList doesn't match", idp.isProvideIdpList());
-        Assert.assertTrue("UseCurrentIDP doesn't match", idp.isUseCurrentIdp());
-        Assert.assertEquals("Number of AuthenticationURIs doesn't match",
-                            4, idp.getAuthenticationURIs().size());
-        Assert.assertEquals("Number of SupportedProtocols doesn't match",
-                            2, idp.getSupportedProtocols().size());
-        Assert.assertEquals("Number of TokenTypesOffered doesn't match",
-                            2, idp.getTokenTypesOffered().size());
-        Assert.assertEquals("Number of applications doesn't match",
-                            2, idp.getApplications().size());
-        Assert.assertEquals("Number of trusted IDPs doesn't match",
-                            1, idp.getTrustedIdps().size());
-        Assert.assertEquals("Number of claims doesn't match",
-                            4, idp.getClaimTypesOffered().size());
+        if ("realm-a".equals(realm)) {
+            Assert.assertEquals("Certificate doesn't match",
+                                "stsKeystoreA.properties", idp.getCertificate());
+            Assert.assertEquals("Certificate password doesn't match",
+                                "realma", idp.getCertificatePassword());
+            Assert.assertEquals("Realm doesn't match",
+                                "urn:org:apache:cxf:fediz:idp:realm-A", idp.getRealm());
+            Assert.assertEquals("ServiceDescription doesn't match",
+                                "IDP of Realm A", idp.getServiceDescription());
+            Assert.assertEquals("ServiceDisplayName doesn't match",
+                                "REALM A", idp.getServiceDisplayName());
+            Assert.assertEquals("IdpUrl doesn't match",
+                                new URL("https://localhost:9443/fediz-idp/federation"), idp.getIdpUrl());
+            Assert.assertEquals("StsUrl doesn't match",
+                                new URL("https://localhost:9443/fediz-idp-sts/REALMA"), idp.getStsUrl());
+            Assert.assertEquals("Uri doesn't match",
+                                "realma", idp.getUri());
+            Assert.assertTrue("ProvideIDPList doesn't match", idp.isProvideIdpList());
+            Assert.assertTrue("UseCurrentIDP doesn't match", idp.isUseCurrentIdp());
+            Assert.assertEquals("Number of AuthenticationURIs doesn't match",
+                                4, idp.getAuthenticationURIs().size());
+            Assert.assertEquals("Number of SupportedProtocols doesn't match",
+                                2, idp.getSupportedProtocols().size());
+            Assert.assertEquals("Number of TokenTypesOffered doesn't match",
+                                2, idp.getTokenTypesOffered().size());
+            Assert.assertEquals("Number of applications doesn't match",
+                                2, idp.getApplications().size());
+            Assert.assertEquals("Number of trusted IDPs doesn't match",
+                                1, idp.getTrustedIdps().size());
+            Assert.assertEquals("Number of claims doesn't match",
+                                4, idp.getClaimTypesOffered().size());
+        } else {
+            Assert.assertEquals("Certificate doesn't match",
+                                "stsKeystoreB.properties", idp.getCertificate());
+            Assert.assertEquals("Certificate password doesn't match",
+                                "realmb", idp.getCertificatePassword());
+            Assert.assertEquals("Realm doesn't match",
+                                "urn:org:apache:cxf:fediz:idp:realm-B", idp.getRealm());
+            Assert.assertEquals("ServiceDescription doesn't match",
+                                "IDP of Realm B", idp.getServiceDescription());
+            Assert.assertEquals("ServiceDisplayName doesn't match",
+                                "REALM B", idp.getServiceDisplayName());
+            Assert.assertEquals("IdpUrl doesn't match",
+                                new URL("https://localhost:12443/fediz-idp-remote/federation"), idp.getIdpUrl());
+            Assert.assertEquals("StsUrl doesn't match",
+                                new URL("https://localhost:12443/fediz-idp-sts/REALMB"), idp.getStsUrl());
+            Assert.assertEquals("Uri doesn't match",
+                                "realmb", idp.getUri());
+            Assert.assertTrue("ProvideIDPList doesn't match", idp.isProvideIdpList());
+            Assert.assertTrue("UseCurrentIDP doesn't match", idp.isUseCurrentIdp());
+            Assert.assertEquals("Number of AuthenticationURIs doesn't match",
+                                4, idp.getAuthenticationURIs().size());
+            Assert.assertEquals("Number of SupportedProtocols doesn't match",
+                                2, idp.getSupportedProtocols().size());
+            Assert.assertEquals("Number of TokenTypesOffered doesn't match",
+                                2, idp.getTokenTypesOffered().size());
+            Assert.assertEquals("Number of applications doesn't match",
+                                1, idp.getApplications().size());
+            Assert.assertEquals("Number of claims doesn't match",
+                                4, idp.getClaimTypesOffered().size());
+        }
     }
 
     @Test
     public void testReadExistingIdpEmbeddedTrustedIdps() throws UnsupportedEncodingException {
-        String address = "https://localhost:" + idpHttpsPort + "/fediz-idp/services/rs";
+        String address = "https://localhost:" + idpHttpsPort + "/" + getContextName() + "/services/rs";
         Client client = ClientBuilder.newClient();
-        Idp idp = client.target(address).path("idps/").path("urn:org:apache:cxf:fediz:idp:realm-A")
-            .request("application/xml").header("Authorization", getBasicAuthentication("admin", "password"))
-            .get(Idp.class);
-        Assert.assertEquals("", "urn:org:apache:cxf:fediz:idp:realm-A", idp.getRealm());
+        
+        if ("realm-a".equals(realm)) {
+            Idp idp = client.target(address).path("idps/").path("urn:org:apache:cxf:fediz:idp:realm-A")
+                .request("application/xml").header("Authorization", getBasicAuthentication("admin", "password"))
+                .get(Idp.class);
+            Assert.assertEquals("", "urn:org:apache:cxf:fediz:idp:realm-A", idp.getRealm());
+        } else {
+            Idp idp = client.target(address).path("idps/").path("urn:org:apache:cxf:fediz:idp:realm-B")
+                .request("application/xml").header("Authorization", getBasicAuthentication("admin", "password"))
+                .get(Idp.class);
+            Assert.assertEquals("", "urn:org:apache:cxf:fediz:idp:realm-B", idp.getRealm());
+        }
     }
     
     @Test
     public void testAddClaimToApplication() throws UnsupportedEncodingException {
         
-        String address = "https://localhost:" + idpHttpsPort + "/fediz-idp/services/rs";
+        String address = "https://localhost:" + idpHttpsPort + "/" + getContextName() + "/services/rs";
         Client client = ClientBuilder.newClient();
         
-        String realm = "urn:org:apache:cxf:fediz:fedizhelloworld:testaddclaim";
+        String realmToAdd = "urn:org:apache:cxf:fediz:fedizhelloworld:testaddclaim";
         Application application = new Application();
-        application.setRealm(realm);
+        application.setRealm(realmToAdd);
         application.setEncryptionCertificate("");
         application.setLifeTime(3600);
         application.setProtocol("http://docs.oasis-open.org/wsfed/federation/200706");
@@ -158,12 +201,12 @@ public class RestITTest {
         requestClaim.setOptional(false);
         requestClaim.setClaimType(URI.create("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/givenname"));
         
-        response = client.target(address).path("applications").path(realm).path("claims")
+        response = client.target(address).path("applications").path(realmToAdd).path("claims")
             .request("application/xml").header("Authorization", getBasicAuthentication("admin", "password"))
             .post(Entity.entity(requestClaim, MediaType.APPLICATION_XML));
         Assert.assertEquals(Status.NO_CONTENT.getStatusCode(), response.getStatus());
         
-        application = client.target(address).path("applications").path(realm).queryParam("expand", "claims")
+        application = client.target(address).path("applications").path(realmToAdd).queryParam("expand", "claims")
             .request("application/xml").header("Authorization", getBasicAuthentication("admin", "password"))
             .get(Application.class);
         Assert.assertEquals("Claims size should be 1 instead of " + application.getRequestedClaims().size(),
@@ -175,5 +218,11 @@ public class RestITTest {
         return "Basic " + Base64.encode(token.getBytes());
     }
 
+    private String getContextName() {
+        if ("realm-a".equals(realm)) {
+            return "fediz-idp";
+        }
+        return "fediz-idp-remote";
+    }
 
 }