Repository navigation
feat(core): let a server manifest declare service environment variables #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
066db5a
feat(core): let a server manifest declare service environment variables
claude 1666d9c
fix(test): assert on the drop-in file, not the harmless cleanup rm -rf
claude b86b466
fix(core): harden Ubuntu service environment override
claude d572270
fix(test): fix unterminated verbatim string literal
claude ae94c3c
fix(test): assert on the drop-in write, not the always-present cleanup
claude e5584ad
fix(security): validate environment variable keys, not just values
claude File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
44 changes: 44 additions & 0 deletions
44
...Tests/Features/MacOsInstallation/Model/MacOsInstallerManifestEnvironmentVariablesTests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| using LocalInstaller.Core.Features.Installation.Models; | ||
| using LocalInstaller.Core.Features.MacOsInstallation.Models; | ||
|
|
||
| namespace LocalInstaller.Core.Tests.Features.MacOsInstallation.Model; | ||
|
|
||
| [TestFixture] | ||
| public class MacOsInstallerManifestEnvironmentVariablesTests | ||
| { | ||
| [Test] | ||
| public void LaunchDaemonPlist_includesServerComponentEnvironmentVariables() | ||
| { | ||
| var product = new ProductManifest("Acme Studio", "acme-studio", "ACMESTUDIO") | ||
| { | ||
| Components = | ||
| [ | ||
| ProductComponent.Server with | ||
| { | ||
| EnvironmentVariables = new Dictionary<string, string> { ["EXAMPLE_FLAG"] = "true" } | ||
| } | ||
| ] | ||
| }; | ||
|
|
||
| var manifest = MacOsInstallerManifest.From(product, "1.0.0"); | ||
| var plist = new MacOsInstallerPlistGenerator(manifest).LaunchDaemonPlist(); | ||
|
|
||
| Assert.That(plist, Does.Contain("<key>EXAMPLE_FLAG</key>")); | ||
| Assert.That(plist, Does.Contain("<string>true</string>")); | ||
| } | ||
|
|
||
| [Test] | ||
| public void LaunchDaemonPlist_omitsExtraEnvironmentVariablesWhenNoneDeclared() | ||
| { | ||
| var product = new ProductManifest("Acme Studio", "acme-studio", "ACMESTUDIO") | ||
| { | ||
| Components = [ProductComponent.Server] | ||
| }; | ||
|
|
||
| var manifest = MacOsInstallerManifest.From(product, "1.0.0"); | ||
| var plist = new MacOsInstallerPlistGenerator(manifest).LaunchDaemonPlist(); | ||
|
|
||
| Assert.That(plist, Does.Contain("ASPNETCORE_URLS")); | ||
| Assert.That(plist, Does.Not.Contain("EXAMPLE_FLAG")); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
...re.Tests/Features/WindowsInstallation/Service/WindowsInstallerCommandsEnvironmentTests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| using LocalInstaller.Core.Features.WindowsInstallation.Models; | ||
| using LocalInstaller.Core.Features.WindowsInstallation.Services; | ||
|
|
||
| namespace LocalInstaller.Core.Tests.Features.WindowsInstallation.Service; | ||
|
|
||
| [TestFixture] | ||
| public class WindowsInstallerCommandsEnvironmentTests | ||
| { | ||
| [Test] | ||
| public void ServiceEnvironmentPowerShell_returnsNullWhenManifestDeclaresNoEnvironmentVariables() | ||
| { | ||
| var manifest = Manifest(null); | ||
|
|
||
| Assert.That(WindowsInstallerCommands.ServiceEnvironmentPowerShell(manifest), Is.Null); | ||
| } | ||
|
|
||
| [Test] | ||
| public void ServiceEnvironmentPowerShell_writesRegistryEnvironmentValueWhenDeclared() | ||
| { | ||
| var manifest = Manifest(new Dictionary<string, string> { ["EXAMPLE_FLAG"] = "true" }); | ||
|
|
||
| var script = WindowsInstallerCommands.ServiceEnvironmentPowerShell(manifest); | ||
|
|
||
| Assert.That(script, Is.Not.Null); | ||
| Assert.That(script, Does.Contain($"HKLM:\\SYSTEM\\CurrentControlSet\\Services\\{manifest.ServiceName}")); | ||
| Assert.That(script, Does.Contain("-Name Environment")); | ||
| Assert.That(script, Does.Contain("-PropertyType MultiString")); | ||
| Assert.That(script, Does.Contain("EXAMPLE_FLAG=true")); | ||
| } | ||
|
|
||
| private static WindowsInstallerManifest Manifest(IReadOnlyDictionary<string, string>? environmentVariables) | ||
| => new( | ||
| ProductName: "Acme Studio", | ||
| Manufacturer: "Acme Labs", | ||
| Version: "1.0.0", | ||
| UpgradeCode: "16357A7B-6C17-4635-85D5-28E74D12F4F3", | ||
| ServiceName: "acme-studio-server", | ||
| CliShimName: "acme-studio.cmd", | ||
| BundleName: "Acme Studio", | ||
| ServerUrl: "http://127.0.0.1:5000", | ||
| EnvironmentVariables: environmentVariables); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.