use of com.synopsys.integration.alert.component.authentication.security.AlertAuthenticationProvider 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());
}
use of com.synopsys.integration.alert.component.authentication.security.AlertAuthenticationProvider in project hub-alert by blackducksoftware.
the class AuthenticationActionsTestIT method testAuthenticationLDAPExceptionIT.
@Test
public void testAuthenticationLDAPExceptionIT() throws Exception {
HttpServletRequest servletRequest = new MockHttpServletRequest();
HttpServletResponse servletResponse = new MockHttpServletResponse();
Authentication authentication = Mockito.mock(Authentication.class);
Mockito.when(authentication.isAuthenticated()).thenReturn(true);
LdapAuthenticationProvider ldapAuthenticationProvider = Mockito.mock(LdapAuthenticationProvider.class);
Mockito.when(ldapAuthenticationProvider.authenticate(Mockito.any(Authentication.class))).thenReturn(authentication);
LdapManager mockLdapManager = Mockito.mock(LdapManager.class);
Mockito.when(mockLdapManager.isLdapEnabled()).thenReturn(true);
Mockito.when(mockLdapManager.getAuthenticationProvider()).thenThrow(new AlertConfigurationException("LDAP CONFIG EXCEPTION"));
DaoAuthenticationProvider databaseProvider = Mockito.mock(DaoAuthenticationProvider.class);
Mockito.when(databaseProvider.authenticate(Mockito.any(Authentication.class))).thenReturn(authentication);
AuthenticationEventManager authenticationEventManager = Mockito.mock(AuthenticationEventManager.class);
Mockito.doNothing().when(authenticationEventManager).sendAuthenticationEvent(Mockito.any(), Mockito.eq(AuthenticationType.LDAP));
RoleAccessor roleAccessor = Mockito.mock(RoleAccessor.class);
AlertDatabaseAuthenticationPerformer alertDatabaseAuthenticationPerformer = new AlertDatabaseAuthenticationPerformer(authenticationEventManager, roleAccessor, databaseProvider);
LdapAuthenticationPerformer ldapAuthenticationPerformer = new LdapAuthenticationPerformer(authenticationEventManager, roleAccessor, mockLdapManager);
AlertAuthenticationProvider authenticationProvider = new AlertAuthenticationProvider(List.of(ldapAuthenticationPerformer, alertDatabaseAuthenticationPerformer));
AuthenticationActions authenticationActions = new AuthenticationActions(authenticationProvider, csrfTokenRepository);
ActionResponse<Void> response = authenticationActions.authenticateUser(servletRequest, servletResponse, mockLoginRestModel.createRestModel());
assertTrue(response.isError());
Mockito.verify(databaseProvider).authenticate(Mockito.any(Authentication.class));
}
Aggregations