cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cohei...@apache.org
Subject [1/4] cxf-fediz git commit: Added SSO test for IdP
Date Wed, 13 Apr 2016 15:38:59 GMT
Repository: cxf-fediz
Updated Branches:
  refs/heads/master 139fb6bd4 -> cc8708e1b


Added SSO test for IdP


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

Branch: refs/heads/master
Commit: 188e20c16b4938f2fc40d32a90baba03db1838a2
Parents: 139fb6b
Author: Colm O hEigeartaigh <coheigea@apache.org>
Authored: Wed Apr 13 15:09:33 2016 +0100
Committer: Colm O hEigeartaigh <coheigea@apache.org>
Committed: Wed Apr 13 15:09:33 2016 +0100

----------------------------------------------------------------------
 .../apache/cxf/fediz/systests/idp/IdpTest.java  | 67 ++++++++++++++++++++
 1 file changed, 67 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf-fediz/blob/188e20c1/systests/idp/src/test/java/org/apache/cxf/fediz/systests/idp/IdpTest.java
----------------------------------------------------------------------
diff --git a/systests/idp/src/test/java/org/apache/cxf/fediz/systests/idp/IdpTest.java b/systests/idp/src/test/java/org/apache/cxf/fediz/systests/idp/IdpTest.java
index 1bc4791..04bc875 100644
--- a/systests/idp/src/test/java/org/apache/cxf/fediz/systests/idp/IdpTest.java
+++ b/systests/idp/src/test/java/org/apache/cxf/fediz/systests/idp/IdpTest.java
@@ -47,6 +47,7 @@ import org.apache.http.auth.UsernamePasswordCredentials;
 import org.apache.wss4j.dom.engine.WSSConfig;
 import org.apache.xml.security.keys.KeyInfo;
 import org.apache.xml.security.signature.XMLSignature;
+import org.apache.xml.security.utils.Base64;
 import org.junit.AfterClass;
 import org.junit.Assert;
 import org.junit.BeforeClass;
@@ -191,6 +192,72 @@ public class IdpTest {
 
         webClient.close();
     }
+    
+    @org.junit.Test
+    public void testSuccessfulSSOInvokeOnIdP() throws Exception {
+        String url = "https://localhost:" + getIdpHttpsPort() + "/fediz-idp/federation?";
+        url += "wa=wsignin1.0";
+        url += "&whr=urn:org:apache:cxf:fediz:idp:realm-A";
+        url += "&wtrealm=urn:org:apache:cxf:fediz:fedizhelloworld";
+        String wreply = "https://localhost:" + getRpHttpsPort() + "/" + getServletContextName()
+ "/secure/fedservlet";
+        url += "&wreply=" + wreply;
+
+        String user = "alice";
+        String password = "ecila";
+
+        final WebClient webClient = new WebClient();
+        webClient.getOptions().setUseInsecureSSL(true);
+        webClient.addRequestHeader("Authorization", "Basic " + Base64.encode((user + ":"
+ password).getBytes()));
+        
+        //
+        // First invocation
+        //
+
+        webClient.getOptions().setJavaScriptEnabled(false);
+        HtmlPage idpPage = webClient.getPage(url);
+        webClient.getOptions().setJavaScriptEnabled(true);
+        Assert.assertEquals("IDP SignIn Response Form", idpPage.getTitleText());
+
+        // Parse the form to get the token (wresult)
+        DomNodeList<DomElement> results = idpPage.getElementsByTagName("input");
+
+        String wresult = null;
+        for (DomElement result : results) {
+            if ("wresult".equals(result.getAttributeNS(null, "name"))) {
+                wresult = result.getAttributeNS(null, "value");
+                break;
+            }
+        }
+
+        Assert.assertNotNull(wresult);
+        
+        //
+        // Second invocation - change the credentials to make sure the session is set up
correctly
+        // 
+
+        webClient.removeRequestHeader("Authorization");
+        webClient.addRequestHeader("Authorization", "Basic " + Base64.encode(("mallory" +
":" + password).getBytes()));
+        
+        webClient.getOptions().setJavaScriptEnabled(false);
+        idpPage = webClient.getPage(url);
+        webClient.getOptions().setJavaScriptEnabled(true);
+        Assert.assertEquals("IDP SignIn Response Form", idpPage.getTitleText());
+
+        // Parse the form to get the token (wresult)
+        results = idpPage.getElementsByTagName("input");
+
+        wresult = null;
+        for (DomElement result : results) {
+            if ("wresult".equals(result.getAttributeNS(null, "name"))) {
+                wresult = result.getAttributeNS(null, "value");
+                break;
+            }
+        }
+
+        Assert.assertNotNull(wresult);
+        
+        webClient.close();
+    }
 
     @Test
     public void testIdPMetadata() throws Exception {


Mime
View raw message