You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dolphinscheduler.apache.org by ca...@apache.org on 2022/06/15 02:19:33 UTC

[dolphinscheduler] branch dev updated: [fix-10386]LDAP user create with status enable (#10426)

This is an automated email from the ASF dual-hosted git repository.

caishunfeng pushed a commit to branch dev
in repository https://gitbox.apache.org/repos/asf/dolphinscheduler.git


The following commit(s) were added to refs/heads/dev by this push:
     new 50846760e5 [fix-10386]LDAP user create with status enable (#10426)
50846760e5 is described below

commit 50846760e5ab5f68cb708edc72725b235e933a34
Author: 旺阳 <qi...@cisco.com>
AuthorDate: Wed Jun 15 10:19:27 2022 +0800

    [fix-10386]LDAP user create with status enable (#10426)
    
    * LDAP user create with status enable
    
    * currect unit test
---
 .../api/service/impl/UsersServiceImpl.java                 |  1 +
 .../api/security/impl/ldap/LdapAuthenticatorTest.java      | 14 ++++++--------
 2 files changed, 7 insertions(+), 8 deletions(-)

diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/UsersServiceImpl.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/UsersServiceImpl.java
index 056cf36082..34cbc91869 100644
--- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/UsersServiceImpl.java
+++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/UsersServiceImpl.java
@@ -241,6 +241,7 @@ public class UsersServiceImpl extends BaseServiceImpl implements UsersService {
         user.setCreateTime(now);
         user.setUpdateTime(now);
         user.setQueue("");
+        user.setState(Flag.YES.getCode());
 
         // save user
         userMapper.insert(user);
diff --git a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/security/impl/ldap/LdapAuthenticatorTest.java b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/security/impl/ldap/LdapAuthenticatorTest.java
index 143d7a6a6f..ba0f72a039 100644
--- a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/security/impl/ldap/LdapAuthenticatorTest.java
+++ b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/security/impl/ldap/LdapAuthenticatorTest.java
@@ -38,6 +38,7 @@ import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
 import org.mockito.Mockito;
+import org.mockito.Spy;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -64,7 +65,7 @@ public class LdapAuthenticatorTest extends AbstractControllerTest {
     private LdapService ldapService;
     @MockBean(name = "sessionServiceImpl")
     private SessionService sessionService;
-    @MockBean(name = "usersServiceImpl")
+    @Spy
     private UsersService usersService;
 
     private LdapAuthenticator ldapAuthenticator;
@@ -102,22 +103,19 @@ public class LdapAuthenticatorTest extends AbstractControllerTest {
 
     @Test
     public void testAuthenticate() {
-        when(usersService.createUser(userType, ldapUid, ldapEmail)).thenReturn(mockUser);
-        when(usersService.getUserByUserName(ldapUid)).thenReturn(mockUser);
-        when(sessionService.createSession(mockUser, ip)).thenReturn(mockSession.getId());
-
+        when(sessionService.createSession(Mockito.any(User.class), Mockito.eq(ip))).thenReturn(mockSession.getId());
         when(ldapService.ldapLogin(ldapUid, ldapUserPwd)).thenReturn(ldapEmail);
 
         Result result = ldapAuthenticator.authenticate(ldapUid, ldapUserPwd, ip);
         Assert.assertEquals(Status.SUCCESS.getCode(), (int) result.getCode());
         logger.info(result.toString());
 
-        when(sessionService.createSession(mockUser, ip)).thenReturn(null);
+        when(sessionService.createSession(Mockito.any(User.class), Mockito.eq(ip))).thenReturn(null);
+
         result = ldapAuthenticator.authenticate(ldapUid, ldapUserPwd, ip);
         Assert.assertEquals(Status.LOGIN_SESSION_FAILED.getCode(), (int) result.getCode());
 
-        when(sessionService.createSession(mockUser, ip)).thenReturn(mockSession.getId());
-        when(usersService.getUserByUserName(ldapUid)).thenReturn(null);
+        when(ldapService.ldapLogin(ldapUid, ldapUserPwd)).thenReturn(null);
         result = ldapAuthenticator.authenticate(ldapUid, ldapUserPwd, ip);
         Assert.assertEquals(Status.USER_NAME_PASSWD_ERROR.getCode(), (int) result.getCode());
     }