Search in sources :

Example 6 with GoConfigRevision

use of com.thoughtworks.go.domain.GoConfigRevision in project gocd by gocd.

the class GoFileConfigDataSourceTest method shouldLoadAsUser_Filesystem_WithMd5Sum.

@Test
public void shouldLoadAsUser_Filesystem_WithMd5Sum() throws Exception {
    GoConfigHolder configHolder = goConfigDao.loadConfigHolder();
    String md5 = DigestUtils.md5Hex(FileUtils.readFileToString(dataSource.fileLocation()));
    assertThat(configHolder.configForEdit.getMd5(), is(md5));
    assertThat(configHolder.config.getMd5(), is(md5));
    CruiseConfig forEdit = configHolder.configForEdit;
    forEdit.addPipeline("my-awesome-group", PipelineConfigMother.createPipelineConfig("pipeline-foo", "stage-bar", "job-baz"));
    FileOutputStream fos = new FileOutputStream(dataSource.fileLocation());
    new MagicalGoConfigXmlWriter(configCache, ConfigElementImplementationRegistryMother.withNoPlugins()).write(forEdit, fos, false);
    configHolder = dataSource.load();
    String xmlText = FileUtils.readFileToString(dataSource.fileLocation());
    String secondMd5 = DigestUtils.md5Hex(xmlText);
    assertThat(configHolder.configForEdit.getMd5(), is(secondMd5));
    assertThat(configHolder.config.getMd5(), is(secondMd5));
    assertThat(configHolder.configForEdit.getMd5(), is(not(md5)));
    GoConfigRevision commitedVersion = configRepository.getRevision(secondMd5);
    assertThat(commitedVersion.getContent(), is(xmlText));
    assertThat(commitedVersion.getUsername(), is(GoFileConfigDataSource.FILESYSTEM));
}
Also used : FileOutputStream(java.io.FileOutputStream) StringContains.containsString(org.hamcrest.core.StringContains.containsString) GoConfigRevision(com.thoughtworks.go.domain.GoConfigRevision) Test(org.junit.Test)

Example 7 with GoConfigRevision

use of com.thoughtworks.go.domain.GoConfigRevision in project gocd by gocd.

the class GoFileConfigDataSourceTest method shouldUse_UserFromSession_asConfigModifyingUserWhenNoneGiven.

@Test
public void shouldUse_UserFromSession_asConfigModifyingUserWhenNoneGiven() throws GitAPIException, IOException {
    SecurityContext context = SecurityContextHolder.getContext();
    context.setAuthentication(new UsernamePasswordAuthenticationToken(new User("loser_boozer", "pass", true, true, true, true, new GrantedAuthority[] {}), null));
    goConfigDao.updateMailHost(getMailHost("mailhost.local"));
    CruiseConfig cruiseConfig = goConfigDao.load();
    GoConfigRevision revision = configRepository.getRevision(cruiseConfig.getMd5());
    assertThat(revision.getUsername(), is("loser_boozer"));
}
Also used : User(org.springframework.security.userdetails.User) SecurityContext(org.springframework.security.context.SecurityContext) UsernamePasswordAuthenticationToken(org.springframework.security.providers.UsernamePasswordAuthenticationToken) GoConfigRevision(com.thoughtworks.go.domain.GoConfigRevision) Test(org.junit.Test)

Example 8 with GoConfigRevision

use of com.thoughtworks.go.domain.GoConfigRevision in project gocd by gocd.

the class GoFileConfigDataSourceTest method shouldVersionTheCruiseConfigXmlWhenSaved.

@Test
public void shouldVersionTheCruiseConfigXmlWhenSaved() throws Exception {
    CachedGoConfig cachedGoConfig = configHelper.getCachedGoConfig();
    CruiseConfig configForEdit = cachedGoConfig.loadForEditing();
    GoConfigHolder configHolder = new GoConfigHolder(cachedGoConfig.currentConfig(), configForEdit);
    Date loserChangedAt = new DateTime().plusDays(2).toDate();
    when(timeProvider.currentTime()).thenReturn(loserChangedAt);
    GoConfigHolder afterFirstSave = dataSource.writeWithLock(new UserAwarePipelineAddingCommand("foo-pipeline", "loser"), configHolder).getConfigHolder();
    Date biggerLoserChangedAt = new DateTime().plusDays(4).toDate();
    when(timeProvider.currentTime()).thenReturn(biggerLoserChangedAt);
    GoConfigHolder afterSecondSave = dataSource.writeWithLock(new UserAwarePipelineAddingCommand("bar-pipeline", "bigger_loser"), afterFirstSave).getConfigHolder();
    String expectedMd5 = afterFirstSave.config.getMd5();
    GoConfigRevision firstRev = configRepository.getRevision(expectedMd5);
    assertThat(firstRev.getUsername(), is("loser"));
    assertThat(firstRev.getGoVersion(), is(CurrentGoCDVersion.getInstance().formatted()));
    assertThat(firstRev.getMd5(), is(expectedMd5));
    assertThat(firstRev.getTime(), is(loserChangedAt));
    assertThat(firstRev.getSchemaVersion(), is(GoConstants.CONFIG_SCHEMA_VERSION));
    assertThat(com.thoughtworks.go.config.ConfigMigrator.load(firstRev.getContent()), is(afterFirstSave.configForEdit));
    CruiseConfig config = afterSecondSave.config;
    assertThat(config.hasPipelineNamed(new CaseInsensitiveString("bar-pipeline")), is(true));
    expectedMd5 = config.getMd5();
    GoConfigRevision secondRev = configRepository.getRevision(expectedMd5);
    assertThat(secondRev.getUsername(), is("bigger_loser"));
    assertThat(secondRev.getGoVersion(), is(CurrentGoCDVersion.getInstance().formatted()));
    assertThat(secondRev.getMd5(), is(expectedMd5));
    assertThat(secondRev.getTime(), is(biggerLoserChangedAt));
    assertThat(secondRev.getSchemaVersion(), is(GoConstants.CONFIG_SCHEMA_VERSION));
    assertThat(com.thoughtworks.go.config.ConfigMigrator.load(secondRev.getContent()), is(afterSecondSave.configForEdit));
}
Also used : StringContains.containsString(org.hamcrest.core.StringContains.containsString) GoConfigRevision(com.thoughtworks.go.domain.GoConfigRevision) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 9 with GoConfigRevision

use of com.thoughtworks.go.domain.GoConfigRevision in project gocd by gocd.

the class GoConfigMigrator method upgradeVersionedConfigFile.

private GoConfigHolder upgradeVersionedConfigFile(Exception originalException) throws Exception {
    GoConfigRevision currentConfigRevision = configRepository.getCurrentRevision();
    if (currentConfigRevision == null) {
        LOGGER.warn("There is no versioned configuration to fallback for migration.");
        throw originalException;
    }
    try {
        File backupFile = this.goConfigMigration.revertFileToVersion(fileLocation(), currentConfigRevision);
        logException(backupFile.getAbsolutePath(), originalException.getMessage());
        return upgradeConfigFile();
    } catch (Exception e) {
        LOGGER.warn("The versioned config file could be invalid or migrating the versioned config resulted in an invalid configuration");
        throw e;
    }
}
Also used : GoConfigRevision(com.thoughtworks.go.domain.GoConfigRevision) File(java.io.File)

Example 10 with GoConfigRevision

use of com.thoughtworks.go.domain.GoConfigRevision in project gocd by gocd.

the class GoConfigAdministrationControllerTest method shouldLoadSpecificConfigVersionWhenHistoricalVersionIsRequested.

@Test
public void shouldLoadSpecificConfigVersionWhenHistoricalVersionIsRequested() throws Exception {
    MockHttpServletResponse response = new MockHttpServletResponse();
    String configXml = "config-content";
    when(goConfigService.getConfigAtVersion("some-md5")).thenReturn(new GoConfigRevision(configXml, "some-md5", "loser", "100.9.3.1", new TimeProvider()));
    controller.getConfigRevision("some-md5", response);
    assertThat(response.getContentAsString(), is(configXml));
    assertThat(response.getHeader(XmlAction.X_CRUISE_CONFIG_MD5).toString(), is("some-md5"));
}
Also used : TimeProvider(com.thoughtworks.go.util.TimeProvider) GoConfigRevision(com.thoughtworks.go.domain.GoConfigRevision) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test)

Aggregations

GoConfigRevision (com.thoughtworks.go.domain.GoConfigRevision)28 Test (org.junit.Test)22 TimeProvider (com.thoughtworks.go.util.TimeProvider)13 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)7 RevCommit (org.eclipse.jgit.revwalk.RevCommit)3 StringContains.containsString (org.hamcrest.core.StringContains.containsString)3 GoConfigRevisions (com.thoughtworks.go.GoConfigRevisions)2 File (java.io.File)2 IOException (java.io.IOException)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 Date (java.util.Date)2 CruiseConfig (com.thoughtworks.go.config.CruiseConfig)1 AgentIdentifier (com.thoughtworks.go.remote.AgentIdentifier)1 FileOutputStream (java.io.FileOutputStream)1 TransformerConfigurationException (javax.xml.transform.TransformerConfigurationException)1 TransformerException (javax.xml.transform.TransformerException)1 DateTime (org.joda.time.DateTime)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)1 SecurityContext (org.springframework.security.context.SecurityContext)1