Search in sources :

Example 26 with FullConfigUpdateCommand

use of com.thoughtworks.go.config.update.FullConfigUpdateCommand in project gocd by gocd.

the class CachedGoConfigIntegrationTest method shouldErrorOutOnUpdateConfigWithValidPartials_WithMainConfigBreakingPartials.

@Test
public void shouldErrorOutOnUpdateConfigWithValidPartials_WithMainConfigBreakingPartials() throws GitAPIException, IOException {
    setupExternalConfigRepoWithDependencyMaterialOnPipelineInMainXml("upstream", "downstream");
    String gitShaBeforeSave = configRepository.getCurrentRevCommit().getName();
    CruiseConfig originalConfig = cachedGoConfig.loadForEditing();
    CruiseConfig editedConfig = GoConfigMother.deepClone(originalConfig);
    editedConfig.getGroups().remove(editedConfig.findGroup("default"));
    try {
        cachedGoConfig.writeFullConfigWithLock(new FullConfigUpdateCommand(editedConfig, goConfigService.configFileMd5()));
        fail("Expected the test to fail");
    } catch (Exception e) {
        String gitShaAfterSave = configRepository.getCurrentRevCommit().getName();
        String configXmlFromConfigFolder = FileUtils.readFileToString(new File(goConfigDao.fileLocation()), UTF_8);
        assertThat(cachedGoConfig.loadForEditing()).isEqualTo(originalConfig);
        assertThat(gitShaAfterSave).isEqualTo(gitShaBeforeSave);
        assertThat(cachedGoConfig.loadForEditing().getMd5()).isEqualTo(configRepository.getCurrentRevision().getMd5());
        assertThat(cachedGoConfig.currentConfig().getMd5()).isEqualTo(configRepository.getCurrentRevision().getMd5());
        assertThat(configXmlFromConfigFolder).isEqualTo(configRepository.getCurrentRevision().getContent());
        RepoConfigOrigin origin = (RepoConfigOrigin) cachedGoPartials.lastValidPartials().get(0).getOrigin();
        assertThat(origin.getRevision()).isEqualTo("r1");
    }
}
Also used : FullConfigUpdateCommand(com.thoughtworks.go.config.update.FullConfigUpdateCommand) RepoConfigOrigin(com.thoughtworks.go.config.remote.RepoConfigOrigin) File(java.io.File) GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) CryptoException(com.thoughtworks.go.security.CryptoException) IOException(java.io.IOException) Test(org.junit.jupiter.api.Test)

Example 27 with FullConfigUpdateCommand

use of com.thoughtworks.go.config.update.FullConfigUpdateCommand in project gocd by gocd.

the class CachedGoConfigIntegrationTest method shouldUpdateConfigWithValidPartialsAndInvalidKnownPartials.

@Test
public void shouldUpdateConfigWithValidPartialsAndInvalidKnownPartials() throws GitAPIException, IOException {
    String gitShaBeforeSave = configRepository.getCurrentRevCommit().getName();
    PartialConfig validPartial = PartialConfigMother.withPipeline("remote_pipeline", new RepoConfigOrigin(configRepo, "revision1"));
    PartialConfig invalidPartial = PartialConfigMother.invalidPartial("invalid", new RepoConfigOrigin(configRepo, "revision2"));
    partialConfigService.onSuccessPartialConfig(configRepo, validPartial);
    partialConfigService.onSuccessPartialConfig(configRepo, invalidPartial);
    assertThat(cachedGoPartials.lastValidPartials().contains(validPartial)).isTrue();
    assertThat(cachedGoPartials.lastKnownPartials().contains(invalidPartial)).isTrue();
    CruiseConfig config = GoConfigMother.deepClone(cachedGoConfig.loadForEditing());
    config.addEnvironment(UUID.randomUUID().toString());
    ConfigSaveState state = cachedGoConfig.writeFullConfigWithLock(new FullConfigUpdateCommand(config, goConfigService.configFileMd5()));
    String gitShaAfterSave = configRepository.getCurrentRevCommit().getName();
    String configXmlFromConfigFolder = FileUtils.readFileToString(new File(goConfigDao.fileLocation()), UTF_8);
    assertThat(state).isEqualTo(ConfigSaveState.UPDATED);
    assertThat(cachedGoConfig.loadForEditing()).isEqualTo(config);
    assertThat(gitShaAfterSave).isNotEqualTo(gitShaBeforeSave);
    assertThat(cachedGoConfig.loadForEditing().getMd5()).isEqualTo(configRepository.getCurrentRevision().getMd5());
    assertThat(cachedGoConfig.currentConfig().getMd5()).isEqualTo(configRepository.getCurrentRevision().getMd5());
    assertThat(configXmlFromConfigFolder).isEqualTo(configRepository.getCurrentRevision().getContent());
    assertThat(cachedGoPartials.lastValidPartials().contains(validPartial)).isTrue();
    assertThat(cachedGoPartials.lastKnownPartials().contains(invalidPartial)).isTrue();
}
Also used : FullConfigUpdateCommand(com.thoughtworks.go.config.update.FullConfigUpdateCommand) PartialConfig(com.thoughtworks.go.config.remote.PartialConfig) RepoConfigOrigin(com.thoughtworks.go.config.remote.RepoConfigOrigin) File(java.io.File) Test(org.junit.jupiter.api.Test)

Example 28 with FullConfigUpdateCommand

use of com.thoughtworks.go.config.update.FullConfigUpdateCommand in project gocd by gocd.

the class FullConfigSaveFlowTestBase method shouldEncryptPluginPropertiesOfPublishTask.

@Test
public void shouldEncryptPluginPropertiesOfPublishTask() throws Exception {
    CruiseConfig cruiseConfig = loader.deserializeConfig(xml);
    Configuration ancestorPluggablePublishAftifactConfigBeforeEncryption = cruiseConfig.pipelineConfigByName(new CaseInsensitiveString("ancestor")).getExternalArtifactConfigs().get(0).getConfiguration();
    assertThat(ancestorPluggablePublishAftifactConfigBeforeEncryption.getProperty("Image").getValue(), is("IMAGE_SECRET"));
    assertThat(ancestorPluggablePublishAftifactConfigBeforeEncryption.getProperty("Image").getEncryptedValue(), is(nullValue()));
    assertThat(ancestorPluggablePublishAftifactConfigBeforeEncryption.getProperty("Image").getConfigValue(), is("IMAGE_SECRET"));
    GoConfigHolder configHolder = getImplementer().execute(new FullConfigUpdateCommand(cruiseConfig, goConfigService.configFileMd5()), new ArrayList<>(), "Upgrade");
    Configuration ancestorPluggablePublishAftifactConfigAfterEncryption = configHolder.configForEdit.pipelineConfigByName(new CaseInsensitiveString("ancestor")).getExternalArtifactConfigs().get(0).getConfiguration();
    assertThat(ancestorPluggablePublishAftifactConfigAfterEncryption.getProperty("Image").getValue(), is("IMAGE_SECRET"));
    assertThat(ancestorPluggablePublishAftifactConfigAfterEncryption.getProperty("Image").getEncryptedValue(), startsWith("AES:"));
    assertThat(ancestorPluggablePublishAftifactConfigAfterEncryption.getProperty("Image").getConfigValue(), is(nullValue()));
    // verify xml on disk contains encrypted Image plugin property
    assertThat(configHelper.getCurrentXml(), containsString(ancestorPluggablePublishAftifactConfigAfterEncryption.getProperty("Image").getEncryptedValue()));
    // verify xml from GoConfigHolder contains encrypted Image plugin property
    assertThat(getImplementer().toXmlString(configHolder.configForEdit), containsString(ancestorPluggablePublishAftifactConfigAfterEncryption.getProperty("Image").getEncryptedValue()));
}
Also used : Configuration(com.thoughtworks.go.domain.config.Configuration) PluginConfiguration(com.thoughtworks.go.plugin.domain.common.PluginConfiguration) ContextConfiguration(org.springframework.test.context.ContextConfiguration) FullConfigUpdateCommand(com.thoughtworks.go.config.update.FullConfigUpdateCommand) Test(org.junit.jupiter.api.Test)

Aggregations

FullConfigUpdateCommand (com.thoughtworks.go.config.update.FullConfigUpdateCommand)28 Test (org.junit.jupiter.api.Test)23 PartialConfig (com.thoughtworks.go.config.remote.PartialConfig)11 File (java.io.File)11 RepoConfigOrigin (com.thoughtworks.go.config.remote.RepoConfigOrigin)8 GoConfigInvalidException (com.thoughtworks.go.config.exceptions.GoConfigInvalidException)4 ConfigElementImplementationRegistry (com.thoughtworks.go.config.registry.ConfigElementImplementationRegistry)3 GoConfigValidity (com.thoughtworks.go.config.validation.GoConfigValidity)3 GoConfigMother (com.thoughtworks.go.helper.GoConfigMother)3 Configuration (com.thoughtworks.go.domain.config.Configuration)2 PluginConfiguration (com.thoughtworks.go.plugin.domain.common.PluginConfiguration)2 ConfigRepository (com.thoughtworks.go.service.ConfigRepository)2 TimeProvider (com.thoughtworks.go.util.TimeProvider)2 IOException (java.io.IOException)2 Arrays.asList (java.util.Arrays.asList)2 Document (org.jdom2.Document)2 BeforeEach (org.junit.jupiter.api.BeforeEach)2 ContextConfiguration (org.springframework.test.context.ContextConfiguration)2 HgMaterialConfig (com.thoughtworks.go.config.materials.mercurial.HgMaterialConfig)1 ConfigElementImplementationRegistrar (com.thoughtworks.go.config.registry.ConfigElementImplementationRegistrar)1