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