Search in sources :

Example 1 with MockLoginRestModel

use of com.synopsys.integration.alert.mock.model.MockLoginRestModel in project hub-alert by blackducksoftware.

the class AuthenticationActionsTestIT method userLoginWithBadCredentialsTest.

@Test
public void userLoginWithBadCredentialsTest() {
    AlertAuthenticationProvider authenticationProvider = Mockito.mock(AlertAuthenticationProvider.class);
    Mockito.when(authenticationProvider.authenticate(Mockito.any())).thenThrow(new BadCredentialsException("Bad credentials test"));
    AuthenticationActions authenticationActions = new AuthenticationActions(authenticationProvider, csrfTokenRepository);
    HttpServletRequest servletRequest = new MockHttpServletRequest();
    HttpServletResponse servletResponse = new MockHttpServletResponse();
    TestProperties testProperties = new TestProperties();
    MockLoginRestModel mockLoginRestModel = new MockLoginRestModel();
    mockLoginRestModel.setAlertUsername(testProperties.getProperty(TestPropertyKey.TEST_BLACKDUCK_PROVIDER_USERNAME));
    mockLoginRestModel.setAlertPassword(testProperties.getProperty(TestPropertyKey.TEST_BLACKDUCK_PROVIDER_PASSWORD));
    ActionResponse<Void> response = authenticationActions.authenticateUser(servletRequest, servletResponse, mockLoginRestModel.createRestModel());
    assertTrue(response.isError());
    assertEquals(HttpStatus.UNAUTHORIZED, response.getHttpStatus());
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) TestProperties(com.synopsys.integration.alert.test.common.TestProperties) MockLoginRestModel(com.synopsys.integration.alert.mock.model.MockLoginRestModel) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) HttpServletResponse(javax.servlet.http.HttpServletResponse) AlertAuthenticationProvider(com.synopsys.integration.alert.component.authentication.security.AlertAuthenticationProvider) BadCredentialsException(org.springframework.security.authentication.BadCredentialsException) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) AlertIntegrationTest(com.synopsys.integration.alert.util.AlertIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 2 with MockLoginRestModel

use of com.synopsys.integration.alert.mock.model.MockLoginRestModel in project hub-alert by blackducksoftware.

the class AuthenticationActionsTestIT method testAuthenticateDBUserFailIT.

@Test
public void testAuthenticateDBUserFailIT() {
    HttpServletRequest servletRequest = new MockHttpServletRequest();
    HttpServletResponse servletResponse = new MockHttpServletResponse();
    mockLoginRestModel.setAlertUsername(properties.getProperty(TestPropertyKey.TEST_BLACKDUCK_PROVIDER_ACTIVE_USER));
    AuthenticationActions authenticationActions = new AuthenticationActions(authenticationProvider, csrfTokenRepository);
    MockLoginRestModel badRestModel = new MockLoginRestModel();
    badRestModel.setAlertPassword("badpassword");
    ActionResponse<Void> response = authenticationActions.authenticateUser(servletRequest, servletResponse, badRestModel.createRestModel());
    assertTrue(response.isError());
    assertFalse(response.hasContent());
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) MockLoginRestModel(com.synopsys.integration.alert.mock.model.MockLoginRestModel) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) HttpServletResponse(javax.servlet.http.HttpServletResponse) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) AlertIntegrationTest(com.synopsys.integration.alert.util.AlertIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 3 with MockLoginRestModel

use of com.synopsys.integration.alert.mock.model.MockLoginRestModel in project hub-alert by blackducksoftware.

the class AuthenticationControllerTestIT method testLogin.

@Test
public void testLogin() throws Exception {
    MockHttpServletRequestBuilder request = MockMvcRequestBuilders.post(loginUrl);
    TestProperties testProperties = new TestProperties();
    MockLoginRestModel mockLoginRestModel = new MockLoginRestModel();
    mockLoginRestModel.setAlertUsername(testProperties.getProperty(TestPropertyKey.TEST_BLACKDUCK_PROVIDER_USERNAME));
    mockLoginRestModel.setAlertPassword(testProperties.getProperty(TestPropertyKey.TEST_BLACKDUCK_PROVIDER_PASSWORD));
    ReflectionTestUtils.setField(alertProperties, "alertTrustCertificate", Boolean.valueOf(testProperties.getProperty(TestPropertyKey.TEST_BLACKDUCK_PROVIDER_TRUST_HTTPS_CERT)));
    String restModel = mockLoginRestModel.getRestModelJson();
    request.content(restModel);
    request.contentType(contentType);
    mockMvc.perform(request).andExpect(MockMvcResultMatchers.status().isNoContent());
}
Also used : TestProperties(com.synopsys.integration.alert.test.common.TestProperties) MockLoginRestModel(com.synopsys.integration.alert.mock.model.MockLoginRestModel) MockHttpServletRequestBuilder(org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder) AlertIntegrationTest(com.synopsys.integration.alert.util.AlertIntegrationTest) Test(org.junit.jupiter.api.Test)

Aggregations

MockLoginRestModel (com.synopsys.integration.alert.mock.model.MockLoginRestModel)3 AlertIntegrationTest (com.synopsys.integration.alert.util.AlertIntegrationTest)3 Test (org.junit.jupiter.api.Test)3 TestProperties (com.synopsys.integration.alert.test.common.TestProperties)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 HttpServletResponse (javax.servlet.http.HttpServletResponse)2 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)2 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)2 AlertAuthenticationProvider (com.synopsys.integration.alert.component.authentication.security.AlertAuthenticationProvider)1 BadCredentialsException (org.springframework.security.authentication.BadCredentialsException)1 MockHttpServletRequestBuilder (org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder)1