From 5b999a1f39a1ac78345edf77558bec337bdac4e1 Mon Sep 17 00:00:00 2001 From: jcule Date: Thu, 6 Jul 2017 21:18:27 +0100 Subject: [PATCH] REPO-2632: REST-API: Enable/Disable Application Auditing - add TAS level test --- .../org/alfresco/rest/audit/AuditTest.java | 24 +++++ .../rest/audit/GetAuditCoreTests.java | 42 ++------ .../rest/audit/PutAuditCoreTests.java | 97 +++++++++++++++++++ 3 files changed, 131 insertions(+), 32 deletions(-) diff --git a/e2e-test/java/org/alfresco/rest/audit/AuditTest.java b/e2e-test/java/org/alfresco/rest/audit/AuditTest.java index deefac86f..084b3c2ea 100644 --- a/e2e-test/java/org/alfresco/rest/audit/AuditTest.java +++ b/e2e-test/java/org/alfresco/rest/audit/AuditTest.java @@ -6,10 +6,12 @@ import org.alfresco.rest.RestTest; import org.alfresco.rest.core.RestRequest; import org.alfresco.rest.core.RestResponse; import org.alfresco.rest.core.RestWrapper; +import org.alfresco.rest.model.RestAuditAppModel; import org.alfresco.rest.model.RestAuditAppModelsCollection; import org.alfresco.utility.model.UserModel; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpMethod; +import org.springframework.http.HttpStatus; import org.testng.annotations.BeforeClass; import com.jayway.restassured.RestAssured; @@ -22,6 +24,9 @@ public abstract class AuditTest extends RestTest protected UserModel userModel; protected RestAuditAppModelsCollection restAuditCollection; + protected RestAuditAppModel syncRestAuditAppModel; + protected RestAuditAppModel taggingRestAuditAppModel; + @BeforeClass(alwaysRun = true) public void dataPreparation() throws Exception @@ -33,4 +38,23 @@ public abstract class AuditTest extends RestTest RestResponse response = restAPI.authenticateUser(dataUser.getAdminUser()).process(request); response.assertThat().body("enabled", is(true)); } + + protected RestAuditAppModel getSyncRestAuditAppModel(UserModel userModel) throws Exception + { + restAuditCollection = restClient.authenticateUser(userModel).withCoreAPI().usingAudit().getAuditApplications(); + restClient.assertStatusCodeIs(HttpStatus.OK); + restAuditCollection.assertThat().entriesListIsNotEmpty(); + RestAuditAppModel syncRestAuditAppModel = restAuditCollection.getEntries().get(0).onModel(); + return syncRestAuditAppModel; + } + + protected RestAuditAppModel getTaggingRestAuditAppModel(UserModel userModel) throws Exception + { + restAuditCollection = restClient.authenticateUser(userModel).withCoreAPI().usingAudit().getAuditApplications(); + restClient.assertStatusCodeIs(HttpStatus.OK); + restAuditCollection.assertThat().entriesListIsNotEmpty(); + RestAuditAppModel taggingRestAuditAppModel = restAuditCollection.getEntries().get(1).onModel(); + return taggingRestAuditAppModel; + } + } diff --git a/e2e-test/java/org/alfresco/rest/audit/GetAuditCoreTests.java b/e2e-test/java/org/alfresco/rest/audit/GetAuditCoreTests.java index 6c765deb0..a9ff76cf1 100644 --- a/e2e-test/java/org/alfresco/rest/audit/GetAuditCoreTests.java +++ b/e2e-test/java/org/alfresco/rest/audit/GetAuditCoreTests.java @@ -2,7 +2,7 @@ package org.alfresco.rest.audit; import static org.testng.Assert.assertEquals; -import org.alfresco.rest.model.RestAuditAppModel; + import org.alfresco.utility.model.TestGroup; import org.alfresco.utility.testrail.ExecutionType; import org.alfresco.utility.testrail.annotation.TestRail; @@ -25,40 +25,18 @@ public class GetAuditCoreTests extends AuditTest @Test(groups = { TestGroup.REST_API, TestGroup.AUDIT, TestGroup.CORE }) @TestRail(section = { TestGroup.REST_API, - TestGroup.AUDIT }, executionType = ExecutionType.SANITY, description = "Verify if the admin user gets audit application info") + TestGroup.AUDIT }, executionType = ExecutionType.SANITY, description = "Verify that the admin user can get audit application info") public void getAuditApplicationInfoWithAdminUser() throws Exception { - restAuditCollection = restClient.authenticateUser(dataUser.getAdminUser()).withCoreAPI().usingAudit().getAuditApplications(); - restClient.assertStatusCodeIs(HttpStatus.OK); - restAuditCollection.assertThat().entriesListIsNotEmpty(); - - RestAuditAppModel firstRestAuditAppModel = restAuditCollection.getEntries().get(0).onModel(); - firstRestAuditAppModel.assertThat().field("isEnabled").is(true); - firstRestAuditAppModel.assertThat().field("name").is("Alfresco Sync Service"); - firstRestAuditAppModel.assertThat().field("id").is("sync"); + syncRestAuditAppModel = getSyncRestAuditAppModel(dataUser.getAdminUser()); + syncRestAuditAppModel.assertThat().field("isEnabled").is(true); + syncRestAuditAppModel.assertThat().field("name").is("Alfresco Sync Service"); + syncRestAuditAppModel.assertThat().field("id").is("sync"); - restClient.authenticateUser(dataUser.getAdminUser()).withCoreAPI().usingAudit() - .getAuditApp(firstRestAuditAppModel).assertThat().field("isEnabled").is(true); - - restClient.authenticateUser(dataUser.getAdminUser()).withCoreAPI().usingAudit() - .getAuditApp(firstRestAuditAppModel).assertThat().field("name").is("Alfresco Sync Service"); - - restClient.authenticateUser(dataUser.getAdminUser()).withCoreAPI().usingAudit() - .getAuditApp(firstRestAuditAppModel).assertThat().field("id").is("sync"); - - RestAuditAppModel secondRestAuditAppModel = restAuditCollection.getEntries().get(1).onModel(); - secondRestAuditAppModel.assertThat().field("isEnabled").is(true); - secondRestAuditAppModel.assertThat().field("name").is("Alfresco Tagging Service"); - secondRestAuditAppModel.assertThat().field("id").is("tagging"); - - restClient.authenticateUser(dataUser.getAdminUser()).withCoreAPI().usingAudit() - .getAuditApp(secondRestAuditAppModel).assertThat().field("isEnabled").is(true); - - restClient.authenticateUser(dataUser.getAdminUser()).withCoreAPI().usingAudit() - .getAuditApp(secondRestAuditAppModel).assertThat().field("name").is("Alfresco Tagging Service"); - - restClient.authenticateUser(dataUser.getAdminUser()).withCoreAPI().usingAudit() - .getAuditApp(secondRestAuditAppModel).assertThat().field("id").is("tagging"); + taggingRestAuditAppModel = getTaggingRestAuditAppModel(dataUser.getAdminUser()); + taggingRestAuditAppModel.assertThat().field("isEnabled").is(true); + taggingRestAuditAppModel.assertThat().field("name").is("Alfresco Tagging Service"); + taggingRestAuditAppModel.assertThat().field("id").is("tagging"); } diff --git a/e2e-test/java/org/alfresco/rest/audit/PutAuditCoreTests.java b/e2e-test/java/org/alfresco/rest/audit/PutAuditCoreTests.java index efdbbedda..05a28bf2f 100644 --- a/e2e-test/java/org/alfresco/rest/audit/PutAuditCoreTests.java +++ b/e2e-test/java/org/alfresco/rest/audit/PutAuditCoreTests.java @@ -1,6 +1,103 @@ package org.alfresco.rest.audit; +import org.alfresco.utility.model.TestGroup; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.springframework.http.HttpStatus; +import org.testng.annotations.Test; + public class PutAuditCoreTests extends AuditTest { + @Test(groups = { TestGroup.REST_API, TestGroup.AUDIT, TestGroup.CORE }) + @TestRail(section = { TestGroup.REST_API, + TestGroup.AUDIT }, executionType = ExecutionType.SANITY, description = "Verify that the admin user can enable/disable sync application auditing") + public void enableDisableSyncApplicationAuditingAsAdminUser() throws Exception + { + //disable sync audit app + syncRestAuditAppModel = getSyncRestAuditAppModel(dataUser.getAdminUser()); + restClient.authenticateUser(dataUser.getAdminUser()).withCoreAPI().usingAudit().updateAuditApp(syncRestAuditAppModel, "isEnabled", "false"); + + //check isEnabled=false + syncRestAuditAppModel = getSyncRestAuditAppModel(dataUser.getAdminUser()); + syncRestAuditAppModel.assertThat().field("isEnabled").is(false); + syncRestAuditAppModel.assertThat().field("name").is("Alfresco Sync Service"); + syncRestAuditAppModel.assertThat().field("id").is("sync"); + + //enable sync audit app + restClient.authenticateUser(dataUser.getAdminUser()).withCoreAPI().usingAudit().updateAuditApp(syncRestAuditAppModel, "isEnabled", "true"); + + //check isEnabled=true + syncRestAuditAppModel = getSyncRestAuditAppModel(dataUser.getAdminUser()); + syncRestAuditAppModel.assertThat().field("isEnabled").is(true); + syncRestAuditAppModel.assertThat().field("name").is("Alfresco Sync Service"); + syncRestAuditAppModel.assertThat().field("id").is("sync"); + + } + + @Test(groups = { TestGroup.REST_API, TestGroup.AUDIT, TestGroup.CORE }) + @TestRail(section = { TestGroup.REST_API, + TestGroup.AUDIT }, executionType = ExecutionType.SANITY, description = "Verify that the admin user can enable/disable tagging application auditing") + public void enableDisableTaggingApplicationAuditingAsAdminUser() throws Exception + { + //disable tagging audit app + taggingRestAuditAppModel = getTaggingRestAuditAppModel(dataUser.getAdminUser()); + restClient.authenticateUser(dataUser.getAdminUser()).withCoreAPI().usingAudit().updateAuditApp(taggingRestAuditAppModel, "isEnabled", "false"); + + //check isEnabled=false + taggingRestAuditAppModel = getTaggingRestAuditAppModel(dataUser.getAdminUser()); + taggingRestAuditAppModel.assertThat().field("isEnabled").is(false); + taggingRestAuditAppModel.assertThat().field("name").is("Alfresco Tagging Service"); + taggingRestAuditAppModel.assertThat().field("id").is("tagging"); + + //enable tagging audit app + restClient.authenticateUser(dataUser.getAdminUser()).withCoreAPI().usingAudit().updateAuditApp(taggingRestAuditAppModel, "isEnabled", "true"); + + //check isEnabled=true + taggingRestAuditAppModel = getTaggingRestAuditAppModel(dataUser.getAdminUser()); + taggingRestAuditAppModel.assertThat().field("isEnabled").is(true); + taggingRestAuditAppModel.assertThat().field("name").is("Alfresco Tagging Service"); + taggingRestAuditAppModel.assertThat().field("id").is("tagging"); + + } + + + @Test(groups = { TestGroup.REST_API, TestGroup.AUDIT, TestGroup.CORE }) + @TestRail(section = { TestGroup.REST_API, + TestGroup.AUDIT }, executionType = ExecutionType.SANITY, description = "Verify that the normal user can't enable/disable sync application auditing") + public void enableDisableSyncApplicationAuditingAsNormalUser() throws Exception + { + //disable sync audit app + syncRestAuditAppModel = getSyncRestAuditAppModel(dataUser.getAdminUser()); + restClient.authenticateUser(userModel).withCoreAPI().usingAudit().updateAuditApp(syncRestAuditAppModel, "isEnabled", "false"); + + //permission denied + restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN); + + //enable sync audit app + restClient.authenticateUser(userModel).withCoreAPI().usingAudit().updateAuditApp(syncRestAuditAppModel, "isEnabled", "true"); + + //permission denied + restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.AUDIT, TestGroup.CORE }) + @TestRail(section = { TestGroup.REST_API, + TestGroup.AUDIT }, executionType = ExecutionType.SANITY, description = "Verify that the normal user can't enable/disable tagging application auditing") + public void enableDisableTaggingApplicationAuditingAsNormalUser() throws Exception + { + //disable tagging audit app + taggingRestAuditAppModel = getTaggingRestAuditAppModel(dataUser.getAdminUser()); + restClient.authenticateUser(userModel).withCoreAPI().usingAudit().updateAuditApp(taggingRestAuditAppModel, "isEnabled", "false"); + + //permission denied + restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN); + + //disable tagging audit app + restClient.authenticateUser(userModel).withCoreAPI().usingAudit().updateAuditApp(taggingRestAuditAppModel, "isEnabled", "true"); + + //permission denied + restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN); + + } }