Search in sources :

Example 96 with Username

use of com.thoughtworks.go.server.domain.Username in project gocd by gocd.

the class EnvironmentConfigServiceIntegrationTest method shouldReturnTheCorrectLocalizedMessageForDuplicatePipelinesInAnEnvironment.

@Test
public void shouldReturnTheCorrectLocalizedMessageForDuplicatePipelinesInAnEnvironment() {
    BasicEnvironmentConfig environmentConfig = environmentConfig("uat");
    goConfigService.addPipeline(PipelineConfigMother.createPipelineConfig("foo", "dev", "job"), "foo-grp");
    environmentConfig.addPipeline(new CaseInsensitiveString("foo"));
    goConfigService.addEnvironment(environmentConfig);
    ArrayList<String> pipelines = new ArrayList<>();
    pipelines.add("foo");
    HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
    service.createEnvironment(env("foo-env", pipelines, new ArrayList<Map<String, String>>(), new ArrayList<String>()), new Username(new CaseInsensitiveString("any")), result);
    result = new HttpLocalizedOperationResult();
    service.createEnvironment(env("env", pipelines, new ArrayList<Map<String, String>>(), new ArrayList<String>()), new Username(new CaseInsensitiveString("any")), result);
    assertThat(result.message(localizer), is("Failed to add environment. Associating pipeline(s) which is already part of uat environment"));
}
Also used : HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) Username(com.thoughtworks.go.server.domain.Username) ArrayList(java.util.ArrayList) StringContains.containsString(org.hamcrest.core.StringContains.containsString) Test(org.junit.Test)

Example 97 with Username

use of com.thoughtworks.go.server.domain.Username in project gocd by gocd.

the class ChangeMaterialsTest method setUp.

@Before
public void setUp() throws Exception {
    username = new Username(new CaseInsensitiveString("gli"));
    dbHelper.onSetUp();
    cruiseConfig = new GoConfigFileHelper().usingCruiseConfigDao(goConfigDao);
    cruiseConfig.onSetUp();
    cruiseConfig.initializeConfigFile();
    hgTestRepo = new HgTestRepo();
    SvnTestRepo svnRepo = new SvnTestRepo();
    cruiseConfig.addPipeline(PIPELINE_NAME, DEV_STAGE, svnRepo.materialConfig(), "foo");
    mingle = cruiseConfig.addStageToPipeline(PIPELINE_NAME, FT_STAGE, "bar");
    pipeline = dbHelper.newPipelineWithAllStagesPassed(mingle);
    listener = new StubScheduleCheckCompletedListener();
    topic.addListener(listener);
}
Also used : StubScheduleCheckCompletedListener(com.thoughtworks.go.server.messaging.StubScheduleCheckCompletedListener) Username(com.thoughtworks.go.server.domain.Username) SvnTestRepo(com.thoughtworks.go.helper.SvnTestRepo) GoConfigFileHelper(com.thoughtworks.go.util.GoConfigFileHelper) HgTestRepo(com.thoughtworks.go.helper.HgTestRepo) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) Before(org.junit.Before)

Example 98 with Username

use of com.thoughtworks.go.server.domain.Username in project gocd by gocd.

the class GoConfigServiceIntegrationTest method shouldUnderstandGettingPipelineConfigForEdit.

@Test
public void shouldUnderstandGettingPipelineConfigForEdit() {
    PipelineConfig pipelineConfig = PipelineConfigMother.createPipelineConfig("my-pipeline", "my-stage", "my-build");
    pipelineConfig.addParam(new ParamConfig("label-param", "param-value"));
    pipelineConfig.setLabelTemplate("${COUNT}-#{label-param}");
    CruiseConfig config = configHelper.currentConfig();
    config.addPipeline("defaultGroup", pipelineConfig);
    configHelper.writeConfigFile(config);
    HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
    ConfigForEdit<PipelineConfig> configForEdit = goConfigService.loadForEdit("my-pipeline", new Username(new CaseInsensitiveString("root")), result);
    assertThat(configForEdit.getProcessedConfig(), is(goConfigService.getCurrentConfig()));
    assertThat(configForEdit.getConfig().getLabelTemplate(), is("${COUNT}-#{label-param}"));
    assertThat(configForEdit.getCruiseConfig().getMd5(), is(goConfigService.configFileMd5()));
    configHelper.addPipeline("pipeline-foo", "stage-foo");
    assertThat(configForEdit.getCruiseConfig().getMd5(), not(goConfigService.configFileMd5()));
}
Also used : HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) Username(com.thoughtworks.go.server.domain.Username) Test(org.junit.Test)

Example 99 with Username

use of com.thoughtworks.go.server.domain.Username in project gocd by gocd.

the class GoConfigServiceIntegrationTest method shouldOnlyAllowAdminsToGetPipelineConfig.

@Test
public void shouldOnlyAllowAdminsToGetPipelineConfig() {
    setupSecurity();
    HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
    ConfigForEdit configForEdit = goConfigService.loadForEdit("my-pipeline", new Username(new CaseInsensitiveString("loser")), result);
    assertThat(configForEdit, is(nullValue()));
    assertThat(result.httpCode(), is(401));
    assertThat(result.message(localizer), is("Unauthorized to edit my-pipeline pipeline."));
    result = new HttpLocalizedOperationResult();
    configForEdit = goConfigService.loadForEdit("my-pipeline", new Username(new CaseInsensitiveString("pipeline_admin")), result);
    assertThat(configForEdit, not(nullValue()));
    assertThat(result.isSuccessful(), is(true));
    result = new HttpLocalizedOperationResult();
    configForEdit = goConfigService.loadForEdit("my-pipeline", new Username(new CaseInsensitiveString("root")), result);
    assertThat(configForEdit, not(nullValue()));
    assertThat(result.isSuccessful(), is(true));
}
Also used : HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) Username(com.thoughtworks.go.server.domain.Username) ConfigForEdit(com.thoughtworks.go.presentation.ConfigForEdit) Test(org.junit.Test)

Example 100 with Username

use of com.thoughtworks.go.server.domain.Username in project gocd by gocd.

the class GoConfigServiceIntegrationTest method shouldInternallyGetGoConfigInvalidExceptionOnValidationErrorAndFailWithATopLevelConfigError.

@Test
public void shouldInternallyGetGoConfigInvalidExceptionOnValidationErrorAndFailWithATopLevelConfigError() throws Exception {
    String oldMd5 = goConfigService.getConfigForEditing().getMd5();
    CruiseConfig user1SeeingConfig = configHelper.load();
    // Setup a pipeline group in the config
    new GoConfigMother().addPipelineWithGroup(user1SeeingConfig, "defaultGroup", "user1_pipeline", "user1_stage", "user1_job");
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    configHelper.getXml(user1SeeingConfig, os);
    GoConfigService.XmlPartialSaver saver = goConfigService.fileSaver(false);
    saver.saveXml(os.toString(), oldMd5);
    CruiseConfig configBeforePipelineGroupWasAddedAtBeginning = configHelper.load();
    String md5BeforeAddingGroupAtBeginning = configBeforePipelineGroupWasAddedAtBeginning.getMd5();
    // User 1 edits config XML and adds a pipeline group before the first group in config
    String configXMLWithGroupAddedAtBeginning = os.toString().replace("</pipelines>", "</pipelines><pipelines group=\"first_group\"/>");
    saver.saveXml(configXMLWithGroupAddedAtBeginning, md5BeforeAddingGroupAtBeginning);
    // User 2 adds another pipeline group, with the same name, through UI, but using the older MD5.
    HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
    ConfigUpdateResponse response = goConfigService.updateConfigFromUI(new UpdateConfigFromUI() {

        public void checkPermission(CruiseConfig cruiseConfig, LocalizedOperationResult result) {
        }

        public Validatable node(CruiseConfig cruiseConfig) {
            return cruiseConfig;
        }

        public Validatable updatedNode(CruiseConfig cruiseConfig) {
            return node(cruiseConfig);
        }

        public void update(Validatable config) {
            CruiseConfig cruiseConfig = (CruiseConfig) config;
            MaterialConfigs materials = new MaterialConfigs(MaterialConfigsMother.mockMaterialConfigs("file:///tmp/foo"));
            new GoConfigMother().addPipelineWithGroup(cruiseConfig, "first_group", "up_pipeline", materials, "down_stage", "down_job");
        }

        public Validatable subject(Validatable node) {
            return node;
        }

        public Validatable updatedSubject(Validatable updatedNode) {
            return subject(updatedNode);
        }
    }, md5BeforeAddingGroupAtBeginning, new Username(new CaseInsensitiveString("admin")), result);
    CruiseConfig config = response.getCruiseConfig();
    assertThat(config.getMd5(), is(md5BeforeAddingGroupAtBeginning));
    assertThat(result.isSuccessful(), is(false));
    assertThat(result.httpCode(), is(SC_CONFLICT));
    assertThat(result.message(localizer), is("Save failed. Duplicate unique value [first_group] declared for identity constraint \"uniquePipelines\" of element \"cruise\"."));
}
Also used : MaterialConfigs(com.thoughtworks.go.config.materials.MaterialConfigs) Matchers.containsString(org.hamcrest.Matchers.containsString) ByteArrayOutputStream(java.io.ByteArrayOutputStream) GoConfigMother(com.thoughtworks.go.helper.GoConfigMother) HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) Username(com.thoughtworks.go.server.domain.Username) LocalizedOperationResult(com.thoughtworks.go.server.service.result.LocalizedOperationResult) HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) ConfigUpdateResponse(com.thoughtworks.go.config.update.ConfigUpdateResponse) UpdateConfigFromUI(com.thoughtworks.go.config.update.UpdateConfigFromUI) Test(org.junit.Test)

Aggregations

Username (com.thoughtworks.go.server.domain.Username)331 Test (org.junit.Test)268 HttpLocalizedOperationResult (com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)133 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)84 Before (org.junit.Before)39 HttpOperationResult (com.thoughtworks.go.server.service.result.HttpOperationResult)35 Pipeline (com.thoughtworks.go.domain.Pipeline)34 MaterialRevision (com.thoughtworks.go.domain.MaterialRevision)28 PipelineMaterialRevision (com.thoughtworks.go.domain.PipelineMaterialRevision)21 StringContains.containsString (org.hamcrest.core.StringContains.containsString)20 GoConfigMother (com.thoughtworks.go.helper.GoConfigMother)18 PipelineInstanceModels (com.thoughtworks.go.presentation.pipelinehistory.PipelineInstanceModels)18 Modification (com.thoughtworks.go.domain.materials.Modification)17 PackageRepository (com.thoughtworks.go.domain.packagerepository.PackageRepository)15 PipelineInstanceModel (com.thoughtworks.go.presentation.pipelinehistory.PipelineInstanceModel)15 ArrayList (java.util.ArrayList)15 DependencyMaterial (com.thoughtworks.go.config.materials.dependency.DependencyMaterial)14 EmptyPipelineInstanceModel (com.thoughtworks.go.presentation.pipelinehistory.EmptyPipelineInstanceModel)13 UpdateConfigFromUI (com.thoughtworks.go.config.update.UpdateConfigFromUI)12 Date (java.util.Date)12