예제 #1
0
  @Test
  public void shouldNotContinueWithConfigSaveIfRequestIsNotFresh() {
    when(goConfigService.isUserAdmin(currentUser)).thenReturn(true);
    when(goConfigService.isGroupAdministrator(currentUser.getUsername())).thenReturn(false);

    SCM updatedScm =
        new SCM(
            "id",
            new PluginConfiguration("plugin-id", "1"),
            new Configuration(
                new ConfigurationProperty(
                    new ConfigurationKey("key1"), new ConfigurationValue("value1"))));
    updatedScm.setName("material");
    when(entityHashingService.md5ForEntity(cruiseConfig.getSCMs().find("id"), "material"))
        .thenReturn("another-md5");
    UpdateSCMConfigCommand command =
        new UpdateSCMConfigCommand(
            updatedScm,
            pluggableScmService,
            goConfigService,
            currentUser,
            result,
            "md5",
            entityHashingService);

    assertThat(command.canContinue(cruiseConfig), is(false));
    assertThat(result.toString(), containsString("STALE_RESOURCE_CONFIG"));
    assertThat(result.toString(), containsString(updatedScm.getName()));
  }
예제 #2
0
  @Test
  public void shouldLoadAutoUpdateValueForSCMWhenLoadedFromConfigFile() throws Exception {
    String configTemplate =
        "<cruise schemaVersion='"
            + GoConstants.CONFIG_SCHEMA_VERSION
            + "'>"
            + "<scms>"
            + "	<scm id='2ef830d7-dd66-42d6-b393-64a84646e557' name='scm-name' autoUpdate='%s' >"
            + "		<pluginConfiguration id='yum' version='1' />"
            + "       <configuration>"
            + "           <property>"
            + "               <key>SCM_URL</key>"
            + "               <value>http://fake-scm/git/go-cd</value>"
            + "               </property>"
            + "       </configuration>"
            + "   </scm>"
            + "</scms>"
            + "</cruise>";
    String configContent = String.format(configTemplate, false);
    GoConfigHolder holder = xmlLoader.loadConfigHolder(configContent);
    SCM scm = holder.config.getSCMs().find("2ef830d7-dd66-42d6-b393-64a84646e557");
    assertThat(scm.isAutoUpdate(), is(false));

    configContent = String.format(configTemplate, true);
    holder = xmlLoader.loadConfigHolder(configContent);
    scm = holder.config.getSCMs().find("2ef830d7-dd66-42d6-b393-64a84646e557");
    assertThat(scm.isAutoUpdate(), is(true));
  }
 @Override
 protected void validateExtras(ValidationContext validationContext) {
   if (!StringUtil.isBlank(scmId)) {
     SCM scm = validationContext.findScmById(scmId);
     if (scm == null) {
       addError(SCM_ID, String.format("Could not find SCM for given scm-id: [%s].", scmId));
     } else if (!scm.doesPluginExist()) {
       addError(SCM_ID, String.format("Could not find plugin for scm-id: [%s].", scmId));
     }
   }
 }
 @Override
 public String getFingerprint() {
   if (scmConfig == null) {
     return null;
   }
   return scmConfig.getFingerprint();
 }
예제 #5
0
 @Override
 public String getFingerprint() {
   if (isEmpty(fingerprint)) {
     return scmConfig == null ? null : scmConfig.getFingerprint();
   }
   return fingerprint;
 }
 @Override
 public CaseInsensitiveString getName() {
   if (nameIsEmpty() && !scmNameIsEmpty()) {
     return new CaseInsensitiveString(scmConfig.getName());
   } else {
     return name;
   }
 }
 @Override
 public String getTypeForDisplay() {
   String type =
       scmConfig == null
           ? null
           : SCMMetadataStore.getInstance()
               .displayValue(scmConfig.getPluginConfiguration().getId());
   return type == null ? "SCM" : type;
 }
 public PluggableSCMMaterialConfig(
     CaseInsensitiveString name, SCM scmConfig, String folder, Filter filter) {
   super(TYPE);
   this.name = name;
   this.scmId = scmConfig == null ? null : scmConfig.getSCMId();
   this.scmConfig = scmConfig;
   this.folder = folder;
   this.filter = filter;
 }
예제 #9
0
 @Override
 public Map<String, Object> getAttributes(boolean addSecureFields) {
   Map<String, Object> materialMap = new HashMap<>();
   materialMap.put("type", "scm");
   materialMap.put("plugin-id", getPluginId());
   Map<String, String> configurationMap =
       scmConfig.getConfiguration().getConfigurationAsMap(addSecureFields);
   materialMap.put("scm-configuration", configurationMap);
   return materialMap;
 }
예제 #10
0
 @Test
 public void shouldUpdateAnExistingSCMWithNewValues() throws Exception {
   SCM updatedScm =
       new SCM(
           "id",
           new PluginConfiguration("plugin-id", "1"),
           new Configuration(
               new ConfigurationProperty(
                   new ConfigurationKey("key1"), new ConfigurationValue("value1"))));
   updatedScm.setName("material");
   UpdateSCMConfigCommand command =
       new UpdateSCMConfigCommand(
           updatedScm,
           pluggableScmService,
           goConfigService,
           currentUser,
           result,
           "md5",
           entityHashingService);
   assertThat(cruiseConfig.getSCMs().contains(scm), is(true));
   command.update(cruiseConfig);
   assertThat(cruiseConfig.getSCMs().contains(updatedScm), is(true));
 }
예제 #11
0
 @Before
 public void setup() throws Exception {
   initMocks(this);
   result = new HttpLocalizedOperationResult();
   currentUser = new Username(new CaseInsensitiveString("user"));
   cruiseConfig = new GoConfigMother().defaultCruiseConfig();
   scm =
       new SCM(
           "id",
           new PluginConfiguration("plugin-id", "1"),
           new Configuration(
               new ConfigurationProperty(
                   new ConfigurationKey("key"), new ConfigurationValue("value"))));
   scm.setName("material");
   scms = new SCMs();
   scms.add(scm);
   cruiseConfig.setSCMs(scms);
 }
예제 #12
0
  @Override
  public void populateEnvironmentContext(
      EnvironmentVariableContext context, MaterialRevision materialRevision, File workingDir) {
    context.setProperty(
        getEnvironmentVariableKey("GO_SCM_%s_%s", "LABEL"),
        materialRevision.getRevision().getRevision(),
        false);
    for (ConfigurationProperty configurationProperty : scmConfig.getConfiguration()) {
      context.setProperty(
          getEnvironmentVariableKey(
              "GO_SCM_%s_%s", configurationProperty.getConfigurationKey().getName()),
          configurationProperty.getValue(),
          configurationProperty.isSecure());
    }
    HashMap<String, String> additionalData =
        materialRevision.getLatestModification().getAdditionalDataMap();
    if (additionalData != null) {
      for (Map.Entry<String, String> entry : additionalData.entrySet()) {
        boolean isSecure = false;
        for (EnvironmentVariableContext.EnvironmentVariable secureEnvironmentVariable :
            context.getSecureEnvironmentVariables()) {
          String urlEncodedValue = null;
          try {
            urlEncodedValue = URLEncoder.encode(secureEnvironmentVariable.value(), "UTF-8");
          } catch (UnsupportedEncodingException e) {
          }
          boolean isSecureEnvironmentVariableEncoded =
              !StringUtil.isBlank(urlEncodedValue)
                  && !secureEnvironmentVariable.value().equals(urlEncodedValue);
          if (isSecureEnvironmentVariableEncoded && entry.getValue().contains(urlEncodedValue)) {
            isSecure = true;
            break;
          }
        }

        String key = entry.getKey();
        String value = entry.getValue();
        context.setProperty(getEnvironmentVariableKey("GO_SCM_%s_%s", key), value, isSecure);
      }
    }
  }
  @Override
  public boolean equals(Object o) {
    if (this == o) {
      return true;
    }
    if (o == null || getClass() != o.getClass()) {
      return false;
    }

    PluggableSCMMaterialConfig that = (PluggableSCMMaterialConfig) o;

    if (folder != null ? !folder.equals(that.folder) : that.folder != null) {
      return false;
    }

    if (scmConfig != null ? !scmConfig.equals(that.scmConfig) : that.scmConfig != null) {
      return false;
    }

    return super.equals(that);
  }
 public void setSCMConfig(SCM scmConfig) {
   this.scmConfig = scmConfig;
   this.scmId = scmConfig == null ? null : scmConfig.getId();
 }
 @Override
 public String getUriForDisplay() {
   return scmConfig.getConfigForDisplay();
 }
 private boolean scmNameIsEmpty() {
   return (scmConfig == null || scmConfig.getName() == null || scmConfig.getName().isEmpty());
 }
 @Override
 public void setAutoUpdate(boolean autoUpdate) {
   scmConfig.setAutoUpdate(autoUpdate);
 }
 @Override
 public boolean isAutoUpdate() {
   return scmConfig.isAutoUpdate();
 }
 @Override
 protected void appendAttributes(Map<String, Object> parameters) {
   parameters.put("scmName", scmConfig.getName());
 }
 public String getPluginId() {
   return scmConfig.getPluginConfiguration().getId();
 }