@Test public void shouldNotCreatePackageRepositoryWhenRepositoryHasDuplicateConfigurationProperties() throws Exception { ConfigurationProperty property = new ConfigurationProperty(new ConfigurationKey("foo"), new ConfigurationValue("bar")); Configuration configuration = new Configuration(property, property); packageRepository.setConfiguration(configuration); CreatePackageRepositoryCommand command = new CreatePackageRepositoryCommand( goConfigService, packageRepositoryService, packageRepository, currentUser, result); assertFalse(command.isValid(cruiseConfig)); assertThat( property.errors().firstError(), is("Duplicate key 'foo' found for Repository 'npmOrg'")); }
@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); } } }