Browse Source

[Improvement-12623][Permission]Remove the unused projectIds in operationPermissionCheck() (#12624)

3.2.0-release
rickchengx 2 years ago committed by GitHub
parent
commit
3ff328c961
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/permission/ResourcePermissionCheckService.java
  2. 2
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/permission/ResourcePermissionCheckServiceImpl.java
  3. 4
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/BaseServiceImpl.java
  4. 4
      dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/permission/ResourcePermissionCheckServiceTest.java
  5. 4
      dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/AccessTokenServiceTest.java
  6. 12
      dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/AlertGroupServiceTest.java
  7. 6
      dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/AlertPluginInstanceServiceTest.java
  8. 4
      dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/DataSourceServiceTest.java
  9. 2
      dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/DqExecuteResultServiceTest.java
  10. 2
      dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/DqRuleServiceTest.java
  11. 6
      dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/EnvironmentServiceTest.java
  12. 2
      dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/MonitorServiceTest.java
  13. 26
      dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ProjectServiceTest.java
  14. 4
      dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/QueueServiceTest.java
  15. 12
      dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/TaskGroupServiceTest.java
  16. 6
      dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/TenantServiceTest.java
  17. 20
      dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/UdfFuncServiceTest.java
  18. 4
      dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/UsersServiceTest.java
  19. 16
      dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/WorkerGroupServiceTest.java

2
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/permission/ResourcePermissionCheckService.java

@ -50,7 +50,7 @@ public interface ResourcePermissionCheckService<T> {
* @param logger * @param logger
* @return * @return
*/ */
boolean operationPermissionCheck(Object authorizationType, Object[] projectIds, Integer userId, boolean operationPermissionCheck(Object authorizationType, Integer userId,
String permissionKey, Logger logger); String permissionKey, Logger logger);
/** /**

2
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/permission/ResourcePermissionCheckServiceImpl.java

@ -122,7 +122,7 @@ public class ResourcePermissionCheckServiceImpl
} }
@Override @Override
public boolean operationPermissionCheck(Object authorizationType, Object[] projectIds, Integer userId, public boolean operationPermissionCheck(Object authorizationType, Integer userId,
String permissionKey, Logger logger) { String permissionKey, Logger logger) {
User user = processService.getUserById(userId); User user = processService.getUserById(userId);
if (user == null) { if (user == null) {

4
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/BaseServiceImpl.java

@ -177,8 +177,8 @@ public class BaseServiceImpl implements BaseService {
*/ */
@Override @Override
public boolean canOperatorPermissions(User user, Object[] ids, AuthorizationType type, String permissionKey) { public boolean canOperatorPermissions(User user, Object[] ids, AuthorizationType type, String permissionKey) {
boolean operationPermissionCheck = resourcePermissionCheckService.operationPermissionCheck(type, boolean operationPermissionCheck =
type.equals(AuthorizationType.PROJECTS) ? ids : null, user.getId(), permissionKey, logger); resourcePermissionCheckService.operationPermissionCheck(type, user.getId(), permissionKey, logger);
boolean resourcePermissionCheck = resourcePermissionCheckService.resourcePermissionCheck(type, ids, boolean resourcePermissionCheck = resourcePermissionCheckService.resourcePermissionCheck(type, ids,
user.getUserType().equals(UserType.ADMIN_USER) ? 0 : user.getId(), logger); user.getUserType().equals(UserType.ADMIN_USER) ? 0 : user.getId(), logger);
return operationPermissionCheck && resourcePermissionCheck; return operationPermissionCheck && resourcePermissionCheck;

4
dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/permission/ResourcePermissionCheckServiceTest.java

@ -79,10 +79,10 @@ public class ResourcePermissionCheckServiceTest {
User user = new User(); User user = new User();
user.setId(1); user.setId(1);
resourcePermissionCheckServices.setApplicationContext(context); resourcePermissionCheckServices.setApplicationContext(context);
Assertions.assertFalse(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.PROJECTS, null, Assertions.assertFalse(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.PROJECTS,
user.getId(), null, logger)); user.getId(), null, logger));
String sourceUrl = "/tmp/"; String sourceUrl = "/tmp/";
Assertions.assertFalse(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.PROJECTS, null, Assertions.assertFalse(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.PROJECTS,
user.getId(), sourceUrl, logger)); user.getId(), sourceUrl, logger));
} }

4
dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/AccessTokenServiceTest.java

@ -143,7 +143,7 @@ public class AccessTokenServiceTest {
User userLogin = new User(); User userLogin = new User();
userLogin.setId(1); userLogin.setId(1);
userLogin.setUserType(UserType.ADMIN_USER); userLogin.setUserType(UserType.ADMIN_USER);
Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.ACCESS_TOKEN, null, 1, Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.ACCESS_TOKEN, 1,
ACCESS_TOKEN_DELETE, baseServiceLogger)).thenReturn(true); ACCESS_TOKEN_DELETE, baseServiceLogger)).thenReturn(true);
Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.ACCESS_TOKEN, null, 0, Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.ACCESS_TOKEN, null, 0,
baseServiceLogger)).thenReturn(true); baseServiceLogger)).thenReturn(true);
@ -171,7 +171,7 @@ public class AccessTokenServiceTest {
User user = new User(); User user = new User();
user.setId(1); user.setId(1);
user.setUserType(UserType.ADMIN_USER); user.setUserType(UserType.ADMIN_USER);
Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.ACCESS_TOKEN, null, 1, Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.ACCESS_TOKEN, 1,
ACCESS_TOKEN_UPDATE, baseServiceLogger)).thenReturn(true); ACCESS_TOKEN_UPDATE, baseServiceLogger)).thenReturn(true);
Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.ACCESS_TOKEN, null, 0, Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.ACCESS_TOKEN, null, 0,
baseServiceLogger)).thenReturn(true); baseServiceLogger)).thenReturn(true);

12
dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/AlertGroupServiceTest.java

@ -130,7 +130,7 @@ public class AlertGroupServiceTest {
user.setUserType(UserType.ADMIN_USER); user.setUserType(UserType.ADMIN_USER);
user.setId(0); user.setId(0);
// success // success
Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.ALERT_GROUP, null, Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.ALERT_GROUP,
user.getId(), ALERT_GROUP_CREATE, baseServiceLogger)).thenReturn(true); user.getId(), ALERT_GROUP_CREATE, baseServiceLogger)).thenReturn(true);
Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.ALERT_GROUP, null, Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.ALERT_GROUP, null,
user.getId(), baseServiceLogger)).thenReturn(true); user.getId(), baseServiceLogger)).thenReturn(true);
@ -148,7 +148,7 @@ public class AlertGroupServiceTest {
User user = new User(); User user = new User();
user.setUserType(UserType.ADMIN_USER); user.setUserType(UserType.ADMIN_USER);
user.setId(0); user.setId(0);
Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.ALERT_GROUP, null, Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.ALERT_GROUP,
user.getId(), ALERT_GROUP_CREATE, baseServiceLogger)).thenReturn(true); user.getId(), ALERT_GROUP_CREATE, baseServiceLogger)).thenReturn(true);
Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.ALERT_GROUP, null, Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.ALERT_GROUP, null,
user.getId(), baseServiceLogger)).thenReturn(true); user.getId(), baseServiceLogger)).thenReturn(true);
@ -170,7 +170,7 @@ public class AlertGroupServiceTest {
user.setUserType(UserType.ADMIN_USER); user.setUserType(UserType.ADMIN_USER);
// not exist // not exist
user.setUserType(UserType.ADMIN_USER); user.setUserType(UserType.ADMIN_USER);
Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.ALERT_GROUP, null, Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.ALERT_GROUP,
user.getId(), ALERT_GROUP_UPDATE, baseServiceLogger)).thenReturn(true); user.getId(), ALERT_GROUP_UPDATE, baseServiceLogger)).thenReturn(true);
Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.ALERT_GROUP, Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.ALERT_GROUP,
new Object[]{1}, 0, baseServiceLogger)).thenReturn(true); new Object[]{1}, 0, baseServiceLogger)).thenReturn(true);
@ -192,7 +192,7 @@ public class AlertGroupServiceTest {
User user = new User(); User user = new User();
user.setId(0); user.setId(0);
user.setUserType(UserType.ADMIN_USER); user.setUserType(UserType.ADMIN_USER);
Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.ALERT_GROUP, null, Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.ALERT_GROUP,
user.getId(), ALERT_GROUP_UPDATE, baseServiceLogger)).thenReturn(true); user.getId(), ALERT_GROUP_UPDATE, baseServiceLogger)).thenReturn(true);
Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.ALERT_GROUP, Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.ALERT_GROUP,
new Object[]{2}, user.getId(), baseServiceLogger)).thenReturn(true); new Object[]{2}, user.getId(), baseServiceLogger)).thenReturn(true);
@ -210,7 +210,7 @@ public class AlertGroupServiceTest {
user.setId(0); user.setId(0);
// no operate // no operate
user.setUserType(UserType.GENERAL_USER); user.setUserType(UserType.GENERAL_USER);
Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.ALERT_GROUP, null, Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.ALERT_GROUP,
user.getId(), ALERT_GROUP_DELETE, baseServiceLogger)).thenReturn(true); user.getId(), ALERT_GROUP_DELETE, baseServiceLogger)).thenReturn(true);
Map<String, Object> result = alertGroupService.delAlertgroupById(user, 1); Map<String, Object> result = alertGroupService.delAlertgroupById(user, 1);
logger.info(result.toString()); logger.info(result.toString());
@ -219,7 +219,7 @@ public class AlertGroupServiceTest {
// not exist // not exist
user.setUserType(UserType.ADMIN_USER); user.setUserType(UserType.ADMIN_USER);
user.setId(0); user.setId(0);
Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.ALERT_GROUP, null, Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.ALERT_GROUP,
user.getId(), ALERT_GROUP_DELETE, baseServiceLogger)).thenReturn(true); user.getId(), ALERT_GROUP_DELETE, baseServiceLogger)).thenReturn(true);
Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.ALERT_GROUP, Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.ALERT_GROUP,
new Object[]{2}, 0, baseServiceLogger)).thenReturn(true); new Object[]{2}, 0, baseServiceLogger)).thenReturn(true);

6
dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/AlertPluginInstanceServiceTest.java

@ -173,7 +173,7 @@ public class AlertPluginInstanceServiceTest {
public void testCreate() { public void testCreate() {
Mockito.when(alertPluginInstanceMapper.existInstanceName("test")).thenReturn(true); Mockito.when(alertPluginInstanceMapper.existInstanceName("test")).thenReturn(true);
Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.ALERT_PLUGIN_INSTANCE, Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.ALERT_PLUGIN_INSTANCE,
null, 1, ALART_INSTANCE_CREATE, baseServiceLogger)).thenReturn(true); 1, ALART_INSTANCE_CREATE, baseServiceLogger)).thenReturn(true);
Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.ALERT_PLUGIN_INSTANCE, Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.ALERT_PLUGIN_INSTANCE,
null, 0, baseServiceLogger)).thenReturn(true); null, 0, baseServiceLogger)).thenReturn(true);
Map<String, Object> result = alertPluginInstanceService.create(user, 1, "test", uiParams); Map<String, Object> result = alertPluginInstanceService.create(user, 1, "test", uiParams);
@ -189,7 +189,7 @@ public class AlertPluginInstanceServiceTest {
List<String> ids = Arrays.asList("11,2,3", null, "98,1"); List<String> ids = Arrays.asList("11,2,3", null, "98,1");
Mockito.when(alertGroupMapper.queryInstanceIdsList()).thenReturn(ids); Mockito.when(alertGroupMapper.queryInstanceIdsList()).thenReturn(ids);
Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.ALERT_PLUGIN_INSTANCE, Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.ALERT_PLUGIN_INSTANCE,
null, 1, ALERT_PLUGIN_DELETE, baseServiceLogger)).thenReturn(true); 1, ALERT_PLUGIN_DELETE, baseServiceLogger)).thenReturn(true);
Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.ALERT_PLUGIN_INSTANCE, Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.ALERT_PLUGIN_INSTANCE,
null, 0, baseServiceLogger)).thenReturn(true); null, 0, baseServiceLogger)).thenReturn(true);
Map<String, Object> result = alertPluginInstanceService.delete(user, 1); Map<String, Object> result = alertPluginInstanceService.delete(user, 1);
@ -205,7 +205,7 @@ public class AlertPluginInstanceServiceTest {
public void testUpdate() { public void testUpdate() {
Mockito.when(alertPluginInstanceMapper.updateById(Mockito.any())).thenReturn(0); Mockito.when(alertPluginInstanceMapper.updateById(Mockito.any())).thenReturn(0);
Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.ALERT_PLUGIN_INSTANCE, Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.ALERT_PLUGIN_INSTANCE,
null, 1, ALERT_PLUGIN_UPDATE, baseServiceLogger)).thenReturn(true); 1, ALERT_PLUGIN_UPDATE, baseServiceLogger)).thenReturn(true);
Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.ALERT_PLUGIN_INSTANCE, Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.ALERT_PLUGIN_INSTANCE,
null, 0, baseServiceLogger)).thenReturn(true); null, 0, baseServiceLogger)).thenReturn(true);
Map<String, Object> result = alertPluginInstanceService.update(user, 1, "testUpdate", uiParams); Map<String, Object> result = alertPluginInstanceService.update(user, 1, "testUpdate", uiParams);

4
dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/DataSourceServiceTest.java

@ -239,7 +239,7 @@ public class DataSourceServiceTest {
loginUser.setUserType(UserType.ADMIN_USER); loginUser.setUserType(UserType.ADMIN_USER);
loginUser.setId(1); loginUser.setId(1);
dataSource.setId(22); dataSource.setId(22);
Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.DATASOURCE, null, Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.DATASOURCE,
loginUser.getId(), DATASOURCE_DELETE, baseServiceLogger)).thenReturn(true); loginUser.getId(), DATASOURCE_DELETE, baseServiceLogger)).thenReturn(true);
Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.DATASOURCE, Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.DATASOURCE,
new Object[]{dataSource.getId()}, 0, baseServiceLogger)).thenReturn(true); new Object[]{dataSource.getId()}, 0, baseServiceLogger)).thenReturn(true);
@ -254,7 +254,7 @@ public class DataSourceServiceTest {
loginUser.setId(1); loginUser.setId(1);
loginUser.setUserType(UserType.ADMIN_USER); loginUser.setUserType(UserType.ADMIN_USER);
int userId = 3; int userId = 3;
Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.DATASOURCE, null, Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.DATASOURCE,
loginUser.getId(), null, baseServiceLogger)).thenReturn(true); loginUser.getId(), null, baseServiceLogger)).thenReturn(true);
Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.DATASOURCE, null, 0, Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.DATASOURCE, null, 0,
baseServiceLogger)).thenReturn(true); baseServiceLogger)).thenReturn(true);

2
dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/DqExecuteResultServiceTest.java

@ -83,7 +83,7 @@ public class DqExecuteResultServiceTest {
User loginUser = new User(); User loginUser = new User();
loginUser.setId(1); loginUser.setId(1);
loginUser.setUserType(UserType.ADMIN_USER); loginUser.setUserType(UserType.ADMIN_USER);
Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.DATA_QUALITY, null, Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.DATA_QUALITY,
loginUser.getId(), null, baseServiceLogger)).thenReturn(true); loginUser.getId(), null, baseServiceLogger)).thenReturn(true);
Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.DATA_QUALITY, null, 0, Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.DATA_QUALITY, null, 0,
baseServiceLogger)).thenReturn(true); baseServiceLogger)).thenReturn(true);

2
dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/DqRuleServiceTest.java

@ -138,7 +138,7 @@ public class DqRuleServiceTest {
User loginUser = new User(); User loginUser = new User();
loginUser.setId(1); loginUser.setId(1);
loginUser.setUserType(UserType.ADMIN_USER); loginUser.setUserType(UserType.ADMIN_USER);
Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.DATA_QUALITY, null, Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.DATA_QUALITY,
loginUser.getId(), null, baseServiceLogger)).thenReturn(true); loginUser.getId(), null, baseServiceLogger)).thenReturn(true);
Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.DATA_QUALITY, null, 0, Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.DATA_QUALITY, null, 0,
baseServiceLogger)).thenReturn(true); baseServiceLogger)).thenReturn(true);

6
dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/EnvironmentServiceTest.java

@ -98,7 +98,7 @@ public class EnvironmentServiceTest {
@Test @Test
public void testCreateEnvironment() { public void testCreateEnvironment() {
User loginUser = getGeneralUser(); User loginUser = getGeneralUser();
Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.ENVIRONMENT, null, Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.ENVIRONMENT,
loginUser.getId(), ENVIRONMENT_CREATE, baseServiceLogger)).thenReturn(true); loginUser.getId(), ENVIRONMENT_CREATE, baseServiceLogger)).thenReturn(true);
Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.ENVIRONMENT, null, Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.ENVIRONMENT, null,
0, baseServiceLogger)).thenReturn(true); 0, baseServiceLogger)).thenReturn(true);
@ -142,7 +142,7 @@ public class EnvironmentServiceTest {
@Test @Test
public void testUpdateEnvironmentByCode() { public void testUpdateEnvironmentByCode() {
User loginUser = getGeneralUser(); User loginUser = getGeneralUser();
Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.ENVIRONMENT, null, Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.ENVIRONMENT,
loginUser.getId(), ENVIRONMENT_UPDATE, baseServiceLogger)).thenReturn(true); loginUser.getId(), ENVIRONMENT_UPDATE, baseServiceLogger)).thenReturn(true);
Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.ENVIRONMENT, null, Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.ENVIRONMENT, null,
0, baseServiceLogger)).thenReturn(true); 0, baseServiceLogger)).thenReturn(true);
@ -238,7 +238,7 @@ public class EnvironmentServiceTest {
@Test @Test
public void testDeleteEnvironmentByCode() { public void testDeleteEnvironmentByCode() {
User loginUser = getGeneralUser(); User loginUser = getGeneralUser();
Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.ENVIRONMENT, null, Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.ENVIRONMENT,
loginUser.getId(), ENVIRONMENT_DELETE, baseServiceLogger)).thenReturn(true); loginUser.getId(), ENVIRONMENT_DELETE, baseServiceLogger)).thenReturn(true);
Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.ENVIRONMENT, null, Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.ENVIRONMENT, null,
0, baseServiceLogger)).thenReturn(true); 0, baseServiceLogger)).thenReturn(true);

2
dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/MonitorServiceTest.java

@ -132,7 +132,7 @@ public class MonitorServiceTest {
} }
private void mockPermissionCheck(String permissionKey, boolean result) { private void mockPermissionCheck(String permissionKey, boolean result) {
Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.MONITOR, null, 1, Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.MONITOR, 1,
permissionKey, serviceLogger)).thenReturn(result); permissionKey, serviceLogger)).thenReturn(result);
Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.MONITOR, null, 0, Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.MONITOR, null, 0,
serviceLogger)).thenReturn(true); serviceLogger)).thenReturn(true);

26
dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ProjectServiceTest.java

@ -105,7 +105,7 @@ public class ProjectServiceTest {
User loginUser = getLoginUser(); User loginUser = getLoginUser();
loginUser.setId(1); loginUser.setId(1);
Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.PROJECTS, null, 1, Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.PROJECTS, 1,
PROJECT_CREATE, baseServiceLogger)).thenReturn(true); PROJECT_CREATE, baseServiceLogger)).thenReturn(true);
Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.PROJECTS, null, 1, Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.PROJECTS, null, 1,
baseServiceLogger)).thenReturn(true); baseServiceLogger)).thenReturn(true);
@ -149,7 +149,6 @@ public class ProjectServiceTest {
project.setUserId(1); project.setUserId(1);
loginUser.setUserType(UserType.ADMIN_USER); loginUser.setUserType(UserType.ADMIN_USER);
Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.PROJECTS, Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.PROJECTS,
new Object[]{project.getId()},
project.getUserId(), PROJECT, baseServiceLogger)).thenReturn(true); project.getUserId(), PROJECT, baseServiceLogger)).thenReturn(true);
Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.PROJECTS, Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.PROJECTS,
new Object[]{project.getId()}, new Object[]{project.getId()},
@ -168,7 +167,6 @@ public class ProjectServiceTest {
project1.setUserId(2); project1.setUserId(2);
loginUser.setUserType(UserType.GENERAL_USER); loginUser.setUserType(UserType.GENERAL_USER);
Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.PROJECTS, Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.PROJECTS,
new Object[]{project.getId()},
loginUser.getId(), PROJECT, baseServiceLogger)).thenReturn(true); loginUser.getId(), PROJECT, baseServiceLogger)).thenReturn(true);
result2 = projectService.checkProjectAndAuth(loginUser, project1, projectCode, PROJECT); result2 = projectService.checkProjectAndAuth(loginUser, project1, projectCode, PROJECT);
Assertions.assertEquals(Status.USER_NO_OPERATION_PROJECT_PERM, result2.get(Constants.STATUS)); Assertions.assertEquals(Status.USER_NO_OPERATION_PROJECT_PERM, result2.get(Constants.STATUS));
@ -191,7 +189,6 @@ public class ProjectServiceTest {
tempUser.setId(Integer.MAX_VALUE); tempUser.setId(Integer.MAX_VALUE);
tempUser.setUserType(UserType.GENERAL_USER); tempUser.setUserType(UserType.GENERAL_USER);
Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.PROJECTS, Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.PROJECTS,
new Object[]{project.getId()},
tempUser.getId(), null, baseServiceLogger)).thenReturn(true); tempUser.getId(), null, baseServiceLogger)).thenReturn(true);
boolean checkResult = projectService.hasProjectAndPerm(tempUser, project, result, null); boolean checkResult = projectService.hasProjectAndPerm(tempUser, project, result, null);
logger.info(result.toString()); logger.info(result.toString());
@ -202,7 +199,6 @@ public class ProjectServiceTest {
project.setUserId(1); project.setUserId(1);
loginUser.setUserType(UserType.ADMIN_USER); loginUser.setUserType(UserType.ADMIN_USER);
Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.PROJECTS, Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.PROJECTS,
new Object[]{project.getId()},
loginUser.getId(), null, baseServiceLogger)).thenReturn(true); loginUser.getId(), null, baseServiceLogger)).thenReturn(true);
Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.PROJECTS, Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.PROJECTS,
new Object[]{project.getId()}, new Object[]{project.getId()},
@ -251,7 +247,6 @@ public class ProjectServiceTest {
tempUser.setId(Integer.MAX_VALUE); tempUser.setId(Integer.MAX_VALUE);
tempUser.setUserType(UserType.GENERAL_USER); tempUser.setUserType(UserType.GENERAL_USER);
Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.PROJECTS, Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.PROJECTS,
new Object[]{project.getId()},
tempUser.getId(), null, baseServiceLogger)).thenReturn(true); tempUser.getId(), null, baseServiceLogger)).thenReturn(true);
boolean checkResult = projectService.hasProjectAndWritePerm(tempUser, project, result); boolean checkResult = projectService.hasProjectAndWritePerm(tempUser, project, result);
logger.info(result.toString()); logger.info(result.toString());
@ -262,7 +257,6 @@ public class ProjectServiceTest {
project.setUserId(1); project.setUserId(1);
loginUser.setUserType(UserType.ADMIN_USER); loginUser.setUserType(UserType.ADMIN_USER);
Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.PROJECTS, Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.PROJECTS,
new Object[]{project.getId()},
loginUser.getId(), null, baseServiceLogger)).thenReturn(true); loginUser.getId(), null, baseServiceLogger)).thenReturn(true);
Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.PROJECTS, Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.PROJECTS,
new Object[]{project.getId()}, new Object[]{project.getId()},
@ -276,9 +270,10 @@ public class ProjectServiceTest {
public void testDeleteProject() { public void testDeleteProject() {
User loginUser = getLoginUser(); User loginUser = getLoginUser();
Mockito.when(projectMapper.queryByCode(1L)).thenReturn(getProject()); Mockito.when(projectMapper.queryByCode(1L)).thenReturn(getProject());
Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.PROJECTS, Mockito.when(
new Object[]{1}, loginUser.getId(), resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.PROJECTS, loginUser.getId(),
PROJECT_DELETE, baseServiceLogger)).thenReturn(true); PROJECT_DELETE, baseServiceLogger))
.thenReturn(true);
// PROJECT_NOT_FOUND // PROJECT_NOT_FOUND
Result result = projectService.deleteProject(loginUser, 11L); Result result = projectService.deleteProject(loginUser, 11L);
logger.info(result.toString()); logger.info(result.toString());
@ -319,9 +314,10 @@ public class ProjectServiceTest {
loginUser.setId(1); loginUser.setId(1);
Project project = getProject(); Project project = getProject();
project.setCode(2L); project.setCode(2L);
Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.PROJECTS, Mockito.when(
new Object[]{1}, loginUser.getId(), resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.PROJECTS, loginUser.getId(),
PROJECT_UPDATE, baseServiceLogger)).thenReturn(true); PROJECT_UPDATE, baseServiceLogger))
.thenReturn(true);
Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.PROJECTS, new Object[]{1}, Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.PROJECTS, new Object[]{1},
loginUser.getId(), loginUser.getId(),
baseServiceLogger)).thenReturn(true); baseServiceLogger)).thenReturn(true);
@ -391,7 +387,7 @@ public class ProjectServiceTest {
// SUCCESS // SUCCESS
loginUser.setUserType(UserType.ADMIN_USER); loginUser.setUserType(UserType.ADMIN_USER);
Mockito.when( Mockito.when(
resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.PROJECTS, new Object[]{1}, resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.PROJECTS,
loginUser.getId(), PROJECT, baseServiceLogger)) loginUser.getId(), PROJECT, baseServiceLogger))
.thenReturn(true); .thenReturn(true);
Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.PROJECTS, new Object[]{1}, Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.PROJECTS, new Object[]{1},
@ -405,7 +401,7 @@ public class ProjectServiceTest {
loginUser.setId(1); loginUser.setId(1);
loginUser.setUserType(UserType.GENERAL_USER); loginUser.setUserType(UserType.GENERAL_USER);
Mockito.when( Mockito.when(
resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.PROJECTS, new Object[]{1}, resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.PROJECTS,
loginUser.getId(), PROJECT, baseServiceLogger)) loginUser.getId(), PROJECT, baseServiceLogger))
.thenReturn(true); .thenReturn(true);
Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.PROJECTS, new Object[]{1}, Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.PROJECTS, new Object[]{1},

4
dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/QueueServiceTest.java

@ -128,7 +128,7 @@ public class QueueServiceTest {
@Test @Test
public void testCreateQueue() { public void testCreateQueue() {
Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.QUEUE, null, Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.QUEUE,
getLoginUser().getId(), YARN_QUEUE_CREATE, baseServiceLogger)).thenReturn(true); getLoginUser().getId(), YARN_QUEUE_CREATE, baseServiceLogger)).thenReturn(true);
Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.QUEUE, null, 0, Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.QUEUE, null, 0,
baseServiceLogger)).thenReturn(true); baseServiceLogger)).thenReturn(true);
@ -155,7 +155,7 @@ public class QueueServiceTest {
Mockito.when(queueMapper.selectById(1)).thenReturn(getQUEUE()); Mockito.when(queueMapper.selectById(1)).thenReturn(getQUEUE());
Mockito.when(queueMapper.existQueue(EXISTS, null)).thenReturn(true); Mockito.when(queueMapper.existQueue(EXISTS, null)).thenReturn(true);
Mockito.when(queueMapper.existQueue(null, EXISTS)).thenReturn(true); Mockito.when(queueMapper.existQueue(null, EXISTS)).thenReturn(true);
Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.QUEUE, null, Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.QUEUE,
getLoginUser().getId(), YARN_QUEUE_UPDATE, baseServiceLogger)).thenReturn(true); getLoginUser().getId(), YARN_QUEUE_UPDATE, baseServiceLogger)).thenReturn(true);
Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.QUEUE, new Object[]{0}, 0, Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.QUEUE, new Object[]{0}, 0,
baseServiceLogger)).thenReturn(true); baseServiceLogger)).thenReturn(true);

12
dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/TaskGroupServiceTest.java

@ -117,7 +117,7 @@ public class TaskGroupServiceTest {
@Test @Test
public void forceStartTask() { public void forceStartTask() {
User loginUser = getLoginUser(); User loginUser = getLoginUser();
Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.TASK_GROUP, null, Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.TASK_GROUP,
loginUser.getId(), ApiFuncIdentificationConstant.TASK_GROUP_QUEUE_START, serviceLogger)) loginUser.getId(), ApiFuncIdentificationConstant.TASK_GROUP_QUEUE_START, serviceLogger))
.thenReturn(false); .thenReturn(false);
Map<String, Object> objectMap = taskGroupService.forceStartTask(loginUser, 1); Map<String, Object> objectMap = taskGroupService.forceStartTask(loginUser, 1);
@ -127,7 +127,7 @@ public class TaskGroupServiceTest {
@Test @Test
public void modifyPriority() { public void modifyPriority() {
User loginUser = getLoginUser(); User loginUser = getLoginUser();
Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.TASK_GROUP, null, Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.TASK_GROUP,
loginUser.getId(), ApiFuncIdentificationConstant.TASK_GROUP_QUEUE_PRIORITY, serviceLogger)) loginUser.getId(), ApiFuncIdentificationConstant.TASK_GROUP_QUEUE_PRIORITY, serviceLogger))
.thenReturn(false); .thenReturn(false);
Map<String, Object> objectMap = taskGroupService.modifyPriority(loginUser, 1, 1); Map<String, Object> objectMap = taskGroupService.modifyPriority(loginUser, 1, 1);
@ -138,7 +138,7 @@ public class TaskGroupServiceTest {
public void testCreate() { public void testCreate() {
User loginUser = getLoginUser(); User loginUser = getLoginUser();
TaskGroup taskGroup = getTaskGroup(); TaskGroup taskGroup = getTaskGroup();
Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.TASK_GROUP, null, Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.TASK_GROUP,
loginUser.getId(), ApiFuncIdentificationConstant.TASK_GROUP_CREATE, serviceLogger)).thenReturn(true); loginUser.getId(), ApiFuncIdentificationConstant.TASK_GROUP_CREATE, serviceLogger)).thenReturn(true);
Mockito.when(taskGroupMapper.insert(taskGroup)).thenReturn(1); Mockito.when(taskGroupMapper.insert(taskGroup)).thenReturn(1);
Mockito.when(taskGroupMapper.queryByName(loginUser.getId(), taskGroupName)).thenReturn(null); Mockito.when(taskGroupMapper.queryByName(loginUser.getId(), taskGroupName)).thenReturn(null);
@ -162,7 +162,7 @@ public class TaskGroupServiceTest {
IPage<TaskGroup> page = new Page<>(1, 10); IPage<TaskGroup> page = new Page<>(1, 10);
page.setRecords(getList()); page.setRecords(getList());
User loginUser = getLoginUser(); User loginUser = getLoginUser();
Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.TASK_GROUP, null, Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.TASK_GROUP,
loginUser.getId(), ApiFuncIdentificationConstant.TASK_GROUP_VIEW, serviceLogger)).thenReturn(true); loginUser.getId(), ApiFuncIdentificationConstant.TASK_GROUP_VIEW, serviceLogger)).thenReturn(true);
Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.TASK_GROUP, null, Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.TASK_GROUP, null,
0, serviceLogger)).thenReturn(true); 0, serviceLogger)).thenReturn(true);
@ -183,7 +183,7 @@ public class TaskGroupServiceTest {
taskGroup.setStatus(Flag.YES.getCode()); taskGroup.setStatus(Flag.YES.getCode());
// Task group status error // Task group status error
Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.TASK_GROUP, null, Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.TASK_GROUP,
loginUser.getId(), ApiFuncIdentificationConstant.TASK_GROUP_EDIT, serviceLogger)).thenReturn(true); loginUser.getId(), ApiFuncIdentificationConstant.TASK_GROUP_EDIT, serviceLogger)).thenReturn(true);
Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.TASK_GROUP, null, Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.TASK_GROUP, null,
0, serviceLogger)).thenReturn(true); 0, serviceLogger)).thenReturn(true);
@ -204,7 +204,7 @@ public class TaskGroupServiceTest {
Mockito.when(taskGroupMapper.selectById(1)).thenReturn(taskGroup); Mockito.when(taskGroupMapper.selectById(1)).thenReturn(taskGroup);
// close failed // close failed
Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.TASK_GROUP, null, Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.TASK_GROUP,
loginUser.getId(), ApiFuncIdentificationConstant.TASK_GROUP_CLOSE, serviceLogger)).thenReturn(true); loginUser.getId(), ApiFuncIdentificationConstant.TASK_GROUP_CLOSE, serviceLogger)).thenReturn(true);
Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.TASK_GROUP, null, Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.TASK_GROUP, null,
0, serviceLogger)).thenReturn(true); 0, serviceLogger)).thenReturn(true);

6
dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/TenantServiceTest.java

@ -110,7 +110,7 @@ public class TenantServiceTest {
User loginUser = getLoginUser(); User loginUser = getLoginUser();
Mockito.when(tenantMapper.existTenant(tenantCode)).thenReturn(true); Mockito.when(tenantMapper.existTenant(tenantCode)).thenReturn(true);
Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.TENANT, null, Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.TENANT,
loginUser.getId(), TENANT_CREATE, baseServiceLogger)).thenReturn(true); loginUser.getId(), TENANT_CREATE, baseServiceLogger)).thenReturn(true);
Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.TENANT, null, 0, Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.TENANT, null, 0,
baseServiceLogger)).thenReturn(true); baseServiceLogger)).thenReturn(true);
@ -182,7 +182,7 @@ public class TenantServiceTest {
@Test @Test
public void testUpdateTenant() throws Exception { public void testUpdateTenant() throws Exception {
Mockito.when(tenantMapper.queryById(1)).thenReturn(getTenant()); Mockito.when(tenantMapper.queryById(1)).thenReturn(getTenant());
Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.TENANT, null, Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.TENANT,
getLoginUser().getId(), TENANT_UPDATE, baseServiceLogger)).thenReturn(true); getLoginUser().getId(), TENANT_UPDATE, baseServiceLogger)).thenReturn(true);
Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.TENANT, null, 0, Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.TENANT, null, 0,
baseServiceLogger)).thenReturn(true); baseServiceLogger)).thenReturn(true);
@ -204,7 +204,7 @@ public class TenantServiceTest {
@Test @Test
public void testDeleteTenantById() throws Exception { public void testDeleteTenantById() throws Exception {
Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.TENANT, null, Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.TENANT,
getLoginUser().getId(), TENANT_DELETE, baseServiceLogger)).thenReturn(true); getLoginUser().getId(), TENANT_DELETE, baseServiceLogger)).thenReturn(true);
Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.TENANT, null, 0, Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.TENANT, null, 0,
baseServiceLogger)).thenReturn(true); baseServiceLogger)).thenReturn(true);

20
dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/UdfFuncServiceTest.java

@ -104,7 +104,7 @@ public class UdfFuncServiceTest {
@Test @Test
public void testCreateUdfFunction() { public void testCreateUdfFunction() {
Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.UDF, null, 1, Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.UDF, 1,
ApiFuncIdentificationConstant.UDF_FUNCTION_CREATE, serviceLogger)).thenReturn(true); ApiFuncIdentificationConstant.UDF_FUNCTION_CREATE, serviceLogger)).thenReturn(true);
Mockito.when( Mockito.when(
resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.UDF, null, 0, serviceLogger)) resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.UDF, null, 0, serviceLogger))
@ -141,7 +141,7 @@ public class UdfFuncServiceTest {
@Test @Test
public void testQueryUdfFuncDetail() { public void testQueryUdfFuncDetail() {
Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.UDF, null, 1, Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.UDF, 1,
ApiFuncIdentificationConstant.UDF_FUNCTION_VIEW, serviceLogger)).thenReturn(true); ApiFuncIdentificationConstant.UDF_FUNCTION_VIEW, serviceLogger)).thenReturn(true);
Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.UDF, new Object[]{2}, 0, Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.UDF, new Object[]{2}, 0,
serviceLogger)).thenReturn(true); serviceLogger)).thenReturn(true);
@ -151,7 +151,7 @@ public class UdfFuncServiceTest {
logger.info(result.toString()); logger.info(result.toString());
Assertions.assertTrue(Status.RESOURCE_NOT_EXIST.getCode() == result.getCode()); Assertions.assertTrue(Status.RESOURCE_NOT_EXIST.getCode() == result.getCode());
// success // success
Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.UDF, null, 1, Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.UDF, 1,
ApiFuncIdentificationConstant.UDF_FUNCTION_VIEW, serviceLogger)).thenReturn(true); ApiFuncIdentificationConstant.UDF_FUNCTION_VIEW, serviceLogger)).thenReturn(true);
Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.UDF, new Object[]{1}, 0, Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.UDF, new Object[]{1}, 0,
serviceLogger)).thenReturn(true); serviceLogger)).thenReturn(true);
@ -167,7 +167,7 @@ public class UdfFuncServiceTest {
Mockito.when(udfFuncMapper.selectUdfById(1)).thenReturn(getUdfFunc()); Mockito.when(udfFuncMapper.selectUdfById(1)).thenReturn(getUdfFunc());
// UDF_FUNCTION_NOT_EXIST // UDF_FUNCTION_NOT_EXIST
Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.UDF, null, 1, Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.UDF, 1,
ApiFuncIdentificationConstant.UDF_FUNCTION_UPDATE, serviceLogger)).thenReturn(true); ApiFuncIdentificationConstant.UDF_FUNCTION_UPDATE, serviceLogger)).thenReturn(true);
Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.UDF, new Object[]{12}, 0, Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.UDF, new Object[]{12}, 0,
serviceLogger)).thenReturn(true); serviceLogger)).thenReturn(true);
@ -187,7 +187,7 @@ public class UdfFuncServiceTest {
Assertions.assertTrue(Status.HDFS_NOT_STARTUP.getCode() == result.getCode()); Assertions.assertTrue(Status.HDFS_NOT_STARTUP.getCode() == result.getCode());
// RESOURCE_NOT_EXIST // RESOURCE_NOT_EXIST
Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.UDF, null, 1, Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.UDF, 1,
ApiFuncIdentificationConstant.UDF_FUNCTION_UPDATE, serviceLogger)).thenReturn(true); ApiFuncIdentificationConstant.UDF_FUNCTION_UPDATE, serviceLogger)).thenReturn(true);
Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.UDF, new Object[]{11}, 0, Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.UDF, new Object[]{11}, 0,
serviceLogger)).thenReturn(true); serviceLogger)).thenReturn(true);
@ -200,7 +200,7 @@ public class UdfFuncServiceTest {
Assertions.assertTrue(Status.RESOURCE_NOT_EXIST.getCode() == result.getCode()); Assertions.assertTrue(Status.RESOURCE_NOT_EXIST.getCode() == result.getCode());
// success // success
Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.UDF, null, 1, Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.UDF, 1,
ApiFuncIdentificationConstant.UDF_FUNCTION_UPDATE, serviceLogger)).thenReturn(true); ApiFuncIdentificationConstant.UDF_FUNCTION_UPDATE, serviceLogger)).thenReturn(true);
try { try {
Mockito.when(storageOperate.exists("")).thenReturn(true); Mockito.when(storageOperate.exists("")).thenReturn(true);
@ -219,7 +219,7 @@ public class UdfFuncServiceTest {
@Test @Test
public void testQueryUdfFuncListPaging() { public void testQueryUdfFuncListPaging() {
Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.UDF, null, 1, Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.UDF, 1,
ApiFuncIdentificationConstant.UDF_FUNCTION_VIEW, serviceLogger)).thenReturn(true); ApiFuncIdentificationConstant.UDF_FUNCTION_VIEW, serviceLogger)).thenReturn(true);
Mockito.when( Mockito.when(
resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.UDF, null, 0, serviceLogger)) resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.UDF, null, 0, serviceLogger))
@ -240,7 +240,7 @@ public class UdfFuncServiceTest {
@Test @Test
public void testQueryUdfFuncList() { public void testQueryUdfFuncList() {
Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.UDF, null, 1, Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.UDF, 1,
ApiFuncIdentificationConstant.UDF_FUNCTION_VIEW, serviceLogger)).thenReturn(true); ApiFuncIdentificationConstant.UDF_FUNCTION_VIEW, serviceLogger)).thenReturn(true);
Mockito.when( Mockito.when(
resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.UDF, null, 1, serviceLogger)) resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.UDF, null, 1, serviceLogger))
@ -263,7 +263,7 @@ public class UdfFuncServiceTest {
@Test @Test
public void testDelete() { public void testDelete() {
Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.UDF, null, 1, Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.UDF, 1,
ApiFuncIdentificationConstant.UDF_FUNCTION_DELETE, serviceLogger)).thenReturn(true); ApiFuncIdentificationConstant.UDF_FUNCTION_DELETE, serviceLogger)).thenReturn(true);
Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.UDF, new Object[]{122}, 0, Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.UDF, new Object[]{122}, 0,
serviceLogger)).thenReturn(true); serviceLogger)).thenReturn(true);
@ -278,7 +278,7 @@ public class UdfFuncServiceTest {
@Test @Test
public void testVerifyUdfFuncByName() { public void testVerifyUdfFuncByName() {
Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.UDF, null, 1, Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.UDF, 1,
ApiFuncIdentificationConstant.UDF_FUNCTION_VIEW, serviceLogger)).thenReturn(true); ApiFuncIdentificationConstant.UDF_FUNCTION_VIEW, serviceLogger)).thenReturn(true);
Mockito.when( Mockito.when(
resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.UDF, null, 0, serviceLogger)) resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.UDF, null, 0, serviceLogger))

4
dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/UsersServiceTest.java

@ -256,7 +256,7 @@ public class UsersServiceTest {
user.setUserType(UserType.ADMIN_USER); user.setUserType(UserType.ADMIN_USER);
user.setId(1); user.setId(1);
Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.ACCESS_TOKEN, null, 1, Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.ACCESS_TOKEN, 1,
USER_MANAGER, serviceLogger)).thenReturn(true); USER_MANAGER, serviceLogger)).thenReturn(true);
Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.ACCESS_TOKEN, null, 0, Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.ACCESS_TOKEN, null, 0,
serviceLogger)).thenReturn(false); serviceLogger)).thenReturn(false);
@ -265,7 +265,7 @@ public class UsersServiceTest {
Assertions.assertEquals(Status.USER_NO_OPERATION_PERM, result.get(Constants.STATUS)); Assertions.assertEquals(Status.USER_NO_OPERATION_PERM, result.get(Constants.STATUS));
// success // success
Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.ACCESS_TOKEN, null, 1, Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.ACCESS_TOKEN, 1,
USER_MANAGER, serviceLogger)).thenReturn(true); USER_MANAGER, serviceLogger)).thenReturn(true);
Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.ACCESS_TOKEN, null, 0, Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.ACCESS_TOKEN, null, 0,
serviceLogger)).thenReturn(true); serviceLogger)).thenReturn(true);

16
dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/WorkerGroupServiceTest.java

@ -103,7 +103,7 @@ public class WorkerGroupServiceTest {
@Test @Test
public void giveNoPermission_whenSaveWorkerGroup_expectNoOperation() { public void giveNoPermission_whenSaveWorkerGroup_expectNoOperation() {
User loginUser = getLoginUser(); User loginUser = getLoginUser();
Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.WORKER_GROUP, null, 1, Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.WORKER_GROUP, 1,
WORKER_GROUP_CREATE, baseServiceLogger)).thenReturn(false); WORKER_GROUP_CREATE, baseServiceLogger)).thenReturn(false);
Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.WORKER_GROUP, null, 1, Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.WORKER_GROUP, null, 1,
baseServiceLogger)).thenReturn(false); baseServiceLogger)).thenReturn(false);
@ -116,7 +116,7 @@ public class WorkerGroupServiceTest {
@Test @Test
public void giveNullName_whenSaveWorkerGroup_expectNAME_NULL() { public void giveNullName_whenSaveWorkerGroup_expectNAME_NULL() {
User loginUser = getLoginUser(); User loginUser = getLoginUser();
Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.WORKER_GROUP, null, 1, Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.WORKER_GROUP, 1,
WORKER_GROUP_CREATE, baseServiceLogger)).thenReturn(true); WORKER_GROUP_CREATE, baseServiceLogger)).thenReturn(true);
Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.WORKER_GROUP, null, 1, Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.WORKER_GROUP, null, 1,
baseServiceLogger)).thenReturn(true); baseServiceLogger)).thenReturn(true);
@ -129,7 +129,7 @@ public class WorkerGroupServiceTest {
@Test @Test
public void giveSameUserName_whenSaveWorkerGroup_expectNAME_EXIST() { public void giveSameUserName_whenSaveWorkerGroup_expectNAME_EXIST() {
User loginUser = getLoginUser(); User loginUser = getLoginUser();
Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.WORKER_GROUP, null, 1, Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.WORKER_GROUP, 1,
WORKER_GROUP_CREATE, baseServiceLogger)).thenReturn(true); WORKER_GROUP_CREATE, baseServiceLogger)).thenReturn(true);
Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.WORKER_GROUP, null, 1, Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.WORKER_GROUP, null, 1,
baseServiceLogger)).thenReturn(true); baseServiceLogger)).thenReturn(true);
@ -147,7 +147,7 @@ public class WorkerGroupServiceTest {
@Test @Test
public void giveInvalidAddress_whenSaveWorkerGroup_expectADDRESS_INVALID() { public void giveInvalidAddress_whenSaveWorkerGroup_expectADDRESS_INVALID() {
User loginUser = getLoginUser(); User loginUser = getLoginUser();
Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.WORKER_GROUP, null, 1, Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.WORKER_GROUP, 1,
WORKER_GROUP_CREATE, baseServiceLogger)).thenReturn(true); WORKER_GROUP_CREATE, baseServiceLogger)).thenReturn(true);
Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.WORKER_GROUP, null, 1, Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.WORKER_GROUP, null, 1,
baseServiceLogger)).thenReturn(true); baseServiceLogger)).thenReturn(true);
@ -169,7 +169,7 @@ public class WorkerGroupServiceTest {
@Test @Test
public void giveValidWorkerGroup_whenSaveWorkerGroup_expectSuccess() { public void giveValidWorkerGroup_whenSaveWorkerGroup_expectSuccess() {
User loginUser = getLoginUser(); User loginUser = getLoginUser();
Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.WORKER_GROUP, null, 1, Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.WORKER_GROUP, 1,
WORKER_GROUP_CREATE, baseServiceLogger)).thenReturn(true); WORKER_GROUP_CREATE, baseServiceLogger)).thenReturn(true);
Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.WORKER_GROUP, null, 1, Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.WORKER_GROUP, null, 1,
baseServiceLogger)).thenReturn(true); baseServiceLogger)).thenReturn(true);
@ -219,7 +219,7 @@ public class WorkerGroupServiceTest {
@Test @Test
public void giveNotExistsWorkerGroup_whenDeleteWorkerGroupById_expectNotExists() { public void giveNotExistsWorkerGroup_whenDeleteWorkerGroupById_expectNotExists() {
User loginUser = getLoginUser(); User loginUser = getLoginUser();
Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.WORKER_GROUP, null, 1, Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.WORKER_GROUP, 1,
WORKER_GROUP_DELETE, baseServiceLogger)).thenReturn(true); WORKER_GROUP_DELETE, baseServiceLogger)).thenReturn(true);
Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.WORKER_GROUP, null, 1, Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.WORKER_GROUP, null, 1,
baseServiceLogger)).thenReturn(true); baseServiceLogger)).thenReturn(true);
@ -233,7 +233,7 @@ public class WorkerGroupServiceTest {
@Test @Test
public void giveRunningProcess_whenDeleteWorkerGroupById_expectFailed() { public void giveRunningProcess_whenDeleteWorkerGroupById_expectFailed() {
User loginUser = getLoginUser(); User loginUser = getLoginUser();
Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.WORKER_GROUP, null, 1, Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.WORKER_GROUP, 1,
WORKER_GROUP_DELETE, baseServiceLogger)).thenReturn(true); WORKER_GROUP_DELETE, baseServiceLogger)).thenReturn(true);
Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.WORKER_GROUP, null, 1, Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.WORKER_GROUP, null, 1,
baseServiceLogger)).thenReturn(true); baseServiceLogger)).thenReturn(true);
@ -255,7 +255,7 @@ public class WorkerGroupServiceTest {
@Test @Test
public void giveValidParams_whenDeleteWorkerGroupById_expectSuccess() { public void giveValidParams_whenDeleteWorkerGroupById_expectSuccess() {
User loginUser = getLoginUser(); User loginUser = getLoginUser();
Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.WORKER_GROUP, null, 1, Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.WORKER_GROUP, 1,
WORKER_GROUP_DELETE, baseServiceLogger)).thenReturn(true); WORKER_GROUP_DELETE, baseServiceLogger)).thenReturn(true);
Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.WORKER_GROUP, null, 1, Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.WORKER_GROUP, null, 1,
baseServiceLogger)).thenReturn(true); baseServiceLogger)).thenReturn(true);

Loading…
Cancel
Save