diff --git a/Scenarios.md b/Scenarios.md index 4817ac4073..d513f29882 100644 --- a/Scenarios.md +++ b/Scenarios.md @@ -1,6 +1,6 @@ ## Chocolatey Usage Scenarios -### ChocolateyInstallCommand [ 34 Scenario(s), 287 Observation(s) ] +### ChocolateyInstallCommand [ 35 Scenario(s), 288 Observation(s) ] #### when force installing a package that depends on an unavailable newer version of an installed dependency forcing dependencies @@ -325,6 +325,10 @@ * [PENDING] should not install the conflicting package in the lib directory * [PENDING] should not upgrade the exact version dependency +#### when installing a package with no sources enabled + + * should have no sources enabled result + #### when installing a side by side package * config should match package result name @@ -391,7 +395,7 @@ * should not have inconclusive package result * should not have warning package result -### ChocolateyListCommand [ 6 Scenario(s), 30 Observation(s) ] +### ChocolateyListCommand [ 7 Scenario(s), 31 Observation(s) ] #### when listing local packages @@ -408,6 +412,10 @@ * should not contain packages and versions with a space between them * should only have messages related to package information +#### when listing packages with no sources enabled + + * should have no sources enabled result + #### when searching all available packages * should contain a summary @@ -613,7 +621,7 @@ * should throw an error that it is not allowed -### ChocolateyUpgradeCommand [ 26 Scenario(s), 214 Observation(s) ] +### ChocolateyUpgradeCommand [ 27 Scenario(s), 215 Observation(s) ] #### when force upgrading a package @@ -853,6 +861,10 @@ * should upgrade the minimum version dependency * should upgrade the package +#### when upgrading a package with no sources enabled + + * should have no sources enabled result + #### when upgrading a package with readonly files * should contain a warning message that it upgraded successfully diff --git a/src/chocolatey.tests.integration/scenarios/InstallScenarios.cs b/src/chocolatey.tests.integration/scenarios/InstallScenarios.cs index a414604ab3..92742c8a3f 100644 --- a/src/chocolatey.tests.integration/scenarios/InstallScenarios.cs +++ b/src/chocolatey.tests.integration/scenarios/InstallScenarios.cs @@ -3333,5 +3333,29 @@ public void should_add_the_insert_value_in_the_config_due_to_XDT_InsertIfMissing _xPathNavigator.SelectSingleNode("//configuration/appSettings/add[@key='insert']/@value").TypedValue.to_string().ShouldEqual("1.0.0"); } } + + [Concern(typeof(ChocolateyInstallCommand))] + public class when_installing_a_package_with_no_sources_enabled : ScenariosBase + { + + public override void Context() + { + base.Context(); + Configuration.Sources = null; + } + + public override void Because() + { + MockLogger.reset(); + Results = Service.install_run(Configuration); + } + + [Fact] + public void should_have_no_sources_enabled_result() + { + MockLogger.contains_message("Installation was NOT successful. There are no sources enabled for packages.", LogLevel.Error).ShouldBeTrue(); + Results.Count().ShouldEqual(0); + } + } } } \ No newline at end of file diff --git a/src/chocolatey.tests.integration/scenarios/ListScenarios.cs b/src/chocolatey.tests.integration/scenarios/ListScenarios.cs index ef2ec14572..66f1a4bff5 100644 --- a/src/chocolatey.tests.integration/scenarios/ListScenarios.cs +++ b/src/chocolatey.tests.integration/scenarios/ListScenarios.cs @@ -340,5 +340,29 @@ public void should_not_contain_debugging_messages() MockLogger.contains_message("End of List", LogLevel.Debug).ShouldBeFalse(); } } + + [Concern(typeof(ChocolateyListCommand))] + public class when_listing_packages_with_no_sources_enabled : ScenariosBase + { + + public override void Context() + { + base.Context(); + Configuration.Sources = null; + } + + public override void Because() + { + MockLogger.reset(); + Results = Service.list_run(Configuration).ToList(); + } + + [Fact] + public void should_have_no_sources_enabled_result() + { + MockLogger.contains_message("Unable to search for packages when there are no sources enabled for packages.", LogLevel.Error).ShouldBeTrue(); + Results.Count().ShouldEqual(0); + } + } } } diff --git a/src/chocolatey.tests.integration/scenarios/UpgradeScenarios.cs b/src/chocolatey.tests.integration/scenarios/UpgradeScenarios.cs index 0c2a778107..3506b0ab6b 100644 --- a/src/chocolatey.tests.integration/scenarios/UpgradeScenarios.cs +++ b/src/chocolatey.tests.integration/scenarios/UpgradeScenarios.cs @@ -2382,5 +2382,29 @@ public void should_have_a_config_with_the_comment_from_the_original() } } + [Concern(typeof(ChocolateyUpgradeCommand))] + public class when_upgrading_a_package_with_no_sources_enabled : ScenariosBase + { + + public override void Context() + { + base.Context(); + Configuration.Sources = null; + //Configuration.PackageNames = Configuration.Input = "installpackage"; + } + + public override void Because() + { + MockLogger.reset(); + Results = Service.upgrade_run(Configuration); + } + + [Fact] + public void should_have_no_sources_enabled_result() + { + MockLogger.contains_message("Upgrading was NOT successful. There are no sources enabled for packages.", LogLevel.Error).ShouldBeTrue(); + Results.Count().ShouldEqual(0); + } + } } } \ No newline at end of file diff --git a/src/chocolatey/infrastructure.app/services/ChocolateyPackageService.cs b/src/chocolatey/infrastructure.app/services/ChocolateyPackageService.cs index 356bc57480..a135f86051 100644 --- a/src/chocolatey/infrastructure.app/services/ChocolateyPackageService.cs +++ b/src/chocolatey/infrastructure.app/services/ChocolateyPackageService.cs @@ -107,6 +107,13 @@ public void list_noop(ChocolateyConfiguration config) public IEnumerable list_run(ChocolateyConfiguration config) { + if (config.Sources == null) + { + this.Log().Error(ChocolateyLoggers.Important, @"Unable to search for packages when there are no sources enabled for packages."); + Environment.ExitCode = 1; + yield break; + } + if (config.RegularOutput) this.Log().Debug(() => "Searching for package information"); var packages = new List(); @@ -304,10 +311,18 @@ public ConcurrentDictionary install_run(ChocolateyConfigu { this.Log().Info(@"Installing the following packages:"); this.Log().Info(ChocolateyLoggers.Important, @"{0}".format_with(config.PackageNames)); - this.Log().Info(@"By installing you accept licenses for the packages."); var packageInstalls = new ConcurrentDictionary(); + if (config.Sources == null) + { + this.Log().Error(ChocolateyLoggers.Important, @"Installation was NOT successful. There are no sources enabled for packages."); + Environment.ExitCode = 1; + return packageInstalls; + } + + this.Log().Info(@"By installing you accept licenses for the packages."); + foreach (var packageConfig in set_config_from_package_names_and_packages_config(config, packageInstalls).or_empty_list_if_null()) { Action action = null; @@ -497,6 +512,14 @@ public ConcurrentDictionary upgrade_run(ChocolateyConfigu { this.Log().Info(@"Upgrading the following packages:"); this.Log().Info(ChocolateyLoggers.Important, @"{0}".format_with(config.PackageNames)); + + if (config.Sources == null) + { + this.Log().Error(ChocolateyLoggers.Important, @"Upgrading was NOT successful. There are no sources enabled for packages."); + Environment.ExitCode = 1; + return new ConcurrentDictionary(); + } + this.Log().Info(@"By upgrading you accept licenses for the packages."); foreach (var packageConfigFile in config.PackageNames.Split(new[] { ApplicationParameters.PackageNamesSeparator }, StringSplitOptions.RemoveEmptyEntries).or_empty_list_if_null().Where(p => p.EndsWith(".config")).ToList())