From e1370e02cde8adf64720766c57cf8f92bc0f79a4 Mon Sep 17 00:00:00 2001 From: Alan Davis Date: Sat, 31 Jan 2015 09:47:13 +0000 Subject: [PATCH] Merged HEAD-BUG-FIX (5.1/Cloud) to HEAD (5.0/Cloud) 87701: Merged V4.2-BUG-FIX (4.2.4) to HEAD-BUG-FIX (5.0/Cloud) 86502: Merged DEV to V4.2-BUG-FIX (4.2.4) 86291: MNT-12303 : Renaming a folder containing a document that is locked due to online editing causes a duplicate folder and file with no content to be created - Refresh lock request should not create new empty resource. - Unit test added. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@94540 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../org/alfresco/repo/webdav/LockMethod.java | 20 +++++++++ .../alfresco/repo/webdav/LockMethodTest.java | 42 ++++++++++++++++++- 2 files changed, 61 insertions(+), 1 deletion(-) diff --git a/source/java/org/alfresco/repo/webdav/LockMethod.java b/source/java/org/alfresco/repo/webdav/LockMethod.java index 42e54bff6c..92eaeaa6b1 100644 --- a/source/java/org/alfresco/repo/webdav/LockMethod.java +++ b/source/java/org/alfresco/repo/webdav/LockMethod.java @@ -261,6 +261,26 @@ public class LockMethod extends WebDAVMethod } catch (FileNotFoundException e) { + if (m_conditions != null) + { + // MNT-12303 fix, check whether this is a refresh lock request + for (Condition condition : m_conditions) + { + List lockTolensMatch = condition.getLockTokensMatch(); + List etagsMatch = condition.getETagsMatch(); + + if (m_request.getContentLength() == -1 && + (lockTolensMatch != null && !lockTolensMatch.isEmpty()) || + (etagsMatch != null && !etagsMatch.isEmpty())) + { + // LOCK method with If header and without body was sent, according to RFC 2518 section 7.8 + // this form of LOCK MUST only be used to "refresh" a lock. However resource doesn't exist -> + // so there is nothing to refresh. Return 403 Forbidden as original SharePoint Server. + throw new WebDAVServerException(HttpServletResponse.SC_FORBIDDEN); + } + } + } + // need to create it String[] splitPath = getDAVHelper().splitPath(path); // check diff --git a/source/test-java/org/alfresco/repo/webdav/LockMethodTest.java b/source/test-java/org/alfresco/repo/webdav/LockMethodTest.java index 2f3142b93f..c2db5709a7 100644 --- a/source/test-java/org/alfresco/repo/webdav/LockMethodTest.java +++ b/source/test-java/org/alfresco/repo/webdav/LockMethodTest.java @@ -85,6 +85,9 @@ public class LockMethodTest */ private static final String CONTENT_1 = "This is some content"; private static final String TEST_FILE_NAME = "file" + GUID.generate(); + private static final String TEST_NEW_FILE_NAME = "new_file" + GUID.generate(); + private static final String TEST_FOLDER_NAME = "folder" + GUID.generate(); + private static final String TEST_NEW_FOLDER_NAME = "new_folder" + GUID.generate(); /** * Data used by the tests @@ -130,7 +133,7 @@ public class LockMethodTest // create test file in test folder folderNodeRef = nodeService.createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName("test"), ContentModel.TYPE_FOLDER, - Collections. singletonMap(ContentModel.PROP_NAME, "folder")).getChildRef(); + Collections. singletonMap(ContentModel.PROP_NAME, TEST_FOLDER_NAME)).getChildRef(); fileNodeRef = nodeService.createNode(folderNodeRef, ContentModel.ASSOC_CONTAINS, QName.createQName("test"), ContentModel.TYPE_CONTENT, Collections. singletonMap(ContentModel.PROP_NAME, TEST_FILE_NAME)).getChildRef(); ContentWriter contentWriter = contentService.getWriter(fileNodeRef, ContentModel.PROP_CONTENT, true); @@ -373,4 +376,41 @@ public class LockMethodTest // try to refresh lock for non-locked node this.transactionService.getRetryingTransactionHelper().doInTransaction(lockExecuteImplCallBack); } + + @Test + public void testMNT_12425() throws Exception + { + MockHttpServletRequest lockRequest = new MockHttpServletRequest(); + MockHttpServletResponse lockResponse = new MockHttpServletResponse(); + + // refresh lock set to 1 hour + lockRequest.addHeader(WebDAV.HEADER_TIMEOUT, WebDAV.SECOND + 3600); + lockRequest.addHeader(WebDAV.HEADER_IF, "(<" + WebDAV.makeLockToken(fileNodeRef, userName) + ">)"); + // specify path to non-existing file + lockRequest.setRequestURI("/" + TEST_NEW_FOLDER_NAME + "/" + TEST_NEW_FILE_NAME); + + lockMethod.setDetails(lockRequest, lockResponse, davHelper, folderNodeRef); + lockMethod.parseRequestHeaders(); + + RetryingTransactionCallback lockExecuteImplCallBack = new RetryingTransactionCallback() + { + @Override + public Void execute() throws Throwable + { + try + { + lockMethod.executeImpl(); + fail("Refresh lock for non-exisitent resource should fail."); + } + catch (WebDAVServerException e) + { + assertEquals(HttpServletResponse.SC_FORBIDDEN, e.getHttpStatusCode()); + } + return null; + } + }; + + // try to lock non-existent file + this.transactionService.getRetryingTransactionHelper().doInTransaction(lockExecuteImplCallBack); + } }