use of com.thoughtworks.go.config.SecurityAuthConfig in project gocd by gocd.
the class SecurityAuthConfigUpdateCommandTest method shouldUpdateExistingProfile.
@Test
public void shouldUpdateExistingProfile() throws Exception {
SecurityAuthConfig oldAuthConfig = new SecurityAuthConfig("foo", "ldap");
SecurityAuthConfig newAuthConfig = new SecurityAuthConfig("foo", "github");
cruiseConfig.server().security().securityAuthConfigs().add(oldAuthConfig);
SecurityAuthConfigUpdateCommand command = new SecurityAuthConfigUpdateCommand(null, newAuthConfig, null, null, null, null, null);
command.update(cruiseConfig);
assertThat(cruiseConfig.server().security().securityAuthConfigs().find("foo"), is(equalTo(newAuthConfig)));
}
use of com.thoughtworks.go.config.SecurityAuthConfig in project gocd by gocd.
the class RevokeStaleAccessTokenServiceTest method shouldRevokeTheTokensWhenTheAuthConfigsIsDeletedFromTheConfig.
@Test
void shouldRevokeTheTokensWhenTheAuthConfigsIsDeletedFromTheConfig() {
BasicCruiseConfig config = new BasicCruiseConfig();
config.server().security().securityAuthConfigs().add(authConfig1);
config.server().security().securityAuthConfigs().add(authConfig2);
when(goConfigService.getConfigForEditing()).thenReturn(config);
when(accessTokenService.findAllTokensForAllUsers(AccessTokenFilter.active)).thenReturn(Arrays.asList(authConfig1_token1, authConfig1_token2, authConfig2_token1));
service.initialize();
verify(accessTokenService, never()).revokeAccessTokenByGoCD(anyInt(), anyString());
BasicCruiseConfig updated = new BasicCruiseConfig();
updated.server().security().securityAuthConfigs().add(authConfig1);
when(goConfigService.getConfigForEditing()).thenReturn(updated);
service.onEntityConfigChange(new SecurityAuthConfig());
verify(accessTokenService).revokeAccessTokenByGoCD(2, "Revoked by GoCD: The authorization configuration 'authConfig2' referenced from the current access token is deleted from GoCD.");
}
use of com.thoughtworks.go.config.SecurityAuthConfig in project gocd by gocd.
the class SecurityAuthConfigServiceTest method shouldReturnAMapOfSecurityAuthConfigs.
@Test
public void shouldReturnAMapOfSecurityAuthConfigs() throws Exception {
SecurityAuthConfig authConfig = new SecurityAuthConfig("ldap", "cd.go.ldap");
SecurityConfig securityConfig = new SecurityConfig();
securityConfig.securityAuthConfigs().add(authConfig);
when(goConfigService.security()).thenReturn(securityConfig);
HashMap<String, SecurityAuthConfig> expectedMap = new HashMap<>();
expectedMap.put("ldap", authConfig);
Map<String, SecurityAuthConfig> authConfigMap = securityAuthConfigService.listAll();
assertThat(authConfigMap.size(), is(1));
assertThat(authConfigMap, is(expectedMap));
}
use of com.thoughtworks.go.config.SecurityAuthConfig in project gocd by gocd.
the class SecurityAuthConfigServiceTest method shouldAddPluginNotFoundErrorOnConfigForANonExistentPluginIdWhileCreating.
@Test
public void shouldAddPluginNotFoundErrorOnConfigForANonExistentPluginIdWhileCreating() throws Exception {
SecurityAuthConfig securityAuthConfig = new SecurityAuthConfig("some-id", "non-existent-plugin", create("key", false, "value"));
Username username = new Username("username");
when(extension.validateAuthConfig(securityAuthConfig.getPluginId(), securityAuthConfig.getConfigurationAsMap(true))).thenThrow(new RecordNotFoundException("some error"));
securityAuthConfigService.create(username, securityAuthConfig, new HttpLocalizedOperationResult());
assertThat(securityAuthConfig.errors().isEmpty(), is(false));
assertThat(securityAuthConfig.errors().on("pluginId"), is("Plugin with id `non-existent-plugin` is not found."));
}
use of com.thoughtworks.go.config.SecurityAuthConfig in project gocd by gocd.
the class SecurityAuthConfigServiceTest method shouldGetAListOfAllConfiguredWebBasedAuthorizationPlugins.
@Test
public void shouldGetAListOfAllConfiguredWebBasedAuthorizationPlugins() {
Set<AuthorizationPluginInfo> installedWebBasedPlugins = new HashSet<>();
String githubPluginId = "cd.go.github";
AuthorizationPluginInfo githubPluginInfo = pluginInfo(githubPluginId, "GitHub Auth Plugin", SupportedAuthType.Web);
installedWebBasedPlugins.add(githubPluginInfo);
installedWebBasedPlugins.add(pluginInfo(githubPluginId, "Google Auth Plugin", SupportedAuthType.Web));
when(authorizationMetadataStore.getPluginsThatSupportsWebBasedAuthentication()).thenReturn(installedWebBasedPlugins);
when(authorizationMetadataStore.getPluginInfo(githubPluginId)).thenReturn(githubPluginInfo);
SecurityConfig securityConfig = new SecurityConfig();
SecurityAuthConfig github = new SecurityAuthConfig("github", githubPluginId);
SecurityAuthConfig ldap = new SecurityAuthConfig("ldap", "cd.go.ldap");
securityConfig.securityAuthConfigs().add(github);
securityConfig.securityAuthConfigs().add(ldap);
when(goConfigService.security()).thenReturn(securityConfig);
List<AuthPluginInfoViewModel> allWebBasedAuthorizationConfigs = securityAuthConfigService.getAllConfiguredWebBasedAuthorizationPlugins();
assertThat(allWebBasedAuthorizationConfigs.size(), is(1));
AuthPluginInfoViewModel pluginInfoViewModel = allWebBasedAuthorizationConfigs.get(0);
assertThat(pluginInfoViewModel.pluginId(), is(githubPluginId));
assertThat(pluginInfoViewModel.name(), is("GitHub Auth Plugin"));
assertThat(pluginInfoViewModel.imageUrl(), is("/go/api/plugin_images/cd.go.github/hash"));
}
Aggregations