Search in sources :

Example 1 with EntityHashingService

use of com.thoughtworks.go.server.service.EntityHashingService in project gocd by gocd.

the class RoleConfigUpdateCommandTest method shouldNotContinueWithConfigSaveIfRequestIsNotFresh.

@Test
public void shouldNotContinueWithConfigSaveIfRequestIsNotFresh() {
    when(goConfigService.isUserAdmin(currentUser)).thenReturn(true);
    PluginRoleConfig oldRole = new PluginRoleConfig("foo", "ldap");
    PluginRoleConfig updatedRole = new PluginRoleConfig("foo", "github");
    cruiseConfig.server().security().getRoles().add(oldRole);
    EntityHashingService entityHashingService = mock(EntityHashingService.class);
    when(entityHashingService.md5ForEntity(oldRole)).thenReturn("md5");
    HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
    RoleConfigCommand command = new RoleConfigUpdateCommand(goConfigService, updatedRole, null, currentUser, result, entityHashingService, "bad-md5");
    assertThat(command.canContinue(cruiseConfig), is(false));
    assertThat(result.toString(), containsString("STALE_RESOURCE_CONFIG"));
}
Also used : HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) EntityHashingService(com.thoughtworks.go.server.service.EntityHashingService) PluginRoleConfig(com.thoughtworks.go.config.PluginRoleConfig) Test(org.junit.Test)

Example 2 with EntityHashingService

use of com.thoughtworks.go.server.service.EntityHashingService in project gocd by gocd.

the class ElasticAgentProfileUpdateCommandTest method shouldNotContinueWithConfigSaveIfRequestIsNotFresh.

@Test
public void shouldNotContinueWithConfigSaveIfRequestIsNotFresh() {
    when(goConfigService.isUserAdmin(currentUser)).thenReturn(true);
    ElasticProfile oldProfile = new ElasticProfile("foo", "docker");
    ElasticProfile newProfile = new ElasticProfile("foo", "aws");
    cruiseConfig.server().getElasticConfig().getProfiles().add(oldProfile);
    EntityHashingService entityHashingService = mock(EntityHashingService.class);
    when(entityHashingService.md5ForEntity(oldProfile)).thenReturn("md5");
    HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
    ElasticAgentProfileUpdateCommand command = new ElasticAgentProfileUpdateCommand(goConfigService, newProfile, null, currentUser, result, entityHashingService, "bad-md5");
    assertThat(command.canContinue(cruiseConfig), is(false));
    assertThat(result.toString(), containsString("STALE_RESOURCE_CONFIG"));
}
Also used : HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) EntityHashingService(com.thoughtworks.go.server.service.EntityHashingService) ElasticProfile(com.thoughtworks.go.config.elastic.ElasticProfile) Test(org.junit.Test)

Example 3 with EntityHashingService

use of com.thoughtworks.go.server.service.EntityHashingService 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.md5ForEntity(oldAuthConfig)).thenReturn("md5");
    HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
    SecurityAuthConfigUpdateCommand command = new SecurityAuthConfigUpdateCommand(goConfigService, newAuthConfig, null, currentUser, result, entityHashingService, "bad-md5");
    assertThat(command.canContinue(cruiseConfig), is(false));
    assertThat(result.toString(), containsString("STALE_RESOURCE_CONFIG"));
}
Also used : SecurityAuthConfig(com.thoughtworks.go.config.SecurityAuthConfig) HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) EntityHashingService(com.thoughtworks.go.server.service.EntityHashingService) Test(org.junit.Test)

Aggregations

EntityHashingService (com.thoughtworks.go.server.service.EntityHashingService)3 HttpLocalizedOperationResult (com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)3 Test (org.junit.Test)3 PluginRoleConfig (com.thoughtworks.go.config.PluginRoleConfig)1 SecurityAuthConfig (com.thoughtworks.go.config.SecurityAuthConfig)1 ElasticProfile (com.thoughtworks.go.config.elastic.ElasticProfile)1