package it.com.atlassian.stash.rest;

import com.atlassian.stash.internal.ApplicationConstants;
import com.atlassian.bitbucket.test.DefaultFuncTestData;
import com.atlassian.bitbucket.test.PermissionsTestHelper;
import com.atlassian.bitbucket.test.ResponsePage;
import com.atlassian.bitbucket.test.RestTestHelper;
import com.atlassian.bitbucket.permission.Permission;
import com.google.common.collect.Maps;
import com.jayway.restassured.RestAssured;
import com.jayway.restassured.path.json.JsonPath;
import com.jayway.restassured.response.Response;
import com.jayway.restassured.specification.RequestSpecification;
import it.com.atlassian.stash.BaseRestTest;
import net.sf.json.JSONObject;
import org.hamcrest.collection.IsIn;
import org.junit.BeforeClass;
import org.junit.Test;

import javax.ws.rs.core.MediaType;
import java.util.HashMap;
import java.util.Map;

import static com.atlassian.bitbucket.test.DefaultFuncTestData.*;
import static com.atlassian.bitbucket.permission.Permission.*;
import static javax.ws.rs.core.Response.Status.*;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.hasEntry;
import static org.junit.Assert.*;

public class PermissionAdminResourceTest extends BaseRestTest {

    private static final String TEST_PROJECT = PermissionAdminResourceTest.class.getSimpleName().toUpperCase();
    private static final String TEST_REPO = PermissionAdminResourceTest.class.getSimpleName().toLowerCase();

    private static final String ADMIN_USER = getAdminUser();
    private static final String REGULAR_USER = getRegularUser();
    private static final String UNLICENSED_USER = "unlicensed";

    private static final String REGULAR_GROUP = ApplicationConstants.STASH_USERS;
    private static final String TEST_GROUP = "permission-test-group";

    private RestTestHelper adminHelper = new RestTestHelper(ADMIN_USER, getAdminPassword());

    @BeforeClass
    public static void createTestGroup() {
        getClassTestContext()
                .project(TEST_PROJECT)
                .repository(TEST_PROJECT, TEST_REPO)
                .group(TEST_GROUP)
                .user(UNLICENSED_USER, false);
    }

    @Test
    public void testGetUsersWithGlobalPermission() throws Exception {
        Map<String, String> expectedWith = new HashMap<>();
        expectedWith.put(ADMIN_USER, SYS_ADMIN.name());
        String[] expectedWithout = new String[]{REGULAR_USER, UNLICENSED_USER};
        testGetUsersWithPermissions("/admin/permissions/users", expectedWith, expectedWithout);
    }

    @Test
    public void testGetUsersWithProjectPermission() throws Exception {
        Map<String, String> results = new HashMap<>();
        results.put(ADMIN_USER, PROJECT_ADMIN.name());
        String[] expectedWithout = new String[]{REGULAR_USER}; // unlicensed user should not be returned here
        testGetUsersWithPermissions("/projects/" + TEST_PROJECT + "/permissions/users", results, expectedWithout);
    }

    @Test
    public void testGetUsersWithRepositoryPermission() throws Exception {
        testContext.repositoryPermission(TEST_PROJECT, TEST_REPO, REGULAR_USER, REPO_READ);
        Map<String, String> expectedWith = new HashMap<>();
        expectedWith.put(REGULAR_USER, REPO_READ.name());
        String[] expectedWithout = new String[]{ADMIN_USER}; // unlicensed user should not be returned here
        testGetUsersWithPermissions("/projects/" + TEST_PROJECT + "/repos/" + TEST_REPO + "/permissions/users",
                expectedWith, expectedWithout);
    }

    @Test
    public void testSetGlobalPermissionForUser() throws Exception {
        final String permission = ADMIN.name();
        testSetPermissionForUser("/admin/permissions/users", permission, 1);
    }

    @Test
    public void testSetGlobalPermissionForMultipleUsers() throws Exception {
        final String permission = ADMIN.name();
        testSetPermissionForMultipleUsers("/admin/permissions/users", permission);
    }

    @Test
    public void testSetGlobalPermissionForUserWithNonGlobalPermissions() throws Exception {
        Permission[] permissions = {PROJECT_ADMIN, REPO_ADMIN};
        for (Permission permission : permissions) {
            adminHelper.put("/admin/permissions/users?permission=" + permission + "&name=" + REGULAR_USER, BAD_REQUEST);
        }
    }

    @Test
    public void testSetGlobalPermissionForEmptyUser() throws Exception {
        adminHelper.put("/admin/permissions/users?permission=" + ADMIN + "&name=", BAD_REQUEST);
    }

    @Test
    public void testSetGlobalPermissionForInexistentUser() throws Exception {
        adminHelper.put("/admin/permissions/users?permission=" + ADMIN + "&name=user123456", NOT_FOUND);
    }

    @Test
    public void testSetProjectPermissionForUser() throws Exception {
        final String permission = PROJECT_ADMIN.name();
        testSetPermissionForUser("/projects/" + TEST_PROJECT + "/permissions/users", permission, 1);
    }

    @Test
    public void testSetProjectPermissionForMultipleUsers() throws Exception {
        final String permission = PROJECT_ADMIN.name();
        testSetPermissionForMultipleUsers("/projects/" + TEST_PROJECT + "/permissions/users", permission);
    }

    @Test
    public void testCanNotSetOrRevokeProjectPermissionOnPersonalProjects() throws Exception {
        String user = ADMIN_USER;
        // personal projects are lazily created, for example when a repository is forked into a personal project
        testContext.fork(DefaultFuncTestData.getProject1(), DefaultFuncTestData.getProject1Repository1(), user, user);

        // granting to a user
        Response response = adminHelper.put("/projects/~" + user + "/permissions/users" + "?permission=" + PROJECT_READ.name() + "&name=" + REGULAR_USER, CONFLICT);
        assertThat(response.asString(), containsString("personal project"));

        // granting to a group
        response = adminHelper.put("/projects/~" + user + "/permissions/groups" + "?permission=" + PROJECT_READ.name() + "&name=" + REGULAR_GROUP, CONFLICT);
        assertThat(response.asString(), containsString("personal project"));

        // revoking from the user
        response = adminHelper.delete("/projects/~" + user + "/permissions/users" + "?permission=" + PROJECT_READ.name() + "&name=" + user, CONFLICT);
        assertThat(response.asString(), containsString("personal project"));

        // revoking from a group
        response = adminHelper.delete("/projects/~" + user + "/permissions/groups" + "?permission=" + PROJECT_READ.name() + "&name=stash-users", CONFLICT);
        assertThat(response.asString(), containsString("personal project"));

        // granting a default project permission
        response = adminHelper.post("/projects/~" + user + "/permissions/" + PROJECT_READ.name() + "/all?allow=true", CONFLICT);
        assertThat(response.asString(), containsString("personal project"));

        // revoking a default project permission
        response = adminHelper.post("/projects/~" + user + "/permissions/" + PROJECT_READ.name() + "/all?allow=false", CONFLICT);
        assertThat(response.asString(), containsString("personal project"));
    }

    @Test
    public void testSetRepositoryPermissionForUser() throws Exception {
        String permission = REPO_ADMIN.name();
        testSetPermissionForUser("/projects/" + TEST_PROJECT + "/repos/" + TEST_REPO + "/permissions/users",
                permission, 0);
    }

    @Test
    public void testSetRepositoryPermissionForMultipleUsers() throws Exception {
        String permission = REPO_ADMIN.name();
        testSetPermissionForMultipleUsers("/projects/" + TEST_PROJECT + "/repos/" + TEST_REPO + "/permissions/users", permission);
    }

    @Test
    public void testSetProjectPermissionForUserWithNonProjectPermissions() throws Exception {
        Permission[] permissions = {ADMIN, REPO_ADMIN};
        for (Permission permission : permissions) {
            adminHelper.put("/projects/" + TEST_PROJECT + "/permissions/users?permission=" + permission + "&name=" + REGULAR_USER, BAD_REQUEST);
        }
    }

    @Test
    public void testGetGroupsWithGlobalPermissions() throws Exception {
        Map<String, String> expectedWith = new HashMap<>();
        expectedWith.put(REGULAR_GROUP, LICENSED_USER.name());
        String[] expectedWithout = new String[]{TEST_GROUP};
        testGetGroupsWithPermissions("/admin/permissions/groups", expectedWith, expectedWithout);
    }

    @Test
    public void testGetGroupsWithProjectPermissions() throws Exception {
        Map<String, String> expectedWith = new HashMap<>();
        expectedWith.put(REGULAR_GROUP, PROJECT_WRITE.name());
        String[] expectedWithout = new String[]{TEST_GROUP};
        try {
            PermissionsTestHelper.setProjectPermissionForGroup(TEST_PROJECT, REGULAR_GROUP, PROJECT_WRITE.name());
            testGetGroupsWithPermissions("/projects/" + TEST_PROJECT + "/permissions/groups", expectedWith, expectedWithout);
        } finally {
            PermissionsTestHelper.revokeProjectPermissionForGroup(TEST_PROJECT, REGULAR_GROUP);
        }
    }

    @Test
    public void testGetGroupsWithRepositoryPermissions() throws Exception {
        Map<String, String> expectedWith = new HashMap<>();
        expectedWith.put(REGULAR_GROUP, REPO_READ.name());
        String[] expectedWithout = new String[]{TEST_GROUP};
        try {
            PermissionsTestHelper.setRepositoryPermissionForGroup(TEST_PROJECT, TEST_REPO, REGULAR_GROUP, REPO_READ.name());
            testGetGroupsWithPermissions("/projects/" + TEST_PROJECT + "/repos/" + TEST_REPO + "/permissions/groups", expectedWith, expectedWithout);
        } finally {
            PermissionsTestHelper.revokeRepositoryPermissionForGroup(TEST_PROJECT, TEST_REPO, REGULAR_GROUP);
        }
    }

    @Test
    public void testSetGlobalPermissionForGroup() throws Exception {
        final String permission = PROJECT_CREATE.name();
        testSetPermissionsForGroup("/admin/permissions/groups", permission, 1);
    }

    @Test
    public void testSetGlobalPermissionForMultipleGroups() throws Exception {
        final String permission = ADMIN.name();
        testSetPermissionForMultipleGroups("/admin/permissions/groups", permission);
    }

    @Test
    public void testSetGlobalPermissionForGroupWithNonGlobalPermissions() throws Exception {
        Permission[] permissions = {PROJECT_ADMIN, REPO_ADMIN};
        for (Permission permission : permissions) {
            adminHelper.put("/admin/permissions/groups?permission=" + permission + "&name=" + TEST_GROUP, BAD_REQUEST);
        }
    }

    @Test
    public void testSetGlobalPermissionForEmptyGroup() throws Exception {
        adminHelper.put("/admin/permissions/groups?permission=" + ADMIN + "&name=", BAD_REQUEST);
    }

    @Test
    public void testSetGlobalPermissionForInexistentGroup() throws Exception {
        adminHelper.put("/admin/permissions/groups?permission=" + ADMIN + "&name=group123456", NOT_FOUND);
    }

    @Test
    public void testSetProjectPermissionsForGroup() throws Exception {
        final String permission = PROJECT_READ.name();
        testSetPermissionsForGroup("/projects/" + TEST_PROJECT + "/permissions/groups", permission, 0);
    }

    @Test
    public void testSetProjectPermissionsForMultipleGroups() throws Exception {
        final String permission = PROJECT_READ.name();
        testSetPermissionForMultipleGroups("/projects/" + TEST_PROJECT + "/permissions/groups", permission);
    }

    @Test
    public void testSetRepositoryPermissionsForGroup() throws Exception {
        final String permission = REPO_READ.name();
        testSetPermissionsForGroup("/projects/" + TEST_PROJECT + "/repos/" + TEST_REPO + "/permissions/groups", permission, 0);
    }

    @Test
    public void testSetRepositoryPermissionsForMultipleGroups() throws Exception {
        final String permission = REPO_READ.name();
        testSetPermissionForMultipleGroups("/projects/" + TEST_PROJECT + "/repos/" + TEST_REPO + "/permissions/groups", permission);
    }

    @Test
    public void testSetProjectPermissionForGroupWithNonProjectPermissions() throws Exception {
        Permission[] permissions = {ADMIN, REPO_ADMIN};
        for (Permission permission : permissions) {
            adminHelper.put("/projects/" + TEST_PROJECT + "/permissions/groups?permission=" + permission + "&name=" + TEST_GROUP, BAD_REQUEST);
        }
    }

    @Test
    public void testProjectAllPermissions() throws Exception {
        testAllAnonPermissionAllowed("/projects/" + TEST_PROJECT + "/permissions/project_write/all");
        testAllAnonPermissionAllowed("/projects/" + TEST_PROJECT + "/permissions/project_admin/all");
    }

    @Test
    public void testProjectAllPermissionsWithNonProjectPermissions() throws Exception {
        Permission[] permissions = {ADMIN, REPO_ADMIN};
        for (Permission permission : permissions) {
            adminHelper.post("/projects/" + TEST_PROJECT + "/permissions/" + permission.name().toLowerCase() + "/all?allow=true", BAD_REQUEST);
        }
    }

    @Test
    public void testInvalidPermissionName() throws Exception {
        adminHelper.put("/admin/permissions/users?permission=BLAH&name=" + REGULAR_USER, BAD_REQUEST);
    }

    @Test
    public void testGlobalPermissionAtRepository() throws Exception {
        adminHelper.put("/projects/" + TEST_PROJECT + "/repos/" + TEST_REPO + "/permissions/users?permission=" + LICENSED_USER.name() + "&name=" + REGULAR_USER, BAD_REQUEST);
    }

    @Test
    public void testProjectPermissionAtRepository() throws Exception {
        adminHelper.put("/projects/" + TEST_PROJECT + "/repos/" + TEST_REPO + "/permissions/users?permission=" + PROJECT_WRITE.name() + "&name=" + REGULAR_USER, BAD_REQUEST);
    }

    @Test
    public void testGlobalPermissionAtProject() throws Exception {
        adminHelper.put("/projects/" + TEST_PROJECT + "/permissions/users?permission=" + SYS_ADMIN.name() + "&name=" + REGULAR_USER, BAD_REQUEST);
    }

    @Test
    public void testRepositoryPermissionAtProject() throws Exception {
        adminHelper.put("/projects/" + TEST_PROJECT + "/permissions/users?permission=" + REPO_WRITE.name() + "&name=" + REGULAR_USER, BAD_REQUEST);
    }

    @Test
    public void testProjectPermissionAtGlobal() throws Exception {
        adminHelper.put("/admin/permissions/users?permission=" + PROJECT_ADMIN.name() + "&name=" + REGULAR_USER, BAD_REQUEST);
    }

    @Test
    public void testUnauthorised() throws Exception {
        RestTestHelper userHelper = new RestTestHelper(getRegularUser(), getRegularUserPassword());
        userHelper.put("/admin/permissions/users?permission=" + SYS_ADMIN + "&name=" + REGULAR_USER, UNAUTHORIZED);
        userHelper.delete("/admin/permissions/users?name=" + ADMIN_USER, UNAUTHORIZED);
    }

    @Test
    public void testCanNotRemoveSelf() throws Exception {
        final String tempAdmin = "tempadmin";

        testContext.user(tempAdmin, tempAdmin, tempAdmin, "email@example.com")
                   .globalPermission(tempAdmin, ADMIN);

        RestAssured.
                given().
                auth().preemptive().basic(tempAdmin, tempAdmin).
                queryParam("name", tempAdmin).
                expect().
                statusCode(CONFLICT.getStatusCode()).
                when().
                delete(DefaultFuncTestData.getRestURL() + "/admin/users");
    }

    @Test
    public void testCanNotDowngradePermissionWhenGrantedThroughMultipleGroups() throws Exception {
        String user = "downgrade-test-user";
        Map<String, Permission> initialGroupPermissions = Maps.newHashMapWithExpectedSize(3);
        initialGroupPermissions.put("downgrade-test-group1", Permission.ADMIN);
        initialGroupPermissions.put("downgrade-test-group2", Permission.ADMIN);

        testContext.user(user, false);
        for (String group : initialGroupPermissions.keySet()) {
            testContext.group(group, user);
        }

        // scenario1: the user has ADMIN permissions through two group memberships and he/she is trying
        // to downgrade the permission of both groups to PROJECT_READ (in _one_ REST call)
        Permission targetPermission = PROJECT_CREATE;
        testCanNotDowngradePermissionWhenGrantedThroughMultipleGroups(user, targetPermission, initialGroupPermissions);

        // scenario2: same scenario but with one group having the SYSADMIN permission instead
        initialGroupPermissions.put("downgrade-test-group1", Permission.SYS_ADMIN);
        testCanNotDowngradePermissionWhenGrantedThroughMultipleGroups(user, targetPermission, initialGroupPermissions);
    }

    private Map<String, String> getPermittedGroups(ResponsePage<JSONObject> page) {
        final Map<String, String> permittedGroups = new HashMap<>();
        for (JSONObject value : page.getValues()) {
            permittedGroups.put(value.getJSONObject("group").getString("name"), value.getString("permission"));
        }
        return permittedGroups;
    }

    private Map<String, String> getPermittedUsers(ResponsePage<JSONObject> page) {
        Map<String, String> permittedUsers = new HashMap<>();
        for (JSONObject jsonObject : page.getValues()) {
            permittedUsers.put(jsonObject.getJSONObject("user").getString("name"), jsonObject.getString("permission"));
        }
        return permittedUsers;
    }

    private void testAllAnonPermissionAllowed(String path) {
        try {
            JsonPath response = adminHelper.get(path, OK);
            assertFalse("All should not be currently permitted", response.getBoolean("permitted"));

            adminHelper.post(path + "?allow=true", NO_CONTENT);
            response = adminHelper.get(path, OK);
            assertTrue("All should be permitted", response.getBoolean("permitted"));

            adminHelper.post(path + "?allow=false", NO_CONTENT);
            response = adminHelper.get(path, OK);
            assertFalse("All should be permitted", response.getBoolean("permitted"));
        } finally {
            adminHelper.post(path + "?allow=false", NO_CONTENT);
        }
    }

    private void testCanNotDowngradePermissionWhenGrantedThroughMultipleGroups(String user, Permission targetPermission,
                                                                               Map<String, Permission> groupPermissions) {
        RequestSpecification request = RestAssured.given().auth().preemptive().basic(user, user)
                .contentType(MediaType.APPLICATION_JSON).queryParam("permission", targetPermission);

        for (Map.Entry<String, Permission> entry : groupPermissions.entrySet()) {
            String group = entry.getKey();
            Permission permission = entry.getValue();
            PermissionsTestHelper.setGlobalPermissionForGroup(group, permission.name());
            request.queryParam("name", group);
        }

        request.expect().
                statusCode(CONFLICT.getStatusCode()).
                body(containsString("would downgrade")).
            when().
                put(DefaultFuncTestData.getRestURL() + "/admin/permissions/groups");
    }

    private void testGetGroupsWithPermissions(String permissionGroupPath, Map<String, String> expectedWith,
                                              String[] expectedWithout) {
        ResponsePage<JSONObject> page = adminHelper.getPage(permissionGroupPath, OK);

        for (JSONObject jsonObject : page.getValues()) {
            String groupName = jsonObject.getJSONObject("group").getString("name");
            String permission = expectedWith.get(groupName);
            if (permission != null) {
                assertEquals(expectedWith.get(groupName), jsonObject.get("permission"));
            }
        }

        page = adminHelper.getPage(permissionGroupPath + "/none", OK);
        for (JSONObject jsonObject : page.getValues()) {
            assertThat(jsonObject.getString("name"), IsIn.isIn(expectedWithout));
        }
        assertEquals("Number of groups without permissions explicitly set", expectedWithout.length, page.getSize());
    }

    private void testGetUsersWithPermissions(String permissionUsersPath, Map<String, String> expectedWith,
                                             String[] expectedWithout) {
        ResponsePage<JSONObject> page = adminHelper.getPage(permissionUsersPath, OK);

        for (JSONObject jsonObject : page.getValues()) {
            String username = jsonObject.getJSONObject("user").getString("name");
            assertThat(username, IsIn.isIn(expectedWith.keySet()));
            assertEquals(username + " has correct permission", expectedWith.get(username), jsonObject.get("permission"));
        }

        assertEquals("Number of users with permissions explicitly set", expectedWith.size(), page.getSize());

        page = adminHelper.getPage(permissionUsersPath + "/none", OK);
        assertEquals("Number of users without permissions explicitly set", expectedWithout.length, page.getSize());
        for (JSONObject jsonObject : page.getValues()) {
            assertThat(jsonObject.getString("name"), IsIn.isIn(expectedWithout));
        }
    }

    private void testSetPermissionsForGroup(String permissionPath, String permission, int withPermission) {
        try {
            int withoutPermission = adminHelper.getPage(permissionPath + "/none", OK).getSize();

            adminHelper.put(permissionPath + "?permission=" + permission + "&name=" + TEST_GROUP, NO_CONTENT);

            ResponsePage<JSONObject> page = adminHelper.getPage(permissionPath, OK);

            Map<String, String> permittedGroups = getPermittedGroups(page);
            assertThat(TEST_GROUP, IsIn.isIn(permittedGroups.keySet()));
            assertEquals(TEST_GROUP + " should have " + permission, permission, permittedGroups.get(TEST_GROUP));

            page = adminHelper.getPage(permissionPath + "/none", OK);
            assertEquals("Group should have permission", withoutPermission - 1, page.getSize());
        } finally {
            adminHelper.delete(permissionPath + "?name=" + TEST_GROUP, NO_CONTENT);
        }
    }

    private void testSetPermissionForMultipleGroups(String permissionPath, String permission) {
        String group1 = "test-multiple-groups1", group2 = "test-multiple-groups2";
        testContext.group(group1).group(group2);

        RestAssured.
                given().
                auth().preemptive().basic(getAdminUser(), getAdminPassword()).
                contentType(MediaType.APPLICATION_JSON).
                queryParam("permission", permission).
                queryParam("name", group1).
                queryParam("name", group2).
                expect().statusCode(NO_CONTENT.getStatusCode()).
                when().
                put(DefaultFuncTestData.getRestURL() + permissionPath);

        Map<String, String> permittedGroups = getPermittedGroups(adminHelper.getPage(permissionPath, OK));
        assertThat(permittedGroups, hasEntry(group1, permission));
        assertThat(permittedGroups, hasEntry(group2, permission));
    }

    private void testSetPermissionForMultipleUsers(String permissionPath, String permission) {
        String user1 = "test-multiple-user1", user2 = "test-multiple-user2";
        testContext.user(user1, false)
                .user(user2, false);
        try {
            RestAssured.
                    given().
                    auth().preemptive().basic(getAdminUser(), getAdminPassword()).
                    contentType(MediaType.APPLICATION_JSON).
                    queryParam("permission", permission).
                    queryParam("name", user1).
                    queryParam("name", user2).
                    expect().statusCode(NO_CONTENT.getStatusCode()).
                    when().
                    put(DefaultFuncTestData.getRestURL() + permissionPath);

            Map<String, String> permittedUsers = getPermittedUsers(adminHelper.getPage(permissionPath, OK));
            assertThat(permittedUsers, hasEntry(user1, permission));
            assertThat(permittedUsers, hasEntry(user2, permission));
        } finally {
            // Explicitly revoke permissions because of delayed user cleanup
            RestAssured.
                    given().
                    auth().preemptive().basic(getAdminUser(), getAdminPassword()).
                    contentType(MediaType.APPLICATION_JSON).
                    queryParam("name", user1).
                    expect().statusCode(NO_CONTENT.getStatusCode()).
                    when().
                    delete(DefaultFuncTestData.getRestURL() + permissionPath);
            RestAssured.
                    given().
                    auth().preemptive().basic(getAdminUser(), getAdminPassword()).
                    contentType(MediaType.APPLICATION_JSON).
                    queryParam("name", user2).
                    expect().statusCode(NO_CONTENT.getStatusCode()).
                    when().
                    delete(DefaultFuncTestData.getRestURL() + permissionPath);
        }
    }

    private void testSetPermissionForUser(String permissionPath, String permission, int withPermissions) {
        try {
            int withoutPermission = adminHelper.getPage(permissionPath + "/none", OK).getSize();

            adminHelper.put(permissionPath + "?permission=" + permission + "&name=" + REGULAR_USER, NO_CONTENT);

            ResponsePage<JSONObject> page = adminHelper.getPage(permissionPath, OK);

            assertEquals("user should have permission", 1 + withPermissions, page.getSize());
            Map<String, String> permittedUsers = getPermittedUsers(page);
            assertThat(REGULAR_USER + " should have " + permission, permittedUsers, hasEntry(REGULAR_USER, permission));

            page = adminHelper.getPage(permissionPath + "/none", OK);
            assertEquals("user should have permission", withoutPermission - 1, page.getSize());
        } finally {
            adminHelper.delete(permissionPath + "?name=" + REGULAR_USER, NO_CONTENT);
        }
    }
}
