Search in sources :

Example 6 with User

use of com.thoughtworks.go.plugin.domain.authorization.User in project gocd by gocd.

the class UserSearchServiceTest method shouldSearchUserUsingPlugins.

@Test
public void shouldSearchUserUsingPlugins() throws Exception {
    final String searchTerm = "foo";
    List<String> pluginIds = asList("plugin-id-1", "plugin-id-2", "plugin-id-3", "plugin-id-4");
    addPluginSupportingUserSearch(pluginIds.get(0));
    addPluginSupportingUserSearch(pluginIds.get(1));
    addPluginSupportingUserSearch(pluginIds.get(2));
    addPluginSupportingUserSearch(pluginIds.get(3));
    when(authorizationExtension.canHandlePlugin(anyString())).thenReturn(true);
    when(goConfigService.security()).thenReturn(new SecurityConfig());
    when(authorizationExtension.searchUsers("plugin-id-1", searchTerm, Collections.emptyList())).thenReturn(asList(getPluginUser(1)));
    when(authorizationExtension.searchUsers("plugin-id-2", searchTerm, Collections.emptyList())).thenReturn(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(asList(new User("username-" + 4, null, null)));
    List<UserSearchModel> models = userSearchService.search(searchTerm, new HttpLocalizedOperationResult());
    assertThat(models, Matchers.containsInAnyOrder(new UserSearchModel(getUser(1), UserSourceType.PLUGIN), new UserSearchModel(getUser(2), UserSourceType.PLUGIN), new UserSearchModel(getUser(3), UserSourceType.PLUGIN), new UserSearchModel(new com.thoughtworks.go.domain.User("username-" + 4, "", ""), UserSourceType.PLUGIN)));
}
Also used : HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) User(com.thoughtworks.go.plugin.domain.authorization.User) SecurityConfig(com.thoughtworks.go.config.SecurityConfig) UserSearchModel(com.thoughtworks.go.presentation.UserSearchModel) Test(org.junit.jupiter.api.Test)

Aggregations

User (com.thoughtworks.go.plugin.domain.authorization.User)6 AuthenticationResponse (com.thoughtworks.go.plugin.domain.authorization.AuthenticationResponse)4 Test (org.junit.jupiter.api.Test)4 SecurityAuthConfig (com.thoughtworks.go.config.SecurityAuthConfig)3 DefaultGoPluginApiResponse (com.thoughtworks.go.plugin.api.response.DefaultGoPluginApiResponse)3 PluginRoleConfig (com.thoughtworks.go.config.PluginRoleConfig)2 SecurityAuthConfigs (com.thoughtworks.go.config.SecurityAuthConfigs)2 InvalidAccessTokenException (com.thoughtworks.go.server.exceptions.InvalidAccessTokenException)2 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)1 SecurityConfig (com.thoughtworks.go.config.SecurityConfig)1 UserSearchModel (com.thoughtworks.go.presentation.UserSearchModel)1 OnlyKnownUsersAllowedException (com.thoughtworks.go.server.security.OnlyKnownUsersAllowedException)1 GoUserPrinciple (com.thoughtworks.go.server.security.userdetail.GoUserPrinciple)1 HttpLocalizedOperationResult (com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)1 ArrayList (java.util.ArrayList)1