use of com.thoughtworks.go.config.SecurityAuthConfig in project gocd by gocd.
the class SecurityAuthConfigDeleteCommandTest method shouldRaiseExceptionInCaseProfileDoesNotExist.
@Test
public void shouldRaiseExceptionInCaseProfileDoesNotExist() throws Exception {
SecurityAuthConfig authConfig = new SecurityAuthConfig("foo", "ldap");
assertThat(cruiseConfig.server().security().securityAuthConfigs(), is(empty()));
SecurityAuthConfigDeleteCommand command = new SecurityAuthConfigDeleteCommand(null, authConfig, null, null, new HttpLocalizedOperationResult());
assertThatThrownBy(() -> command.update(cruiseConfig)).isInstanceOf(RecordNotFoundException.class);
assertThat(cruiseConfig.server().security().securityAuthConfigs(), is(empty()));
}
use of com.thoughtworks.go.config.SecurityAuthConfig in project gocd by gocd.
the class SecurityAuthConfigDeleteCommandTest method shouldValidateIfProfileIsNotInUseByPipeline.
@Test
public void shouldValidateIfProfileIsNotInUseByPipeline() throws Exception {
SecurityAuthConfig authConfig = new SecurityAuthConfig("foo", "ldap");
assertThat(cruiseConfig.server().security().securityAuthConfigs(), is(empty()));
SecurityAuthConfigDeleteCommand command = new SecurityAuthConfigDeleteCommand(null, authConfig, null, null, new HttpLocalizedOperationResult());
assertTrue(command.isValid(cruiseConfig));
}
use of com.thoughtworks.go.config.SecurityAuthConfig in project gocd by gocd.
the class PluginProfileCommandTest method shouldValidateIfSecurityAuthConfigIdIsNull.
@Test
public void shouldValidateIfSecurityAuthConfigIdIsNull() {
HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
SecurityAuthConfig securityAuthConfig = new SecurityAuthConfig(null, "some-plugin", new ConfigurationProperty(new ConfigurationKey("key"), new ConfigurationValue("value")));
cruiseConfig.server().security().securityAuthConfigs().add(securityAuthConfig);
PluginProfileCommand command = new StubSecurityAuthConfigCommand(goConfigService, securityAuthConfig, currentUser, result);
assertThatThrownBy(() -> command.isValid(cruiseConfig)).hasMessageContaining(EntityType.ElasticProfile.idCannotBeBlank());
}
use of com.thoughtworks.go.config.SecurityAuthConfig in project gocd by gocd.
the class PluginProfileCommandTest method shouldContinueWithConfigSaveIfUserIsAdmin.
@Test
public void shouldContinueWithConfigSaveIfUserIsAdmin() throws Exception {
SecurityAuthConfig securityAuthConfig = new SecurityAuthConfig("ldap", "cd.go.ldap");
when(goConfigService.isUserAdmin(currentUser)).thenReturn(true);
HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
PluginProfileCommand command = new StubSecurityAuthConfigCommand(goConfigService, securityAuthConfig, currentUser, result);
assertThat(cruiseConfig.server().security().securityAuthConfigs().find("ldap"), nullValue());
assertThat(command.canContinue(cruiseConfig), is(true));
}
use of com.thoughtworks.go.config.SecurityAuthConfig in project gocd by gocd.
the class PluginProfileCommandTest method shouldNotContinueWithConfigSaveIfUserIsUnauthorized.
@Test
public void shouldNotContinueWithConfigSaveIfUserIsUnauthorized() throws Exception {
SecurityAuthConfig securityAuthConfig = new SecurityAuthConfig("ldap", "cd.go.ldap");
when(goConfigService.isUserAdmin(currentUser)).thenReturn(false);
HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
PluginProfileCommand command = new StubSecurityAuthConfigCommand(goConfigService, securityAuthConfig, currentUser, result);
assertThat(cruiseConfig.server().security().securityAuthConfigs().find("foo"), nullValue());
assertThat(command.canContinue(cruiseConfig), is(false));
assertThat(result.message(), equalTo("Unauthorized to edit."));
}
Aggregations