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"));
}
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);
}
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()));
}
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));
}
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\"."));
}
Aggregations