Skip to content
This repository was archived by the owner on Sep 16, 2024. It is now read-only.

Commit 30f4be0

Browse files
committed
Fixing tests based on 3.17.0 and ML 10.0-2
1 parent 1e22f4d commit 30f4be0

File tree

5 files changed

+62
-90
lines changed

5 files changed

+62
-90
lines changed

src/test/java/com/marklogic/appdeployer/MergeResourcesWhileDeployingTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.marklogic.appdeployer.command.appservers.DeployOtherServersCommand;
44
import com.marklogic.appdeployer.command.databases.DeployOtherDatabasesCommand;
5+
import com.marklogic.appdeployer.command.security.DeployPrivilegeRolesCommand;
56
import com.marklogic.appdeployer.command.security.DeployPrivilegesCommand;
67
import com.marklogic.appdeployer.command.security.DeployRolesCommand;
78
import com.marklogic.appdeployer.command.security.DeployUsersCommand;
@@ -79,7 +80,7 @@ public void roles() {
7980

8081
@Test
8182
public void privileges() {
82-
initializeAppDeployer(new DeployPrivilegesCommand());
83+
initializeAppDeployer(new DeployPrivilegesCommand(), new DeployPrivilegeRolesCommand());
8384
deploySampleApp();
8485

8586
PrivilegeManager mgr = new PrivilegeManager(manageClient);

src/test/java/com/marklogic/appdeployer/command/modules/LoadModulesTest.java

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ public void customModuleTimestampsPath() {
7171
appDeployer.deploy(appConfig);
7272
assertTrue("The custom file should have been created when the modules were loaded", customFile.exists());
7373

74-
DefaultModulesLoader loader = (DefaultModulesLoader)command.getModulesLoader();
75-
PropertiesModuleManager manager = (PropertiesModuleManager)loader.getModulesManager();
74+
DefaultModulesLoader loader = (DefaultModulesLoader) command.getModulesLoader();
75+
PropertiesModuleManager manager = (PropertiesModuleManager) loader.getModulesManager();
7676
assertEquals("The host should have been set on the PropertiesModuleManager via DefaultModulesLoaderFactory " +
7777
"so that module timestamps account for the host", appConfig.getHost(), manager.getHost());
7878
}
@@ -101,19 +101,13 @@ public void loadModulesWithCustomPermissions() {
101101
appDeployer.deploy(appConfig);
102102

103103
PermissionsFragment perms = getDocumentPermissions("/ext/sample-lib.xqy", modulesXccTemplate);
104-
perms.assertPermissionCount(6);
105-
106104
// Default permissions set by AppConfig
107105
perms.assertPermissionExists("rest-admin", "read");
108106
perms.assertPermissionExists("rest-admin", "update");
109107
perms.assertPermissionExists("rest-extension-user", "execute");
110108

111109
// Custom permission
112110
perms.assertPermissionExists("app-user", "execute");
113-
114-
// Permissions that the REST API still applies, which seems like a bug
115-
perms.assertPermissionExists("rest-reader", "read");
116-
perms.assertPermissionExists("rest-writer", "update");
117111
}
118112

119113
@Test
@@ -184,27 +178,11 @@ public void includeModulesPattern() {
184178

185179
private void assertModuleExistsWithDefaultPermissions(String message, String uri) {
186180
assertEquals(message, "true", modulesXccTemplate.executeAdhocQuery(format("fn:doc-available('%s')", uri)));
187-
assertDefaultPermissionsExists(uri);
188-
}
189-
190-
/**
191-
* Apparently, the REST API won't let you remove these 3 default permissions, they're always present.
192-
* <p>
193-
* And, now that we're loading modules via the REST API by default, rest-reader/read and rest-writer/update are
194-
* always present, at least on 8.0-6.3 and 9.0-1.1, which seems like a bug.
195-
*/
196-
private void assertDefaultPermissionsExists(String uri) {
197181
PermissionsFragment perms = getDocumentPermissions(uri, modulesXccTemplate);
198-
perms.assertPermissionCount(5);
199182
perms.assertPermissionExists("rest-admin", "read");
200183
perms.assertPermissionExists("rest-admin", "update");
201184
perms.assertPermissionExists("rest-extension-user", "execute");
202-
203-
// Not really expected!
204-
perms.assertPermissionExists("rest-reader", "read");
205-
perms.assertPermissionExists("rest-writer", "update");
206185
}
207-
208186
}
209187

210188
class TestFileFilter extends DefaultFileFilter {
Lines changed: 44 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,5 @@
11
package com.marklogic.appdeployer.command.restapis;
22

3-
import java.io.File;
4-
5-
import org.junit.After;
6-
import org.junit.Before;
7-
import org.junit.Test;
8-
import org.springframework.beans.factory.annotation.Autowired;
9-
103
import com.marklogic.appdeployer.AbstractAppDeployerTest;
114
import com.marklogic.appdeployer.ConfigDir;
125
import com.marklogic.appdeployer.command.security.DeployRolesCommand;
@@ -15,58 +8,59 @@
158
import com.marklogic.mgmt.ManageClient;
169
import com.marklogic.mgmt.ManageConfig;
1710
import com.marklogic.xcc.template.XccTemplate;
11+
import org.junit.After;
12+
import org.junit.Before;
13+
import org.junit.Test;
14+
import org.springframework.beans.factory.annotation.Autowired;
1815

19-
public class CreateRestApiAsNonAdminUserTest extends AbstractAppDeployerTest {
16+
import java.io.File;
2017

21-
@Autowired
22-
private ManageConfig manageConfig;
18+
public class CreateRestApiAsNonAdminUserTest extends AbstractAppDeployerTest {
2319

24-
private XccTemplate xccTemplate;
20+
@Autowired
21+
private ManageConfig manageConfig;
2522

26-
@Before
27-
public void setup() {
28-
xccTemplate = newModulesXccTemplate();
29-
}
23+
private XccTemplate xccTemplate;
3024

31-
@After
32-
public void teardown() {
33-
undeploySampleApp();
34-
}
25+
@Before
26+
public void setup() {
27+
xccTemplate = newModulesXccTemplate();
28+
}
3529

36-
@Test
37-
@SuppressWarnings("deprecation")
38-
public void test() {
39-
// Use config specific to this test
40-
appConfig.setConfigDir(new ConfigDir(new File("src/test/resources/non-admin-test/ml-config")));
41-
appConfig.getModulePaths().clear();
42-
appConfig.getModulePaths().add("src/test/resources/non-admin-test/ml-modules");
30+
@After
31+
public void teardown() {
32+
undeploySampleApp();
33+
}
4334

44-
// Now rebuild ManageClient using a ManageConfig that doesn't require the admin user
45-
ManageConfig newConfig = new ManageConfig(manageConfig.getHost(), manageConfig.getPort(),
46-
"sample-app-manage-admin", "sample-app-manage-admin");
47-
// Need to set this to the admin user so that user is used to create our app-specific users/roles/privileges
48-
newConfig.setAdminUsername(manageConfig.getUsername());
49-
newConfig.setAdminPassword(manageConfig.getPassword());
50-
this.manageClient = new ManageClient(newConfig);
35+
@Test
36+
@SuppressWarnings("deprecation")
37+
public void test() {
38+
// Use config specific to this test
39+
appConfig.setConfigDir(new ConfigDir(new File("src/test/resources/non-admin-test/ml-config")));
40+
appConfig.getModulePaths().clear();
41+
appConfig.getModulePaths().add("src/test/resources/non-admin-test/ml-modules");
5142

52-
// And ensure we use our custom user for loading modules; the custom app role has the privileges required for
53-
// inserting modules via the REST API
54-
appConfig.setRestAdminUsername("sample-app-rest-admin");
55-
appConfig.setRestAdminPassword("sample-app-rest-admin");
43+
// Now rebuild ManageClient using a ManageConfig that doesn't require the admin user
44+
ManageConfig newConfig = new ManageConfig(manageConfig.getHost(), manageConfig.getPort(),
45+
"sample-app-manage-admin", "sample-app-manage-admin");
46+
// Need to set this to the admin user so that user is used to create our app-specific users/roles/privileges
47+
newConfig.setAdminUsername(manageConfig.getUsername());
48+
newConfig.setAdminPassword(manageConfig.getPassword());
49+
this.manageClient = new ManageClient(newConfig);
5650

57-
initializeAppDeployer(new DeployRestApiServersCommand(true), new DeployRolesCommand(), new DeployUsersCommand(),
58-
buildLoadModulesCommand());
59-
appDeployer.deploy(appConfig);
51+
// And ensure we use our custom user for loading modules; the custom app role has the privileges required for
52+
// inserting modules via the REST API
53+
appConfig.setRestAdminUsername("sample-app-rest-admin");
54+
appConfig.setRestAdminPassword("sample-app-rest-admin");
6055

61-
// And now ensure that the module was loaded correctly
62-
PermissionsFragment perms = getDocumentPermissions("/ext/hello-lib.xqy", xccTemplate);
63-
perms.assertPermissionCount(5);
64-
perms.assertPermissionExists("rest-admin", "read");
65-
perms.assertPermissionExists("rest-admin", "update");
66-
perms.assertPermissionExists("rest-extension-user", "execute");
56+
initializeAppDeployer(new DeployRestApiServersCommand(true), new DeployRolesCommand(), new DeployUsersCommand(),
57+
buildLoadModulesCommand());
58+
appDeployer.deploy(appConfig);
6759

68-
// Non-expected permissions that ML, as of 9.0-1.1, still adds by default
69-
perms.assertPermissionExists("rest-reader", "read");
70-
perms.assertPermissionExists("rest-writer", "update");
71-
}
60+
// And now ensure that the module was loaded correctly
61+
PermissionsFragment perms = getDocumentPermissions("/ext/hello-lib.xqy", xccTemplate);
62+
perms.assertPermissionExists("rest-admin", "read");
63+
perms.assertPermissionExists("rest-admin", "update");
64+
perms.assertPermissionExists("rest-extension-user", "execute");
65+
}
7266
}

src/test/java/com/marklogic/appdeployer/scaffold/WritePrivilegeTest.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.marklogic.appdeployer.scaffold;
22

3+
import com.marklogic.appdeployer.command.security.DeployPrivilegeRolesCommand;
34
import com.marklogic.appdeployer.command.security.DeployPrivilegesCommand;
45
import com.marklogic.mgmt.api.security.Privilege;
56
import com.marklogic.mgmt.template.security.PrivilegeTemplateBuilder;
@@ -11,7 +12,7 @@ public class WritePrivilegeTest extends AbstractResourceWriterTest {
1112

1213
@Test
1314
public void defaultValues() {
14-
initializeAppDeployer(new DeployPrivilegesCommand());
15+
initializeAppDeployer(new DeployPrivilegesCommand(), new DeployPrivilegeRolesCommand());
1516
buildResourceAndDeploy(new PrivilegeTemplateBuilder());
1617

1718
Privilege p = api.privilegeExecute("CHANGEME-name-of-privilege");
@@ -31,16 +32,13 @@ public void uriPrivilege() {
3132
propertyMap.put("privilege-name", "CHANGEME-uri-privilege");
3233
propertyMap.put("action", "test");
3334
propertyMap.put("kind", "uri");
35+
propertyMap.put("role", null);
3436
buildResourceAndDeploy(new PrivilegeTemplateBuilder());
3537

3638
Privilege p = api.privilegeUri("CHANGEME-uri-privilege");
3739
// Odd, the Manage API automatically appends a "/"
3840
assertEquals("test/", p.getAction());
3941
assertEquals("uri", p.getKind());
40-
41-
List<String> roles = p.getRole();
42-
assertEquals(2, roles.size());
43-
assertTrue(roles.contains("rest-reader"));
44-
assertTrue(roles.contains("rest-writer"));
42+
assertNull(p.getRole());
4543
}
4644
}

src/test/java/com/marklogic/mgmt/api/security/SortRolesTest.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -92,17 +92,18 @@ public void evenMoreRolesWithDependencies() throws Exception {
9292

9393
sortRoles();
9494

95+
List<String> roleNames = new ArrayList<>();
96+
for (Role role : roles) {
97+
roleNames.add(role.getRoleName());
98+
}
99+
95100
assertEquals("xyz-reader", roles.get(0).getRoleName());
96101
assertEquals("xyz-writer", roles.get(1).getRoleName());
97-
assertEquals("xyz-admin", roles.get(2).getRoleName());
98-
assertEquals("abc-sss-ui-role", roles.get(3).getRoleName());
99-
assertEquals("abc-ui-offline-user", roles.get(4).getRoleName());
100-
assertEquals("abc-ui-offline-admin", roles.get(5).getRoleName());
101-
assertEquals("Doesn't matter when this is created because it has no dependencies",
102-
"abc-ui-developer", roles.get(6).getRoleName());
103-
assertEquals("abc-ui-admin", roles.get(7).getRoleName());
104-
assertEquals("Doesn't matter when this is created because it has no dependencies",
105-
"abc-login-role", roles.get(8).getRoleName());
102+
103+
// The exact positions of these don't matter, but rather the order does
104+
assertTrue(roleNames.indexOf("abc-ui-offline-user") > roleNames.indexOf("abc-sss-ui-role"));
105+
assertTrue(roleNames.indexOf("abc-ui-offline-admin") > roleNames.indexOf("abc-ui-offline-user"));
106+
assertTrue(roleNames.indexOf("abc-ui-admin") > roleNames.indexOf("abc-ui-offline-admin"));
106107
}
107108

108109
private void sortRoles() {

0 commit comments

Comments
 (0)