use of com.thoughtworks.go.config.SecurityAuthConfig in project gocd by gocd.
the class SecurityAuthConfigCreateCommandTest method shouldAddSecurityAuthConfig.
@Test
public void shouldAddSecurityAuthConfig() throws Exception {
BasicCruiseConfig cruiseConfig = GoConfigMother.defaultCruiseConfig();
SecurityAuthConfig authConfig = new SecurityAuthConfig("foo", "ldap");
SecurityAuthConfigCreateCommand command = new SecurityAuthConfigCreateCommand(null, authConfig, extension, null, null);
command.update(cruiseConfig);
assertThat(cruiseConfig.server().security().securityAuthConfigs().find("foo"), equalTo(authConfig));
}
use of com.thoughtworks.go.config.SecurityAuthConfig in project gocd by gocd.
the class SecurityAuthConfigUpdateCommandTest method shouldRaiseErrorWhenUpdatingNonExistentProfile.
@Test
public void shouldRaiseErrorWhenUpdatingNonExistentProfile() throws Exception {
cruiseConfig.server().security().securityAuthConfigs().clear();
SecurityAuthConfigUpdateCommand command = new SecurityAuthConfigUpdateCommand(null, new SecurityAuthConfig("foo", "ldap"), null, null, new HttpLocalizedOperationResult(), null, null);
assertThatThrownBy(() -> command.update(cruiseConfig)).isInstanceOf(RecordNotFoundException.class);
}
use of com.thoughtworks.go.config.SecurityAuthConfig in project gocd by gocd.
the class SecurityAuthConfigCommandTest method shouldNotContinueWithConfigSaveIfUserIsUnauthorized.
@Test
public void shouldNotContinueWithConfigSaveIfUserIsUnauthorized() throws Exception {
SecurityAuthConfig securityAuthConfig = new SecurityAuthConfig("blackbird", "ldap");
when(goConfigService.isUserAdmin(currentUser)).thenReturn(false);
HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
SecurityAuthConfigCommand command = new SecurityAuthConfigCommandTest.StubCommand(goConfigService, securityAuthConfig, extension, currentUser, result);
assertThat(cruiseConfig.server().security().securityAuthConfigs().find("foo"), nullValue());
assertThat(command.canContinue(cruiseConfig), is(false));
assertThat(result.message(), is(EntityType.SecurityAuthConfig.forbiddenToEdit(securityAuthConfig.getId(), currentUser.getUsername())));
}
use of com.thoughtworks.go.config.SecurityAuthConfig in project gocd by gocd.
the class SecurityAuthConfigCommandTest method shouldContinueWithConfigSaveIfUserIsAdmin.
@Test
public void shouldContinueWithConfigSaveIfUserIsAdmin() throws Exception {
SecurityAuthConfig securityAuthConfig = new SecurityAuthConfig("blackbird", "ldap");
when(goConfigService.isUserAdmin(currentUser)).thenReturn(true);
HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
SecurityAuthConfigCommand command = new SecurityAuthConfigCommandTest.StubCommand(goConfigService, securityAuthConfig, extension, 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 SecurityAuthConfigDeleteCommandTest method shouldDeleteAProfile.
@Test
public void shouldDeleteAProfile() throws Exception {
SecurityAuthConfig authConfig = new SecurityAuthConfig("foo", "ldap");
cruiseConfig.server().security().securityAuthConfigs().add(authConfig);
SecurityAuthConfigDeleteCommand command = new SecurityAuthConfigDeleteCommand(null, authConfig, null, null, null);
command.update(cruiseConfig);
assertThat(cruiseConfig.server().security().securityAuthConfigs(), is(empty()));
}
Aggregations