You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicemix.apache.org by gn...@apache.org on 2006/11/15 18:48:11 UTC

svn commit: r475325 - in /incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/test: java/org/apache/servicemix/http/security/ resources/org/apache/servicemix/http/security/

Author: gnodet
Date: Wed Nov 15 09:48:10 2006
New Revision: 475325

URL: http://svn.apache.org/viewvc?view=rev&rev=475325
Log:
Improve junit tests.
Remove ASF header which cause failures in junit test (until we upgrade WSS4J)

Added:
    incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/test/resources/org/apache/servicemix/http/security/request-bc.xml   (with props)
    incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/test/resources/org/apache/servicemix/http/security/request-uu.xml   (with props)
Modified:
    incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/test/java/org/apache/servicemix/http/security/HttpSecurityTest.java
    incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/test/resources/org/apache/servicemix/http/security/request.xml

Modified: incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/test/java/org/apache/servicemix/http/security/HttpSecurityTest.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/test/java/org/apache/servicemix/http/security/HttpSecurityTest.java?view=diff&rev=475325&r1=475324&r2=475325
==============================================================================
--- incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/test/java/org/apache/servicemix/http/security/HttpSecurityTest.java (original)
+++ incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/test/java/org/apache/servicemix/http/security/HttpSecurityTest.java Wed Nov 15 09:48:10 2006
@@ -27,10 +27,13 @@
 import org.apache.commons.httpclient.auth.AuthScope;
 import org.apache.commons.httpclient.methods.PostMethod;
 import org.apache.commons.httpclient.methods.StringRequestEntity;
+import org.apache.servicemix.jbi.jaxp.SourceTransformer;
+import org.apache.servicemix.jbi.jaxp.StringSource;
 import org.apache.servicemix.jbi.util.FileUtil;
 import org.apache.servicemix.tck.SpringTestSupport;
 import org.apache.xbean.spring.context.ClassPathXmlApplicationContext;
 import org.springframework.context.support.AbstractXmlApplicationContext;
+import org.w3c.dom.Element;
 
 public class HttpSecurityTest extends SpringTestSupport {
     
@@ -88,10 +91,10 @@
             method.setDoAuthentication(true);
             method.setRequestEntity(new StringRequestEntity("<hello>world</hello>"));
             int state = client.executeMethod(method);
+            FileUtil.copyInputStream(method.getResponseBodyAsStream(), System.err);
             if (state != HttpServletResponse.SC_OK && state != HttpServletResponse.SC_ACCEPTED) {
                 throw new IllegalStateException("Http status: " + state);
             }
-            FileUtil.copyInputStream(method.getResponseBodyAsStream(), System.err);
         } finally {
             method.releaseConnection();
         }
@@ -107,10 +110,58 @@
             method.setDoAuthentication(true);
             method.setRequestEntity(new StringRequestEntity(request));
             int state = client.executeMethod(method);
+            FileUtil.copyInputStream(method.getResponseBodyAsStream(), System.err);
             if (state != HttpServletResponse.SC_OK && state != HttpServletResponse.SC_ACCEPTED) {
                 throw new IllegalStateException("Http status: " + state);
             }
-            FileUtil.copyInputStream(method.getResponseBodyAsStream(), System.err);
+        } finally {
+            method.releaseConnection();
+        }
+    }
+
+    public void testWSSecBadCred() throws Exception {
+        ByteArrayOutputStream out = new ByteArrayOutputStream();
+        FileUtil.copyInputStream(getClass().getResourceAsStream("request-bc.xml"), out);
+        String request = out.toString();
+        HttpClient client = new HttpClient();
+        PostMethod method = new PostMethod("http://localhost:8192/WSSec/");
+        try {
+            method.setDoAuthentication(true);
+            method.setRequestEntity(new StringRequestEntity(request));
+            int state = client.executeMethod(method);
+            String str = method.getResponseBodyAsString();
+            System.err.println(str);
+            assertEquals(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, state);
+            Element e = new SourceTransformer().toDOMElement(new StringSource(str));
+            assertEquals("Envelope", e.getLocalName());
+            e = (Element) e.getFirstChild();
+            assertEquals("Body", e.getLocalName());
+            e = (Element) e.getFirstChild();
+            assertEquals("Fault", e.getLocalName());
+        } finally {
+            method.releaseConnection();
+        }
+    }
+
+    public void testWSSecUnkownUser() throws Exception {
+        ByteArrayOutputStream out = new ByteArrayOutputStream();
+        FileUtil.copyInputStream(getClass().getResourceAsStream("request-uu.xml"), out);
+        String request = out.toString();
+        HttpClient client = new HttpClient();
+        PostMethod method = new PostMethod("http://localhost:8192/WSSec/");
+        try {
+            method.setDoAuthentication(true);
+            method.setRequestEntity(new StringRequestEntity(request));
+            int state = client.executeMethod(method);
+            String str = method.getResponseBodyAsString();
+            System.err.println(str);
+            assertEquals(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, state);
+            Element e = new SourceTransformer().toDOMElement(new StringSource(str));
+            assertEquals("Envelope", e.getLocalName());
+            e = (Element) e.getFirstChild();
+            assertEquals("Body", e.getLocalName());
+            e = (Element) e.getFirstChild();
+            assertEquals("Fault", e.getLocalName());
         } finally {
             method.releaseConnection();
         }

Added: incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/test/resources/org/apache/servicemix/http/security/request-bc.xml
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/test/resources/org/apache/servicemix/http/security/request-bc.xml?view=auto&rev=475325
==============================================================================
--- incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/test/resources/org/apache/servicemix/http/security/request-bc.xml (added)
+++ incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/test/resources/org/apache/servicemix/http/security/request-bc.xml Wed Nov 15 09:48:10 2006
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
+               xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
+  <soap:Header>
+    <wsse:Security soap:mustUnderstand="1">
+      <wsse:UsernameToken>
+        <wsse:Username>user1</wsse:Username>
+        <wsse:Password>userxc1</wsse:Password>
+      </wsse:UsernameToken>
+    </wsse:Security>
+  </soap:Header>
+  <soap:Body>
+    <hello>world</hello>
+  </soap:Body>
+</soap:Envelope>

Propchange: incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/test/resources/org/apache/servicemix/http/security/request-bc.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/test/resources/org/apache/servicemix/http/security/request-bc.xml
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/test/resources/org/apache/servicemix/http/security/request-bc.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml

Added: incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/test/resources/org/apache/servicemix/http/security/request-uu.xml
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/test/resources/org/apache/servicemix/http/security/request-uu.xml?view=auto&rev=475325
==============================================================================
--- incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/test/resources/org/apache/servicemix/http/security/request-uu.xml (added)
+++ incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/test/resources/org/apache/servicemix/http/security/request-uu.xml Wed Nov 15 09:48:10 2006
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
+               xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
+  <soap:Header>
+    <wsse:Security soap:mustUnderstand="1">
+      <wsse:UsernameToken>
+        <wsse:Username>user--1</wsse:Username>
+        <wsse:Password>usecxzr1</wsse:Password>
+      </wsse:UsernameToken>
+    </wsse:Security>
+  </soap:Header>
+  <soap:Body>
+    <hello>world</hello>
+  </soap:Body>
+</soap:Envelope>

Propchange: incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/test/resources/org/apache/servicemix/http/security/request-uu.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/test/resources/org/apache/servicemix/http/security/request-uu.xml
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/test/resources/org/apache/servicemix/http/security/request-uu.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml

Modified: incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/test/resources/org/apache/servicemix/http/security/request.xml
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/test/resources/org/apache/servicemix/http/security/request.xml?view=diff&rev=475325&r1=475324&r2=475325
==============================================================================
--- incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/test/resources/org/apache/servicemix/http/security/request.xml (original)
+++ incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/test/resources/org/apache/servicemix/http/security/request.xml Wed Nov 15 09:48:10 2006
@@ -1,22 +1,4 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<!--
-
-    Licensed to the Apache Software Foundation (ASF) under one or more
-    contributor license agreements.  See the NOTICE file distributed with
-    this work for additional information regarding copyright ownership.
-    The ASF licenses this file to You under the Apache License, Version 2.0
-    (the "License"); you may not use this file except in compliance with
-    the License.  You may obtain a copy of the License at
-
-       http://www.apache.org/licenses/LICENSE-2.0
-
-    Unless required by applicable law or agreed to in writing, software
-    distributed under the License is distributed on an "AS IS" BASIS,
-    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-    See the License for the specific language governing permissions and
-    limitations under the License.
-
--->
 <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
                xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
   <soap:Header>