Merged HEAD-BUG-FIX (5.1/Cloud) to HEAD (5.1/Cloud)

108203: Merged 5.0.N (5.0.3) to HEAD-BUG-FIX (5.1/Cloud)
      108157: Merged V4.2-BUG-FIX (4.2.5) to 5.0.N (5.0.3)
         108115: Merged DEV to V4.2-BUG-FIX (4.2.5)
            107373 : MNT-13057 : Problem when using CMIS and with document names containing %
               - Updated some code, was added unit test.
            107742 : MNT-13057 : Problem when using CMIS and with document names containing %
               - Changed the logic that checks whether uri is cmis uri to be more specific.


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@108219 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Alan Davis
2015-07-14 07:02:53 +00:00
parent a58e05d267
commit 4bfbc7e5f9
2 changed files with 75 additions and 2 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2005-2012 Alfresco Software Limited.
* Copyright (C) 2005-2015 Alfresco Software Limited.
*
* This file is part of Alfresco
*
@@ -18,6 +18,8 @@
*/
package org.alfresco.rest.api;
import java.util.regex.Pattern;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@@ -31,6 +33,8 @@ import org.springframework.extensions.webscripts.servlet.ServletAuthenticatorFac
public class PublicApiTenantWebScriptServletRuntime extends TenantWebScriptServletRuntime
{
private static final Pattern CMIS_URI_PATTERN = Pattern.compile(".*/cmis/versions/[0-9]+\\.[0-9]+/.*");
public PublicApiTenantWebScriptServletRuntime(RuntimeContainer container, ServletAuthenticatorFactory authFactory, HttpServletRequest req,
HttpServletResponse res, ServerProperties serverProperties)
{
@@ -54,6 +58,11 @@ public class PublicApiTenantWebScriptServletRuntime extends TenantWebScriptServl
// NOTE: this is unlikely, and we'll take the hit if the path contains a semi-colon
pathInfo = req.getPathInfo();
}
// MNT-13057 fix, do not decode CMIS uris.
else if (CMIS_URI_PATTERN.matcher(requestURI).matches())
{
pathInfo = requestURI.substring(serviceContextPath.length());
}
else
{
pathInfo = URLDecoder.decode(requestURI.substring(serviceContextPath.length()));

View File

@@ -127,7 +127,7 @@ import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.test.AssertThrows;
import org.springframework.extensions.surf.util.URLEncoder;
public class TestCMIS extends EnterpriseTestApi
{
@@ -2081,6 +2081,70 @@ public class TestCMIS extends EnterpriseTestApi
assertEquals("Ipsum and so on", content);
}
@Test
public void testMNT_13057() throws Exception
{
final TestNetwork network1 = getTestFixture().getRandomNetwork();
String username = "user" + System.currentTimeMillis();
PersonInfo personInfo = new PersonInfo(username, username, username, TEST_PASSWORD, null, null, null, null, null, null, null);
TestPerson person1 = network1.createUser(personInfo);
String person1Id = person1.getId();
String guid = GUID.generate();
String name = guid + "_KRUIS_LOGO_100%_PMS.txt";
String urlFileName = guid + "_KRUIS_LOGO_100%25_PMS.txt";
final String siteName = "site" + System.currentTimeMillis();
TenantUtil.runAsUserTenant(new TenantRunAsWork<NodeRef>()
{
@Override
public NodeRef doWork() throws Exception
{
SiteInformation siteInfo = new SiteInformation(siteName, siteName, siteName, SiteVisibility.PRIVATE);
TestSite site = repoService.createSite(null, siteInfo);
String name = GUID.generate();
NodeRef folderNodeRef = repoService.createFolder(site.getContainerNodeRef(DOCUMENT_LIBRARY_CONTAINER_NAME), name);
return folderNodeRef;
}
}, person1Id, network1.getId());
// Create a document...
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1Id));
CmisSession cmisSession = publicApiClient.createPublicApiCMISSession(Binding.atom, CMIS_VERSION_11);
Folder docLibrary = (Folder)cmisSession.getObjectByPath("/Sites/" + siteName + "/documentLibrary");
Map<String, Object> properties = new HashMap<String, Object>();
{
properties.put(PropertyIds.OBJECT_TYPE_ID, TYPE_CMIS_DOCUMENT);
properties.put(PropertyIds.NAME, name);
}
ContentStreamImpl fileContent = new ContentStreamImpl();
{
ContentWriter writer = new FileContentWriter(TempFileProvider.createTempFile(GUID.generate(), ".txt"));
writer.putContent("Ipsum");
ContentReader reader = writer.getReader();
fileContent.setMimeType(MimetypeMap.MIMETYPE_TEXT_PLAIN);
fileContent.setStream(reader.getContentInputStream());
}
/* Create document */
Document doc = docLibrary.createDocument(properties, fileContent, VersioningState.MAJOR);
String id = doc.getId();
assertNotNull(id);
Map<String, String> params = new HashMap<String, String>();
params.put("id", URLEncoder.encode(id));
urlFileName += "?id=" + URLEncoder.encode(id);
HttpResponse response = publicApiClient.get("/" + network1.getId() + "/public/cmis/versions/1.1/atom/content/" + urlFileName, null);
assertEquals(200, response.getStatusCode());
}
@Test
public void testMNT10430() throws Exception
{