Skip to content

Commit bf0d8b9

Browse files
committed
(maint) Extract all used environment variables
These changes extracts all of the environment variables that we make use of while running Chocolatey CLI. Both variables that are used as part of running package scripts, and variables we use only when they are set on the system. A change to make these environment variables and all other internal types available to other products and the test projects has been made.
1 parent d836138 commit bf0d8b9

File tree

21 files changed

+830
-196
lines changed

21 files changed

+830
-196
lines changed

src/chocolatey.console/Properties/AssemblyInfo.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,19 @@
1414
// See the License for the specific language governing permissions and
1515
// limitations under the License.
1616

17+
using System.Runtime.CompilerServices;
1718
using System.Runtime.InteropServices;
1819

1920
// The following GUID is for the ID of the typelib if this project is exposed to COM
2021

2122
[assembly: Guid("2f406051-3fe2-45f4-97bf-40968b86c5a9")]
23+
24+
// TODO: Make internals visible to Chocolatey Licensed Extension. This section is commented out as it will cause problems upstream when ilmerged.
25+
// We allow the officially built chocolatey.extension to always see the internals.
26+
//[assembly: InternalsVisibleTo("chocolatey.licensed, PublicKey=002400000480000094000000060200000024000052534131000400000100010001f55d4a9065e32d5e9854e592ffa5f7b3a707f55a17796937faf70f3ade21346dcf735216015d20304acd25d260d01202a390ac648ace0e93f6c4d6ac7cbede5b3e8f66e536d03ffa2d09594ac8de7bd147419c17e0fa1fa112b81b1b65a9e8b0ca148dc3a77e7b2917f448455ce9dbad266351710d097424692be8854704e8")]
27+
//[assembly: InternalsVisibleTo("chocolatey.interfaces, PublicKey=002400000480000094000000060200000024000052534131000400000100010001f55d4a9065e32d5e9854e592ffa5f7b3a707f55a17796937faf70f3ade21346dcf735216015d20304acd25d260d01202a390ac648ace0e93f6c4d6ac7cbede5b3e8f66e536d03ffa2d09594ac8de7bd147419c17e0fa1fa112b81b1b65a9e8b0ca148dc3a77e7b2917f448455ce9dbad266351710d097424692be8854704e8")]
28+
29+
//#if !FORCE_CHOCOLATEY_OFFICIAL_KEY
30+
//[assembly: InternalsVisibleTo("chocolatey.licensed, PublicKey=00240000048000009400000006020000002400005253413100040000010001003f70732af6adf3f525d983852cc7049878c498e4f8a413bd7685c9edc503ed6c6e4087354c7c1797b7c9f6d9bd3c25cdd5f97b0e810b7dd1aaba2e489f60d17d1f03c0f4db27c63146ee64ce797e4c92d591a750d8c342f5b67775710f6f9b3d9d10b4121522779a1ff72776bcce3962ca66f1755919972fb70ffb289bc082b3")]
31+
//[assembly: InternalsVisibleTo("chocolatey.interfaces, PublicKey=00240000048000009400000006020000002400005253413100040000010001003f70732af6adf3f525d983852cc7049878c498e4f8a413bd7685c9edc503ed6c6e4087354c7c1797b7c9f6d9bd3c25cdd5f97b0e810b7dd1aaba2e489f60d17d1f03c0f4db27c63146ee64ce797e4c92d591a750d8c342f5b67775710f6f9b3d9d10b4121522779a1ff72776bcce3962ca66f1755919972fb70ffb289bc082b3")]
32+
//#endif
596 Bytes
Binary file not shown.

src/chocolatey.tests.integration/chocolatey.tests.integration.csproj

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,12 @@
7878
<ErrorReport>prompt</ErrorReport>
7979
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
8080
</PropertyGroup>
81+
<PropertyGroup>
82+
<SignAssembly>true</SignAssembly>
83+
</PropertyGroup>
84+
<PropertyGroup>
85+
<AssemblyOriginatorKeyFile>TestKey.snk</AssemblyOriginatorKeyFile>
86+
</PropertyGroup>
8187
<ItemGroup>
8288
<Reference Include="Chocolatey.NuGet.Common">
8389
<HintPath>..\packages\Chocolatey.NuGet.Common.3.3.0\lib\net472\Chocolatey.NuGet.Common.dll</HintPath>
@@ -176,6 +182,7 @@
176182
<None Include="packages.config">
177183
<SubType>Designer</SubType>
178184
</None>
185+
<None Include="TestKey.snk" />
179186
</ItemGroup>
180187
<ItemGroup>
181188
<ProjectReference Include="..\chocolatey.tests\chocolatey.tests.csproj">

src/chocolatey.tests.integration/infrastructure.app/builders/ConfigurationBuilderSpecs.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ namespace chocolatey.tests.integration.infrastructure.app.builders
3434
using Microsoft.Win32;
3535
using scenarios;
3636
using FluentAssertions;
37+
using static chocolatey.StringResources;
3738

3839
public class ConfigurationBuilderSpecs
3940
{
@@ -116,11 +117,11 @@ public override void Context()
116117

117118
if (EnvironmentVariableSet)
118119
{
119-
Environment.Setup(e => e.GetEnvironmentVariable(It.IsIn("http_proxy", "https_proxy"))).Returns(EnvironmentVariableProxyValue);
120+
Environment.Setup(e => e.GetEnvironmentVariable(It.IsIn(EnvironmentVariables.System.HttpProxy, EnvironmentVariables.System.HttpsProxy))).Returns(EnvironmentVariableProxyValue);
120121
}
121122
else
122123
{
123-
Environment.Setup(e => e.GetEnvironmentVariable(It.IsIn("http_proxy", "https_proxy"))).Returns(string.Empty);
124+
Environment.Setup(e => e.GetEnvironmentVariable(It.IsIn(EnvironmentVariables.System.HttpProxy, EnvironmentVariables.System.HttpsProxy))).Returns(string.Empty);
124125
}
125126

126127
if (ConfigSet)
@@ -192,11 +193,11 @@ public override void Context()
192193

193194
if (EnvironmentVariableSet)
194195
{
195-
Environment.Setup(e => e.GetEnvironmentVariable("no_proxy")).Returns(EnvironmentVariableProxyValue);
196+
Environment.Setup(e => e.GetEnvironmentVariable(EnvironmentVariables.System.NoProxy)).Returns(EnvironmentVariableProxyValue);
196197
}
197198
else
198199
{
199-
Environment.Setup(e => e.GetEnvironmentVariable("no_proxy")).Returns(string.Empty);
200+
Environment.Setup(e => e.GetEnvironmentVariable(EnvironmentVariables.System.NoProxy)).Returns(string.Empty);
200201
}
201202

202203
if (ArgumentSet)

src/chocolatey.tests/TestKey.snk

596 Bytes
Binary file not shown.

src/chocolatey.tests/TinySpec.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ namespace chocolatey.tests
2424
using chocolatey.infrastructure.logging;
2525
using System.IO;
2626
using chocolatey.infrastructure.app.nuget;
27+
using static chocolatey.StringResources;
2728

2829
// ReSharper disable InconsistentNaming
2930

@@ -32,12 +33,12 @@ public class NUnitSetup
3233
{
3334
public static MockLogger MockLogger { get; set; }
3435

35-
private static readonly string _installLocationVariable = Environment.GetEnvironmentVariable(ApplicationParameters.ChocolateyInstallEnvironmentVariableName);
36+
private static readonly string _installLocationVariable = Environment.GetEnvironmentVariable(EnvironmentVariables.System.ChocolateyInstall);
3637

3738
[OneTimeSetUp]
3839
public virtual void BeforeEverything()
3940
{
40-
Environment.SetEnvironmentVariable(ApplicationParameters.ChocolateyInstallEnvironmentVariableName, string.Empty);
41+
Environment.SetEnvironmentVariable(EnvironmentVariables.System.ChocolateyInstall, string.Empty);
4142
MockLogger = new MockLogger();
4243
Log.InitializeWith(MockLogger);
4344
// do not log trace messages
@@ -48,7 +49,7 @@ public virtual void BeforeEverything()
4849
[OneTimeTearDown]
4950
public void AfterEverything()
5051
{
51-
Environment.SetEnvironmentVariable(ApplicationParameters.ChocolateyInstallEnvironmentVariableName, _installLocationVariable);
52+
Environment.SetEnvironmentVariable(EnvironmentVariables.System.ChocolateyInstall, _installLocationVariable);
5253
}
5354
}
5455

src/chocolatey.tests/chocolatey.tests.csproj

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,12 @@
7777
<ErrorReport>prompt</ErrorReport>
7878
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
7979
</PropertyGroup>
80+
<PropertyGroup>
81+
<SignAssembly>true</SignAssembly>
82+
</PropertyGroup>
83+
<PropertyGroup>
84+
<AssemblyOriginatorKeyFile>TestKey.snk</AssemblyOriginatorKeyFile>
85+
</PropertyGroup>
8086
<ItemGroup>
8187
<Reference Include="Chocolatey.NuGet.Commands">
8288
<HintPath>..\packages\Chocolatey.NuGet.Commands.3.3.0\lib\net472\Chocolatey.NuGet.Commands.dll</HintPath>
@@ -223,6 +229,7 @@
223229
<None Include="packages.config">
224230
<SubType>Designer</SubType>
225231
</None>
232+
<None Include="TestKey.snk" />
226233
</ItemGroup>
227234
<ItemGroup>
228235
<ProjectReference Include="..\chocolatey\chocolatey.csproj">

src/chocolatey.tests/infrastructure/filesystem/DotNetFileSystemSpecs.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ namespace chocolatey.tests.infrastructure.filesystem
2525
using Moq;
2626
using NUnit.Framework;
2727
using FluentAssertions;
28+
using static chocolatey.StringResources;
2829

2930
public class DotNetFileSystemSpecs
3031
{
@@ -135,8 +136,8 @@ public class When_finding_paths_to_executables_with_dotNetFileSystem : DotNetFil
135136
public override void Context()
136137
{
137138
base.Context();
138-
Environment.Setup(x => x.GetEnvironmentVariable(ApplicationParameters.Environment.PathExtensions)).Returns(".COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC;.CPL");
139-
Environment.Setup(x => x.GetEnvironmentVariable(ApplicationParameters.Environment.Path)).Returns(
139+
Environment.Setup(x => x.GetEnvironmentVariable(EnvironmentVariables.System.PathExtensions)).Returns(".COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC;.CPL");
140+
Environment.Setup(x => x.GetEnvironmentVariable(EnvironmentVariables.System.Path)).Returns(
140141
@"C:\ProgramData\Chocolatey\bin{0}C:\Program Files\Microsoft\Web Platform Installer\{0}C:\Users\yes\AppData\Roaming\Boxstarter{0}C:\tools\ChocolateyPackageUpdater{0}C:\Windows\system32{0}C:\Windows{0}C:\Windows\System32\Wbem{0}C:\Windows\System32\WindowsPowerShell\v1.0\{0}"
141142
.FormatWith(Path.PathSeparator)
142143
);
@@ -192,8 +193,8 @@ public class When_finding_paths_to_executables_with_dotNetFileSystem_with_empty_
192193
public override void Context()
193194
{
194195
base.Context();
195-
Environment.Setup(x => x.GetEnvironmentVariable(ApplicationParameters.Environment.PathExtensions)).Returns(string.Empty);
196-
Environment.Setup(x => x.GetEnvironmentVariable(ApplicationParameters.Environment.Path)).Returns(
196+
Environment.Setup(x => x.GetEnvironmentVariable(EnvironmentVariables.System.PathExtensions)).Returns(string.Empty);
197+
Environment.Setup(x => x.GetEnvironmentVariable(EnvironmentVariables.System.Path)).Returns(
197198
"/usr/local/bin{0}/usr/bin/{0}/bin{0}/usr/sbin{0}/sbin"
198199
.FormatWith(Path.PathSeparator)
199200
);

src/chocolatey/GetChocolatey.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ namespace chocolatey
4343
using IFileSystem = infrastructure.filesystem.IFileSystem;
4444
using ILog = infrastructure.logging.ILog;
4545
using System.Linq;
46+
using static chocolatey.StringResources;
4647

4748
/// <summary>
4849
/// Entry point for API
@@ -490,19 +491,19 @@ private void EnsureEnvironment()
490491
string chocolateyInstall = string.Empty;
491492

492493
#if !DEBUG
493-
chocolateyInstall = Environment.GetEnvironmentVariable(ApplicationParameters.ChocolateyInstallEnvironmentVariableName, EnvironmentVariableTarget.Machine);
494+
chocolateyInstall = Environment.GetEnvironmentVariable(EnvironmentVariables.System.ChocolateyInstall, EnvironmentVariableTarget.Machine);
494495
if (string.IsNullOrWhiteSpace(chocolateyInstall))
495496
{
496-
chocolateyInstall = Environment.GetEnvironmentVariable(ApplicationParameters.ChocolateyInstallEnvironmentVariableName, EnvironmentVariableTarget.User);
497+
chocolateyInstall = Environment.GetEnvironmentVariable(EnvironmentVariables.System.ChocolateyInstall, EnvironmentVariableTarget.User);
497498
}
498499
#endif
499500

500501
if (string.IsNullOrWhiteSpace(chocolateyInstall))
501502
{
502-
chocolateyInstall = Environment.GetEnvironmentVariable(ApplicationParameters.ChocolateyInstallEnvironmentVariableName);
503+
chocolateyInstall = Environment.GetEnvironmentVariable(EnvironmentVariables.System.ChocolateyInstall);
503504
}
504505

505-
Environment.SetEnvironmentVariable(ApplicationParameters.ChocolateyInstallEnvironmentVariableName, chocolateyInstall);
506+
Environment.SetEnvironmentVariable(EnvironmentVariables.System.ChocolateyInstall, chocolateyInstall);
506507
}
507508

508509
private void ExtractResources()

src/chocolatey/Properties/AssemblyInfo.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,23 @@
1414
// See the License for the specific language governing permissions and
1515
// limitations under the License.
1616

17+
using System.Runtime.CompilerServices;
1718
using System.Runtime.InteropServices;
1819

1920
// The following GUID is for the ID of the typelib if this project is exposed to COM
2021

2122
[assembly: Guid("bd59231e-97d1-4fc0-a975-80c3fed498b7")]
23+
24+
[assembly: InternalsVisibleTo("chocolatey.tests, PublicKey=002400000480000094000000060200000024000052534131000400000100010059b0331d79eca3ed9087221c6252d3383087f35fa7c54f2ce6223c40905ed2c44e2de8576ae81bcd2f0471961bdbc083a8457d564912d3d3263477756337565ac8ce8dfe912b15cd762ac9e5c4641d82768d9da09265cde5b414ed08e654a3ebf48b9c70b34ebeab0adcb145c439289b5fa8790ef218a6d8123c8d02251c33cf")]
25+
26+
[assembly: InternalsVisibleTo("chocolatey.tests.integration, PublicKey=002400000480000094000000060200000024000052534131000400000100010059b0331d79eca3ed9087221c6252d3383087f35fa7c54f2ce6223c40905ed2c44e2de8576ae81bcd2f0471961bdbc083a8457d564912d3d3263477756337565ac8ce8dfe912b15cd762ac9e5c4641d82768d9da09265cde5b414ed08e654a3ebf48b9c70b34ebeab0adcb145c439289b5fa8790ef218a6d8123c8d02251c33cf")]
27+
28+
// TODO: Make internals visible to Chocolatey Licensed Extension. This section is commented out as it will cause problems upstream when ilmerged.
29+
// We allow the officially built chocolatey.extension to always see the internals.
30+
//[assembly: InternalsVisibleTo("chocolatey.licensed, PublicKey=002400000480000094000000060200000024000052534131000400000100010001f55d4a9065e32d5e9854e592ffa5f7b3a707f55a17796937faf70f3ade21346dcf735216015d20304acd25d260d01202a390ac648ace0e93f6c4d6ac7cbede5b3e8f66e536d03ffa2d09594ac8de7bd147419c17e0fa1fa112b81b1b65a9e8b0ca148dc3a77e7b2917f448455ce9dbad266351710d097424692be8854704e8")]
31+
//[assembly: InternalsVisibleTo("chocolatey.interfaces, PublicKey=002400000480000094000000060200000024000052534131000400000100010001f55d4a9065e32d5e9854e592ffa5f7b3a707f55a17796937faf70f3ade21346dcf735216015d20304acd25d260d01202a390ac648ace0e93f6c4d6ac7cbede5b3e8f66e536d03ffa2d09594ac8de7bd147419c17e0fa1fa112b81b1b65a9e8b0ca148dc3a77e7b2917f448455ce9dbad266351710d097424692be8854704e8")]
32+
33+
//#if !FORCE_CHOCOLATEY_OFFICIAL_KEY
34+
//[assembly: InternalsVisibleTo("chocolatey.licensed, PublicKey=00240000048000009400000006020000002400005253413100040000010001003f70732af6adf3f525d983852cc7049878c498e4f8a413bd7685c9edc503ed6c6e4087354c7c1797b7c9f6d9bd3c25cdd5f97b0e810b7dd1aaba2e489f60d17d1f03c0f4db27c63146ee64ce797e4c92d591a750d8c342f5b67775710f6f9b3d9d10b4121522779a1ff72776bcce3962ca66f1755919972fb70ffb289bc082b3")]
35+
//[assembly: InternalsVisibleTo("chocolatey.interfaces, PublicKey=00240000048000009400000006020000002400005253413100040000010001003f70732af6adf3f525d983852cc7049878c498e4f8a413bd7685c9edc503ed6c6e4087354c7c1797b7c9f6d9bd3c25cdd5f97b0e810b7dd1aaba2e489f60d17d1f03c0f4db27c63146ee64ce797e4c92d591a750d8c342f5b67775710f6f9b3d9d10b4121522779a1ff72776bcce3962ca66f1755919972fb70ffb289bc082b3")]
36+
//#endif

0 commit comments

Comments
 (0)