|
1 | 1 | package com.marklogic.appdeployer.command.restapis; |
2 | 2 |
|
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 | | - |
10 | 3 | import com.marklogic.appdeployer.AbstractAppDeployerTest; |
11 | 4 | import com.marklogic.appdeployer.ConfigDir; |
12 | 5 | import com.marklogic.appdeployer.command.security.DeployRolesCommand; |
|
15 | 8 | import com.marklogic.mgmt.ManageClient; |
16 | 9 | import com.marklogic.mgmt.ManageConfig; |
17 | 10 | 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; |
18 | 15 |
|
19 | | -public class CreateRestApiAsNonAdminUserTest extends AbstractAppDeployerTest { |
| 16 | +import java.io.File; |
20 | 17 |
|
21 | | - @Autowired |
22 | | - private ManageConfig manageConfig; |
| 18 | +public class CreateRestApiAsNonAdminUserTest extends AbstractAppDeployerTest { |
23 | 19 |
|
24 | | - private XccTemplate xccTemplate; |
| 20 | + @Autowired |
| 21 | + private ManageConfig manageConfig; |
25 | 22 |
|
26 | | - @Before |
27 | | - public void setup() { |
28 | | - xccTemplate = newModulesXccTemplate(); |
29 | | - } |
| 23 | + private XccTemplate xccTemplate; |
30 | 24 |
|
31 | | - @After |
32 | | - public void teardown() { |
33 | | - undeploySampleApp(); |
34 | | - } |
| 25 | + @Before |
| 26 | + public void setup() { |
| 27 | + xccTemplate = newModulesXccTemplate(); |
| 28 | + } |
35 | 29 |
|
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 | + } |
43 | 34 |
|
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"); |
51 | 42 |
|
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); |
56 | 50 |
|
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"); |
60 | 55 |
|
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); |
67 | 59 |
|
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 | + } |
72 | 66 | } |
0 commit comments