use of com.thoughtworks.go.presentation.UserSearchModel in project gocd by gocd.
the class UserSearchServiceTest method shouldReturnWarningMessageWhenPasswordSearchFails.
@Test
public void shouldReturnWarningMessageWhenPasswordSearchFails() throws Exception {
HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
when(goConfigService.isPasswordFileConfigured()).thenReturn(true);
when(passwordFileUserSearch.search("foo")).thenThrow(new RuntimeException("Password file not found"));
when(ldapUserSearch.search("foo")).thenReturn(new ArrayList<>());
List<UserSearchModel> models = userSearchService.search("foo", result);
assertThat(models.size(), is(0));
assertThat(result.localizable(), is(LocalizedMessage.string("PASSWORD_SEARCH_FAILED")));
}
use of com.thoughtworks.go.presentation.UserSearchModel in project gocd by gocd.
the class UserSearchServiceTest method shouldAddPluginSearchResultsWhenPluginImplementsAuthenticationExtension.
@Test
public void shouldAddPluginSearchResultsWhenPluginImplementsAuthenticationExtension() {
String searchTerm = "foo";
List<String> pluginIds = Arrays.asList("plugin-id-1", "plugin-id-2", "plugin-id-3", "plugin-id-4");
when(authenticationPluginRegistry.getAuthenticationPlugins()).thenReturn(new HashSet<String>(pluginIds));
when(authenticationExtension.canHandlePlugin(anyString())).thenReturn(true);
when(authenticationExtension.searchUser("plugin-id-1", searchTerm)).thenReturn(Arrays.asList(getPluginUser(1)));
when(authenticationExtension.searchUser("plugin-id-2", searchTerm)).thenReturn(Arrays.asList(getPluginUser(2), getPluginUser(3)));
when(authenticationExtension.searchUser("plugin-id-3", searchTerm)).thenReturn(new ArrayList<com.thoughtworks.go.plugin.access.authentication.models.User>());
when(authenticationExtension.searchUser("plugin-id-4", searchTerm)).thenReturn(Arrays.asList(new com.thoughtworks.go.plugin.access.authentication.models.User("username-" + 4, null, null)));
List<UserSearchModel> models = userSearchService.search(searchTerm, new HttpLocalizedOperationResult());
assertThat(models, is(Arrays.asList(new UserSearchModel(getUser(1), UserSourceType.PLUGIN), new UserSearchModel(getUser(2), UserSourceType.PLUGIN), new UserSearchModel(getUser(3), UserSourceType.PLUGIN), new UserSearchModel(new User("username-" + 4, "", ""), UserSourceType.PLUGIN))));
}
use of com.thoughtworks.go.presentation.UserSearchModel in project gocd by gocd.
the class UserSearchServiceTest method shouldLimitSearchResultsAndWarnTheUser.
@Test
public void shouldLimitSearchResultsAndWarnTheUser() throws Exception {
HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
User foo = new User("fooUser", "Foo User", "foo@user.com");
User bar = new User("barUser", "boo User", "boo@user.com");
when(ldapUserSearch.search("foo")).thenThrow(new LdapUserSearch.NotAllResultsShownException(Arrays.asList(foo, bar)));
when(passwordFileUserSearch.search("foo")).thenReturn(new ArrayList<>());
List<UserSearchModel> models = userSearchService.search("foo", result);
assertThat(models.size(), is(2));
assertThat(result.localizable(), is(LocalizedMessage.string("NOT_ALL_RESULTS_SHOWN")));
}
use of com.thoughtworks.go.presentation.UserSearchModel in project gocd by gocd.
the class UserSearchServiceTest method shouldReturnWarningMessageWhenLdapSearchFails.
@Test
public void shouldReturnWarningMessageWhenLdapSearchFails() throws Exception {
User foo = new User("foo", new ArrayList<>(), "foo@cruise.com", false);
HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
when(goConfigService.isPasswordFileConfigured()).thenReturn(true);
when(ldapUserSearch.search("foo")).thenThrow(new RuntimeException("Ldap Error"));
when(passwordFileUserSearch.search("foo")).thenReturn(Arrays.asList(foo));
List<UserSearchModel> models = userSearchService.search("foo", result);
assertThat(models, is(Arrays.asList(new UserSearchModel(foo, UserSourceType.PASSWORD_FILE))));
assertThat(result.localizable(), is(LocalizedMessage.string("LDAP_ERROR")));
}
use of com.thoughtworks.go.presentation.UserSearchModel in project gocd by gocd.
the class UserSearchServiceTest method shouldAddPluginSearchResults.
@Test
public void shouldAddPluginSearchResults() throws Exception {
String searchTerm = "foo";
User foo = new User("foo", new ArrayList<>(), "foo@cruise.com", false);
User bar = new User("bar-foo", new ArrayList<>(), "bar@go.com", true);
when(ldapUserSearch.search(searchTerm)).thenReturn(Arrays.asList(foo, bar));
List<String> pluginIds = Arrays.asList("plugin-id-1", "plugin-id-2", "plugin-id-3", "plugin-id-4");
when(metadataStore.getPluginsThatSupportsUserSearch()).thenReturn(new HashSet<>(pluginIds));
when(authorizationExtension.canHandlePlugin(anyString())).thenReturn(true);
when(goConfigService.security()).thenReturn(new SecurityConfig());
when(authorizationExtension.searchUsers("plugin-id-1", searchTerm, Collections.emptyList())).thenReturn(Arrays.asList(getPluginUser(1)));
when(authorizationExtension.searchUsers("plugin-id-2", searchTerm, Collections.emptyList())).thenReturn(Arrays.asList(getPluginUser(2), getPluginUser(3)));
when(authorizationExtension.searchUsers("plugin-id-3", searchTerm, Collections.emptyList())).thenReturn(new ArrayList<>());
when(authorizationExtension.searchUsers("plugin-id-4", searchTerm, Collections.emptyList())).thenReturn(Arrays.asList(new com.thoughtworks.go.plugin.access.authentication.models.User("username-" + 4, null, null)));
List<UserSearchModel> models = userSearchService.search(searchTerm, new HttpLocalizedOperationResult());
assertThat(models, is(Arrays.asList(new UserSearchModel(foo, UserSourceType.LDAP), new UserSearchModel(bar, UserSourceType.LDAP), new UserSearchModel(getUser(1), UserSourceType.PLUGIN), new UserSearchModel(getUser(2), UserSourceType.PLUGIN), new UserSearchModel(getUser(3), UserSourceType.PLUGIN), new UserSearchModel(new User("username-" + 4, "", ""), UserSourceType.PLUGIN))));
}
Aggregations