From b0cf0b1bd8b071e8a330e662e45bc261f8534046 Mon Sep 17 00:00:00 2001 From: Henrik Jensen Date: Mon, 19 Jan 2026 07:39:33 +0100 Subject: [PATCH 1/3] Fix Aspire extension package references --- Directory.Packages.props | 17 +++++++++-------- examples/Aspire.Website/Views/Home/Index.cshtml | 2 +- .../ResourceBuilderExtensions.cs | 3 +++ .../ReverseProxy.Aspire.csproj | 5 +++-- src/ReverseProxy/ReverseProxy.csproj | 2 +- 5 files changed, 17 insertions(+), 12 deletions(-) diff --git a/Directory.Packages.props b/Directory.Packages.props index eb10b6b..9e391bf 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -3,24 +3,25 @@ true + + + + - - + + - - - - - + - + + diff --git a/examples/Aspire.Website/Views/Home/Index.cshtml b/examples/Aspire.Website/Views/Home/Index.cshtml index f31a46c..492cbf1 100644 --- a/examples/Aspire.Website/Views/Home/Index.cshtml +++ b/examples/Aspire.Website/Views/Home/Index.cshtml @@ -9,6 +9,6 @@

Website

You should see this page when navigating to "https://example-website.local/".

This website do not use SSL. Instead, a secure HTTPS connection is provided by the reverse proxy.

-

In case "example-website.local" cannot be found then you need to map it to 127.0.0.1 and ::1 in your local hosts file.

+

In case "example-website.local" cannot be found then you need to map it in your local hosts file.

diff --git a/src/ReverseProxy.Aspire/ResourceBuilderExtensions.cs b/src/ReverseProxy.Aspire/ResourceBuilderExtensions.cs index 006ad0d..bcad6f2 100644 --- a/src/ReverseProxy.Aspire/ResourceBuilderExtensions.cs +++ b/src/ReverseProxy.Aspire/ResourceBuilderExtensions.cs @@ -14,6 +14,9 @@ // limitations under the License. // +using Aspire.Hosting; +using Aspire.Hosting.ApplicationModel; + namespace Hj.ReverseProxy.Aspire; public static class ResourceBuilderExtensions diff --git a/src/ReverseProxy.Aspire/ReverseProxy.Aspire.csproj b/src/ReverseProxy.Aspire/ReverseProxy.Aspire.csproj index e08a0f5..4ef0813 100644 --- a/src/ReverseProxy.Aspire/ReverseProxy.Aspire.csproj +++ b/src/ReverseProxy.Aspire/ReverseProxy.Aspire.csproj @@ -1,4 +1,4 @@ - + net8.0;net10.0 @@ -13,7 +13,7 @@ testing;reverse-proxy;aspire README.md LICENSE - 1.0.0-beta5 + 1.0.0-beta6 @@ -31,6 +31,7 @@ + diff --git a/src/ReverseProxy/ReverseProxy.csproj b/src/ReverseProxy/ReverseProxy.csproj index 47ad7a0..86c6c45 100644 --- a/src/ReverseProxy/ReverseProxy.csproj +++ b/src/ReverseProxy/ReverseProxy.csproj @@ -13,7 +13,7 @@ testing;reverse-proxy;certificates README.md LICENSE - 1.0.0-beta5 + 1.0.0-beta6 From 1e250b6db11b311f9b12df8d9520123025c2edee Mon Sep 17 00:00:00 2001 From: Henrik Jensen Date: Mon, 19 Jan 2026 08:24:04 +0100 Subject: [PATCH 2/3] Improve REVERSEPROXY_HOME env var --- .../Certificate/CertificateConfig.cs | 10 +++-- .../Certificate/CertificateConfigTests.cs | 43 +++++++++++-------- 2 files changed, 32 insertions(+), 21 deletions(-) diff --git a/src/ReverseProxy/Certificate/CertificateConfig.cs b/src/ReverseProxy/Certificate/CertificateConfig.cs index b2e06f1..3641563 100644 --- a/src/ReverseProxy/Certificate/CertificateConfig.cs +++ b/src/ReverseProxy/Certificate/CertificateConfig.cs @@ -31,12 +31,14 @@ public SelfSignedOptions GetOptions() throw new InvalidOperationException("CA file path is not configured"); } - // Expand {REVERSEPROXY_HOME} token if present: use env var if set, otherwise use user home directory - // If token is not present, use the path as-is (physical file path) if (selfSignedOptions.CaFilePath.Contains("{REVERSEPROXY_HOME}", StringComparison.Ordinal)) { - var reverseProxyHome = Environment.GetEnvironmentVariable("REVERSEPROXY_HOME") - ?? Environment.GetFolderPath(Environment.SpecialFolder.UserProfile); + var reverseProxyHome = Environment.GetEnvironmentVariable("REVERSEPROXY_HOME"); + if (string.IsNullOrWhiteSpace(reverseProxyHome)) + { + throw new InvalidOperationException("Environment variable REVERSEPROXY_HOME is not set"); + } + selfSignedOptions.CaFilePath = selfSignedOptions.CaFilePath.Replace("{REVERSEPROXY_HOME}", reverseProxyHome, StringComparison.Ordinal); } diff --git a/test/ReverseProxy.UnitTest/Certificate/CertificateConfigTests.cs b/test/ReverseProxy.UnitTest/Certificate/CertificateConfigTests.cs index 901161a..c7232ac 100644 --- a/test/ReverseProxy.UnitTest/Certificate/CertificateConfigTests.cs +++ b/test/ReverseProxy.UnitTest/Certificate/CertificateConfigTests.cs @@ -3,6 +3,7 @@ namespace Hj.ReverseProxy.UnitTest.Certificate; +[Collection("EnvironmentVariable")] public class CertificateConfigTests { [Fact] @@ -78,34 +79,42 @@ public void GetOptions_GivenPhysicalFilePath_UsesPathAsIs() Assert.Equal(expectedPath, result.CaFilePath); } - [Fact] - public void GetOptions_GivenReverseProxyHomeToken_ExpandsToUserHomeWhenEnvVarNotSet() + [Theory] + [InlineData(null)] + [InlineData("")] + public void GetOptions_GivenInvalidReverseProxyHome_Throws(string? homeValue) { // arrange - Environment.SetEnvironmentVariable("REVERSEPROXY_HOME", null); - var expectedPath = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile); - var configuration = CreateConfiguration(new() + var originalHome = Environment.GetEnvironmentVariable("REVERSEPROXY_HOME"); + try { - { "SelfSignedCertificate:CaFilePath", "{REVERSEPROXY_HOME}" }, - }); + Environment.SetEnvironmentVariable("REVERSEPROXY_HOME", homeValue); - var sut = new CertificateConfig(configuration); + var configuration = CreateConfiguration(new() + { + { "SelfSignedCertificate:CaFilePath", "{REVERSEPROXY_HOME}" }, + }); - // act - var result = sut.GetOptions(); + var sut = new CertificateConfig(configuration); - // assert - Assert.Equal(expectedPath, result.CaFilePath); + // act & assert + Assert.ThrowsAny(sut.GetOptions); + } + finally + { + Environment.SetEnvironmentVariable("REVERSEPROXY_HOME", originalHome); + } } [Fact] - public void GetOptions_GivenReverseProxyHomeToken_ExpandsToEnvVarWhenSet() + public void GetOptions_GivenReverseProxyHome_UsesPathFromEnv() { // arrange - const string CustomPath = "/custom/reverseproxy/path"; + var originalHome = Environment.GetEnvironmentVariable("REVERSEPROXY_HOME"); try { - Environment.SetEnvironmentVariable("REVERSEPROXY_HOME", CustomPath); + Environment.SetEnvironmentVariable("REVERSEPROXY_HOME", "/custom"); + var configuration = CreateConfiguration(new() { { "SelfSignedCertificate:CaFilePath", "{REVERSEPROXY_HOME}" }, @@ -117,11 +126,11 @@ public void GetOptions_GivenReverseProxyHomeToken_ExpandsToEnvVarWhenSet() var result = sut.GetOptions(); // assert - Assert.Equal(CustomPath, result.CaFilePath); + Assert.Equal("/custom", result.CaFilePath); } finally { - Environment.SetEnvironmentVariable("REVERSEPROXY_HOME", null); + Environment.SetEnvironmentVariable("REVERSEPROXY_HOME", originalHome); } } From 53987487f916746d615eaf955fba7cdf69662c35 Mon Sep 17 00:00:00 2001 From: Henrik Jensen <1175002+henrikhimself@users.noreply.github.com> Date: Mon, 19 Jan 2026 08:33:15 +0100 Subject: [PATCH 3/3] Update examples/Aspire.Website/Views/Home/Index.cshtml Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- examples/Aspire.Website/Views/Home/Index.cshtml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/Aspire.Website/Views/Home/Index.cshtml b/examples/Aspire.Website/Views/Home/Index.cshtml index 492cbf1..8ff6797 100644 --- a/examples/Aspire.Website/Views/Home/Index.cshtml +++ b/examples/Aspire.Website/Views/Home/Index.cshtml @@ -8,7 +8,7 @@

Website

You should see this page when navigating to "https://example-website.local/".

-

This website do not use SSL. Instead, a secure HTTPS connection is provided by the reverse proxy.

+

This website does not use SSL. Instead, a secure HTTPS connection is provided by the reverse proxy.

In case "example-website.local" cannot be found then you need to map it in your local hosts file.