-
Notifications
You must be signed in to change notification settings - Fork 0
Develop #36
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
Develop #36
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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<InvalidOperationException>(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); | ||
| } | ||
| } | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.