REPO-2156 / MNT-16748: Failing to extract auditing entries from SearchService using Share, CMIS.

- Added two JUnit tests that test that the audit records are added when using SearchService query(SearchParameters): one in the AuditMethodInterceptorTest and another one in AuditWebScriptTest that is using the Rest-API get audit method to query the audit
- Refactored also an existing test in AuditMethodInterceptorTest

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/DEV/5.2.N/root@135899 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Andrei Forascu
2017-03-16 15:11:27 +00:00
parent 242cc5b406
commit c9c30849f9
2 changed files with 52 additions and 14 deletions

View File

@@ -45,6 +45,7 @@ import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService; import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.repository.StoreRef; import org.alfresco.service.cmr.repository.StoreRef;
import org.alfresco.service.cmr.search.ResultSet; import org.alfresco.service.cmr.search.ResultSet;
import org.alfresco.service.cmr.search.SearchParameters;
import org.alfresco.service.cmr.search.SearchService; import org.alfresco.service.cmr.search.SearchService;
import org.alfresco.service.namespace.NamespaceService; import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.namespace.QName; import org.alfresco.service.namespace.QName;
@@ -201,26 +202,62 @@ public class AuditMethodInterceptorTest extends TestCase
/** /**
* Test for <a href="https://issues.alfresco.com/jira/browse/MNT-16748">MNT-16748</a> <br> * Test for <a href="https://issues.alfresco.com/jira/browse/MNT-16748">MNT-16748</a> <br>
* Use {@link SearchService} to perform a query. * Use {@link SearchService#query(StoreRef, String, String)} to perform a query.
*/ */
public void testAuditSearchService_MNT16748() throws Exception public void testAuditSearchServiceQuery() throws Exception
{ {
// Run as admin // Run as admin
AuthenticationUtil.setAdminUserAsFullyAuthenticatedUser(); AuthenticationUtil.setAdminUserAsFullyAuthenticatedUser();
// Perform a search // Perform a search
@SuppressWarnings("unused") @SuppressWarnings("unused")
ResultSet rs = transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<ResultSet>() ResultSet rs = transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<ResultSet>()
{ {
@Override @Override
public ResultSet execute() throws Throwable public ResultSet execute() throws Throwable
{ {
return searchService.query(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, SearchService.LANGUAGE_XPATH, "/company_home"); return searchService.query(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, SearchService.LANGUAGE_XPATH, "/app:company_home");
} }
}, true, false); }, true, false);
// Search for audit // Check the audit entries
checkAuditEntries(APPLICATION_NAME_MNT_16748, SearchService.LANGUAGE_XPATH, "/app:company_home", 1);
}
/**
* Test for <a href="https://issues.alfresco.com/jira/browse/MNT-16748">MNT-16748</a> <br>
* Use {@link SearchService#query(SearchParameters)} to perform a query.
*/
public void testAuditSearchServiceSearchParametersQuery() throws Exception
{
// Run as admin
AuthenticationUtil.setAdminUserAsFullyAuthenticatedUser();
// Create SearchParameters to be used in query
SearchParameters sp = new SearchParameters();
sp.setLanguage(SearchService.LANGUAGE_XPATH);
sp.setQuery("/app:company_home/app:dictionary");
sp.addStore(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE);
// Perform a search
@SuppressWarnings("unused")
ResultSet rs = transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<ResultSet>()
{
@Override
public ResultSet execute() throws Throwable
{
return searchService.query(sp);
}
}, true, false);
// Check the audit entries
checkAuditEntries(APPLICATION_NAME_MNT_16748, SearchService.LANGUAGE_XPATH, "/app:company_home/app:dictionary", 1);
}
private void checkAuditEntries(String applicationName, String language, String query, int resultsNumber)
{
final StringBuilder sb = new StringBuilder(); final StringBuilder sb = new StringBuilder();
final MutableInt rowCount = new MutableInt(); final MutableInt rowCount = new MutableInt();
AuditQueryCallback callback = new AuditQueryCallback() AuditQueryCallback callback = new AuditQueryCallback()
@@ -257,21 +294,20 @@ public class AuditMethodInterceptorTest extends TestCase
AuditQueryParameters params = new AuditQueryParameters(); AuditQueryParameters params = new AuditQueryParameters();
params.setForward(true); params.setForward(true);
params.setUser(AuthenticationUtil.getAdminUserName()); params.setUser(AuthenticationUtil.getAdminUserName());
params.setApplicationName(APPLICATION_NAME_MNT_16748); params.setApplicationName(applicationName);
rowCount.setValue(0); rowCount.setValue(0);
auditComponent.auditQuery(callback, params, Integer.MAX_VALUE); auditComponent.auditQuery(callback, params, Integer.MAX_VALUE);
assertEquals("Incorrect number of audit entries", 1, rowCount.intValue()); assertEquals("Incorrect number of audit entries", resultsNumber, rowCount.intValue());
assertTrue( assertTrue("The requested language should be in the audit entry.",
"The requested language should be in the audit entry.", sb.toString().contains(language));
sb.toString().contains(SearchService.LANGUAGE_XPATH)); assertTrue("The used query should be in the audit entry.",
assertTrue( sb.toString().contains(query));
"The requested language should be in the audit entry.",
sb.toString().contains("/company_home"));
if (logger.isDebugEnabled()) if (logger.isDebugEnabled())
{ {
logger.debug(sb.toString()); logger.debug(sb.toString());
} }
} }
} }

View File

@@ -31,7 +31,7 @@
<!-- Take the entire post-call data for 'SearchService.query' method and route it to '/searchaudit/query'--> <!-- Take the entire post-call data for 'SearchService.query' method and route it to '/searchaudit/query'-->
<PathMap source="/alfresco-api/post/SearchService/query" target="/searchaudit/query" /> <PathMap source="/alfresco-api/post/SearchService/query" target="/searchaudit/query" />
</PathMappings> </PathMappings>
<Application name="SearchAudit" key="searchaudit"> <Application name="SearchAudit" key="searchaudit">
<AuditPath key="queryX"> <AuditPath key="queryX">
<RecordValue key="storeX" dataExtractor="simpleValue" <RecordValue key="storeX" dataExtractor="simpleValue"
@@ -40,6 +40,8 @@
dataSource="/searchaudit/query/args/language" dataTrigger="/searchaudit/query/no-error" /> dataSource="/searchaudit/query/args/language" dataTrigger="/searchaudit/query/no-error" />
<RecordValue key="queryX" dataExtractor="simpleValue" <RecordValue key="queryX" dataExtractor="simpleValue"
dataSource="/searchaudit/query/args/query" dataTrigger="/searchaudit/query/no-error" /> dataSource="/searchaudit/query/args/query" dataTrigger="/searchaudit/query/no-error" />
<RecordValue key="searchParametersX" dataExtractor="simpleValue"
dataSource="/searchaudit/query/args/searchParameters" dataTrigger="/searchaudit/query/no-error" />
</AuditPath> </AuditPath>
</Application> </Application>