@Test public void postGroupAsXmlPartial_shouldEnforcePipelineGroupAdminPermissionsForPipelineTemplates() throws Exception { String md5 = setUpPipelineGroupsWithAdminPermissions(); ConfigElementImplementationRegistry registry = ConfigElementImplementationRegistryMother.withNoPlugins(); XmlUtils.validate( new FileInputStream(configHelper.getConfigFile()), GoConfigSchema.getCurrentSchema(), new XsdErrorTranslator(), new SAXBuilder(), registry.xsds()); controller.postGroupAsXmlPartial( TemplatesConfig.PIPELINE_TEMPLATES_FAKE_GROUP_NAME, NEW_TEMPLATES, md5, response); assertThat(response.getStatus(), is(SC_UNAUTHORIZED)); XmlUtils.validate( new FileInputStream(configHelper.getConfigFile()), GoConfigSchema.getCurrentSchema(), new XsdErrorTranslator(), new SAXBuilder(), registry.xsds()); setCurrentUser("admin"); controller.postGroupAsXmlPartial( TemplatesConfig.PIPELINE_TEMPLATES_FAKE_GROUP_NAME, NEW_TEMPLATES, md5, response); assertThat(response.getStatus(), is(SC_OK)); }
/** * Creates config dao that has custom remote configuration parts provided by partialConfig * argument */ public static GoConfigDao createTestingDao(GoPartialConfig partialConfig) { SystemEnvironment systemEnvironment = new SystemEnvironment(); try { ServerHealthService serverHealthService = new ServerHealthService(); ConfigRepository configRepository = new ConfigRepository(systemEnvironment); configRepository.initialize(); FullConfigSaveNormalFlow normalFlow = new FullConfigSaveNormalFlow( new ConfigCache(), com.thoughtworks.go.util.ConfigElementImplementationRegistryMother.withNoPlugins(), systemEnvironment, new ServerVersion(), new TimeProvider(), configRepository, new CachedGoPartials(serverHealthService)); GoFileConfigDataSource dataSource = new GoFileConfigDataSource( new DoNotUpgrade(), configRepository, systemEnvironment, new TimeProvider(), new ConfigCache(), new ServerVersion(), com.thoughtworks.go.util.ConfigElementImplementationRegistryMother.withNoPlugins(), serverHealthService, new CachedGoPartials(serverHealthService), null, normalFlow); dataSource.upgradeIfNecessary(); CachedGoPartials cachedGoPartials = new CachedGoPartials(serverHealthService); CachedGoConfig cachedConfigService = new CachedGoConfig(serverHealthService, dataSource, cachedGoPartials, null, null); cachedConfigService.loadConfigIfNull(); return new GoConfigDao(cachedConfigService); } catch (IOException e) { throw new RuntimeException(e); } }
@Test public void shouldConflictWhenGivenMd5IsDifferent() throws Exception { configHelper.addPipeline("pipeline", "stage", "build1", "build2"); controller.getCurrentConfigXml("crapy_md5", response); ByteArrayOutputStream os = new ByteArrayOutputStream(); new MagicalGoConfigXmlWriter( new ConfigCache(), ConfigElementImplementationRegistryMother.withNoPlugins(), metricsProbeService) .write(goConfigDao.loadForEditing(), os, true); assertValidContentAndStatus( SC_CONFLICT, "text/plain; charset=utf-8", CONFIG_CHANGED_PLEASE_REFRESH); assertThat( response.getHeader(XmlAction.X_CRUISE_CONFIG_MD5), is(goConfigDao.md5OfConfigFile())); }
public void getXml(CruiseConfig cruiseConfig, ByteArrayOutputStream buffer) throws Exception { new MagicalGoConfigXmlWriter( new ConfigCache(), com.thoughtworks.go.util.ConfigElementImplementationRegistryMother.withNoPlugins()) .write(cruiseConfig, buffer, false); }