use of com.thoughtworks.go.plugin.api.material.packagerepository.RepositoryConfiguration in project gocd by gocd.
the class PackageRepositoryServiceTest method shouldPerformCheckConnectionOnPluginAndCatchAnyExceptionsThrownByThePlugin.
@Test
void shouldPerformCheckConnectionOnPluginAndCatchAnyExceptionsThrownByThePlugin() {
String pluginId = "yum";
PackageRepository packageRepository = packageRepository(pluginId);
HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
PackageRepositoryService service = new PackageRepositoryService(pluginManager, packageRepositoryExtension, goConfigService, securityService, entityHashingService, secretParamResolver);
ArgumentCaptor<RepositoryConfiguration> argumentCaptor = ArgumentCaptor.forClass(RepositoryConfiguration.class);
when(packageRepositoryExtension.checkConnectionToRepository(eq(pluginId), argumentCaptor.capture())).thenThrow(new RuntimeException("Check Connection not implemented!!"));
service.checkConnection(packageRepository, result);
assertThat(result.isSuccessful()).isFalse();
assertThat(result.message()).isEqualTo("Could not connect to package repository. Reason(s): Check Connection not implemented!!");
verify(packageRepositoryExtension).checkConnectionToRepository(eq(pluginId), any(RepositoryConfiguration.class));
}
use of com.thoughtworks.go.plugin.api.material.packagerepository.RepositoryConfiguration in project gocd by gocd.
the class PackageRepositoryServiceTest method shouldInvokePluginValidationsBeforeSavingPackageRepository.
@Test
void shouldInvokePluginValidationsBeforeSavingPackageRepository() {
String pluginId = "yum";
PackageRepository packageRepository = new PackageRepository();
RepositoryMetadataStore.getInstance().addMetadataFor(pluginId, new PackageConfigurations());
packageRepository.setPluginConfiguration(new PluginConfiguration(pluginId, "1.0"));
packageRepository.getConfiguration().add(ConfigurationPropertyMother.create("url", false, "junk-url"));
ArgumentCaptor<RepositoryConfiguration> packageConfigurationsArgumentCaptor = ArgumentCaptor.forClass(RepositoryConfiguration.class);
ValidationResult expectedValidationResult = new ValidationResult();
expectedValidationResult.addError(new ValidationError("url", "url format incorrect"));
when(pluginManager.getPluginDescriptorFor(pluginId)).thenReturn(getPluginDescriptor("yum"));
when(packageRepositoryExtension.isRepositoryConfigurationValid(eq(pluginId), packageConfigurationsArgumentCaptor.capture())).thenReturn(expectedValidationResult);
service = new PackageRepositoryService(pluginManager, packageRepositoryExtension, goConfigService, securityService, entityHashingService, secretParamResolver);
service.performPluginValidationsFor(packageRepository);
assertThat(packageRepository.getConfiguration().get(0).getConfigurationValue().errors().getAllOn("value")).isEqualTo(Arrays.asList("url format incorrect"));
}
use of com.thoughtworks.go.plugin.api.material.packagerepository.RepositoryConfiguration in project gocd by gocd.
the class PackageRepositoryServiceTest method shouldPerformCheckConnectionOnPlugin.
@Test
void shouldPerformCheckConnectionOnPlugin() {
String pluginId = "yum";
PackageRepository packageRepository = packageRepository(pluginId);
HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
PackageRepositoryService service = new PackageRepositoryService(pluginManager, packageRepositoryExtension, goConfigService, securityService, entityHashingService, secretParamResolver);
ArgumentCaptor<RepositoryConfiguration> argumentCaptor = ArgumentCaptor.forClass(RepositoryConfiguration.class);
when(packageRepositoryExtension.checkConnectionToRepository(eq(pluginId), argumentCaptor.capture())).thenReturn(new Result().withSuccessMessages("Accessed Repo File!!!"));
service.checkConnection(packageRepository, result);
RepositoryConfiguration packageConfigurations = argumentCaptor.getValue();
PackageMaterialTestHelper.assertPackageConfiguration(packageConfigurations.list(), packageRepository.getConfiguration());
assertThat(result.isSuccessful()).isTrue();
assertThat(result.message()).isEqualTo("Connection OK. Accessed Repo File!!!");
verify(packageRepositoryExtension).checkConnectionToRepository(eq(pluginId), any(RepositoryConfiguration.class));
}
use of com.thoughtworks.go.plugin.api.material.packagerepository.RepositoryConfiguration in project gocd by gocd.
the class PackageRepositoryServiceTest method shouldPerformPluginValidationsUsingMetaDataBeforeSavingPackageRepository.
@Test
void shouldPerformPluginValidationsUsingMetaDataBeforeSavingPackageRepository() {
// metadata setup
String pluginId = "yum";
PackageConfigurations repositoryConfiguration = new PackageConfigurations();
repositoryConfiguration.add(new PackageConfiguration("required").with(PackageConfiguration.REQUIRED, true));
repositoryConfiguration.add(new PackageConfiguration("required_secure").with(PackageConfiguration.REQUIRED, true).with(PackageConfiguration.SECURE, true));
repositoryConfiguration.add(new PackageConfiguration("secure").with(PackageConfiguration.SECURE, true).with(PackageConfiguration.REQUIRED, false));
repositoryConfiguration.add(new PackageConfiguration("not_required_not_secure"));
RepositoryMetadataStore.getInstance().addMetadataFor(pluginId, repositoryConfiguration);
PackageRepository packageRepository = new PackageRepository();
packageRepository.setPluginConfiguration(new PluginConfiguration(pluginId, "1.0"));
packageRepository.getConfiguration().add(ConfigurationPropertyMother.create("required", false, ""));
packageRepository.getConfiguration().add(ConfigurationPropertyMother.create("required_secure", true, ""));
packageRepository.getConfiguration().add(ConfigurationPropertyMother.create("secure", true, ""));
packageRepository.getConfiguration().add(ConfigurationPropertyMother.create("not_required_not_secure", false, ""));
when(packageRepositoryExtension.isRepositoryConfigurationValid(eq(pluginId), any(RepositoryConfiguration.class))).thenReturn(new ValidationResult());
when(pluginManager.getPluginDescriptorFor(pluginId)).thenReturn(getPluginDescriptor(pluginId));
service.performPluginValidationsFor(packageRepository);
assertThat(packageRepository.getConfiguration().get(0).getConfigurationValue().errors().getAllOn("value")).isEqualTo(Arrays.asList("This field is required"));
assertThat(packageRepository.getConfiguration().get(1).getEncryptedConfigurationValue().errors().getAllOn("value")).isEqualTo(Arrays.asList("This field is required"));
}
use of com.thoughtworks.go.plugin.api.material.packagerepository.RepositoryConfiguration in project gocd by gocd.
the class PackageRepositoryServiceTest method shouldSendResolvedValuesForCheckConnectionOnPlugin.
@Test
void shouldSendResolvedValuesForCheckConnectionOnPlugin() {
String pluginId = "yum";
PackageRepository packageRepository = packageRepository(pluginId);
packageRepository.getConfiguration().get(0).setConfigurationValue(new ConfigurationValue("{{SECRET:[secret_config_id][username]}}"));
HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
PackageRepositoryService service = new PackageRepositoryService(pluginManager, packageRepositoryExtension, goConfigService, securityService, entityHashingService, secretParamResolver);
when(packageRepositoryExtension.checkConnectionToRepository(eq(pluginId), any())).thenReturn(new Result().withErrorMessages("Repo invalid!!", "Could not connect"));
doAnswer(invocation -> {
PackageRepository config = invocation.getArgument(0);
config.getSecretParams().get(0).setValue("resolved-value");
return config;
}).when(secretParamResolver).resolve(packageRepository);
service.checkConnection(packageRepository, result);
assertThat(result.isSuccessful()).isFalse();
assertThat(result.message()).isEqualTo("Could not connect to package repository. Reason(s): Repo invalid!!\nCould not connect");
ArgumentCaptor<RepositoryConfiguration> argumentCaptor = ArgumentCaptor.forClass(RepositoryConfiguration.class);
verify(packageRepositoryExtension).checkConnectionToRepository(eq(pluginId), argumentCaptor.capture());
RepositoryConfiguration packageConfigurations = argumentCaptor.getValue();
assertThat(packageConfigurations.list().get(0).getValue()).isEqualTo("resolved-value");
}
Aggregations