use of com.thoughtworks.go.config.SecurityAuthConfig in project gocd by gocd.
the class SecurityAuthConfigCommandTest method shouldContinueWithConfigSaveIfUserIsAuthorized.
@Test
public void shouldContinueWithConfigSaveIfUserIsAuthorized() 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));
assertThat(result.httpCode(), is(200));
}
use of com.thoughtworks.go.config.SecurityAuthConfig in project gocd by gocd.
the class SecurityAuthConfigCommandTest method shouldValidateWithErrorIfNameIsNull.
@Test
public void shouldValidateWithErrorIfNameIsNull() {
HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
SecurityAuthConfig securityAuthConfig = new SecurityAuthConfig(null, "ldap");
cruiseConfig.server().security().securityAuthConfigs().add(securityAuthConfig);
SecurityAuthConfigCommand command = new SecurityAuthConfigCommandTest.StubCommand(goConfigService, securityAuthConfig, extension, currentUser, result);
assertThatThrownBy(() -> command.isValid(cruiseConfig)).hasMessageContaining(EntityType.SecurityAuthConfig.idCannotBeBlank());
}
use of com.thoughtworks.go.config.SecurityAuthConfig in project gocd by gocd.
the class SecurityAuthConfigCommandTest method shouldPassValidationIfNameIsNotNull.
@Test
public void shouldPassValidationIfNameIsNotNull() {
HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
SecurityAuthConfig securityAuthConfig = new SecurityAuthConfig("foo", "ldap");
cruiseConfig.server().security().securityAuthConfigs().add(securityAuthConfig);
when(extension.validateAuthConfig(eq("ldap"), ArgumentMatchers.anyMap())).thenReturn(new ValidationResult());
SecurityAuthConfigCommand command = new SecurityAuthConfigCommandTest.StubCommand(goConfigService, securityAuthConfig, extension, currentUser, result);
boolean isValid = command.isValid(cruiseConfig);
assertTrue(isValid);
}
use of com.thoughtworks.go.config.SecurityAuthConfig in project gocd by gocd.
the class SecurityAuthConfigDeleteCommandTest method shouldNotValidateIfProfileIsInUseByRole.
@Test
public void shouldNotValidateIfProfileIsInUseByRole() throws Exception {
SecurityAuthConfig authConfig = new SecurityAuthConfig("foo", "ldap");
cruiseConfig.server().security().addRole(new PluginRoleConfig("blackbird", "foo"));
SecurityAuthConfigDeleteCommand command = new SecurityAuthConfigDeleteCommand(null, authConfig, null, null, new HttpLocalizedOperationResult());
assertThatThrownBy(() -> command.isValid(cruiseConfig)).isInstanceOf(GoConfigInvalidException.class).hasMessageContaining("The security auth config 'foo' is being referenced by role(s): blackbird.");
}
use of com.thoughtworks.go.config.SecurityAuthConfig in project gocd by gocd.
the class SecurityAuthConfigUpdateCommandTest method shouldNotContinueWithConfigSaveIfRequestIsNotFresh.
@Test
public void shouldNotContinueWithConfigSaveIfRequestIsNotFresh() {
when(goConfigService.isUserAdmin(currentUser)).thenReturn(true);
SecurityAuthConfig oldAuthConfig = new SecurityAuthConfig("foo", "ldap");
SecurityAuthConfig newAuthConfig = new SecurityAuthConfig("foo", "github");
cruiseConfig.server().security().securityAuthConfigs().add(oldAuthConfig);
EntityHashingService entityHashingService = mock(EntityHashingService.class);
when(entityHashingService.hashForEntity(oldAuthConfig)).thenReturn("digest");
HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
SecurityAuthConfigUpdateCommand command = new SecurityAuthConfigUpdateCommand(goConfigService, newAuthConfig, null, currentUser, result, entityHashingService, "bad-digest");
assertThat(command.canContinue(cruiseConfig), is(false));
assertThat(result.toString(), containsString("Someone has modified the configuration for"));
;
}
Aggregations