jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From resc...@apache.org
Subject svn commit: r701129 - in /jackrabbit/trunk/jackrabbit-webdav/src: main/java/org/apache/jackrabbit/webdav/ test/java/org/apache/jackrabbit/webdav/server/
Date Thu, 02 Oct 2008 13:59:13 GMT
Author: reschke
Date: Thu Oct  2 06:59:13 2008
New Revision: 701129

URL: http://svn.apache.org/viewvc?rev=701129&view=rev
Log:
JCR-1782: fix potential NPE in parsing Destination header, add RFC 4918 compliant parsing,
add test cases

Added:
    jackrabbit/trunk/jackrabbit-webdav/src/test/java/org/apache/jackrabbit/webdav/server/RFC4918DestinationHeaderTest.java
    jackrabbit/trunk/jackrabbit-webdav/src/test/java/org/apache/jackrabbit/webdav/server/WebdavServerTests.java
Modified:
    jackrabbit/trunk/jackrabbit-webdav/src/main/java/org/apache/jackrabbit/webdav/DavServletRequest.java
    jackrabbit/trunk/jackrabbit-webdav/src/main/java/org/apache/jackrabbit/webdav/WebdavRequestImpl.java

Modified: jackrabbit/trunk/jackrabbit-webdav/src/main/java/org/apache/jackrabbit/webdav/DavServletRequest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-webdav/src/main/java/org/apache/jackrabbit/webdav/DavServletRequest.java?rev=701129&r1=701128&r2=701129&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-webdav/src/main/java/org/apache/jackrabbit/webdav/DavServletRequest.java
(original)
+++ jackrabbit/trunk/jackrabbit-webdav/src/main/java/org/apache/jackrabbit/webdav/DavServletRequest.java
Thu Oct  2 06:59:13 2008
@@ -60,7 +60,7 @@
      * @return locator of the resource specified with the Destination header.
      * @see DavConstants#HEADER_DESTINATION
      */
-    public DavResourceLocator getDestinationLocator();
+    public DavResourceLocator getDestinationLocator() throws DavException;
 
     /**
      * Returns true if the {@link DavConstants#HEADER_OVERWRITE Overwrite header}

Modified: jackrabbit/trunk/jackrabbit-webdav/src/main/java/org/apache/jackrabbit/webdav/WebdavRequestImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-webdav/src/main/java/org/apache/jackrabbit/webdav/WebdavRequestImpl.java?rev=701129&r1=701128&r2=701129&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-webdav/src/main/java/org/apache/jackrabbit/webdav/WebdavRequestImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-webdav/src/main/java/org/apache/jackrabbit/webdav/WebdavRequestImpl.java
Thu Oct  2 06:59:13 2008
@@ -163,32 +163,12 @@
      * resource.
      *
      * @return path of the destination resource.
+     * @throws DavException 
      * @see #HEADER_DESTINATION
      * @see DavServletRequest#getDestinationLocator
      */
-    public DavResourceLocator getDestinationLocator() {
-        String destination = httpRequest.getHeader(HEADER_DESTINATION);
-        if (destination != null) {
-            try {
-                URI uri = new URI(destination);
-                if (uri.getAuthority().equals(httpRequest.getHeader("Host"))) {
-                    destination = uri.getRawPath();
-                }
-            } catch (URISyntaxException e) {
-                log.debug("Destination is path is not a valid URI (" + e.getMessage() + ".");
-                int pos = destination.lastIndexOf(":");
-                if (pos > 0) {
-                    destination = destination.substring(destination.indexOf("/", pos));
-                    log.debug("Tried to retrieve resource destination path from invalid URI:
" + destination);
-                }
-            }
-            // cut off the context path
-            String contextPath = httpRequest.getContextPath();
-            if (destination.startsWith(contextPath)) {
-                destination = destination.substring(contextPath.length());
-            }
-        }
-        return factory.createResourceLocator(hrefPrefix, destination);
+    public DavResourceLocator getDestinationLocator() throws DavException {
+        return getHrefLocator(httpRequest.getHeader(HEADER_DESTINATION));
     }
 
     /**
@@ -201,7 +181,7 @@
         String ref = href;
         if (ref != null) {
             //href should be a Simple-ref production as defined in RFC4918, so it is either
an absolute URI
-            //or an absoltute path
+            //or an absolute path
             try {
                 URI uri = new URI(ref);
                 String auth = uri.getAuthority();

Added: jackrabbit/trunk/jackrabbit-webdav/src/test/java/org/apache/jackrabbit/webdav/server/RFC4918DestinationHeaderTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-webdav/src/test/java/org/apache/jackrabbit/webdav/server/RFC4918DestinationHeaderTest.java?rev=701129&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-webdav/src/test/java/org/apache/jackrabbit/webdav/server/RFC4918DestinationHeaderTest.java
(added)
+++ jackrabbit/trunk/jackrabbit-webdav/src/test/java/org/apache/jackrabbit/webdav/server/RFC4918DestinationHeaderTest.java
Thu Oct  2 06:59:13 2008
@@ -0,0 +1,117 @@
+/*
+ * 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.
+ */
+package org.apache.jackrabbit.webdav.server;
+
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+
+import junit.framework.TestCase;
+
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.HttpException;
+import org.apache.commons.httpclient.UsernamePasswordCredentials;
+import org.apache.commons.httpclient.auth.AuthScope;
+import org.apache.commons.httpclient.methods.HeadMethod;
+import org.apache.commons.httpclient.methods.PutMethod;
+import org.apache.jackrabbit.webdav.DavException;
+import org.apache.jackrabbit.webdav.client.methods.DeleteMethod;
+import org.apache.jackrabbit.webdav.client.methods.MoveMethod;
+
+/**
+ * Test cases for WebDAV BIND functionality (see <a href="http://greenbytes.de/tech/webdav/draft-ietf-webdav-bind-20.html">draft-ietf-webdav-bind-20</a>
+ * <p>
+ * Required system properties:
+ * <ul>
+ *   <li>webdav.test.url</li>
+ *   <li>webdav.test.username</li>
+ *   <li>webdav.test.password</li>
+ * </ul>
+ */
+
+public class RFC4918DestinationHeaderTest extends TestCase {
+
+    private String root;
+    private URI uri;
+    private String username, password;
+    private HttpClient client;
+    
+    protected void setUp() throws Exception {
+        this.uri = URI.create(System.getProperty("webdav.test.url"));
+        this.root = this.uri.toASCIIString();
+        if (!this.root.endsWith("/")) {
+            this.root += "/";
+        }
+        this.username = System.getProperty(("webdav.test.username"), "");
+        this.password = System.getProperty(("webdav.test.password"), "");
+        this.client = new HttpClient();
+        this.client.getState().setCredentials(
+                new AuthScope(this.uri.getHost(), this.uri.getPort()),
+                new UsernamePasswordCredentials(this.username, this.password));
+        super.setUp();
+    }
+
+    protected void tearDown() throws Exception {
+        super.tearDown();
+    }
+    
+    public void testMove() throws HttpException, IOException, DavException, URISyntaxException
{
+
+        String testuri = this.root + "movetest";
+        String destinationuri = testuri + "2";
+        String destinationpath = new URI(destinationuri).getRawPath();
+        // make sure the scheme is removed
+        assertTrue(destinationpath.indexOf(":") < 0);
+        
+        int status;
+        try {
+            PutMethod put = new PutMethod(testuri);
+            status = this.client.executeMethod(put);
+            assertTrue("status: " + status, status == 200 || status == 201 || status == 204);
+
+            // try to move outside the servlet's name space
+            MoveMethod move = new MoveMethod(testuri, "/foobar", true);
+            status = this.client.executeMethod(move);
+            assertTrue("status: " + status, status == 403);
+
+            // try a relative path
+            move = new MoveMethod(testuri, "foobar", true);
+            status = this.client.executeMethod(move);
+            assertTrue("status: " + status, status == 400);
+
+            move = new MoveMethod(testuri, destinationpath, true);
+            status = this.client.executeMethod(move);
+            assertTrue("status: " + status, status == 200 || status == 201 || status == 204);
+            
+            HeadMethod head = new HeadMethod(destinationuri);
+            status = this.client.executeMethod(head);
+            assertTrue("status: " + status, status == 200);
+
+            head = new HeadMethod(testuri);
+            status = this.client.executeMethod(head);
+            assertTrue("status: " + status, status == 404);
+
+        } finally {
+            DeleteMethod delete = new DeleteMethod(testuri);
+            status = this.client.executeMethod(delete);
+            assertTrue("status: " + status, status == 200 || status == 204 || status == 404);
+            delete = new DeleteMethod(destinationuri);
+            status = this.client.executeMethod(delete);
+            assertTrue("status: " + status, status == 200 || status == 204 || status == 404);
+        }
+    }
+}

Added: jackrabbit/trunk/jackrabbit-webdav/src/test/java/org/apache/jackrabbit/webdav/server/WebdavServerTests.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-webdav/src/test/java/org/apache/jackrabbit/webdav/server/WebdavServerTests.java?rev=701129&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-webdav/src/test/java/org/apache/jackrabbit/webdav/server/WebdavServerTests.java
(added)
+++ jackrabbit/trunk/jackrabbit-webdav/src/test/java/org/apache/jackrabbit/webdav/server/WebdavServerTests.java
Thu Oct  2 06:59:13 2008
@@ -0,0 +1,33 @@
+/*
+ * 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.
+ */
+package org.apache.jackrabbit.webdav.server;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+public class WebdavServerTests extends TestCase {
+
+    public static Test suite() {
+        TestSuite suite = new TestSuite("WebDAV Server Tests");
+
+        suite.addTestSuite(BindTest.class);
+        suite.addTestSuite(RFC4918DestinationHeaderTest.class);
+
+        return suite;
+    }
+}
\ No newline at end of file



Mime
View raw message