Moved the GS Tests to InsightEngine package to avoid compiliation errors in SearchServices mirror

This commit is contained in:
meenal.bhave@alfresco.com
2019-10-03 16:58:26 +01:00
parent 7f8aedc531
commit 5f281abadd
4 changed files with 9 additions and 684 deletions
@@ -1,314 +0,0 @@
/*
* Copyright 2019 Alfresco Software, Ltd. All rights reserved.
* License rights for this program may be obtained from Alfresco Software, Ltd.
* pursuant to a written agreement and any use of this program without such an
* agreement is prohibited.
*/
package org.alfresco.test.search.functional.gs;
import static org.alfresco.rest.rm.community.utils.FilePlanComponentsUtil.createRecordCategoryChildModel;
import static org.alfresco.rest.rm.community.utils.FilePlanComponentsUtil.createRecordCategoryModel;
import static org.alfresco.utility.data.RandomData.getRandomAlphanumeric;
import java.util.List;
import org.alfresco.dataprep.SiteService.RMSiteCompliance;
import org.alfresco.rest.core.RestAPIFactory;
import org.alfresco.rest.rm.community.model.record.Record;
import org.alfresco.rest.rm.community.model.recordcategory.RecordCategory;
import org.alfresco.rest.rm.community.model.recordcategory.RecordCategoryChild;
import org.alfresco.rest.rm.community.requests.gscore.api.RMSiteAPI;
import org.alfresco.rest.rm.community.requests.gscore.api.RecordFolderAPI;
import org.alfresco.rest.rm.community.requests.gscore.api.RecordsAPI;
import org.alfresco.rest.rm.enterprise.service.ClassificationService;
import org.alfresco.test.search.functional.insightEngine.AbstractInsightEngineE2ETest;
import org.alfresco.utility.data.RandomData;
import org.alfresco.utility.model.FileModel;
import org.alfresco.utility.model.FileType;
import org.alfresco.utility.model.SiteModel;
import org.alfresco.utility.model.UserModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.testng.Assert;
import org.testng.annotations.BeforeClass;
/**
* Base test class for GS tests.
*
* @author Cristina Diaconu
* @author Meenal Bhave
*/
public abstract class AbstractGSE2ETest extends AbstractInsightEngineE2ETest
{
protected static final String FILE_PLAN_ALIAS = "-filePlan-";
protected static final String RECORD_TYPE = "rma:record";
protected static final String RECORD_FOLDER_TYPE = "rma:recordFolder";
protected static final String RECORD_CATEGORY_TYPE = "rma:recordCategory";
protected static final String CONTENT_TYPE = "cm:content";
protected static final String ASPECTS_COMPLETED_RECORD = "rma:declaredRecord";
protected static final String NON_ELECTRONIC_RECORD_TYPE = "rma:nonElectronicDocument";
protected static final String RECORD_CATEGORY_TITLE = "RM_CATEGORY_TITLE";
protected static final String ROOT_CATEGORY_NAME = RandomData.getRandomName("RM_Cat");
protected static final String CATEGORY1 = RandomData.getRandomName("RM_child_cat1");
protected static final String CATEGORY2 = RandomData.getRandomName("RM_child_cat2");
protected static final String FOLDER1 = RandomData.getRandomName("RM_folder1");
protected static final String FOLDER2 = RandomData.getRandomName("RM_folder2");
protected static final String ELECTRONIC_FILE = RandomData.getRandomName("RM_electonic_file");
protected static final String NON_ELECTRONIC_FILE = RandomData.getRandomName("RM_nonelectonic_file");
protected static final String SEARCH_LANGUAGE_CMIS = "cmis";
protected RecordCategory rootCategory;
protected Record electronicRecord, nonElectronicRecord;
@Autowired
protected RestAPIFactory restAPIFactory;
@Autowired
private ClassificationService classificationService;
@BeforeClass(alwaysRun = true)
public void rmDataPreparation()
{
serverHealth.assertServerIsOnline();
testSite = createRMSite();
// create the Root category
rootCategory = createRootCategory(ROOT_CATEGORY_NAME);
Assert.assertNotNull(rootCategory, "Root category was not created!");
// Add two children (categories) on Root category
RecordCategoryChild childCategory1 = createRecordCategoryChild(rootCategory.getId(), CATEGORY1);
Assert.assertNotNull(childCategory1, "Child category 1 was not created!");
RecordCategoryChild childCategory2 = createRecordCategoryChild(rootCategory.getId(), CATEGORY2);
Assert.assertNotNull(childCategory2, "Child category 2 was not created!");
// Create two folders with records (electronic and nonElectronic files) on Child category 1
RecordCategoryChild folder1 = createRecordFolder(childCategory1.getId(), FOLDER1);
RecordCategoryChild folder2 = createRecordFolder(childCategory1.getId(), FOLDER2);
// Create two folders on Child Category2
createRecordFolder(childCategory2.getId(), FOLDER1);
createRecordFolder(childCategory2.getId(), FOLDER2);
// Complete a file
electronicRecord = createElectronicRecord(folder1.getId(), ELECTRONIC_FILE);
completeRecord(electronicRecord.getId());
nonElectronicRecord = createNonElectronicRecord(folder1.getId(), NON_ELECTRONIC_FILE);
// Add an electronic record on folder2
createElectronicRecord(folder2.getId(), ELECTRONIC_FILE);
}
public ClassificationService getClassificationService()
{
return classificationService;
}
/**
* Create a new RM Site. If the site already exists then remove it and create a new one.
*/
public SiteModel createRMSite()
{
RMSiteAPI rmSiteAPI = restAPIFactory.getRMSiteAPI();
if (rmSiteAPI.existsRMSite())
{
rmSiteAPI.deleteRMSite();
}
return dataSite.createRMSite(RMSiteCompliance.STANDARD);
}
protected RestAPIFactory getRestAPIFactory()
{
return restAPIFactory;
}
/**
* Helper method to create root category as the admin user
*
* @param categoryName The name of the category
* @return The created category
*/
public RecordCategory createRootCategory(String categoryName)
{
return createRootCategory(adminUserModel, categoryName, RECORD_CATEGORY_TITLE);
}
/**
* Helper method to create root category
*
* @param userModel The user under whose privileges this structure is going to be created
* @param categoryName The name of the category
* @param categoryTitle The title of the category
* @return The created category
*/
public RecordCategory createRootCategory(UserModel userModel, String categoryName, String categoryTitle)
{
RecordCategory recordCategoryModel = createRecordCategoryModel(categoryName, categoryTitle);
return restAPIFactory.getFilePlansAPI(userModel).createRootRecordCategory(recordCategoryModel, FILE_PLAN_ALIAS);
}
/**
* Helper method to create a record category as the admin user
*
* @param recordCategoryId The id of the record category
* @param name The name of the record category child
* @return The created child category
*/
public RecordCategoryChild createRecordCategoryChild(String recordCategoryId, String name)
{
return createRecordCategoryChild(adminUserModel, recordCategoryId, name, RECORD_CATEGORY_TYPE);
}
/**
* Helper method to create a record category child
*
* @param user The user under whose privileges the node is going to be created
* @param recordCategoryId The id of the record category
* @param name The name of the record category child
* @param type The type of the record category child
* @return The created child category
*/
public RecordCategoryChild createRecordCategoryChild(UserModel user, String recordCategoryId, String name,
String type)
{
RecordCategoryChild recordCategoryChildModel = createRecordCategoryChildModel(name, type);
return restAPIFactory.getRecordCategoryAPI(user).createRecordCategoryChild(recordCategoryChildModel,
recordCategoryId);
}
/**
* Helper method to create a record folder as the admin user
*
* @param recordCategoryId The id of the record category
* @param name The name of the record category child
* @return The created record folder.
*/
public RecordCategoryChild createRecordFolder(String recordCategoryId, String name)
{
return createRecordCategoryChild(adminUserModel, recordCategoryId, name, RECORD_FOLDER_TYPE);
}
/**
* Create an electronic record
*
* @param parentId The id of the parent
* @param name The name of the record
* @return The created record
*/
public Record createElectronicRecord(String parentId, String name)
{
return createElectronicRecord(parentId, name, null);
}
/**
* Create an electronic record
*
* @param parentId The id of the parent
* @param name The name of the record
* @return The created electronic record
*/
public Record createElectronicRecord(String parentId, String name, UserModel user)
{
RecordFolderAPI recordFolderAPI = restAPIFactory.getRecordFolderAPI(user);
Record recordModel = Record.builder().name(name).nodeType(CONTENT_TYPE).build();
return recordFolderAPI.createRecord(recordModel, parentId);
}
/**
* Create a non-electronic record
*
* @param parentId The id of the parent
* @param name The name of the record
* @return The created non electronic record
*/
public Record createNonElectronicRecord(String parentId, String name)
{
return createNonElectronicRecord(parentId, name, null);
}
/**
* Create a non-electronic record
*
* @param parentId The id of the parent
* @param name The name of the record
* @param user The user who creates the non-electronic record
* @return The created non electronic record
*/
public Record createNonElectronicRecord(String parentId, String name, UserModel user)
{
RecordFolderAPI recordFolderAPI = restAPIFactory.getRecordFolderAPI(user);
Record recordModel = Record.builder().name(name).nodeType(NON_ELECTRONIC_RECORD_TYPE).build();
return recordFolderAPI.createRecord(recordModel, parentId);
}
/**
* Helper method to complete record
*
* @param recordId The id of the record to complete
* @return The completed record
*/
public Record completeRecord(String recordId)
{
RecordsAPI recordsAPI = restAPIFactory.getRecordsAPI();
List<String> aspects = recordsAPI.getRecord(recordId).getAspectNames();
// this operation is only valid for records
Assert.assertTrue(aspects.contains(RECORD_TYPE));
// a record mustn't be completed
Assert.assertFalse(aspects.contains(ASPECTS_COMPLETED_RECORD));
// add completed record aspect
aspects.add(ASPECTS_COMPLETED_RECORD);
Record updateRecord = recordsAPI.updateRecord(Record.builder().aspectNames(aspects).build(), recordId);
restAPIFactory.getRmRestWrapper().assertStatusCodeIs(HttpStatus.OK);
return updateRecord;
}
/**
* Helper method to create root category
*
* @return The created category
*/
public RecordCategoryChild createCategoryFolderInFilePlan()
{
// create root category
RecordCategory recordCategory = createRootCategory("Category " + getRandomAlphanumeric());
return createFolder(recordCategory.getId(), "Folder " + getRandomAlphanumeric());
}
/**
* Helper method to create record folder
*
* @param recordCategoryId The id of the record category
* @param name The name of the folder
* @return The created folder
*/
public RecordCategoryChild createFolder(String recordCategoryId, String name)
{
UserModel asUser = dataContent.getAdminUser();
RecordCategoryChild recordFolderModel = createRecordCategoryChildModel(name, RECORD_FOLDER_TYPE);
return getRestAPIFactory().getRecordCategoryAPI(asUser).createRecordCategoryChild(recordFolderModel, recordCategoryId);
}
/**
* Helper method to create a test user with rm role
*
* @param user to which the rm role is to be assigned
* @param userRole the rm role
* @return the created user model
*/
protected UserModel createUserWithRMRole(UserModel user, String userRole)
{
getRestAPIFactory().getRMUserAPI().assignRoleToUser(user.getUsername(), userRole);
return user;
}
}
@@ -1,63 +0,0 @@
/*
* Copyright 2019 Alfresco Software, Ltd. All rights reserved.
* License rights for this program may be obtained from Alfresco Software, Ltd.
* pursuant to a written agreement and any use of this program without such an
* agreement is prohibited.
*/
package org.alfresco.test.search.functional.gs.search;
import org.alfresco.rest.search.RestRequestQueryModel;
import org.alfresco.rest.search.SearchResponse;
import org.alfresco.search.TestGroup;
import org.alfresco.test.search.functional.gs.AbstractGSE2ETest;
import org.alfresco.utility.model.FolderModel;
import org.springframework.http.HttpStatus;
import org.testng.Assert;
import org.testng.annotations.Test;
/**
* The purpose of this test is to create basic queries using a RM site and a basic file plan.
*
* @author Cristina Diaconu
* @author Meenal Bhave
*/
public class SearchServicesGSE2ETest extends AbstractGSE2ETest
{
@Test(priority = 1, groups = {TestGroup.AGS_302})
public void testBasicSearch()
{
// Create a new folder
FolderModel testFolder = dataContent.usingUser(testUser).usingSite(testSite).createFolder();
// Search for the new folder using folder name
boolean indexingInProgress = isContentInSearchResults(testFolder.getName(), testFolder.getName(), true);
Assert.assertTrue(indexingInProgress, "Expected folder is not found: " + testFolder.getName());
// Search for a folder name using cmis query
String query = "select * from cmis:folder where cmis:name='" + testFolder.getName() + "'";
RestRequestQueryModel queryModel = new RestRequestQueryModel();
queryModel.setQuery(query);
queryModel.setLanguage(SEARCH_LANGUAGE_CMIS);
SearchResponse response = queryAsUser(dataUser.getAdminUser(), queryModel);
restClient.assertStatusCodeIs(HttpStatus.OK);
Assert.assertEquals(response.getPagination().getCount(), 1, "Expected folder is not found: " + testFolder.getName());
// Search for a file name
query = "select * from cmis:document where cmis:name like '" + NON_ELECTRONIC_FILE + "%'";
queryModel = new RestRequestQueryModel();
queryModel.setQuery(query);
queryModel.setLanguage(SEARCH_LANGUAGE_CMIS);
response = queryAsUser(dataUser.getAdminUser(), queryModel);
restClient.assertStatusCodeIs(HttpStatus.OK);
Assert.assertEquals(response.getPagination().getCount(), 1, "Expected file is not found: " + NON_ELECTRONIC_FILE);
}
}
@@ -1,298 +0,0 @@
/*
* Copyright 2019 Alfresco Software, Ltd. All rights reserved.
* License rights for this program may be obtained from Alfresco Software, Ltd.
* pursuant to a written agreement and any use of this program without such an
* agreement is prohibited.
*/
package org.alfresco.test.search.functional.gs.sql;
import static java.util.Arrays.asList;
import static org.apache.commons.collections4.CollectionUtils.isEqualCollection;
import static org.alfresco.rest.rm.community.model.user.UserRoles.ROLE_RM_USER;
import static org.testng.Assert.assertTrue;
import java.util.List;
import org.alfresco.rest.core.RestResponse;
import org.alfresco.rest.rm.community.model.record.Record;
import org.alfresco.rest.rm.community.model.recordcategory.RecordCategoryChild;
import org.alfresco.rest.rm.community.model.user.UserPermissions;
import org.alfresco.rest.rm.enterprise.core.ClassificationData;
import org.alfresco.rest.search.SearchResponse;
import org.alfresco.rest.search.SearchSqlRequest;
import org.alfresco.search.TestGroup;
import org.alfresco.test.search.functional.gs.AbstractGSE2ETest;
import org.alfresco.utility.constants.UserRole;
import org.alfresco.utility.model.FileModel;
import org.alfresco.utility.model.FileType;
import org.alfresco.utility.model.FolderModel;
import org.alfresco.utility.model.UserModel;
import org.hamcrest.Matchers;
import org.testng.Assert;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
/**
* The purpose of this test is to create basic queries using a RM site and a basic file plan.
*
* @author Meenal Bhave
*/
public class SearchSqlGSE2ETest extends AbstractGSE2ETest
{
private UserModel testUserGSTopSecret, testUserSecret, testUserConfidential, testUserNoAccess;
private FolderModel testFolder;
private FileModel fileRecord, fileRecordElectronic, fileUnclassified, fileClassifiedAsTopSecret,
fileClassifiedAsSecret, fileClassifiedAsConfidential;
private String TOPSECRET_FILE, SECRET_FILE, CONFIDENTIAL_FILE, UNCLASSIFIED_FILE;
private final String RECORD_IDENTIFIER = "rma:identifier:'*'";
@BeforeClass(alwaysRun = true)
public void dataPreparation() throws Exception
{
super.setup();
// Create other users to check access permissions
testUser = createUserWithRMRole(testUser, ROLE_RM_USER.roleId);
testUserGSTopSecret = dataUser.createRandomTestUser("UserTopSecret");
testUserSecret = dataUser.createRandomTestUser("UserSecret");
testUserConfidential = dataUser.createRandomTestUser("UserConfidential");
testUserNoAccess = dataUser.createRandomTestUser("UserSearchNoAccess");
// Add users to testSite
getDataUser().addUserToSite(testUserGSTopSecret, testSite, UserRole.SiteCollaborator);
getDataUser().addUserToSite(testUserSecret, testSite, UserRole.SiteContributor);
getDataUser().addUserToSite(testUserConfidential, testSite, UserRole.SiteConsumer);
// Assign classification levels
getClassificationService().assignClearance(adminUserModel, testUser, ClassificationData.TOP_SECRET_CLASSIFICATION_LEVEL_ID);
getClassificationService().assignClearance(adminUserModel, testUserGSTopSecret, ClassificationData.TOP_SECRET_CLASSIFICATION_LEVEL_ID);
getClassificationService().assignClearance(adminUserModel, testUserSecret, ClassificationData.SECRET_CLASSIFICATION_LEVEL_ID);
getClassificationService().assignClearance(adminUserModel, testUserConfidential, ClassificationData.CONFIDENTIAL_CLASSIFICATION_LEVEL_ID);
getClassificationService().assignClearance(adminUserModel, testUserNoAccess, ClassificationData.UNCLASSIFIED_CLASSIFICATION_LEVEL_ID);
// Create a folder and files
testFolder = dataContent.usingUser(testUser).usingSite(testSite).createFolder();
fileRecord = new FileModel(unique_searchString + "record-1.txt", "record1", "record1", FileType.TEXT_PLAIN, "record1");
dataContent.usingUser(testUser).usingSite(testSite).createContent(fileRecord);
fileRecordElectronic = new FileModel(unique_searchString + "e-record-1.txt", "e-record1", "e-record1", FileType.TEXT_PLAIN, "e-record1");
dataContent.usingUser(testUser).usingSite(testSite).createContent(fileRecordElectronic);
// Create Files to be classified later
fileClassifiedAsTopSecret = new FileModel(unique_searchString + "TopS-1.txt", "top", "top", FileType.TEXT_PLAIN, "top");
dataContent.usingUser(testUser).usingSite(testSite).createContent(fileClassifiedAsTopSecret);
fileClassifiedAsSecret = new FileModel(unique_searchString + "Secret-1.txt", "secret", "secret", FileType.TEXT_PLAIN, "secret");
dataContent.usingUser(testUser).usingSite(testSite).createContent(fileClassifiedAsSecret);
fileClassifiedAsConfidential = new FileModel(unique_searchString + "conf-1.txt", "conf", "conf", FileType.TEXT_PLAIN, "conf");
dataContent.usingUser(testUser).usingSite(testSite).createContent(fileClassifiedAsConfidential);
fileUnclassified = new FileModel(unique_searchString + "Unclassified-1.txt", "Unclassified1", "Unclassified1", FileType.TEXT_PLAIN, "Unclassified1");
dataContent.usingUser(testUser).usingSite(testSite).createContent(fileUnclassified);
// Classify files
getClassificationService().classifyNode(adminUserModel, fileClassifiedAsTopSecret.getNodeRefWithoutVersion(), ClassificationData.TOP_SECRET_CLASSIFICATION_LEVEL_ID);
getClassificationService().classifyNode(testUser, fileClassifiedAsSecret.getNodeRefWithoutVersion(), ClassificationData.SECRET_CLASSIFICATION_LEVEL_ID);
getClassificationService().classifyNode(testUser, fileClassifiedAsConfidential.getNodeRefWithoutVersion(), ClassificationData.CONFIDENTIAL_CLASSIFICATION_LEVEL_ID);
getClassificationService().classifyNode(testUser, fileUnclassified.getNodeRefWithoutVersion(), ClassificationData.UNCLASSIFIED_CLASSIFICATION_LEVEL_ID);
TOPSECRET_FILE = fileClassifiedAsTopSecret.getName();
SECRET_FILE = fileClassifiedAsSecret.getName();
CONFIDENTIAL_FILE = fileClassifiedAsConfidential.getName();
UNCLASSIFIED_FILE = fileUnclassified.getName();
}
@Test(priority = 1, groups = { TestGroup.AGS_302 })
public void testSQLRespectsSitePermissions()
{
// Search for a file name to ensure content is indexed
boolean indexingInProgress = isContentInSearchResults(fileRecord.getName(), fileRecord.getName(), true);
assertTrue(indexingInProgress, "Expected record file, not found");
indexingInProgress = isContentInSearchResults(testFolder.getName(), testFolder.getName(), true);
assertTrue(indexingInProgress, "Expected folder, not found");
// Search using sql: userNoAccess is not expected to find the record
SearchSqlRequest sqlRequest = new SearchSqlRequest();
sqlRequest.setSql("select * from alfresco where cm_name = '" + fileRecord.getName() + "'");
// Verify that testUserNoAccess can't see content of the Private site that he is not a member of
RestResponse response = searchSql(sqlRequest, testUserNoAccess);
response.assertThat().body("list.pagination.count", Matchers.equalTo(0));
// Verify that the site member can see the content: Collaborator
response = searchSql(sqlRequest, testUserSecret);
response.assertThat().body("list.pagination.count", Matchers.equalTo(1));
// Verify that the site member can see the content: Consumer
response = searchSql(sqlRequest, testUserConfidential);
response.assertThat().body("list.pagination.count", Matchers.equalTo(1));
}
@Test(priority = 2, groups = { TestGroup.AGS_302 })
public void testSQLFiltersClassifiedFiles()
{
// Wait for the files to be indexed
boolean fileFound = isContentInSearchResults("sc_classification:c", CONFIDENTIAL_FILE, true);
assertTrue(fileFound, "Expected confidential file, not found");
// Check Aggregate query response doesn't bring up classification levels the user should not see
SearchSqlRequest sqlRequest = new SearchSqlRequest();
sqlRequest.setSql("select sc_classification, count(*) from alfresco group by sc_classification");
// User should only see aggregate results for security level he can access
RestResponse response = searchSql(sqlRequest, testUserGSTopSecret);
response.assertThat().body("list.pagination.count", Matchers.equalTo(4));
response = searchSql(sqlRequest, testUserSecret);
response.assertThat().body("list.pagination.count", Matchers.equalTo(3));
response = searchSql(sqlRequest, testUserConfidential);
response.assertThat().body("list.pagination.count", Matchers.equalTo(2));
sqlRequest = new SearchSqlRequest();
sqlRequest.setSql("select sc_classification, count(*) from alfresco where SITE = '" + testSite.getId() + "' group by sc_classification");
response = searchSql(sqlRequest, testUserGSTopSecret);
response.assertThat().body("list.pagination.count", Matchers.equalTo(4));
response = searchSql(sqlRequest, testUserSecret);
response.assertThat().body("list.pagination.count", Matchers.equalTo(3));
response = searchSql(sqlRequest, testUserConfidential);
response.assertThat().body("list.pagination.count", Matchers.equalTo(2));
response = searchSql(sqlRequest, testUserNoAccess);
response.assertThat().body("list.pagination.count", Matchers.equalTo(0));
// Check Query results include content based on classification level, starting with unclassified file
sqlRequest = new SearchSqlRequest();
sqlRequest.setSql("select cm_name from alfresco where sc_classification = '*' and SITE = '" + testSite.getId() + "'");
List<String> expectedResult = asList(TOPSECRET_FILE, SECRET_FILE, CONFIDENTIAL_FILE, UNCLASSIFIED_FILE);
List<String> results = getContentListForSolrRequest(sqlRequest, testUserGSTopSecret);
assertTrue(isEqualCollection(expectedResult, results), "Unexpected files in the response: " + results.toString());
expectedResult = asList(SECRET_FILE, CONFIDENTIAL_FILE, UNCLASSIFIED_FILE);
results = getContentListForSolrRequest(sqlRequest, testUserSecret);
assertTrue(isEqualCollection(expectedResult, results), "Unexpected files in the response: " + results.toString());
expectedResult = asList(CONFIDENTIAL_FILE, UNCLASSIFIED_FILE);
results = getContentListForSolrRequest(sqlRequest, testUserConfidential);
assertTrue(isEqualCollection(expectedResult, results), "Unexpected files in the response: " + results.toString());
results = getContentListForSolrRequest(sqlRequest, testUserNoAccess);
assertTrue(results.isEmpty(), "Unexpected files in the response: " + results.toString());
}
@Test(priority = 3, groups = { TestGroup.AGS_302 })
public void testSQLFiltersElectronicRecords()
{
// File a Electronic Record
RecordCategoryChild recordFolder = createCategoryFolderInFilePlan();
Record elecRecord = createElectronicRecord(recordFolder.getId(), fileRecord.getName());
// Add permission for the GS user to Read Records
getRestAPIFactory().getRMUserAPI().addUserPermission(recordFolder.getParentId(), testUser, UserPermissions.PERMISSION_READ_RECORDS);
// Wait for the record to be indexed and check that it can be found
boolean fileFound = isContentInSearchResults(RECORD_IDENTIFIER, elecRecord.getName(), true);
assertTrue(fileFound, "Expected record file, not found");
SearchResponse result = queryAsUser(testUserGSTopSecret, RECORD_IDENTIFIER);
Assert.assertEquals(result.getPagination().getCount(), 0, "Expected count of entries 0, found more");
SearchSqlRequest sqlRequest = new SearchSqlRequest();
sqlRequest.setSql("select cm_name, PATH from alfresco where rma_identifier = '*' and type = 'cm:content'");
// Verify that user can see the electronic record with minimum read records permissions
RestResponse response = searchSql(sqlRequest, testUser);
response.assertThat().body("list.pagination.count", Matchers.equalTo(1));
// Verify that users can not see the electronic record without read record permissions
response = searchSql(sqlRequest, testUserGSTopSecret);
response.assertThat().body("list.pagination.count", Matchers.equalTo(0));
}
@Test(priority = 4, groups = { TestGroup.AGS_302 })
public void testSQLFiltersInPlaceRecords()
{
// Declare a file as Record
Record inPlaceRecord = getRestAPIFactory().getFilesAPI().declareAsRecord(fileRecord.getNodeRefWithoutVersion());
// Wait for the record to be indexed
boolean fileFound = isContentInSearchResults(RECORD_IDENTIFIER, inPlaceRecord.getName(), true);
assertTrue(fileFound, "Expected in place record file, not found");
// Verify that user can see the in place record without any additional permissions
SearchSqlRequest sqlRequest = new SearchSqlRequest();
sqlRequest.setSql("select cm_name from alfresco where rma_identifier = '*' and Site = '" + testSite.getId() + "'");
RestResponse response = searchSql(sqlRequest, testUser);
response.assertThat().body("list.pagination.count", Matchers.equalTo(1));
response.assertThat().body("list.entries.entry[0].value", Matchers.contains(inPlaceRecord.getName()));
// Verify that other site members can see the in place record with no additional permissions
response = searchSql(sqlRequest, testUserGSTopSecret);
response.assertThat().body("list.pagination.count", Matchers.equalTo(1));
response.assertThat().body("list.entries.entry[0].value", Matchers.contains(inPlaceRecord.getName()));
response = searchSql(sqlRequest, testUserConfidential);
response.assertThat().body("list.pagination.count", Matchers.equalTo(1));
response.assertThat().body("list.entries.entry[0].value", Matchers.contains(inPlaceRecord.getName()));
response = searchSql(sqlRequest, testUserNoAccess);
response.assertThat().body("list.pagination.count", Matchers.equalTo(0));
}
@Test(priority = 5, groups = { TestGroup.AGS_302 })
public void testSQLFiltersRecordsCascadedPermissions()
{
// Search for records when user does not have read permission
boolean fileFound = isContentInSearchResults(NON_ELECTRONIC_FILE, nonElectronicRecord.getName(), false);
assertTrue(fileFound, "Non electronic record file found in the results, when user doesn't have read permissions");
// Search for records when user does not have read permission
fileFound = isContentInSearchResults(ELECTRONIC_FILE, electronicRecord.getName(), false);
assertTrue(fileFound, "Electronic record file found in the results, when user doesn't have read permissions");
// Assign Read permissions to the user at rootCategory level
getRestAPIFactory().getRMUserAPI().addUserPermission(rootCategory.getId(), testUser, UserPermissions.PERMISSION_READ_RECORDS);
getRestAPIFactory().getRMUserAPI().addUserPermission(rootCategory.getId(), testUserGSTopSecret, UserPermissions.PERMISSION_READ_RECORDS);
// Check that the non electronic record can now be found
isContentInSearchResults(NON_ELECTRONIC_FILE, nonElectronicRecord.getName(), true);
assertTrue(fileFound, "Expected non electronic record file, not found");
// Check that the electronic record can now be found
fileFound = isContentInSearchResults(ELECTRONIC_FILE, electronicRecord.getName(), true);
assertTrue(fileFound, "Expected electronic record file, not found");
// Check that the electronic record and non electronic record both can be found with cascaded permissions
String recordFiles = String.format("('%s' , '%s')", nonElectronicRecord.getName(), electronicRecord.getName());
SearchSqlRequest sqlRequest = new SearchSqlRequest();
sqlRequest.setSql("select cm_name from alfresco where rma_identifier = '*' and cm_name in " + recordFiles + " order by cm_name");
RestResponse response = searchSql(sqlRequest, testUser);
response.assertThat().body("list.pagination.count", Matchers.equalTo(2));
response.assertThat().body("list.entries.entry[0].value", Matchers.contains(electronicRecord.getName()));
response.assertThat().body("list.entries.entry[1].value", Matchers.contains(nonElectronicRecord.getName()));
response = searchSql(sqlRequest, testUserGSTopSecret);
response.assertThat().body("list.pagination.count", Matchers.equalTo(2));
response.assertThat().body("list.entries.entry[0].value", Matchers.contains(electronicRecord.getName()));
response.assertThat().body("list.entries.entry[1].value", Matchers.contains(nonElectronicRecord.getName()));
}
}
@@ -1,22 +1,22 @@
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="IEGSCompatibilitySuite" verbose="6" preserve-order="true">
<groups>
<run>
<exclude name="Not_InsightEngine" />
<include name="AGS_302" />
</run>
</groups>
<listeners>
<listener class-name="org.alfresco.utility.report.HtmlReportListener"/>
<listener class-name="org.alfresco.utility.report.log.LogsListener"/>
</listeners>
<test name="SS-With-GS">
<packages>
<package name="org.alfresco.test.search.functional.gs.search.*"/>
</packages>
</test>
<test name="IE-With-GS">
<packages>
<package name="org.alfresco.test.search.functional.gs.sql.*"/>
<package name="org.alfresco.test.search.functional.insightEngine.gs.*"/>
</packages>
</test>
<suite-files>
<suite-file path="src/test/resources/InsightSuite.xml"></suite-file>
</suite-files>
</suite-files>
</suite>