Search in sources :

Example 1 with LoginActions

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());
}
Also used : LoginActions(com.blackducksoftware.integration.hub.alert.web.actions.LoginActions) AlertFieldException(com.blackducksoftware.integration.hub.alert.exception.AlertFieldException) Test(org.junit.Test)

Example 2 with LoginActions

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());
}
Also used : LoginActions(com.blackducksoftware.integration.hub.alert.web.actions.LoginActions) Test(org.junit.Test)

Example 3 with LoginActions

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());
}
Also used : MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) HttpServletRequest(javax.servlet.http.HttpServletRequest) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) HttpSession(javax.servlet.http.HttpSession) HttpServletResponse(javax.servlet.http.HttpServletResponse) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) LoginActions(com.blackducksoftware.integration.hub.alert.web.actions.LoginActions) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test)

Example 4 with LoginActions

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());
}
Also used : IntegrationRestException(com.blackducksoftware.integration.hub.rest.exception.IntegrationRestException) HttpStatus(org.springframework.http.HttpStatus) LoginActions(com.blackducksoftware.integration.hub.alert.web.actions.LoginActions) Test(org.junit.Test)

Example 5 with LoginActions

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());
}
Also used : MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) HttpServletRequest(javax.servlet.http.HttpServletRequest) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) HttpSession(javax.servlet.http.HttpSession) HttpServletResponse(javax.servlet.http.HttpServletResponse) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) LoginActions(com.blackducksoftware.integration.hub.alert.web.actions.LoginActions) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test)

Aggregations

LoginActions (com.blackducksoftware.integration.hub.alert.web.actions.LoginActions)5 Test (org.junit.Test)5 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 HttpServletResponse (javax.servlet.http.HttpServletResponse)2 HttpSession (javax.servlet.http.HttpSession)2 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)2 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)2 AlertFieldException (com.blackducksoftware.integration.hub.alert.exception.AlertFieldException)1 IntegrationRestException (com.blackducksoftware.integration.hub.rest.exception.IntegrationRestException)1 HttpStatus (org.springframework.http.HttpStatus)1