-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#435 Ensuring that 'admin' role cannot be deleted on undeploy
- Loading branch information
Showing
4 changed files
with
87 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
src/test/java/com/marklogic/appdeployer/command/security/DontUndeployCertainRolesTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package com.marklogic.appdeployer.command.security; | ||
|
||
import com.marklogic.appdeployer.AbstractAppDeployerTest; | ||
import com.marklogic.mgmt.resource.security.RoleManager; | ||
import com.marklogic.mgmt.resource.security.UserManager; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.io.File; | ||
import java.util.Set; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
public class DontUndeployCertainRolesTest extends AbstractAppDeployerTest { | ||
|
||
@Test | ||
public void test() { | ||
final String testRole = "ml-app-deployer-test-role"; | ||
final String adminRole = "admin"; | ||
|
||
appConfig.getFirstConfigDir().setBaseDir(new File("src/test/resources/sample-app/users-to-not-undeploy")); | ||
initializeAppDeployer(new DeployRolesCommand()); | ||
|
||
RoleManager mgr = new RoleManager(manageClient); | ||
assertFalse(mgr.exists(testRole)); | ||
assertTrue(mgr.exists(adminRole)); | ||
|
||
deploySampleApp(); | ||
|
||
try { | ||
assertTrue(mgr.exists(testRole)); | ||
assertTrue(mgr.exists(adminRole)); | ||
} finally { | ||
undeploySampleApp(); | ||
|
||
assertFalse(mgr.exists(testRole)); | ||
assertTrue(mgr.exists(adminRole), "The 'admin' role should not have been deleted since it's in the list of " + | ||
"roles to not undeploy"); | ||
} | ||
} | ||
|
||
@Test | ||
public void verifySetOfDefaultRoles() { | ||
Set<String> roles = new DeployRolesCommand().getDefaultRolesToNotUndeploy(); | ||
assertEquals(3, roles.size(), "The main role we don't want to delete is admin, but manage-admin and " + | ||
"security are included as well just to be safe, as those two roles together can allow for any other " + | ||
"role to be recreated"); | ||
assertTrue(roles.contains("admin")); | ||
assertTrue(roles.contains("manage-admin")); | ||
assertTrue(roles.contains("security")); | ||
} | ||
|
||
} |
4 changes: 4 additions & 0 deletions
4
src/test/resources/sample-app/users-to-not-undeploy/security/roles/admin.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"role-name": "admin", | ||
"description": "Not clear why someone would try to modify this role, but just in case, we don't want to delete it on undeploy" | ||
} |
4 changes: 4 additions & 0 deletions
4
src/test/resources/sample-app/users-to-not-undeploy/security/roles/testRole.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"role-name": "ml-app-deployer-test-role", | ||
"description": "This is here to make sure we can delete it" | ||
} |