|
|
@ -38,6 +38,7 @@ import org.junit.Assert; |
|
|
|
import org.junit.Before; |
|
|
|
import org.junit.Before; |
|
|
|
import org.junit.Test; |
|
|
|
import org.junit.Test; |
|
|
|
import org.mockito.Mockito; |
|
|
|
import org.mockito.Mockito; |
|
|
|
|
|
|
|
import org.mockito.Spy; |
|
|
|
import org.slf4j.Logger; |
|
|
|
import org.slf4j.Logger; |
|
|
|
import org.slf4j.LoggerFactory; |
|
|
|
import org.slf4j.LoggerFactory; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
@ -64,7 +65,7 @@ public class LdapAuthenticatorTest extends AbstractControllerTest { |
|
|
|
private LdapService ldapService; |
|
|
|
private LdapService ldapService; |
|
|
|
@MockBean(name = "sessionServiceImpl") |
|
|
|
@MockBean(name = "sessionServiceImpl") |
|
|
|
private SessionService sessionService; |
|
|
|
private SessionService sessionService; |
|
|
|
@MockBean(name = "usersServiceImpl") |
|
|
|
@Spy |
|
|
|
private UsersService usersService; |
|
|
|
private UsersService usersService; |
|
|
|
|
|
|
|
|
|
|
|
private LdapAuthenticator ldapAuthenticator; |
|
|
|
private LdapAuthenticator ldapAuthenticator; |
|
|
@ -102,22 +103,19 @@ public class LdapAuthenticatorTest extends AbstractControllerTest { |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testAuthenticate() { |
|
|
|
public void testAuthenticate() { |
|
|
|
when(usersService.createUser(userType, ldapUid, ldapEmail)).thenReturn(mockUser); |
|
|
|
when(sessionService.createSession(Mockito.any(User.class), Mockito.eq(ip))).thenReturn(mockSession.getId()); |
|
|
|
when(usersService.getUserByUserName(ldapUid)).thenReturn(mockUser); |
|
|
|
|
|
|
|
when(sessionService.createSession(mockUser, ip)).thenReturn(mockSession.getId()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
when(ldapService.ldapLogin(ldapUid, ldapUserPwd)).thenReturn(ldapEmail); |
|
|
|
when(ldapService.ldapLogin(ldapUid, ldapUserPwd)).thenReturn(ldapEmail); |
|
|
|
|
|
|
|
|
|
|
|
Result result = ldapAuthenticator.authenticate(ldapUid, ldapUserPwd, ip); |
|
|
|
Result result = ldapAuthenticator.authenticate(ldapUid, ldapUserPwd, ip); |
|
|
|
Assert.assertEquals(Status.SUCCESS.getCode(), (int) result.getCode()); |
|
|
|
Assert.assertEquals(Status.SUCCESS.getCode(), (int) result.getCode()); |
|
|
|
logger.info(result.toString()); |
|
|
|
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); |
|
|
|
result = ldapAuthenticator.authenticate(ldapUid, ldapUserPwd, ip); |
|
|
|
Assert.assertEquals(Status.LOGIN_SESSION_FAILED.getCode(), (int) result.getCode()); |
|
|
|
Assert.assertEquals(Status.LOGIN_SESSION_FAILED.getCode(), (int) result.getCode()); |
|
|
|
|
|
|
|
|
|
|
|
when(sessionService.createSession(mockUser, ip)).thenReturn(mockSession.getId()); |
|
|
|
when(ldapService.ldapLogin(ldapUid, ldapUserPwd)).thenReturn(null); |
|
|
|
when(usersService.getUserByUserName(ldapUid)).thenReturn(null); |
|
|
|
|
|
|
|
result = ldapAuthenticator.authenticate(ldapUid, ldapUserPwd, ip); |
|
|
|
result = ldapAuthenticator.authenticate(ldapUid, ldapUserPwd, ip); |
|
|
|
Assert.assertEquals(Status.USER_NAME_PASSWD_ERROR.getCode(), (int) result.getCode()); |
|
|
|
Assert.assertEquals(Status.USER_NAME_PASSWD_ERROR.getCode(), (int) result.getCode()); |
|
|
|
} |
|
|
|
} |
|
|
|