use of com.thoughtworks.go.config.rules.Allow in project gocd by gocd.
the class PartialConfigTest method validatePermissionsOnSubtreeFailsWhenNoRuleMatchesGroups.
@Test
void validatePermissionsOnSubtreeFailsWhenNoRuleMatchesGroups() {
configRepo.getRules().add(new Allow("refer", "pipeline_group", "team1"));
BasicPipelineConfigs team1 = new BasicPipelineConfigs("team1", new Authorization());
BasicPipelineConfigs first = new BasicPipelineConfigs("first", new Authorization());
first.add(PipelineConfigMother.pipelineConfig("up42"));
partial.setPipelines(new PipelineGroups(first, team1));
partial.setOrigins(partial.getOrigin());
partial.validatePermissionsOnSubtree();
assertTrue(partial.hasErrors());
assertEquals(1, partial.errors().size());
assertEquals("Not allowed to refer to pipeline group 'first'. Check the 'Rules' of this config repository.", partial.errors().on("pipeline_group"));
}
use of com.thoughtworks.go.config.rules.Allow in project gocd by gocd.
the class PartialConfigTest method validatePermissionsOnSubtreeFailsWhenNoRuleMatchesEnvironments.
@Test
void validatePermissionsOnSubtreeFailsWhenNoRuleMatchesEnvironments() {
configRepo.getRules().add(new Allow("refer", "environment", "prod"));
EnvironmentsConfig allEnvs = new EnvironmentsConfig();
CaseInsensitiveString prodEnv = new CaseInsensitiveString("prod");
CaseInsensitiveString uatEnv = new CaseInsensitiveString("uat");
allEnvs.add(new BasicEnvironmentConfig(uatEnv));
allEnvs.add(new BasicEnvironmentConfig(prodEnv));
partial.setEnvironments(allEnvs);
partial.setOrigins(partial.getOrigin());
partial.validatePermissionsOnSubtree();
assertTrue(partial.hasErrors());
assertEquals(1, partial.errors().size());
assertEquals("Not allowed to refer to environment 'uat'. Check the 'Rules' of this config repository.", partial.errors().on("environment"));
}
use of com.thoughtworks.go.config.rules.Allow in project gocd by gocd.
the class BuildCauseProducerServiceConfigRepoIntegrationTest method setup.
@BeforeEach
public void setup(@TempDir Path tempDir) throws Exception {
diskSpaceSimulator = new DiskSpaceSimulator();
hgRepo = new HgTestRepo("testHgRepo", tempDir);
dbHelper.onSetUp();
configHelper.usingCruiseConfigDao(goConfigDao);
configHelper.onSetUp();
materialConfig = hgRepo.materialConfig();
ConfigRepoConfig config = ConfigRepoConfig.createConfigRepoConfig(materialConfig, "gocd-xml", "gocd-id");
config.getRules().add(new Allow("refer", "*", "*"));
configHelper.addConfigRepo(config);
logger = mock(MDUPerformanceLogger.class);
TestingEmailSender emailSender = new TestingEmailSender();
SystemDiskSpaceChecker mockDiskSpaceChecker = Mockito.mock(SystemDiskSpaceChecker.class);
StageService stageService = mock(StageService.class);
ConfigDbStateRepository configDbStateRepository = mock(ConfigDbStateRepository.class);
goDiskSpaceMonitor = new GoDiskSpaceMonitor(goConfigService, systemEnvironment, serverHealthService, emailSender, mockDiskSpaceChecker, mock(ArtifactsService.class), stageService, configDbStateRepository);
goDiskSpaceMonitor.initialize();
xmlWriter = new MagicalGoConfigXmlWriter(configCache, ConfigElementImplementationRegistryMother.withNoPlugins());
configTestRepo = new ConfigTestRepo(hgRepo, xmlWriter);
this.material = (HgMaterial) materialConfigConverter.toMaterial(materialConfig);
pipelineConfig = PipelineConfigMother.createPipelineConfigWithStages("pipe1", "build", "test");
pipelineConfig.materialConfigs().clear();
pipelineConfig.materialConfigs().add(materialConfig);
PIPELINE_NAME = CaseInsensitiveString.str(pipelineConfig.name());
configTestRepo.addPipelineToRepositoryAndPush(fileName, pipelineConfig);
materialUpdateService.updateMaterial(material);
// time for messages to pass through all services
waitForMaterialNotInProgress();
pipelineConfig = goConfigService.pipelineConfigNamed(pipelineConfig.name());
pipelineScheduleQueue.clear();
// check test setup
Materials materials = materialConfigConverter.toMaterials(pipelineConfig.materialConfigs());
MaterialRevisions peggedRevisions = new MaterialRevisions();
firstRevisions = materialChecker.findLatestRevisions(peggedRevisions, materials);
assertThat(firstRevisions.isMissingModifications(), is(false));
}
use of com.thoughtworks.go.config.rules.Allow in project gocd by gocd.
the class BuildCauseProducerServiceIntegrationTest method shouldTriggerMDUOfConfigRepoMaterialIfThePipelineIsDefinedRemotelyInAConfigRepo_ManualTriggerOfPipeline_EvenIfMDUOptionIsTurnedOFFInRequest.
@Test
public void shouldTriggerMDUOfConfigRepoMaterialIfThePipelineIsDefinedRemotelyInAConfigRepo_ManualTriggerOfPipeline_EvenIfMDUOptionIsTurnedOFFInRequest() throws Exception {
ConfigRepoConfig repoConfig = ConfigRepoConfig.createConfigRepoConfig(git("url2"), "plugin", "id-2");
repoConfig.getRules().add(new Allow("refer", "*", "*"));
configHelper.addConfigRepo(repoConfig);
PartialConfig partialConfig = PartialConfigMother.withPipelineMultipleMaterials("remote_pipeline", new RepoConfigOrigin(repoConfig, "4567"));
PipelineConfig remotePipeline = partialConfig.getGroups().first().getPipelines().get(0);
GitMaterial git = u.wf((GitMaterial) new MaterialConfigConverter().toMaterial(remotePipeline.materialConfigs().getGitMaterial()), "git");
u.checkinInOrder(git, u.d(1), "g1r1");
SvnMaterial svn = u.wf((SvnMaterial) new MaterialConfigConverter().toMaterial(remotePipeline.materialConfigs().getSvnMaterial()), "svn");
u.checkinInOrder(svn, u.d(1), "svn1r11");
GitMaterial configRepoMaterial = u.wf((GitMaterial) new MaterialConfigConverter().toMaterial(repoConfig.getRepo()), "git");
u.checkinInOrder(configRepoMaterial, u.d(1), "s1");
partialConfigService.onSuccessPartialConfig(repoConfig, partialConfig);
assertTrue(goConfigService.hasPipelineNamed(remotePipeline.name()));
scheduleOptions.shouldPerformMDUBeforeScheduling(false);
service.manualSchedulePipeline(username, remotePipeline.name(), scheduleOptions, result);
assertThat(result.isSuccess(), is(true));
assertThat(result.message(), is("Request to schedule pipeline remote_pipeline accepted"));
assertThat(materialUpdateStatusNotifier.hasListenerFor(remotePipeline), is(true));
assertMDUPendingForMaterial(remotePipeline, configRepoMaterial);
assertMDUNotPendingForMaterial(remotePipeline, svn);
assertMDUNotPendingForMaterial(remotePipeline, git);
assertThat(triggerMonitor.isAlreadyTriggered(remotePipeline.name()), is(true));
BuildCause buildCause = pipelineScheduleQueue.toBeScheduled().get(remotePipeline.name().toString());
assertNull(buildCause);
}
use of com.thoughtworks.go.config.rules.Allow in project gocd by gocd.
the class PartialConfigServiceIntegrationTest method createConfigRepoWithDefaultRules.
private ConfigRepoConfig createConfigRepoWithDefaultRules(GitMaterialConfig materialConfig, String plugin, String id) {
ConfigRepoConfig config = ConfigRepoConfig.createConfigRepoConfig(materialConfig, plugin, id);
config.getRules().add(new Allow("refer", "*", "*"));
return config;
}
Aggregations