@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()));
  }
コード例 #3
0
 /** Creates config dao that accesses single file */
 public static GoConfigDao createTestingDao() {
   SystemEnvironment systemEnvironment = new SystemEnvironment();
   try {
     ServerHealthService serverHealthService = new ServerHealthService();
     ConfigRepository configRepository = new ConfigRepository(systemEnvironment);
     configRepository.initialize();
     ConfigCache configCache = new ConfigCache();
     ConfigElementImplementationRegistry configElementImplementationRegistry =
         ConfigElementImplementationRegistryMother.withNoPlugins();
     CachedGoPartials cachedGoPartials = new CachedGoPartials(serverHealthService);
     FullConfigSaveNormalFlow normalFlow =
         new FullConfigSaveNormalFlow(
             configCache,
             configElementImplementationRegistry,
             systemEnvironment,
             new ServerVersion(),
             new TimeProvider(),
             configRepository,
             cachedGoPartials);
     GoFileConfigDataSource dataSource =
         new GoFileConfigDataSource(
             new DoNotUpgrade(),
             configRepository,
             systemEnvironment,
             new TimeProvider(),
             configCache,
             new ServerVersion(),
             configElementImplementationRegistry,
             serverHealthService,
             cachedGoPartials,
             null,
             normalFlow);
     dataSource.upgradeIfNecessary();
     CachedGoConfig cachedConfigService =
         new CachedGoConfig(serverHealthService, dataSource, cachedGoPartials, null, null);
     cachedConfigService.loadConfigIfNull();
     return new GoConfigDao(cachedConfigService);
   } catch (IOException e) {
     throw new RuntimeException(e);
   }
 }