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