33
44namespace Hj . ReverseProxy . UnitTest . Certificate ;
55
6+ [ Collection ( "EnvironmentVariable" ) ]
67public 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