From 06c1fb06f554d0eee167575e8ab0450f1a79dc16 Mon Sep 17 00:00:00 2001 From: "meenal.bhave@alfresco.com" Date: Wed, 18 Sep 2019 18:41:10 +0100 Subject: [PATCH] Search-1857: Implemented a basic sanity test for sql api and amended the suite xml file --- .../functional/gs/AbstractGSE2ETest.java | 8 -- .../functional/gs/sql/SearchSqlGSE2ETest.java | 109 ++++++++++++++++++ .../search-compatibility-with-GS-suite.xml | 5 + 3 files changed, 114 insertions(+), 8 deletions(-) create mode 100644 e2e-test/src/test/java/org/alfresco/test/search/functional/gs/sql/SearchSqlGSE2ETest.java diff --git a/e2e-test/src/test/java/org/alfresco/test/search/functional/gs/AbstractGSE2ETest.java b/e2e-test/src/test/java/org/alfresco/test/search/functional/gs/AbstractGSE2ETest.java index 4147c9152..35362d0c6 100644 --- a/e2e-test/src/test/java/org/alfresco/test/search/functional/gs/AbstractGSE2ETest.java +++ b/e2e-test/src/test/java/org/alfresco/test/search/functional/gs/AbstractGSE2ETest.java @@ -72,9 +72,6 @@ public abstract class AbstractGSE2ETest extends AbstractInsightEngineE2ETest @Getter (value = PROTECTED) private RestAPIFactory restAPIFactory; - @Autowired - private RecordsAPI recordsAPI; - @Autowired private ClassificationService classificationService; @@ -113,11 +110,6 @@ public abstract class AbstractGSE2ETest extends AbstractInsightEngineE2ETest createElectronicRecord(folder2.getId(), ELECTRONIC_FILE); } - public RecordsAPI getRecordsAPI() - { - return recordsAPI; - } - public ClassificationService getClassificationService() { return classificationService; diff --git a/e2e-test/src/test/java/org/alfresco/test/search/functional/gs/sql/SearchSqlGSE2ETest.java b/e2e-test/src/test/java/org/alfresco/test/search/functional/gs/sql/SearchSqlGSE2ETest.java new file mode 100644 index 000000000..2840cc3e2 --- /dev/null +++ b/e2e-test/src/test/java/org/alfresco/test/search/functional/gs/sql/SearchSqlGSE2ETest.java @@ -0,0 +1,109 @@ +/* + * 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 org.alfresco.rest.rm.community.model.user.UserRoles.ROLE_RM_USER; +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.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.springframework.http.HttpStatus; +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 testUserGSAccess, testUserNoAccess; + + private FolderModel testFolder; + private RecordCategoryChild recordFolder; + + private FileModel fileRecord, fileUnclassified; + + private String fileClassifiedAsTopSecret, fileClassifiedAsSecret, fileClassifiedAsConfidential; + + private Record elecRecord; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + super.setup(); + // Create other users to check access permissions + testUserGSAccess = createUserWithRMRole(testUser, ROLE_RM_USER.roleId);; + testUserNoAccess = dataUser.createRandomTestUser("UserSearchNoAccess"); + + // Create classified files + fileClassifiedAsTopSecret = createClassifiedFile(TOP_SECRET_CLASSIFICATION_LEVEL_ID); + fileClassifiedAsSecret = createClassifiedFile(SECRET_CLASSIFICATION_LEVEL_ID); + fileClassifiedAsConfidential = createClassifiedFile(CONFIDENTIAL_CLASSIFICATION_LEVEL_ID); + + // Create unclassified file + fileUnclassified = new FileModel(unique_searchString + "Unclassified-1.txt", "Unclassified1", "Unclassified1", FileType.TEXT_PLAIN, "Unclassified1"); + dataContent.usingUser(testUser).usingSite(testSite).createContent(fileUnclassified); + + // Create a folder and a file + 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); + + // File a Electronic Record + recordFolder = createCategoryFolderInFilePlan(); + elecRecord = createElectronicRecord(recordFolder.getId(), fileRecord.getName()); + } + + @Test(priority = 1, groups = {TestGroup.ACS_611n}) + public void testSQLRespectsSitePermissions() throws Exception + { + // Search for a file name to ensure content is indexed + boolean indexingInProgress = isContentInSearchResults(fileRecord.getName(), fileRecord.getName(), true); + + Assert.assertTrue(indexingInProgress, "Expected record file, not found"); + + indexingInProgress = isContentInSearchResults(testFolder.getName(), testFolder.getName(), true); + + Assert.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() + "'"); + sqlRequest.setLimit(10); + + RestResponse response = searchSql(sqlRequest, testUserNoAccess); + + restClient.assertStatusCodeIs(HttpStatus.OK); + response.assertThat().body("list.pagination.count", Matchers.equalTo(0)); + + // Add user as a SiteMember + dataUser.addUserToSite(testUserNoAccess, testSite, UserRole.SiteConsumer); + + response = searchSql(sqlRequest, testUserNoAccess); + + restClient.assertStatusCodeIs(HttpStatus.OK); + response.assertThat().body("list.pagination.count", Matchers.equalTo(1)); + } + + @Test(priority = 2, groups = {TestGroup.ACS_611n}, enabled = false) + public void testSQLFiltersClassifiedFiles() throws Exception + { + // TODO: Relevant tests to be implemented + } +} diff --git a/e2e-test/src/test/resources/search-compatibility-with-GS-suite.xml b/e2e-test/src/test/resources/search-compatibility-with-GS-suite.xml index 22940f430..ed7ae444c 100644 --- a/e2e-test/src/test/resources/search-compatibility-with-GS-suite.xml +++ b/e2e-test/src/test/resources/search-compatibility-with-GS-suite.xml @@ -5,4 +5,9 @@ + + + + +