Merged BRANCHES/DEV/HEAD_QUICK_SHARE_TMP to HEAD:

41641: Merged from THOR1_SPRINTS to HEAD_QUICK_SHARE_TMP
        36472: Merged DEV/THOR1_QUICK_SHARE to DEV/THOR1_SPRINTS
           Improvements for THOR-1270 "F387: As the link receiver, I can view the Document Preview in the browser without having to login"
           - Added new component evaluator for bringing in different components based on page id
           - The title of the quickshare page now contains the document's name (to improve the social "Share with:" experience)
           - Added new icon for page not found screen
        36601: Merge from THOR1_QUICK_SHARE to THOR1_SPRINTS
           36599: Improvements for THOR-1270 "F387: As the link receiver, I can view the Document Preview in the browser without having to login"
              - Made the "Preparing previewer... text get rendered using javascript so Google+ won't
                include it in its description when sharing quickshare links
        36735: THOR-1430: QuickShare link breaks after uploading a new version of a shared file
   41656: Merged from CLOUD1 to HEAD_QUICK_SHARE_TMP
        37200: Fix issue from "V4.0-BUG-FIX to CLOUD1 merge" r37178
           - Removed trailing === of property "system.quickshare.enabled"
        37226: Fix issue from "V4.0-BUG-FIX to CLOUD1 merge" r37178 part 3
           - When "date-format.defaultFTL" was removed from common.properties freemarker code in node-header that depended upon it got an exception, 
             code is now refactored to use client side date handling instead.
   41659: Merged CLOUD1 to HEAD_QUICK_SHARE_TMP
        39206 Fixed CLOUD-198 "WASA - XSS issue with quickshare"
   41661: Merge from CLOUD1-BUG-FIX to HEAD_QUICK_SHARE_TMP
   41680: Merged BRANCHES/DEV/V4.1-BUG-FIX to BRANCHES/DEV/HEAD_QUICK_SHARE_TMP:
        41679: Minor: fix for non-MT (required for QuickShare Unshare when running non-MT)
   41681: Fix pesky solrcore.properties
   41715: QuickShare: fix test and add to suite


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@41738 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Jan Vonka
2012-09-18 15:01:58 +00:00
parent 4f7aee6432
commit 6da7aceb6e
3 changed files with 76 additions and 24 deletions

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2005-2010 Alfresco Software Limited. * Copyright (C) 2005-2012 Alfresco Software Limited.
* *
* This file is part of Alfresco * This file is part of Alfresco
* *
@@ -35,6 +35,7 @@ import org.alfresco.repo.web.scripts.invitation.InvitationWebScriptTest;
import org.alfresco.repo.web.scripts.invite.InviteServiceTest; import org.alfresco.repo.web.scripts.invite.InviteServiceTest;
import org.alfresco.repo.web.scripts.person.PersonServiceTest; import org.alfresco.repo.web.scripts.person.PersonServiceTest;
import org.alfresco.repo.web.scripts.preference.PreferenceServiceTest; import org.alfresco.repo.web.scripts.preference.PreferenceServiceTest;
import org.alfresco.repo.web.scripts.quickshare.QuickShareRestApiTest;
import org.alfresco.repo.web.scripts.rating.RatingRestApiTest; import org.alfresco.repo.web.scripts.rating.RatingRestApiTest;
import org.alfresco.repo.web.scripts.replication.ReplicationRestApiTest; import org.alfresco.repo.web.scripts.replication.ReplicationRestApiTest;
import org.alfresco.repo.web.scripts.rule.RuleServiceTest; import org.alfresco.repo.web.scripts.rule.RuleServiceTest;
@@ -49,7 +50,6 @@ import org.alfresco.repo.web.scripts.wcm.sandbox.SandboxTest;
import org.alfresco.repo.web.scripts.workflow.ActivitiWorkflowRestApiTest; import org.alfresco.repo.web.scripts.workflow.ActivitiWorkflowRestApiTest;
import org.alfresco.repo.web.scripts.workflow.JBPMWorkflowRestApiTest; import org.alfresco.repo.web.scripts.workflow.JBPMWorkflowRestApiTest;
import org.alfresco.repo.web.scripts.workflow.WorkflowModelBuilderTest; import org.alfresco.repo.web.scripts.workflow.WorkflowModelBuilderTest;
import org.alfresco.repo.web.scripts.workflow.AbstractWorkflowRestApiTest;
/** /**
* Web Scripts test suite * Web Scripts test suite
@@ -59,11 +59,12 @@ public class WebScriptTestSuite extends TestSuite
public static Test suite() public static Test suite()
{ {
TestSuite suite = new TestSuite(); TestSuite suite = new TestSuite();
// Ensure that a suitable context is available // Ensure that a suitable context is available
TestWebScriptRepoServer.getTestServer(); TestWebScriptRepoServer.getTestServer();
// Add the tests // Add the tests
suite.addTestSuite( QuickShareRestApiTest.class );
suite.addTestSuite( AdminWebScriptTest.class ); suite.addTestSuite( AdminWebScriptTest.class );
suite.addTestSuite( AuditWebScriptTest.class ); suite.addTestSuite( AuditWebScriptTest.class );
suite.addTestSuite( BlogServiceTest.class ); suite.addTestSuite( BlogServiceTest.class );
@@ -94,7 +95,7 @@ public class WebScriptTestSuite extends TestSuite
suite.addTestSuite( WorkflowModelBuilderTest.class ); suite.addTestSuite( WorkflowModelBuilderTest.class );
suite.addTestSuite( ActivitiWorkflowRestApiTest.class ); suite.addTestSuite( ActivitiWorkflowRestApiTest.class );
suite.addTestSuite( JBPMWorkflowRestApiTest.class ); suite.addTestSuite( JBPMWorkflowRestApiTest.class );
// This uses a slightly different context // This uses a slightly different context
// As such, we can't run it in the same suite as the others, // As such, we can't run it in the same suite as the others,
// due to finalisers closing caches when we're not looking // due to finalisers closing caches when we're not looking
@@ -102,4 +103,4 @@ public class WebScriptTestSuite extends TestSuite
return suite; return suite;
} }
} }

View File

@@ -18,12 +18,17 @@
*/ */
package org.alfresco.repo.web.scripts.quickshare; package org.alfresco.repo.web.scripts.quickshare;
import java.io.File;
import java.io.FileInputStream;
import java.io.Serializable; import java.io.Serializable;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import org.alfresco.model.ContentModel; import org.alfresco.model.ContentModel;
import org.alfresco.repo.content.MimetypeMap; import org.alfresco.repo.content.MimetypeMap;
import org.alfresco.repo.content.transform.AbstractContentTransformerTest;
import org.alfresco.repo.content.transform.ContentTransformer;
import org.alfresco.repo.content.transform.magick.ImageTransformationOptions;
import org.alfresco.repo.model.Repository; import org.alfresco.repo.model.Repository;
import org.alfresco.repo.security.authentication.AuthenticationUtil; import org.alfresco.repo.security.authentication.AuthenticationUtil;
import org.alfresco.repo.transaction.RetryingTransactionHelper; import org.alfresco.repo.transaction.RetryingTransactionHelper;
@@ -50,12 +55,14 @@ import org.springframework.extensions.webscripts.TestWebScriptServer.Response;
* This class tests QuickShare REST API * This class tests QuickShare REST API
* *
* @author janv * @author janv
* @since Cloud/4.1 * @since Cloud/4.2
*/ */
public class QuickShareRestApiTest extends BaseWebScriptTest public class QuickShareRestApiTest extends BaseWebScriptTest
{ {
private static final String USER_ONE = "UserOne"; private static final String RUN_ID = ""+System.currentTimeMillis();
private static final String USER_TWO = "UserTwo";
private static final String USER_ONE = "UserOne-"+RUN_ID;
private static final String USER_TWO = "UserTwo-"+RUN_ID;
private final static String SHARE_URL = "/api/internal/shared/share/{node_ref_3}"; private final static String SHARE_URL = "/api/internal/shared/share/{node_ref_3}";
@@ -73,9 +80,9 @@ public class QuickShareRestApiTest extends BaseWebScriptTest
private NodeRef testNode; private NodeRef testNode;
private final static String TEST_NAME = "test node"; private final static String TEST_NAME = "test node";
private final static String TEST_CONTENT = "test content"; private static byte[] TEST_CONTENT = null;
private final static String TEST_MIMETYPE_TEXT_PLAIN = MimetypeMap.MIMETYPE_TEXT_PLAIN; private final static String TEST_MIMETYPE_JPEG = MimetypeMap.MIMETYPE_IMAGE_JPEG;
private final static String TEST_MIMETYPE_IMAGE_PNG = MimetypeMap.MIMETYPE_IMAGE_PNG; private final static String TEST_MIMETYPE_PNG = MimetypeMap.MIMETYPE_IMAGE_PNG;
private MutableAuthenticationService authenticationService; private MutableAuthenticationService authenticationService;
private NodeService nodeService; private NodeService nodeService;
@@ -108,6 +115,14 @@ public class QuickShareRestApiTest extends BaseWebScriptTest
{ {
public NodeRef execute() throws Throwable public NodeRef execute() throws Throwable
{ {
// no pun intended
File quickFile = AbstractContentTransformerTest.loadQuickTestFile("jpg");
TEST_CONTENT = new byte[new Long(quickFile.length()).intValue()];
new FileInputStream(quickFile).read(TEST_CONTENT);
Map<QName, Serializable> props = new HashMap<QName, Serializable>(1); Map<QName, Serializable> props = new HashMap<QName, Serializable>(1);
props.put(ContentModel.PROP_NAME, TEST_NAME); props.put(ContentModel.PROP_NAME, TEST_NAME);
ChildAssociationRef result = nodeService.createNode(repositoryHelper.getUserHome(personService.getPerson(USER_ONE)), ChildAssociationRef result = nodeService.createNode(repositoryHelper.getUserHome(personService.getPerson(USER_ONE)),
@@ -116,8 +131,8 @@ public class QuickShareRestApiTest extends BaseWebScriptTest
NodeRef nodeRef = result.getChildRef(); NodeRef nodeRef = result.getChildRef();
ContentWriter writer = contentService.getWriter(nodeRef, ContentModel.PROP_CONTENT, true); ContentWriter writer = contentService.getWriter(nodeRef, ContentModel.PROP_CONTENT, true);
writer.setMimetype(TEST_MIMETYPE_TEXT_PLAIN); writer.setMimetype(TEST_MIMETYPE_JPEG);
writer.putContent(TEST_CONTENT); writer.putContent(quickFile);
return nodeRef; return nodeRef;
} }
@@ -154,8 +169,34 @@ public class QuickShareRestApiTest extends BaseWebScriptTest
deleteUser(USER_TWO); deleteUser(USER_TWO);
} }
private void checkTransformer()
{
ContentTransformer transformer = this.contentService.getImageTransformer();
assertNotNull("No transformer returned for 'getImageTransformer'", transformer);
// Check that it is working
ImageTransformationOptions imageTransformationOptions = new ImageTransformationOptions();
if (!transformer.isTransformable(MimetypeMap.MIMETYPE_IMAGE_JPEG, -1, MimetypeMap.MIMETYPE_IMAGE_PNG,
imageTransformationOptions))
{
fail("Image transformer is not working. Please check your image conversion command setup.");
}
}
private void checkBytes(byte[] content1, byte[] content2)
{
assertEquals(content1.length, content2.length);
for (int i = 0; i < content1.length; i++)
{
assertEquals(content1[i], content2[i]);
}
}
public void testSanityCheckUrls() throws Exception public void testSanityCheckUrls() throws Exception
{ {
checkTransformer();
final int expectedStatusOK = 200; final int expectedStatusOK = 200;
final int expectedStatusNotFound = 404; final int expectedStatusNotFound = 404;
final int expectedStatusServerError = 500; // currently mapped from AccessDenied (should it be 403, 404 or does it depend on use-case) final int expectedStatusServerError = 500; // currently mapped from AccessDenied (should it be 403, 404 or does it depend on use-case)
@@ -170,17 +211,17 @@ public class QuickShareRestApiTest extends BaseWebScriptTest
String name = jsonRsp.getString("name"); String name = jsonRsp.getString("name");
assertEquals(TEST_NAME, name); assertEquals(TEST_NAME, name);
String mimetype = jsonRsp.getString("mimetype"); String mimetype = jsonRsp.getString("mimetype");
assertEquals(TEST_MIMETYPE_TEXT_PLAIN, mimetype); assertEquals(TEST_MIMETYPE_JPEG, mimetype);
// get content for node (authenticated) // get content for node (authenticated)
rsp = sendRequest(new GetRequest(AUTH_CONTENT_URL.replace("{node_ref_3}", testNodeRef_3)), expectedStatusOK, USER_ONE); rsp = sendRequest(new GetRequest(AUTH_CONTENT_URL.replace("{node_ref_3}", testNodeRef_3)), expectedStatusOK, USER_ONE);
String content = rsp.getContentAsString(); byte[] content = rsp.getContentAsByteArray();
assertEquals(TEST_CONTENT, content); checkBytes(TEST_CONTENT, content);
// get content thumbnail for node (authenticated) // get content thumbnail for node (authenticated)
rsp = sendRequest(new GetRequest(AUTH_CONTENT_THUMBNAIL_URL.replace("{node_ref_3}", testNodeRef_3).replace("{thumbnailname}", "doclib")), expectedStatusOK, USER_ONE); rsp = sendRequest(new GetRequest(AUTH_CONTENT_THUMBNAIL_URL.replace("{node_ref_3}", testNodeRef_3).replace("{thumbnailname}", "doclib")), expectedStatusOK, USER_ONE);
String type = rsp.getContentType(); String type = rsp.getContentType();
assertEquals(TEST_MIMETYPE_IMAGE_PNG, type); assertEquals(TEST_MIMETYPE_PNG, type);
// As user two ... // As user two ...
@@ -205,17 +246,17 @@ public class QuickShareRestApiTest extends BaseWebScriptTest
name = jsonRsp.getString("name"); name = jsonRsp.getString("name");
assertEquals(TEST_NAME, name); assertEquals(TEST_NAME, name);
mimetype = jsonRsp.getString("mimetype"); mimetype = jsonRsp.getString("mimetype");
assertEquals(TEST_MIMETYPE_TEXT_PLAIN, mimetype); assertEquals(TEST_MIMETYPE_JPEG, mimetype);
// get content for share (note: can be unauthenticated) // get content for share (note: can be unauthenticated)
rsp = sendRequest(new GetRequest(SHARE_CONTENT_URL.replace("{shared_id}", sharedId)), expectedStatusOK, USER_TWO); rsp = sendRequest(new GetRequest(SHARE_CONTENT_URL.replace("{shared_id}", sharedId)), expectedStatusOK, USER_TWO);
content = rsp.getContentAsString(); content = rsp.getContentAsByteArray();
assertEquals(TEST_CONTENT, content); checkBytes(TEST_CONTENT, content);
// get content thumbnail for share (note: can be unauthenticated) // get content thumbnail for share (note: can be unauthenticated)
rsp = sendRequest(new GetRequest(SHARE_CONTENT_THUMBNAIL_URL.replace("{shared_id}", sharedId).replace("{thumbnailname}", "doclib")), expectedStatusOK, USER_TWO); rsp = sendRequest(new GetRequest(SHARE_CONTENT_THUMBNAIL_URL.replace("{shared_id}", sharedId).replace("{thumbnailname}", "doclib")), expectedStatusOK, USER_TWO);
type = rsp.getContentType(); type = rsp.getContentType();
assertEquals(TEST_MIMETYPE_IMAGE_PNG, type); assertEquals(TEST_MIMETYPE_PNG, type);
// As user one ... // As user one ...

View File

@@ -143,16 +143,26 @@ public class UnshareContentDelete extends AbstractQuickShareContent implements N
// behaviour - currently registered for content only !! // behaviour - currently registered for content only !!
// note: will remove "share" even if node is only being archived (ie. moved to trash) => a subsequent restore will *not* restore the "share" // note: will remove "share" even if node is only being archived (ie. moved to trash) => a subsequent restore will *not* restore the "share"
public void beforeDeleteNode(final NodeRef nodeRef) public void beforeDeleteNode(final NodeRef beforeDeleteNodeRef)
{ {
AuthenticationUtil.runAsSystem(new RunAsWork<Void>() AuthenticationUtil.runAsSystem(new RunAsWork<Void>()
{ {
public Void doWork() throws Exception public Void doWork() throws Exception
{ {
String sharedId = (String)nodeService.getProperty(nodeRef, QuickShareModel.PROP_QSHARE_SHAREDID); String sharedId = (String)nodeService.getProperty(beforeDeleteNodeRef, QuickShareModel.PROP_QSHARE_SHAREDID);
if (sharedId != null) if (sharedId != null)
{ {
removeSharedId(sharedId); Pair<String, NodeRef> pair = getTenantNodeRefFromSharedId(attributeService, tenantService, sharedId);
@SuppressWarnings("unused")
final String tenantDomain = pair.getFirst();
final NodeRef nodeRef = pair.getSecond();
// note: deleted nodeRef might not match, eg. for upload new version -> checkin -> delete working copy
if (nodeRef.equals(beforeDeleteNodeRef))
{
removeSharedId(sharedId);
}
} }
return null; return null;
} }