use of com.blackducksoftware.integration.hub.alert.web.actions.LoginActions in project hub-alert by blackducksoftware.
the class LoginHandlerTest method authenticateUserWithAlertFieldExceptionTest.
@Test
public void authenticateUserWithAlertFieldExceptionTest() throws IntegrationException {
final LoginActions loginActions = Mockito.mock(LoginActions.class);
final LoginHandler loginHandler = new LoginHandler(objectTransformer, loginActions, csrfTokenRepository);
Mockito.when(loginActions.authenticateUser(Mockito.any(), Mockito.any())).thenThrow(new AlertFieldException(Collections.emptyMap()));
final ResponseEntity<String> response = loginHandler.authenticateUser(null, null, null);
assertEquals(HttpStatus.BAD_REQUEST, response.getStatusCode());
}
use of com.blackducksoftware.integration.hub.alert.web.actions.LoginActions in project hub-alert by blackducksoftware.
the class LoginHandlerTest method authenticateUserWithExceptionTest.
@Test
public void authenticateUserWithExceptionTest() throws IntegrationException {
final LoginActions loginActions = Mockito.mock(LoginActions.class);
final LoginHandler loginHandler = new LoginHandler(objectTransformer, loginActions, csrfTokenRepository);
Mockito.when(loginActions.authenticateUser(Mockito.any(), Mockito.any())).thenThrow(new NullPointerException());
final ResponseEntity<String> response = loginHandler.authenticateUser(null, null, null);
assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, response.getStatusCode());
}
use of com.blackducksoftware.integration.hub.alert.web.actions.LoginActions in project hub-alert by blackducksoftware.
the class LoginHandlerTest method userLoginWithValidSessionTest.
@Test
public void userLoginWithValidSessionTest() throws IntegrationException {
final LoginActions loginActions = Mockito.mock(LoginActions.class);
final LoginHandler loginHandler = new LoginHandler(objectTransformer, loginActions, csrfTokenRepository);
final HttpServletRequest request = new MockHttpServletRequest();
final HttpSession session = request.getSession(true);
session.setMaxInactiveInterval(30);
final HttpServletResponse httpResponse = new MockHttpServletResponse();
Mockito.when(loginActions.authenticateUser(Mockito.any(), Mockito.any())).thenReturn(true);
final ResponseEntity<String> response = loginHandler.userLogin(request, httpResponse, null);
assertEquals(HttpStatus.OK, response.getStatusCode());
}
use of com.blackducksoftware.integration.hub.alert.web.actions.LoginActions in project hub-alert by blackducksoftware.
the class LoginHandlerTest method authenticateUserWithIntegrationRestExceptionTest.
@Test
public void authenticateUserWithIntegrationRestExceptionTest() throws IntegrationException {
final LoginActions loginActions = Mockito.mock(LoginActions.class);
final LoginHandler loginHandler = new LoginHandler(objectTransformer, loginActions, csrfTokenRepository);
final HttpStatus responseCode = HttpStatus.BAD_GATEWAY;
Mockito.when(loginActions.authenticateUser(Mockito.any(), Mockito.any())).thenThrow(new IntegrationRestException(responseCode.value(), "", ""));
final ResponseEntity<String> response = loginHandler.authenticateUser(null, null, null);
assertEquals(responseCode, response.getStatusCode());
}
use of com.blackducksoftware.integration.hub.alert.web.actions.LoginActions in project hub-alert by blackducksoftware.
the class LoginHandlerTest method userLoginWithInvalidSessionTest.
@Test
public void userLoginWithInvalidSessionTest() throws IntegrationException {
final LoginActions loginActions = Mockito.mock(LoginActions.class);
final LoginHandler loginHandler = new LoginHandler(objectTransformer, loginActions, csrfTokenRepository);
final HttpServletRequest request = new MockHttpServletRequest();
HttpSession session = request.getSession(false);
if (session != null) {
session = null;
}
Mockito.when(loginActions.authenticateUser(Mockito.any(), Mockito.any())).thenReturn(false);
final HttpServletResponse httpResponse = new MockHttpServletResponse();
final ResponseEntity<String> response = loginHandler.userLogin(request, httpResponse, null);
assertEquals(HttpStatus.UNAUTHORIZED, response.getStatusCode());
}
Aggregations