Search in sources :

Example 1 with Allow

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"));
}
Also used : PipelineGroups(com.thoughtworks.go.domain.PipelineGroups) Allow(com.thoughtworks.go.config.rules.Allow) Test(org.junit.jupiter.api.Test)

Example 2 with Allow

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"));
}
Also used : Allow(com.thoughtworks.go.config.rules.Allow) Test(org.junit.jupiter.api.Test)

Example 3 with Allow

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));
}
Also used : MDUPerformanceLogger(com.thoughtworks.go.server.perf.MDUPerformanceLogger) ConfigRepoConfig(com.thoughtworks.go.config.remote.ConfigRepoConfig) MaterialRevisions(com.thoughtworks.go.domain.MaterialRevisions) Materials(com.thoughtworks.go.config.materials.Materials) GoDiskSpaceMonitor(com.thoughtworks.go.server.cronjob.GoDiskSpaceMonitor) HgTestRepo(com.thoughtworks.go.helper.HgTestRepo) Allow(com.thoughtworks.go.config.rules.Allow) ConfigTestRepo(com.thoughtworks.go.helper.ConfigTestRepo) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 4 with Allow

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);
}
Also used : PipelineConfig(com.thoughtworks.go.config.PipelineConfig) GitMaterial(com.thoughtworks.go.config.materials.git.GitMaterial) ConfigRepoConfig(com.thoughtworks.go.config.remote.ConfigRepoConfig) SvnMaterial(com.thoughtworks.go.config.materials.svn.SvnMaterial) PartialConfig(com.thoughtworks.go.config.remote.PartialConfig) RepoConfigOrigin(com.thoughtworks.go.config.remote.RepoConfigOrigin) Allow(com.thoughtworks.go.config.rules.Allow) BuildCause(com.thoughtworks.go.domain.buildcause.BuildCause) Test(org.junit.jupiter.api.Test)

Example 5 with Allow

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;
}
Also used : ConfigRepoConfig(com.thoughtworks.go.config.remote.ConfigRepoConfig) Allow(com.thoughtworks.go.config.rules.Allow)

Aggregations

Allow (com.thoughtworks.go.config.rules.Allow)17 Test (org.junit.jupiter.api.Test)10 ConfigRepoConfig (com.thoughtworks.go.config.remote.ConfigRepoConfig)9 RepoConfigOrigin (com.thoughtworks.go.config.remote.RepoConfigOrigin)5 PipelineGroups (com.thoughtworks.go.domain.PipelineGroups)4 BeforeEach (org.junit.jupiter.api.BeforeEach)4 Rules (com.thoughtworks.go.config.rules.Rules)3 MaterialConfigs (com.thoughtworks.go.config.materials.MaterialConfigs)2 PartialConfig (com.thoughtworks.go.config.remote.PartialConfig)2 ConfigTestRepo (com.thoughtworks.go.helper.ConfigTestRepo)2 HgTestRepo (com.thoughtworks.go.helper.HgTestRepo)2 GoDiskSpaceMonitor (com.thoughtworks.go.server.cronjob.GoDiskSpaceMonitor)2 File (java.io.File)2 PipelineConfig (com.thoughtworks.go.config.PipelineConfig)1 Materials (com.thoughtworks.go.config.materials.Materials)1 GitMaterial (com.thoughtworks.go.config.materials.git.GitMaterial)1 SvnMaterial (com.thoughtworks.go.config.materials.svn.SvnMaterial)1 ConfigReposConfig (com.thoughtworks.go.config.remote.ConfigReposConfig)1 Deny (com.thoughtworks.go.config.rules.Deny)1 MaterialRevisions (com.thoughtworks.go.domain.MaterialRevisions)1