Skip to content

Commit 096134e

Browse files
Merge pull request #36 from henrikhimself/develop
Develop
2 parents 2d306b5 + 5398748 commit 096134e

7 files changed

Lines changed: 50 additions & 34 deletions

File tree

Directory.Packages.props

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,25 @@
33
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
44
</PropertyGroup>
55
<ItemGroup>
6+
<PackageVersion Include="Aspire.Hosting" Version="13.1.0" />
7+
<PackageVersion Include="coverlet.collector" Version="6.0.4" />
8+
<PackageVersion Include="HenrikJensen.SutFactory" Version="1.0.0-beta2" />
9+
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp" Version="5.0.0" />
610
<PackageVersion Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="10.0.0" />
7-
<PackageVersion Include="Yarp.ReverseProxy" Version="2.3.0" />
8-
<PackageVersion Include="System.Security.Cryptography.Pkcs" Version="8.0.1" />
911
<PackageVersion Include="Microsoft.Extensions.Http.Resilience" Version="9.9.0" />
1012
<PackageVersion Include="Microsoft.Extensions.ServiceDiscovery" Version="10.1.0" />
13+
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="18.0.1" />
14+
<PackageVersion Include="NSubstitute" Version="5.3.0" />
1115
<PackageVersion Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" Version="1.13.0" />
1216
<PackageVersion Include="OpenTelemetry.Extensions.Hosting" Version="1.13.0" />
1317
<PackageVersion Include="OpenTelemetry.Instrumentation.AspNetCore" Version="1.12.0" />
1418
<PackageVersion Include="OpenTelemetry.Instrumentation.Http" Version="1.12.0" />
1519
<PackageVersion Include="OpenTelemetry.Instrumentation.Runtime" Version="1.12.0" />
16-
<PackageVersion Include="HenrikJensen.SutFactory" Version="1.0.0-beta2" />
17-
<PackageVersion Include="NSubstitute" Version="5.3.0" />
18-
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp" Version="5.0.0" />
1920
<PackageVersion Include="StyleCop.Analyzers" Version="1.1.118" />
20-
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="18.0.1" />
21-
<PackageVersion Include="xunit" Version="2.9.3" />
21+
<PackageVersion Include="System.Security.Cryptography.Pkcs" Version="8.0.1" />
2222
<PackageVersion Include="xunit.analyzers" Version="1.25.0" />
2323
<PackageVersion Include="xunit.runner.visualstudio" Version="3.1.5" />
24-
<PackageVersion Include="coverlet.collector" Version="6.0.4" />
24+
<PackageVersion Include="xunit" Version="2.9.3" />
25+
<PackageVersion Include="Yarp.ReverseProxy" Version="2.3.0" />
2526
</ItemGroup>
2627
</Project>

examples/Aspire.Website/Views/Home/Index.cshtml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<body>
99
<h1>Website</h1>
1010
<p><b>You should see this page when navigating to "https://example-website.local/".</b></p>
11-
<p>This website do not use SSL. Instead, a secure HTTPS connection is provided by the reverse proxy.</p>
12-
<p>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.</p>
11+
<p>This website does not use SSL. Instead, a secure HTTPS connection is provided by the reverse proxy.</p>
12+
<p>In case "example-website.local" cannot be found then you need to map it in your local hosts file.</p>
1313
</body>
1414
</html>

src/ReverseProxy.Aspire/ResourceBuilderExtensions.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
// limitations under the License.
1515
// </copyright>
1616

17+
using Aspire.Hosting;
18+
using Aspire.Hosting.ApplicationModel;
19+
1720
namespace Hj.ReverseProxy.Aspire;
1821

1922
public static class ResourceBuilderExtensions

src/ReverseProxy.Aspire/ReverseProxy.Aspire.csproj

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Project Sdk="Aspire.AppHost.Sdk/13.1.0">
1+
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
44
<TargetFrameworks>net8.0;net10.0</TargetFrameworks>
@@ -13,7 +13,7 @@
1313
<PackageTags>testing;reverse-proxy;aspire</PackageTags>
1414
<PackageReadmeFile>README.md</PackageReadmeFile>
1515
<PackageLicenseFile>LICENSE</PackageLicenseFile>
16-
<Version>1.0.0-beta5</Version>
16+
<Version>1.0.0-beta6</Version>
1717
</PropertyGroup>
1818

1919
<ItemGroup>
@@ -31,6 +31,7 @@
3131
</ItemGroup>
3232

3333
<ItemGroup>
34+
<PackageReference Include="Aspire.Hosting" />
3435
<PackageReference Include="Yarp.ReverseProxy" />
3536
</ItemGroup>
3637

src/ReverseProxy/Certificate/CertificateConfig.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,14 @@ public SelfSignedOptions GetOptions()
3131
throw new InvalidOperationException("CA file path is not configured");
3232
}
3333

34-
// Expand {REVERSEPROXY_HOME} token if present: use env var if set, otherwise use user home directory
35-
// If token is not present, use the path as-is (physical file path)
3634
if (selfSignedOptions.CaFilePath.Contains("{REVERSEPROXY_HOME}", StringComparison.Ordinal))
3735
{
38-
var reverseProxyHome = Environment.GetEnvironmentVariable("REVERSEPROXY_HOME")
39-
?? Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
36+
var reverseProxyHome = Environment.GetEnvironmentVariable("REVERSEPROXY_HOME");
37+
if (string.IsNullOrWhiteSpace(reverseProxyHome))
38+
{
39+
throw new InvalidOperationException("Environment variable REVERSEPROXY_HOME is not set");
40+
}
41+
4042
selfSignedOptions.CaFilePath = selfSignedOptions.CaFilePath.Replace("{REVERSEPROXY_HOME}", reverseProxyHome, StringComparison.Ordinal);
4143
}
4244

src/ReverseProxy/ReverseProxy.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<PackageTags>testing;reverse-proxy;certificates</PackageTags>
1414
<PackageReadmeFile>README.md</PackageReadmeFile>
1515
<PackageLicenseFile>LICENSE</PackageLicenseFile>
16-
<Version>1.0.0-beta5</Version>
16+
<Version>1.0.0-beta6</Version>
1717
</PropertyGroup>
1818

1919
<ItemGroup>

test/ReverseProxy.UnitTest/Certificate/CertificateConfigTests.cs

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
namespace Hj.ReverseProxy.UnitTest.Certificate;
55

6+
[Collection("EnvironmentVariable")]
67
public class CertificateConfigTests
78
{
89
[Fact]
@@ -78,34 +79,42 @@ public void GetOptions_GivenPhysicalFilePath_UsesPathAsIs()
7879
Assert.Equal(expectedPath, result.CaFilePath);
7980
}
8081

81-
[Fact]
82-
public void GetOptions_GivenReverseProxyHomeToken_ExpandsToUserHomeWhenEnvVarNotSet()
82+
[Theory]
83+
[InlineData(null)]
84+
[InlineData("")]
85+
public void GetOptions_GivenInvalidReverseProxyHome_Throws(string? homeValue)
8386
{
8487
// arrange
85-
Environment.SetEnvironmentVariable("REVERSEPROXY_HOME", null);
86-
var expectedPath = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
87-
var configuration = CreateConfiguration(new()
88+
var originalHome = Environment.GetEnvironmentVariable("REVERSEPROXY_HOME");
89+
try
8890
{
89-
{ "SelfSignedCertificate:CaFilePath", "{REVERSEPROXY_HOME}" },
90-
});
91+
Environment.SetEnvironmentVariable("REVERSEPROXY_HOME", homeValue);
9192

92-
var sut = new CertificateConfig(configuration);
93+
var configuration = CreateConfiguration(new()
94+
{
95+
{ "SelfSignedCertificate:CaFilePath", "{REVERSEPROXY_HOME}" },
96+
});
9397

94-
// act
95-
var result = sut.GetOptions();
98+
var sut = new CertificateConfig(configuration);
9699

97-
// assert
98-
Assert.Equal(expectedPath, result.CaFilePath);
100+
// act & assert
101+
Assert.ThrowsAny<InvalidOperationException>(sut.GetOptions);
102+
}
103+
finally
104+
{
105+
Environment.SetEnvironmentVariable("REVERSEPROXY_HOME", originalHome);
106+
}
99107
}
100108

101109
[Fact]
102-
public void GetOptions_GivenReverseProxyHomeToken_ExpandsToEnvVarWhenSet()
110+
public void GetOptions_GivenReverseProxyHome_UsesPathFromEnv()
103111
{
104112
// arrange
105-
const string CustomPath = "/custom/reverseproxy/path";
113+
var originalHome = Environment.GetEnvironmentVariable("REVERSEPROXY_HOME");
106114
try
107115
{
108-
Environment.SetEnvironmentVariable("REVERSEPROXY_HOME", CustomPath);
116+
Environment.SetEnvironmentVariable("REVERSEPROXY_HOME", "/custom");
117+
109118
var configuration = CreateConfiguration(new()
110119
{
111120
{ "SelfSignedCertificate:CaFilePath", "{REVERSEPROXY_HOME}" },
@@ -117,11 +126,11 @@ public void GetOptions_GivenReverseProxyHomeToken_ExpandsToEnvVarWhenSet()
117126
var result = sut.GetOptions();
118127

119128
// assert
120-
Assert.Equal(CustomPath, result.CaFilePath);
129+
Assert.Equal("/custom", result.CaFilePath);
121130
}
122131
finally
123132
{
124-
Environment.SetEnvironmentVariable("REVERSEPROXY_HOME", null);
133+
Environment.SetEnvironmentVariable("REVERSEPROXY_HOME", originalHome);
125134
}
126135
}
127136

0 commit comments

Comments
 (0)