use of com.thoughtworks.go.config.SecurityConfig in project gocd by gocd.
the class SecurityAuthConfigServiceTest method shouldGetNullIfSecurityAuthConfigByGivenIdIsNotPresent.
@Test
public void shouldGetNullIfSecurityAuthConfigByGivenIdIsNotPresent() {
when(goConfigService.security()).thenReturn(new SecurityConfig());
assertNull(securityAuthConfigService.findProfile("ldap"));
}
use of com.thoughtworks.go.config.SecurityConfig in project gocd by gocd.
the class PasswordBasedPluginAuthenticationProviderTest method setUp.
@BeforeEach
void setUp() {
SecurityService securityService = mock(SecurityService.class);
AuthorityGranter authorityGranter = new AuthorityGranter(securityService);
GoConfigService goConfigService = mock(GoConfigService.class);
userService = mock(UserService.class);
authorizationExtension = mock(AuthorizationExtension.class);
pluginRoleService = mock(PluginRoleService.class);
clock = new TestingClock();
securityConfig = new SecurityConfig();
when(goConfigService.security()).thenReturn(securityConfig);
provider = new PasswordBasedPluginAuthenticationProvider(authorizationExtension, authorityGranter, goConfigService, pluginRoleService, userService, clock);
}
use of com.thoughtworks.go.config.SecurityConfig in project gocd by gocd.
the class FileAuthenticationProviderTest method setupFile.
private void setupFile(String userAndPasswordAndRoles) throws IOException {
final File passwordFile = TestFileUtil.createTempFile("password.properties");
passwordFile.deleteOnExit();
FileUtils.writeStringToFile(passwordFile, userAndPasswordAndRoles);
final SecurityConfig securityConfig = new SecurityConfig(new LdapConfig(new GoCipher()), new PasswordFileConfig(passwordFile.getAbsolutePath()), true, null);
when(goConfigService.security()).thenReturn(securityConfig);
}
use of com.thoughtworks.go.config.SecurityConfig 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))));
}
use of com.thoughtworks.go.config.SecurityConfig in project gocd by gocd.
the class FileAuthenticationProviderTest method shouldThrowExceptionIfFileDoesNotExist.
@Test(expected = UsernameNotFoundException.class)
public void shouldThrowExceptionIfFileDoesNotExist() throws Exception {
when(goConfigService.security()).thenReturn(new SecurityConfig(new LdapConfig(new GoCipher()), new PasswordFileConfig("ueyrweiyri"), true, null));
AuthorityGranter authorityGranter = new AuthorityGranter(securityService);
FileAuthenticationProvider provider = new FileAuthenticationProvider(goConfigService, authorityGranter, userService, securityService);
provider.retrieveUser("blah", null);
}
Aggregations