Search in sources :

Example 11 with Allow

use of com.thoughtworks.go.config.rules.Allow in project gocd by gocd.

the class MagicalGoConfigXmlLoaderTest method shouldLoadSecretConfigs.

@Test
void shouldLoadSecretConfigs() {
    String content = config("<secretConfigs>" + "<secretConfig id=\"my_secret\" pluginId=\"gocd_file_based_plugin\">\n" + "    <description>All secrets for env1</description>" + "    <configuration>" + "       <property>\n" + "           <key>PasswordFilePath</key>\n" + "           <value>/godata/config/password.properties</value>\n" + "       </property>\n" + "    </configuration>" + "    <rules>\n" + "        <deny action=\"refer\" type=\"pipeline_group\">my_group</deny>\n" + "        <allow action=\"refer\" type=\"pipeline_group\">other_group</allow>  \n" + "    </rules>\n" + "</secretConfig>" + "</secretConfigs>", 116);
    CruiseConfig config = ConfigMigrator.load(content);
    SecretConfigs secretConfigs = config.getSecretConfigs();
    assertThat(secretConfigs.size()).isEqualTo(1);
    SecretConfig secretConfig = secretConfigs.first();
    assertThat(secretConfig.getId()).isEqualTo("my_secret");
    assertThat(secretConfig.getPluginId()).isEqualTo("gocd_file_based_plugin");
    assertThat(secretConfig.getDescription()).isEqualTo("All secrets for env1");
    Configuration configuration = secretConfig.getConfiguration();
    assertThat(configuration.size()).isEqualTo(1);
    assertThat(configuration.getProperty("PasswordFilePath").getValue()).isEqualTo("/godata/config/password.properties");
    Rules rules = secretConfig.getRules();
    assertThat(rules.size()).isEqualTo(2);
    assertThat(rules).containsExactly(new Deny("refer", "pipeline_group", "my_group"), new Allow("refer", "pipeline_group", "other_group"));
}
Also used : RepositoryConfiguration(com.thoughtworks.go.plugin.api.material.packagerepository.RepositoryConfiguration) PluginConfiguration(com.thoughtworks.go.plugin.domain.common.PluginConfiguration) PackageConfiguration(com.thoughtworks.go.plugin.access.packagematerial.PackageConfiguration) Deny(com.thoughtworks.go.config.rules.Deny) Rules(com.thoughtworks.go.config.rules.Rules) Allow(com.thoughtworks.go.config.rules.Allow) Test(org.junit.jupiter.api.Test)

Example 12 with Allow

use of com.thoughtworks.go.config.rules.Allow in project gocd by gocd.

the class PartialConfigServiceTest method keepsLastValidPartialOnFailureWhenRulesAllow.

@Test
void keepsLastValidPartialOnFailureWhenRulesAllow() {
    when(goConfigService.updateConfig(any(UpdateConfigCommand.class))).thenThrow(new RuntimeException("Nope"));
    when(partialConfigHelper.isEquivalent(any(PartialConfig.class), any(PartialConfig.class))).thenReturn(false);
    // an empty set guarantees violations
    final Rules rules = new Rules();
    rules.add(new Allow("refer", SupportedEntity.PIPELINE_GROUP.getType(), "two"));
    configRepoConfig.setRules(rules);
    final PartialConfig lastValid = withPipelineInGroup("p1", "two");
    lastValid.setOrigins(new RepoConfigOrigin(configRepoConfig, "1"));
    final PartialConfig incoming = withPipelineInGroup("p1", "one");
    incoming.setOrigins(new RepoConfigOrigin(configRepoConfig, "2"));
    cachedGoPartials.cacheAsLastKnown(configRepoConfig.getRepo().getFingerprint(), lastValid);
    cachedGoPartials.markAllKnownAsValid();
    // baseline
    assertEquals(1, cachedGoPartials.lastValidPartials().size());
    assertEquals(lastValid, cachedGoPartials.lastValidPartials().get(0));
    assertFalse(lastValid.hasErrors());
    assertFalse(incoming.hasErrors());
    service.onSuccessPartialConfig(configRepoConfig, incoming);
    final String violationMessage = "Not allowed to refer to pipeline group 'one'. Check the 'Rules' of this config repository.";
    assertTrue(incoming.hasErrors(), "should have rule violations");
    assertEquals(violationMessage, incoming.errors().on("pipeline_group"));
    assertFalse(lastValid.hasErrors(), "should not have rule violations");
    assertEquals(1, cachedGoPartials.lastValidPartials().size());
    assertEquals(lastValid, cachedGoPartials.lastValidPartials().get(0));
    verify(goConfigService).updateConfig(any(UpdateConfigCommand.class));
}
Also used : PartialConfig(com.thoughtworks.go.config.remote.PartialConfig) RepoConfigOrigin(com.thoughtworks.go.config.remote.RepoConfigOrigin) Rules(com.thoughtworks.go.config.rules.Rules) Allow(com.thoughtworks.go.config.rules.Allow) Test(org.junit.jupiter.api.Test)

Example 13 with Allow

use of com.thoughtworks.go.config.rules.Allow in project gocd by gocd.

the class GoConfigServiceTest method shouldReturnSecretConfigBySecretConfigId.

@Test
public void shouldReturnSecretConfigBySecretConfigId() throws Exception {
    Rules rules = new Rules(new Allow("refer", "pipeline_group", "default"));
    SecretConfig secretConfig = new SecretConfig("secret_config_id", "plugin_id", rules);
    GoConfigMother configMother = new GoConfigMother();
    CruiseConfig config = GoConfigMother.configWithSecretConfig(secretConfig);
    configMother.addPipelineWithGroup(config, "default", "pipeline1", "stage1", "job1");
    expectLoad(config);
    assertThat(goConfigService.getSecretConfigById("secret_config_id"), is(secretConfig));
}
Also used : Rules(com.thoughtworks.go.config.rules.Rules) Allow(com.thoughtworks.go.config.rules.Allow) GoConfigMother(com.thoughtworks.go.helper.GoConfigMother) Test(org.junit.jupiter.api.Test)

Example 14 with Allow

use of com.thoughtworks.go.config.rules.Allow in project gocd by gocd.

the class GoFileConfigDataSourceIntegrationTest method setUp.

@BeforeEach
public void setUp(@TempDir File configDir) throws Exception {
    String absolutePath = new File(configDir, "cruise-config.xml").getAbsolutePath();
    systemEnvironment.setProperty(SystemEnvironment.CONFIG_FILE_PROPERTY, absolutePath);
    configHelper = new GoConfigFileHelper(DEFAULT_XML_WITH_2_AGENTS);
    configHelper.usingCruiseConfigDao(goConfigDao);
    configHelper.onSetUp();
    ConfigRepoConfig config = ConfigRepoConfig.createConfigRepoConfig(MaterialConfigsMother.gitMaterialConfig("url"), XmlPartialConfigProvider.providerName, "git-id");
    config.getRules().add(new Allow("refer", "*", "*"));
    repoConfig = config;
    configHelper.addConfigRepo(repoConfig);
    configHelper.addPipeline("upstream", "upstream_stage_original");
    goConfigService.forceNotifyListeners();
    cachedGoPartials.clear();
    configRepo = configWatchList.getCurrentConfigRepos().get(0);
    upstreamPipeline = goConfigService.pipelineConfigNamed(new CaseInsensitiveString("upstream"));
    partialConfig = PartialConfigMother.pipelineWithDependencyMaterial(remoteDownstream, upstreamPipeline, new RepoConfigOrigin(configRepo, "r1"));
    partialConfigService.onSuccessPartialConfig(configRepo, partialConfig);
    systemEnvironment.set(SystemEnvironment.ENABLE_CONFIG_MERGE_FEATURE, true);
}
Also used : ConfigRepoConfig(com.thoughtworks.go.config.remote.ConfigRepoConfig) RepoConfigOrigin(com.thoughtworks.go.config.remote.RepoConfigOrigin) FileUtils.readFileToString(org.apache.commons.io.FileUtils.readFileToString) File(java.io.File) Allow(com.thoughtworks.go.config.rules.Allow) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 15 with Allow

use of com.thoughtworks.go.config.rules.Allow in project gocd by gocd.

the class ConfigMaterialUpdateListenerIntegrationTest 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 = hg(hgRepo.projectRepositoryUrl(), null);
    ConfigRepoConfig config = ConfigRepoConfig.createConfigRepoConfig(materialConfig, "gocd-xml", "gocd-id");
    config.getRules().add(new Allow("refer", "*", "*"));
    configHelper.addConfigRepo(config);
    TestingEmailSender emailSender = new TestingEmailSender();
    SystemDiskSpaceChecker mockDiskSpaceChecker = Mockito.mock(SystemDiskSpaceChecker.class);
    StageService stageService = mock(StageService.class);
    ConfigDbStateRepository configDbStateRepository = mock(ConfigDbStateRepository.class);
    GoDiskSpaceMonitor 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 = configTestRepo.getMaterial();
}
Also used : ConfigTestRepo(com.thoughtworks.go.helper.ConfigTestRepo) ConfigRepoConfig(com.thoughtworks.go.config.remote.ConfigRepoConfig) GoDiskSpaceMonitor(com.thoughtworks.go.server.cronjob.GoDiskSpaceMonitor) HgTestRepo(com.thoughtworks.go.helper.HgTestRepo) Allow(com.thoughtworks.go.config.rules.Allow) BeforeEach(org.junit.jupiter.api.BeforeEach)

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